feat: recipe sync

This commit is contained in:
2021-08-10 12:21:42 +02:00
parent c6ea18311e
commit 83671f42a2
4 changed files with 220 additions and 8 deletions

View File

@ -296,3 +296,49 @@ func UpdateAppComposeTag(recipe, image, tag string) error {
return nil
}
func UpdateAppComposeLabel(recipe, serviceName, newLabel string) error {
pattern := fmt.Sprintf("%s/%s/compose**yml", APPS_DIR, recipe)
composeFiles, err := filepath.Glob(pattern)
if err != nil {
return err
}
for _, composeFile := range composeFiles {
opts := options.Deploy{Composefiles: []string{composeFile}}
compose, err := loader.LoadComposefile(opts)
if err != nil {
return err
}
serviceExists := false
var service composetypes.ServiceConfig
for _, s := range compose.Services {
if s.Name == serviceName {
service = s
serviceExists = true
}
}
if !serviceExists {
continue
}
for oldLabel, value := range service.Deploy.Labels {
if strings.HasPrefix(oldLabel, "coop-cloud") {
bytes, err := ioutil.ReadFile(composeFile)
if err != nil {
return err
}
old := fmt.Sprintf("coop-cloud.${STACK_NAME}.%s.version=%s", service.Name, value)
replacedBytes := strings.Replace(string(bytes), old, newLabel, -1)
if err := ioutil.WriteFile(compose.Filename, []byte(replacedBytes), 0644); err != nil {
return err
}
}
}
}
return nil
}