fix: more reliable syncing
This commit is contained in:
parent
fccbd7c7d7
commit
fc3742212c
|
@ -177,28 +177,11 @@ will know that things are likely to change.
|
||||||
}
|
}
|
||||||
|
|
||||||
mainService := "app"
|
mainService := "app"
|
||||||
var services []string
|
|
||||||
hasAppService := false
|
|
||||||
for _, service := range recipe.Config.Services {
|
|
||||||
services = append(services, service.Name)
|
|
||||||
if service.Name == "app" {
|
|
||||||
hasAppService = true
|
|
||||||
logrus.Debugf("detected app service in %s", recipe.Name)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if !hasAppService {
|
|
||||||
logrus.Fatalf("%s has no main app service?", recipe.Name)
|
|
||||||
}
|
|
||||||
|
|
||||||
logrus.Debugf("selecting %s as the service to sync version label", mainService)
|
|
||||||
|
|
||||||
label := fmt.Sprintf("coop-cloud.${STACK_NAME}.version=%s", nextTag)
|
label := fmt.Sprintf("coop-cloud.${STACK_NAME}.version=%s", nextTag)
|
||||||
if !internal.Dry {
|
if !internal.Dry {
|
||||||
if err := recipe.UpdateLabel(mainService, label); err != nil {
|
if err := recipe.UpdateLabel("compose.y*ml", mainService, label); err != nil {
|
||||||
logrus.Fatal(err)
|
logrus.Fatal(err)
|
||||||
}
|
}
|
||||||
logrus.Infof("synced label %s to service %s", label, mainService)
|
|
||||||
} else {
|
} else {
|
||||||
logrus.Infof("dry run: not syncing label %s for recipe %s", nextTag, recipe.Name)
|
logrus.Infof("dry run: not syncing label %s for recipe %s", nextTag, recipe.Name)
|
||||||
}
|
}
|
||||||
|
|
|
@ -130,11 +130,18 @@ func UpdateLabel(pattern, serviceName, label, recipeName string) error {
|
||||||
old := fmt.Sprintf("coop-cloud.${STACK_NAME}.version=%s", value)
|
old := fmt.Sprintf("coop-cloud.${STACK_NAME}.version=%s", value)
|
||||||
replacedBytes := strings.Replace(string(bytes), old, label, -1)
|
replacedBytes := strings.Replace(string(bytes), old, label, -1)
|
||||||
|
|
||||||
|
if old == label {
|
||||||
|
logrus.Warnf("%s is already set, nothing to do?", label)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
logrus.Debugf("updating %s to %s in %s", old, label, compose.Filename)
|
logrus.Debugf("updating %s to %s in %s", old, label, compose.Filename)
|
||||||
|
|
||||||
if err := ioutil.WriteFile(compose.Filename, []byte(replacedBytes), 0644); err != nil {
|
if err := ioutil.WriteFile(compose.Filename, []byte(replacedBytes), 0644); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logrus.Infof("synced label %s to service %s", label, serviceName)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,9 +25,9 @@ type Recipe struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateLabel updates a recipe label
|
// UpdateLabel updates a recipe label
|
||||||
func (r Recipe) UpdateLabel(serviceName, label string) error {
|
func (r Recipe) UpdateLabel(pattern, serviceName, label string) error {
|
||||||
pattern := fmt.Sprintf("%s/%s/compose**yml", config.APPS_DIR, r.Name)
|
fullPattern := fmt.Sprintf("%s/%s/%s", config.APPS_DIR, r.Name, pattern)
|
||||||
if err := compose.UpdateLabel(pattern, serviceName, label, r.Name); err != nil {
|
if err := compose.UpdateLabel(fullPattern, serviceName, label, r.Name); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|
Loading…
Reference in New Issue