Compare commits

..

14 Commits

Author SHA1 Message Date
Moritz 72c807e31a refactor: replace some functions with general getLabel function 2023-02-01 12:27:35 +01:00
Moritz 8e16d2f350 evaluate if autoupdates are enabled 2023-02-01 12:23:32 +01:00
Moritz b62b46a1c6 Refactor upgrade function: extract logical parts 2023-02-01 12:23:32 +01:00
Moritz fe62b677e0 change .gitignore and add kadabras main.go 2023-02-01 12:23:32 +01:00
Moritz d02a049dde more verbose update info 2023-02-01 12:23:32 +01:00
Moritz df42585490 pull recipe and lint it 2023-02-01 12:23:32 +01:00
Moritz ddead5dac6 updater: read chaos deployment from docker label 2023-02-01 12:23:27 +01:00
Moritz 1931a9b74d PoC auto updater 2023-02-01 12:22:11 +01:00
Moritz 76717531bd resolve PR: include the service info in the log message 2023-01-31 16:15:11 +01:00
Moritz 6774893412 add env ENABLE_AUTO_UPDATE as label to enable/disable the auto update process 2023-01-31 16:12:02 +01:00
moritz ebb86391af add a label to signal that a deploy is a chaos deploy (!265)
Resolves coop-cloud/organising#390 by adding the following label `coop-cloud.${STACK_NAME}.chaos=true` (according to the version label).
This is required for the auto updater coop-cloud/organising#236 (comment)

Co-authored-by: Moritz <moritz.m@local-it.org>
Reviewed-on: coop-cloud/abra#265
2023-01-31 15:06:35 +00:00
moritz 50db39424c add a label to signal that a deploy is connected with a recipe (!264)
Resolves coop-cloud/organising#391 by adding the following label `coop-cloud.${STACK_NAME}.recipe=${RECIPE}` (according to the version label).
This is required for the auto updater coop-cloud/organising#236 (comment)

Co-authored-by: Moritz <moritz.m@local-it.org>
Reviewed-on: coop-cloud/abra#264
2023-01-31 14:35:43 +00:00
moritz ca1ea32c46 Expose all env vars to `app` container. (!263)
Resolves coop-cloud/organising#393 and is required for the auto updater coop-cloud/organising#236 (comment)

Co-authored-by: Moritz <moritz.m@local-it.org>
Reviewed-on: coop-cloud/abra#263
2023-01-31 14:13:43 +00:00
Moritz 32851d4d99 fix: always fetch all repository tags 2023-01-31 11:52:15 +01:00
5 changed files with 56 additions and 52 deletions

View File

