Browse Source

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

master
Simon Marsh 1 year ago
parent
commit
57ba0d2e46
Signed by: burble <[email protected]> GPG Key ID: 7B9FE8780CFB6593
2 changed files with 25 additions and 12 deletions
  1. +2
    -2
      dn42regsrv.go
  2. +23
    -10
      registry.go

+ 2
- 2
dn42regsrv.go 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()


+ 23
- 10
registry.go 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


Loading…
Cancel
Save