Tidy updating of th registry to fix use on non-master branches
This commit is contained in:
parent
cdba1d94f7
commit
57ba0d2e46
@ -122,7 +122,7 @@ func main() {
|
|||||||
refreshInterval = flag.StringP("Refresh", "i", "60m", "Refresh interval")
|
refreshInterval = flag.StringP("Refresh", "i", "60m", "Refresh interval")
|
||||||
gitPath = flag.StringP("GitPath", "g", "/usr/bin/git", "Path to git executable")
|
gitPath = flag.StringP("GitPath", "g", "/usr/bin/git", "Path to git executable")
|
||||||
autoPull = flag.BoolP("AutoPull", "a", true, "Automatically pull the registry")
|
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()
|
flag.Parse()
|
||||||
|
|
||||||
@ -139,7 +139,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
InitialiseRegistryData(*regDir, interval,
|
InitialiseRegistryData(*regDir, interval,
|
||||||
*gitPath, *autoPull, *pullURL)
|
*gitPath, *autoPull, *branch)
|
||||||
|
|
||||||
// initialise router
|
// initialise router
|
||||||
router := mux.NewRouter()
|
router := mux.NewRouter()
|
||||||
|
33
registry.go
33
registry.go
@ -600,30 +600,43 @@ func getCommitHash(regDir string, gitPath string) string {
|
|||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
// refresh the registry
|
// 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
|
// run git fetch to get the current commits from the master
|
||||||
cmd := exec.Command(gitPath, "pull", pullURL)
|
cmd := exec.Command(gitPath, "fetch")
|
||||||
cmd.Dir = regDir
|
cmd.Dir = regDir
|
||||||
// execute
|
// execute
|
||||||
out, err := cmd.Output()
|
if out, err := cmd.Output(); err != nil {
|
||||||
if err != nil {
|
|
||||||
log.WithFields(log.Fields{
|
log.WithFields(log.Fields{
|
||||||
"error": err,
|
"error": err,
|
||||||
"gitPath": gitPath,
|
"gitPath": gitPath,
|
||||||
"regDir": regDir,
|
"regDir": regDir,
|
||||||
"pullURL": pullURL,
|
}).Error("Failed to execute git fetch")
|
||||||
}).Error("Failed to execute git log")
|
} 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
|
// called from main to initialse the registry data and syncing
|
||||||
|
|
||||||
func InitialiseRegistryData(regDir string, refresh time.Duration,
|
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
|
// validate that the regDir/data path exists
|
||||||
dataPath := regDir + "/data"
|
dataPath := regDir + "/data"
|
||||||
@ -675,7 +688,7 @@ func InitialiseRegistryData(regDir string, refresh time.Duration,
|
|||||||
|
|
||||||
// automatically try to refresh the registry ?
|
// automatically try to refresh the registry ?
|
||||||
if autoPull {
|
if autoPull {
|
||||||
refreshRegistry(regDir, gitPath, pullURL)
|
refreshRegistry(regDir, gitPath, branch)
|
||||||
}
|
}
|
||||||
|
|
||||||
// get the latest hash
|
// get the latest hash
|
||||||
|
Loading…
x
Reference in New Issue
Block a user