@ -178,10 +178,10 @@ recipes.
if err != nil {
logrus.Fatal(err)
}
config.SetUpdateLabel(compose, stackName, app.Env)
config.ExposeAllEnv(compose, app.Env)
config.SetChaosLabel(compose, stackName, internal.Chaos)
config.ExposeAllEnv(stackName, compose, app.Env)
config.SetRecipeLabel(compose, stackName, app.Recipe)
config.SetChaosLabel(compose, stackName, internal.Chaos)
config.SetUpdateLabel(compose, stackName, app.Env)
if !internal.Force {
if err := internal.NewVersionOverview(app, deployedVersion, chosenDowngrade, ""); err != nil {

View File

@ -189,10 +189,10 @@ recipes.
if err != nil {
logrus.Fatal(err)
}
config.SetUpdateLabel(compose, stackName, app.Env)
config.ExposeAllEnv(compose, app.Env)
config.SetChaosLabel(compose, stackName, internal.Chaos)
config.ExposeAllEnv(stackName, compose, app.Env)
config.SetRecipeLabel(compose, stackName, app.Recipe)
config.SetChaosLabel(compose, stackName, internal.Chaos)
config.SetUpdateLabel(compose, stackName, app.Env)
if err := internal.NewVersionOverview(app, deployedVersion, chosenUpgrade, releaseNotes); err != nil {
logrus.Fatal(err)

View File

@ -134,10 +134,10 @@ func DeployAction(c *cli.Context) error {
if err != nil {
logrus.Fatal(err)
}
config.SetUpdateLabel(compose, app.StackName(), app.Env)
config.ExposeAllEnv(compose, app.Env)
config.SetChaosLabel(compose, app.StackName(), Chaos)
config.ExposeAllEnv(app.StackName(), compose, app.Env)
config.SetRecipeLabel(compose, app.StackName(), app.Recipe)
config.SetChaosLabel(compose, app.StackName(), Chaos)
config.SetUpdateLabel(compose, app.StackName(), app.Env)
if err := DeployOverview(app, version, "continue with deployment?"); err != nil {
logrus.Fatal(err)

View File

@ -140,7 +140,7 @@ func getEnv(cl *dockerclient.Client, stackName string) config.AppEnv {
}
k := splitString[0]
v := splitString[1]
//logrus.Debugf("Env Key: %s Value: %s", k, v)
logrus.Debugf("Env Key: %s Value: %s", k, v)
envMap[k] = v
}
}
@ -255,7 +255,7 @@ func createDeployConfig(recipeName string, stackName string, env config.AppEnv)
if err != nil {
logrus.Fatal(err)
}
config.ExposeAllEnv(compose, env)
config.ExposeAllEnv(stackName, compose, env)
// after the upgrade the deployment won't be in chaos state anymore
config.SetChaosLabel(compose, stackName, false)
config.SetRecipeLabel(compose, stackName, recipeName)

View File

@ -449,7 +449,50 @@ func GetAppComposeConfig(recipe string, opts stack.Deploy, appEnv AppEnv) (*comp
return compose, nil
}
// add env ENABLE_AUTO_UPDATE as label to enable/disable the auto update process for this app
// ExposeAllEnv exposes all env variables to the app container
func ExposeAllEnv(stackName string, compose *composetypes.Config, appEnv AppEnv) {
for _, service := range compose.Services {
if service.Name == "app" {
logrus.Debugf("Add the following environment to the app service config of %s:", stackName)
for k, v := range appEnv {
_, exists := service.Environment[k]
if !exists {
value := v
service.Environment[k] = &value
logrus.Debugf("Add Key: %s Value: %s to %s", k, value, stackName)
}
}
}
}
}
// 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
}
}
}
// SetChaosLabel adds the label 'coop-cloud.${STACK_NAME}.chaos=true/false' to the app container
// to signal if the app is deployed in chaos mode
func SetChaosLabel(compose *composetypes.Config, stackName string, chaos bool) {
for _, service := range compose.Services {
if service.Name == "app" {
logrus.Debugf("set label 'coop-cloud.%s.chaos' to %s for %s", stackName, chaos, stackName)
labelKey := fmt.Sprintf("coop-cloud.%s.chaos", stackName)
service.Deploy.Labels[labelKey] = strconv.FormatBool(chaos)
}
}
}
// SetUpdateLabel adds env ENABLE_AUTO_UPDATE as label to enable/disable the
// auto update process for this app. The default if this variable is not set is to disable
// the auto update process.
func SetUpdateLabel(compose *composetypes.Config, stackName string, appEnv AppEnv) {
for _, service := range compose.Services {
if service.Name == "app" {
@ -457,48 +500,9 @@ func SetUpdateLabel(compose *composetypes.Config, stackName string, appEnv AppEn
if !exists {
enable_auto_update = "false"
}
logrus.Debugf("set auto update label to %s", enable_auto_update)
logrus.Debugf("set label 'coop-cloud.%s.autoupdate' to %s for %s", stackName, enable_auto_update, stackName)
labelKey := fmt.Sprintf("coop-cloud.%s.autoupdate", stackName)
service.Deploy.Labels[labelKey] = enable_auto_update
}
}
}
// expose all env variables to the app container
func ExposeAllEnv(compose *composetypes.Config, appEnv AppEnv) {
for _, service := range compose.Services {
if service.Name == "app" {
logrus.Debug("Add the following environment to the app service config:")
for k, v := range appEnv {
_, exists := service.Environment[k]
if !exists {
value := v
service.Environment[k] = &value
logrus.Debugf("Add Key: %s Value: %s", k, value)
}
}
}
}
}
// add a label to signal that a deploy is a chaos deploy
func SetChaosLabel(compose *composetypes.Config, stackName string, chaos bool) {
for _, service := range compose.Services {
if service.Name == "app" {
logrus.Debugf("set chaos label to %s", chaos)
labelKey := fmt.Sprintf("coop-cloud.%s.chaos", stackName)
service.Deploy.Labels[labelKey] = strconv.FormatBool(chaos)
}
}
}
// add a label to signal that a deploy is connected with a recipe
func SetRecipeLabel(compose *composetypes.Config, stackName string, recipe string) {
for _, service := range compose.Services {
if service.Name == "app" {
logrus.Debugf("set recipe label to %s", recipe)
labelKey := fmt.Sprintf("coop-cloud.%s.recipe", stackName)
service.Deploy.Labels[labelKey] = recipe
}
}
}