feat: make sync use wizard mode

Some bugs squashed while testing this extensively.
This commit is contained in:
2021-11-06 23:40:22 +01:00
parent a539033b55
commit 2b9395be1a
6 changed files with 312 additions and 170 deletions

View File

@ -117,8 +117,11 @@ func UpdateLabel(pattern, serviceName, label, recipeName string) error {
continue
}
discovered := false
for oldLabel, value := range service.Deploy.Labels {
if strings.HasPrefix(oldLabel, "coop-cloud") {
discovered = true
bytes, err := ioutil.ReadFile(composeFile)
if err != nil {
return err
@ -127,13 +130,19 @@ func UpdateLabel(pattern, serviceName, label, recipeName string) error {
old := fmt.Sprintf("coop-cloud.${STACK_NAME}.version=%s", value)
replacedBytes := strings.Replace(string(bytes), old, label, -1)
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 {
return err
}
}
}
if !discovered {
logrus.Warn("no existing label found, cannot continue...")
logrus.Fatalf("add '%s' manually, automagic insertion not supported yet", label)
}
}
return nil