forked from coop-cloud/abra
updater: read chaos deployment from docker label
This commit is contained in:
parent
1931a9b74d
commit
ddead5dac6
|
@ -4,6 +4,7 @@ import (
|
|||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"coopcloud.tech/abra/cli/internal"
|
||||
|
@ -31,7 +32,6 @@ var UpgradeApp = cli.Command{
|
|||
Flags: []cli.Flag{
|
||||
internal.DebugFlag,
|
||||
internal.ForceFlag,
|
||||
internal.DontWaitConvergeFlag,
|
||||
},
|
||||
Before: internal.SubCommandBefore,
|
||||
Description: `Upgrade an app`,
|
||||
|
@ -73,10 +73,11 @@ var UpgradeAll = cli.Command{
|
|||
for _, stackInfo := range stacks {
|
||||
stackName := stackInfo.Name
|
||||
recipeName := getRecipe(cl, stackName)
|
||||
// TODO: read chaos from docker label
|
||||
if recipeName != "" {
|
||||
logrus.Debugf("RecipeName: %s", recipeName)
|
||||
chaos := getChaos(cl, stackName)
|
||||
if recipeName != "" && (!chaos || internal.Force) {
|
||||
upgrade(cl, stackName, recipeName)
|
||||
} else {
|
||||
logrus.Debugf("Don't update %s due to missing recipe name or chaos deployment", stackName)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
@ -102,6 +103,29 @@ func getRecipe(cl *dockerclient.Client, stackName string) string {
|
|||
return ""
|
||||
}
|
||||
|
||||
// Read chaos deployment from docker label
|
||||
func getChaos(cl *dockerclient.Client, stackName string) bool {
|
||||
filter := filters.NewArgs()
|
||||
filter.Add("label", fmt.Sprintf("%s=%s", convert.LabelNamespace, stackName))
|
||||
|
||||
services, err := cl.ServiceList(context.Background(), types.ServiceListOptions{Filters: filter})
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
for _, service := range services {
|
||||
labelKey := fmt.Sprintf("coop-cloud.%s.chaos", stackName)
|
||||
if chaosLabel, ok := service.Spec.Labels[labelKey]; ok {
|
||||
chaos, err := strconv.ParseBool(chaosLabel)
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
return chaos
|
||||
}
|
||||
}
|
||||
logrus.Debugf("no chaos label found for %s", stackName)
|
||||
return false
|
||||
}
|
||||
|
||||
// Read Env variables from docker services
|
||||
func getEnv(cl *dockerclient.Client, stackName string) config.AppEnv {
|
||||
envMap := make(map[string]string)
|
||||
|
@ -139,7 +163,6 @@ func upgrade(cl *dockerclient.Client, stackName string, recipeName string) {
|
|||
}
|
||||
// Workaround, is there a better way?
|
||||
app.Env["STACK_NAME"] = stackName
|
||||
// TODO: read COMPOSE_FILE from docker label
|
||||
// TODO: evaluate ENABLE_AUTO_UPDATE env var
|
||||
|
||||
logrus.Debugf("Retrieve deployed version whether %s is already deployed", stackName)
|
||||
|
@ -193,7 +216,8 @@ func upgrade(cl *dockerclient.Client, stackName string, recipeName string) {
|
|||
}
|
||||
|
||||
if len(availableUpgrades) == 0 {
|
||||
logrus.Fatalf("no available upgrades, you're on latest (%s) ✌️", deployedVersion)
|
||||
logrus.Debugf("no available upgrades, you're on latest (%s) ✌️", deployedVersion)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -236,6 +260,10 @@ func upgrade(cl *dockerclient.Client, stackName string, recipeName string) {
|
|||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
config.ExposeAllEnv(compose, app.Env)
|
||||
// after the upgrade the deployment won't be in chaos state any more
|
||||
config.SetChaosLabel(compose, stackName, false)
|
||||
config.SetRecipeLabel(compose, stackName, app.Recipe)
|
||||
|
||||
if err := stack.RunDeploy(cl, deployOpts, compose, stackName, true); err != nil {
|
||||
logrus.Fatal(err)
|
||||
|
@ -245,7 +273,7 @@ func upgrade(cl *dockerclient.Client, stackName string, recipeName string) {
|
|||
func newAbraApp(version, commit string) *cli.App {
|
||||
app := &cli.App{
|
||||
Name: "kadabra",
|
||||
Usage: `The Co-op Cloud update daemon
|
||||
Usage: `The Co-op Cloud autoupdater
|
||||
____ ____ _ _
|
||||
/ ___|___ ___ _ __ / ___| | ___ _ _ __| |
|
||||
| | / _ \ _____ / _ \| '_ \ | | | |/ _ \| | | |/ _' |
|
||||
|
|
Loading…
Reference in New Issue