From 50db39424c7f86fe93b9b19aa0d3a55019a15e84 Mon Sep 17 00:00:00 2001 From: moritz Date: Tue, 31 Jan 2023 14:35:43 +0000 Subject: [PATCH] add a label to signal that a deploy is connected with a recipe (!264) Resolves https://git.coopcloud.tech/coop-cloud/organising/issues/391 by adding the following label `coop-cloud.${STACK_NAME}.recipe=${RECIPE}` (according to the version label). This is required for the auto updater https://git.coopcloud.tech/coop-cloud/organising/issues/236#issuecomment-15390 Co-authored-by: Moritz Reviewed-on: https://git.coopcloud.tech/coop-cloud/abra/pulls/264 --- cli/app/rollback.go | 1 + cli/app/upgrade.go | 1 + cli/internal/deploy.go | 1 + pkg/config/app.go | 12 ++++++++++++ 4 files changed, 15 insertions(+) diff --git a/cli/app/rollback.go b/cli/app/rollback.go index 98acf56f..cadd4d47 100644 --- a/cli/app/rollback.go +++ b/cli/app/rollback.go @@ -179,6 +179,7 @@ recipes. logrus.Fatal(err) } config.ExposeAllEnv(stackName, compose, app.Env) + config.SetRecipeLabel(compose, stackName, app.Recipe) if !internal.Force { if err := internal.NewVersionOverview(app, deployedVersion, chosenDowngrade, ""); err != nil { diff --git a/cli/app/upgrade.go b/cli/app/upgrade.go index fa46b8d3..5037a490 100644 --- a/cli/app/upgrade.go +++ b/cli/app/upgrade.go @@ -190,6 +190,7 @@ recipes. logrus.Fatal(err) } config.ExposeAllEnv(stackName, compose, app.Env) + config.SetRecipeLabel(compose, stackName, app.Recipe) if err := internal.NewVersionOverview(app, deployedVersion, chosenUpgrade, releaseNotes); err != nil { logrus.Fatal(err) diff --git a/cli/internal/deploy.go b/cli/internal/deploy.go index 6b3047fb..68a007e5 100644 --- a/cli/internal/deploy.go +++ b/cli/internal/deploy.go @@ -135,6 +135,7 @@ func DeployAction(c *cli.Context) error { logrus.Fatal(err) } config.ExposeAllEnv(app.StackName(), compose, app.Env) + config.SetRecipeLabel(compose, app.StackName(), app.Recipe) if err := DeployOverview(app, version, "continue with deployment?"); err != nil { logrus.Fatal(err) diff --git a/pkg/config/app.go b/pkg/config/app.go index 15253634..bb06e10d 100644 --- a/pkg/config/app.go +++ b/pkg/config/app.go @@ -464,3 +464,15 @@ func ExposeAllEnv(stackName string, compose *composetypes.Config, appEnv AppEnv) } } } + +// SetRecipeLabel adds the label 'coop-cloud.${STACK_NAME}.recipe=${RECIPE}' to the app container +// to signal which recipe is connected to the deployed app +func SetRecipeLabel(compose *composetypes.Config, stackName string, recipe string) { + for _, service := range compose.Services { + if service.Name == "app" { + logrus.Debugf("set recipe label 'coop-cloud.%s.recipe' to %s for %s", stackName, recipe, stackName) + labelKey := fmt.Sprintf("coop-cloud.%s.recipe", stackName) + service.Deploy.Labels[labelKey] = recipe + } + } +}