1
mirror of https://git.burble.com/burble.dn42/dn42regsrv.git synced 2024-02-26 20:28:04 +01:00

Tidy updating of th registry to fix use on non-master branches

This commit is contained in:
Simon Marsh 2019-06-01 19:46:23 +01:00
parent cdba1d94f7
commit 57ba0d2e46
No known key found for this signature in database
GPG Key ID: 7B9FE8780CFB6593
2 changed files with 25 additions and 12 deletions

View File

@ -122,7 +122,7 @@ func main() {
refreshInterval = flag.StringP("Refresh", "i", "60m", "Refresh interval")
gitPath = flag.StringP("GitPath", "g", "/usr/bin/git", "Path to git executable")
autoPull = flag.BoolP("AutoPull", "a", true, "Automatically pull the registry")
pullURL = flag.StringP("PullURL", "p", "origin", "URL to auto pull")
branch = flag.StringP("Branch", "p", "master", "git branch to pull")
)
flag.Parse()
@ -139,7 +139,7 @@ func main() {
}
InitialiseRegistryData(*regDir, interval,
*gitPath, *autoPull, *pullURL)
*gitPath, *autoPull, *branch)
// initialise router
router := mux.NewRouter()

View File

@ -600,30 +600,43 @@ func getCommitHash(regDir string, gitPath string) string {
//////////////////////////////////////////////////////////////////////////
// refresh the registry
func refreshRegistry(regDir string, gitPath string, pullURL string) {
func refreshRegistry(regDir string, gitPath string, branch string) {
// run git to get the latest commit hash
cmd := exec.Command(gitPath, "pull", pullURL)
// run git fetch to get the current commits from the master
cmd := exec.Command(gitPath, "fetch")
cmd.Dir = regDir
// execute
out, err := cmd.Output()
if err != nil {
if out, err := cmd.Output(); err != nil {
log.WithFields(log.Fields{
"error": err,
"gitPath": gitPath,
"regDir": regDir,
"pullURL": pullURL,
}).Error("Failed to execute git log")
}).Error("Failed to execute git fetch")
} else {
fmt.Printf("Git Fetch: %s", string(out))
}
fmt.Println(string(out))
// then reset hard to match the master
cmd = exec.Command(gitPath, "reset", "--hard", "origin/"+branch)
cmd.Dir = regDir
// execute
if out, err := cmd.Output(); err != nil {
log.WithFields(log.Fields{
"error": err,
"gitPath": gitPath,
"regDir": regDir,
"branch": branch,
}).Error("Failed to execute git reset")
} else {
fmt.Printf("Git Reset: %s", string(out))
}
}
//////////////////////////////////////////////////////////////////////////
// called from main to initialse the registry data and syncing
func InitialiseRegistryData(regDir string, refresh time.Duration,
gitPath string, autoPull bool, pullURL string) {
gitPath string, autoPull bool, branch string) {
// validate that the regDir/data path exists
dataPath := regDir + "/data"
@ -675,7 +688,7 @@ func InitialiseRegistryData(regDir string, refresh time.Duration,
// automatically try to refresh the registry ?
if autoPull {
refreshRegistry(regDir, gitPath, pullURL)
refreshRegistry(regDir, gitPath, branch)
}
// get the latest hash