diff --git a/cli/app/deploy.go b/cli/app/deploy.go index c9ba68b9..39c1bd95 100644 --- a/cli/app/deploy.go +++ b/cli/app/deploy.go @@ -122,21 +122,23 @@ checkout as-is. Recipe commit hashes are also supported as values for } } - isChaosCommit, err = app.Recipe.EnsureVersion(toDeployVersion) - if err != nil { - log.Fatal(err) - } - - if isChaosCommit { - log.Debugf("assuming chaos commit: %s", toDeployVersion) - - internal.Chaos = true - toDeployChaosVersion = toDeployVersion - - toDeployVersion, err = app.Recipe.GetVersionLabelLocal() + if !internal.Chaos { + isChaosCommit, err = app.Recipe.EnsureVersion(toDeployVersion) if err != nil { log.Fatal(err) } + + if isChaosCommit { + log.Debugf("assuming chaos commit: %s", toDeployVersion) + + internal.Chaos = true + toDeployChaosVersion = toDeployVersion + + toDeployVersion, err = app.Recipe.GetVersionLabelLocal() + if err != nil { + log.Fatal(err) + } + } } if err := validateSecrets(cl, app); err != nil { @@ -171,7 +173,7 @@ checkout as-is. Recipe commit hashes are also supported as values for toDeployChaosVersionLabel := toDeployChaosVersion if app.Recipe.Dirty { - toDeployChaosVersionLabel = fmt.Sprintf("%s%s", toDeployChaosVersion, config.DIRTY_DEFAULT) + toDeployChaosVersionLabel = formatter.AddDirtyMarker(toDeployChaosVersionLabel) } appPkg.ExposeAllEnv(stackName, compose, app.Env) diff --git a/cli/app/env.go b/cli/app/env.go index 372a09cf..d16a87e8 100644 --- a/cli/app/env.go +++ b/cli/app/env.go @@ -7,7 +7,6 @@ import ( "coopcloud.tech/abra/cli/internal" "coopcloud.tech/abra/pkg/autocomplete" "coopcloud.tech/abra/pkg/formatter" - "coopcloud.tech/abra/pkg/log" "github.com/spf13/cobra" ) @@ -26,10 +25,6 @@ var AppEnvCommand = &cobra.Command{ Run: func(cmd *cobra.Command, args []string) { app := internal.ValidateApp(args) - if err := app.Recipe.Ensure(internal.GetEnsureContext()); err != nil { - log.Fatal(err) - } - var envKeys []string for k := range app.Env { envKeys = append(envKeys, k) diff --git a/cli/app/rollback.go b/cli/app/rollback.go index 78b1d6f4..a049d29b 100644 --- a/cli/app/rollback.go +++ b/cli/app/rollback.go @@ -232,7 +232,7 @@ func chooseDowngrade( Options: internal.SortVersionsDesc(availableDowngrades), } - if err := survey.AskOne(prompt, &chosenDowngrade); err != nil { + if err := survey.AskOne(prompt, chosenDowngrade); err != nil { return err } diff --git a/cli/app/undeploy.go b/cli/app/undeploy.go index 54016294..32d5640c 100644 --- a/cli/app/undeploy.go +++ b/cli/app/undeploy.go @@ -81,7 +81,12 @@ Passing "--prune/-p" does not remove those volumes.`, } } - if err := app.WriteRecipeVersion(deployMeta.Version, false); err != nil { + toWriteVersion := deployMeta.Version + if deployMeta.IsChaos { + toWriteVersion = chaosVersion + } + + if err := app.WriteRecipeVersion(toWriteVersion, false); err != nil { log.Fatalf("writing recipe version failed: %s", err) } }, diff --git a/cli/app/upgrade.go b/cli/app/upgrade.go index f3e3b85f..89257d02 100644 --- a/cli/app/upgrade.go +++ b/cli/app/upgrade.go @@ -274,7 +274,7 @@ func chooseUpgrade( Options: internal.SortVersionsDesc(availableUpgrades), } - if err := survey.AskOne(prompt, &chosenUpgrade); err != nil { + if err := survey.AskOne(prompt, chosenUpgrade); err != nil { return err } diff --git a/cli/internal/deploy.go b/cli/internal/deploy.go index d7d4bc42..eaa97763 100644 --- a/cli/internal/deploy.go +++ b/cli/internal/deploy.go @@ -10,6 +10,7 @@ import ( "coopcloud.tech/abra/pkg/config" "coopcloud.tech/abra/pkg/formatter" "coopcloud.tech/abra/pkg/log" + "coopcloud.tech/abra/pkg/recipe" "coopcloud.tech/tagcmp" "github.com/AlecAivazis/survey/v2" "github.com/charmbracelet/lipgloss" @@ -70,15 +71,15 @@ func NewVersionOverview( {"CONFIG", deployConfig}, {"CURRENT DEPLOYMENT", "---"}, - {"VERSION", deployedVersion}, - {"CHAOS ", deployedChaosVersion}, + {"VERSION", formatter.BoldDirtyDefault(deployedVersion)}, + {"CHAOS ", formatter.BoldDirtyDefault(deployedChaosVersion)}, {upperKind, "---"}, - {"VERSION", toDeployVersion}, + {"VERSION", formatter.BoldDirtyDefault(toDeployVersion)}, {fmt.Sprintf("%s.ENV", strings.ToUpper(app.Domain)), "---"}, - {"CURRENT VERSION", app.Recipe.EnvVersion}, - {"NEW VERSION", toDeployVersion}, + {"CURRENT VERSION", formatter.BoldDirtyDefault(app.Recipe.EnvVersion)}, + {"NEW VERSION", formatter.BoldDirtyDefault(toDeployVersion)}, } overview := formatter.CreateOverview( @@ -143,10 +144,23 @@ func DeployOverview( domain = config.NO_DOMAIN_DEFAULT } - deployedChaosVersion = formatter.BoldDirtyDefault(deployedChaosVersion) - if app.Recipe.Dirty { - toDeployChaosVersion = formatter.BoldDirtyDefault(toDeployChaosVersion) + toWriteVersion = formatter.AddDirtyMarker(toWriteVersion) + toDeployChaosVersion = formatter.AddDirtyMarker(toDeployChaosVersion) + } + + recipeName, exists := app.Env["RECIPE"] + if !exists { + recipeName = app.Env["TYPE"] + } + + envVersion, err := recipe.GetEnvVersionRaw(recipeName) + if err != nil { + return err + } + + if envVersion == "" { + envVersion = config.NO_VERSION_DEFAULT } rows := [][]string{ @@ -156,16 +170,16 @@ func DeployOverview( {"CONFIG", deployConfig}, {"CURRENT DEPLOYMENT", "---"}, - {"VERSION", deployedVersion}, - {"CHAOS", deployedChaosVersion}, + {"VERSION", formatter.BoldDirtyDefault(deployedVersion)}, + {"CHAOS", formatter.BoldDirtyDefault(deployedChaosVersion)}, {"NEW DEPLOYMENT", "---"}, - {"VERSION", toDeployVersion}, - {"CHAOS", toDeployChaosVersion}, + {"VERSION", formatter.BoldDirtyDefault(toDeployVersion)}, + {"CHAOS", formatter.BoldDirtyDefault(toDeployChaosVersion)}, {fmt.Sprintf("%s.ENV", strings.ToUpper(app.Name)), "---"}, - {"CURRENT VERSION", app.Recipe.EnvVersion}, - {"NEW VERSION", toWriteVersion}, + {"CURRENT VERSION", formatter.BoldDirtyDefault(envVersion)}, + {"NEW VERSION", formatter.BoldDirtyDefault(toWriteVersion)}, } overview := formatter.CreateOverview("DEPLOY OVERVIEW", rows) @@ -213,10 +227,6 @@ func UndeployOverview( domain = config.NO_DOMAIN_DEFAULT } - if app.Recipe.Dirty { - chaosVersion = formatter.BoldDirtyDefault(chaosVersion) - } - rows := [][]string{ {"APP", domain}, {"RECIPE", app.Recipe.Name}, @@ -224,12 +234,12 @@ func UndeployOverview( {"CONFIG", deployConfig}, {"CURRENT DEPLOYMENT", "---"}, - {"DEPLOYED", version}, - {"CHAOS", chaosVersion}, + {"VERSION", formatter.BoldDirtyDefault(version)}, + {"CHAOS", formatter.BoldDirtyDefault(chaosVersion)}, {fmt.Sprintf("%s.ENV", strings.ToUpper(app.Name)), "---"}, - {"CURRENT VERSION", app.Recipe.EnvVersion}, - {"NEW VERSION", version}, + {"CURRENT VERSION", formatter.BoldDirtyDefault(app.Recipe.EnvVersion)}, + {"NEW VERSION", formatter.BoldDirtyDefault(version)}, } overview := formatter.CreateOverview("UNDEPLOY OVERVIEW", rows) diff --git a/pkg/formatter/formatter.go b/pkg/formatter/formatter.go index ff6a685d..5d11c955 100644 --- a/pkg/formatter/formatter.go +++ b/pkg/formatter/formatter.go @@ -268,3 +268,8 @@ func BoldDirtyDefault(v string) string { return v } + +// AddDirtyMarker adds the dirty marker to a version string. +func AddDirtyMarker(v string) string { + return fmt.Sprintf("%s%s", v, config.DIRTY_DEFAULT) +} diff --git a/pkg/recipe/git.go b/pkg/recipe/git.go index 77479477..64cada7f 100644 --- a/pkg/recipe/git.go +++ b/pkg/recipe/git.go @@ -105,7 +105,7 @@ func (r Recipe) IsChaosCommit(version string) (bool, error) { isChaosCommit = true } - return true, nil + return isChaosCommit, nil } // EnsureVersion checks whether a specific version exists for a recipe. diff --git a/pkg/recipe/recipe.go b/pkg/recipe/recipe.go index aed00ce1..821d59df 100644 --- a/pkg/recipe/recipe.go +++ b/pkg/recipe/recipe.go @@ -125,6 +125,20 @@ type Features struct { SSO string `json:"sso"` } +func GetEnvVersionRaw(name string) (string, error) { + var version string + + if strings.Contains(name, ":") { + split := strings.Split(name, ":") + if len(split) > 2 { + return version, fmt.Errorf("version seems invalid: %s", name) + } + version = split[1] + } + + return version, nil +} + func Get(name string) Recipe { version := "" if strings.Contains(name, ":") { diff --git a/pkg/recipe/recipe_test.go b/pkg/recipe/recipe_test.go index a94bba06..8afd9df6 100644 --- a/pkg/recipe/recipe_test.go +++ b/pkg/recipe/recipe_test.go @@ -110,3 +110,11 @@ func TestDirtyMarkerRemoved(t *testing.T) { r := Get("abra-test-recipe:1e83340e+U") assert.Equal(t, "1e83340e", r.EnvVersion) } + +func TestGetEnvVersionRaw(t *testing.T) { + v, err := GetEnvVersionRaw("abra-test-recipe:1e83340e+U") + if err != nil { + t.Fatal(err) + } + assert.Equal(t, "1e83340e+U", v) +} diff --git a/tests/integration/app_deploy_overview.bats b/tests/integration/app_deploy_overview.bats new file mode 100644 index 00000000..baca1376 --- /dev/null +++ b/tests/integration/app_deploy_overview.bats @@ -0,0 +1,320 @@ +#!/usr/bin/env bash + +setup_file(){ + load "$PWD/tests/integration/helpers/common" + _common_setup + _add_server + _new_app +} + +teardown_file(){ + _rm_app + _rm_server + _reset_recipe +} + +setup(){ + load "$PWD/tests/integration/helpers/common" + _common_setup +} + +teardown(){ + _reset_recipe + _reset_app + _undeploy_app + _reset_tags + + run rm -rf "$ABRA_DIR/recipes/$TEST_RECIPE/foo" + assert_not_exists "$ABRA_DIR/recipes/$TEST_RECIPE/foo" +} + +@test "first deploy with empty env version" { + latestRelease=$(_latest_release) + + _wipe_env_version + + run $ABRA app deploy "$TEST_APP_DOMAIN" \ + --no-input --no-converge-checks + assert_success + + # current deployment + assert_output --regexp 'VERSION.*N/A' + assert_output --regexp 'CHAOS.*false' + + # new deployment + assert_output --regexp 'VERSION.* ' + "${latestRelease}" + assert_output --regexp 'CHAOS.*false' + + # env version + assert_output --regexp 'CURRENT VERSION.*N/A' + assert_output --regexp 'NEW VERSION.*' + "${latestRelease}" + + run grep -q "TYPE=$TEST_RECIPE:${latestRelease}" \ + "$ABRA_DIR/servers/$TEST_SERVER/$TEST_APP_DOMAIN.env" + assert_success +} + +@test "first deploy to latest version" { + latestRelease=$(_latest_release) + + run $ABRA app deploy "$TEST_APP_DOMAIN" \ + --no-input --no-converge-checks + assert_success + + # current deployment + assert_output --regexp 'VERSION.*N/A' + assert_output --regexp 'CHAOS.*false' + + # new deployment + assert_output --regexp 'VERSION.* ' + "${latestRelease}" + assert_output --regexp 'CHAOS.*false' + + # env version + assert_output --regexp 'CURRENT VERSION.*' + "${latestRelease}" + assert_output --regexp 'NEW VERSION.*' + "${latestRelease}" + + run grep -q "TYPE=$TEST_RECIPE:${latestRelease}" \ + "$ABRA_DIR/servers/$TEST_SERVER/$TEST_APP_DOMAIN.env" + assert_success +} + +# bats test_tags=slow +@test "deploy, re-deploy, choose env version" { + run $ABRA app deploy "$TEST_APP_DOMAIN" "0.1.1+1.20.2" \ + --no-input --no-converge-checks + assert_success + + _undeploy_app + + run $ABRA app deploy "$TEST_APP_DOMAIN" \ + --no-input --no-converge-checks + assert_success + + # current deployment + assert_output --regexp 'VERSION.*N/A' + assert_output --regexp 'CHAOS.*false' + + # new deployment + assert_output --regexp 'VERSION.*' + "0.1.1+1.20.2" + assert_output --regexp 'CHAOS.*false' + + # env version + assert_output --regexp 'CURRENT VERSION.*' + "0.1.1+1.20.2" + assert_output --regexp 'NEW VERSION.*' + "0.1.1+1.20.2" + + run grep -q "TYPE=$TEST_RECIPE:0.1.1+1.20.2" \ + "$ABRA_DIR/servers/$TEST_SERVER/$TEST_APP_DOMAIN.env" + assert_success +} + +@test "deploy, re-deploy, ignore env version" { + latestRelease=$(_latest_release) + + run $ABRA app deploy "$TEST_APP_DOMAIN" "0.1.1+1.20.2" \ + --no-input --no-converge-checks + assert_success + + _undeploy_app + + run $ABRA app deploy "$TEST_APP_DOMAIN" \ + --no-input --no-converge-checks --ignore-env-version + assert_success + + # current deployment + assert_output --regexp 'VERSION.*N/A' + assert_output --regexp 'CHAOS.*false' + + # new deployment + assert_output --regexp 'VERSION.*' + "${latestRelease}" + assert_output --regexp 'CHAOS.*false' + + # env version + assert_output --regexp 'CURRENT VERSION.*' + "0.1.1+1.20.2" + assert_output --regexp 'NEW VERSION.*' + "${latestRelease}" + + run grep -q "TYPE=$TEST_RECIPE:${latestRelease}" \ + "$ABRA_DIR/servers/$TEST_SERVER/$TEST_APP_DOMAIN.env" + assert_success +} + +@test "deploy then chaos deploy" { + headHash=$(_get_head_hash) + latestRelease=$(_latest_release) + + run $ABRA app deploy "$TEST_APP_DOMAIN" \ + --no-input --no-converge-checks + assert_success + + run bash -c 'echo "unstaged changes" >> "$ABRA_DIR/recipes/$TEST_RECIPE/foo"' + assert_success + assert_exists "$ABRA_DIR/recipes/$TEST_RECIPE/foo" + + run $ABRA app deploy "$TEST_APP_DOMAIN" \ + --no-input --no-converge-checks --chaos + assert_success + + # current deployment + assert_output --regexp 'VERSION.*' + "${latestRelease}" + assert_output --regexp 'CHAOS.*false' + + # new deployment + assert_output --regexp 'VERSION.*' + "${latestRelease}" + assert_output --regexp 'CHAOS.*' + "${headHash:0:8}+U" + + # env version + assert_output --regexp 'CURRENT VERSION.*' + "${latestRelease}" + assert_output --regexp 'NEW VERSION.*' + "${headHash:0:8}+U" + + run rm -rf "$ABRA_DIR/recipes/$TEST_RECIPE/foo" + assert_not_exists "$ABRA_DIR/recipes/$TEST_RECIPE/foo" + + run grep -q "TYPE=$TEST_RECIPE:${headHash:0:8}" \ + "$ABRA_DIR/servers/$TEST_SERVER/$TEST_APP_DOMAIN.env" + assert_success +} + +@test "chaos deploy then force deploy" { + headHash=$(_get_head_hash) + latestRelease=$(_latest_release) + + run bash -c 'echo "unstaged changes" >> "$ABRA_DIR/recipes/$TEST_RECIPE/foo"' + assert_success + assert_exists "$ABRA_DIR/recipes/$TEST_RECIPE/foo" + + run $ABRA app deploy "$TEST_APP_DOMAIN" \ + --no-input --no-converge-checks --chaos + assert_success + + run rm -rf "$ABRA_DIR/recipes/$TEST_RECIPE/foo" + assert_not_exists "$ABRA_DIR/recipes/$TEST_RECIPE/foo" + + run $ABRA app deploy "$TEST_APP_DOMAIN" \ + --no-input --no-converge-checks --force + assert_success + + # current deployment + assert_output --regexp 'VERSION.*' + "${latestRelease}" + assert_output --regexp 'CHAOS.*' + "${headHash:0:8}+U" + + # new deployment + assert_output --regexp 'VERSION.*' + "${latestRelease}" + assert_output --regexp 'CHAOS.*false' + + # env version + assert_output --regexp 'CURRENT VERSION.*' + "${headHash:0:8}+U" + assert_output --regexp 'NEW VERSION.*' + "${latestRelease}" + + run grep -q "TYPE=$TEST_RECIPE:${latestRelease}" \ + "$ABRA_DIR/servers/$TEST_SERVER/$TEST_APP_DOMAIN.env" + assert_success +} + +@test "deploy then force chaos commit deploy" { + headHash=$(_get_head_hash) + latestRelease=$(_latest_release) + + run $ABRA app deploy "$TEST_APP_DOMAIN" \ + --no-input --no-converge-checks + assert_success + + run grep -q "TYPE=$TEST_RECIPE:${latestRelease}" \ + "$ABRA_DIR/servers/$TEST_SERVER/$TEST_APP_DOMAIN.env" + assert_success + + run $ABRA app deploy "$TEST_APP_DOMAIN" "${headHash:0:8}" \ + --no-input --no-converge-checks --force + assert_success + + # current deployment + assert_output --regexp 'VERSION.*' + "${latestRelease}" + assert_output --regexp 'CHAOS.*false' + + # new deployment + assert_output --regexp 'VERSION.*' + "${latestRelease}" + assert_output --regexp 'CHAOS.*' + "${headHash:0:8}" + + # env version + assert_output --regexp 'CURRENT VERSION.*' + "${latestRelease}" + assert_output --regexp 'NEW VERSION.*' + "${headHash:0:8}" + + run grep -q "TYPE=$TEST_RECIPE:${headHash:0:8}" \ + "$ABRA_DIR/servers/$TEST_SERVER/$TEST_APP_DOMAIN.env" + assert_success +} + +@test "chaos deploy then chaos deploy with unstaged" { + headHash=$(_get_head_hash) + latestRelease=$(_latest_release) + + run $ABRA app deploy "$TEST_APP_DOMAIN" \ + --no-input --no-converge-checks --chaos + assert_success + + # current deployment + assert_output --regexp 'VERSION.*N/A' + assert_output --regexp 'CHAOS.*false' + + # new deployment + assert_output --regexp 'VERSION.*' + "${latestRelease}" + assert_output --regexp 'CHAOS.*' + "${headHash:0:8}" + + # env version + assert_output --regexp 'CURRENT VERSION.*' + "${latestRelease}" + assert_output --regexp 'NEW VERSION.*' + "${headHash:0:8}" + + run bash -c 'echo "unstaged changes" >> "$ABRA_DIR/recipes/$TEST_RECIPE/foo"' + assert_success + assert_exists "$ABRA_DIR/recipes/$TEST_RECIPE/foo" + + run $ABRA app deploy "$TEST_APP_DOMAIN" \ + --no-input --no-converge-checks --chaos + assert_success + + # current deployment + assert_output --regexp 'VERSION.*' + "${latestRelease}" + assert_output --regexp 'CHAOS.*' + "${headHash:0:8}" + + # new deployment + assert_output --regexp 'VERSION.*' + "${latestRelease}" + assert_output --regexp 'CHAOS.*' + "${headHash:0:8}+U" + + # env version + assert_output --regexp 'CURRENT VERSION.*' + "${latestRelease}" + assert_output --regexp 'NEW VERSION.*' + "${headHash:0:8}+U" + + run grep -q "TYPE=$TEST_RECIPE:${headHash:0:8}" \ + "$ABRA_DIR/servers/$TEST_SERVER/$TEST_APP_DOMAIN.env" + assert_success + + run rm -rf "$ABRA_DIR/recipes/$TEST_RECIPE/foo" + assert_not_exists "$ABRA_DIR/recipes/$TEST_RECIPE/foo" +} + +@test "hash deploy then force deploy" { + headHash=$(_get_head_hash) + latestRelease=$(_latest_release) + + run $ABRA app deploy "$TEST_APP_DOMAIN" "${headHash:0:8}" \ + --no-input --no-converge-checks + assert_success + + run $ABRA app deploy "$TEST_APP_DOMAIN" \ + --no-input --no-converge-checks --force + assert_success + + # current deployment + assert_output --regexp 'VERSION.*' + "${latestRelease}" + assert_output --regexp 'CHAOS.*' + "${headHash:0:8}" + + # new deployment + assert_output --regexp 'VERSION.*' + "${latestRelease}" + assert_output --regexp 'CHAOS.*false' + + # env version + assert_output --regexp 'CURRENT VERSION.*' + "${headHash:0:8}" + assert_output --regexp 'NEW VERSION.*' + "${latestRelease}" + + run grep -q "TYPE=$TEST_RECIPE:${latestRelease}" \ + "$ABRA_DIR/servers/$TEST_SERVER/$TEST_APP_DOMAIN.env" + assert_success +} diff --git a/tests/integration/app_env.bats b/tests/integration/app_env.bats index dd61f631..926b9259 100644 --- a/tests/integration/app_env.bats +++ b/tests/integration/app_env.bats @@ -32,7 +32,6 @@ teardown(){ assert_failure } -# bats test_tags=slow @test "show env version" { latestRelease=$(_latest_release) @@ -40,3 +39,8 @@ teardown(){ assert_success assert_output --partial "$latestRelease" } + +@test "show env version despite --chaos" { + run $ABRA app env "$TEST_APP_DOMAIN" + assert_success +} diff --git a/tests/integration/app_rollback_overview.bats b/tests/integration/app_rollback_overview.bats new file mode 100644 index 00000000..9a739bfa --- /dev/null +++ b/tests/integration/app_rollback_overview.bats @@ -0,0 +1,76 @@ +#!/usr/bin/env bash + +setup_file(){ + load "$PWD/tests/integration/helpers/common" + _common_setup + _add_server + _new_app +} + +teardown_file(){ + _rm_app + _rm_server + _reset_recipe +} + +setup(){ + load "$PWD/tests/integration/helpers/common" + _common_setup +} + +teardown(){ + _undeploy_app + _reset_recipe +} + +@test "deploy then rollback" { + run $ABRA app deploy "$TEST_APP_DOMAIN" "0.2.0+1.21.0" \ + --no-input --no-converge-checks + assert_success + + run $ABRA app rollback "$TEST_APP_DOMAIN" "0.1.0+1.20.0" \ + --no-input --no-converge-checks + assert_success + + # current deployment + assert_output --regexp 'VERSION.*' + "0.2.0+1.21.0" + assert_output --regexp 'CHAOS.*false' + + # new deployment + assert_output --regexp 'VERSION.*' + "0.1.0+1.20.0" + assert_output --regexp 'CHAOS.*false' + + # env version + assert_output --regexp 'CURRENT VERSION.*' + "0.2.0+1.21.0" + assert_output --regexp 'NEW VERSION.*' + "0.1.0+1.20.0" + + run grep -q "TYPE=$TEST_RECIPE:0.1.0+1.20.0" \ + "$ABRA_DIR/servers/$TEST_SERVER/$TEST_APP_DOMAIN.env" + assert_success +} + +@test "force rollback" { + run $ABRA app deploy "$TEST_APP_DOMAIN" "0.2.0+1.21.0" \ + --no-input --no-converge-checks + assert_success + + run $ABRA app rollback "$TEST_APP_DOMAIN" "0.2.0+1.21.0" \ + --no-input --no-converge-checks --force + assert_success + + # current deployment + assert_output --regexp 'VERSION.*' + "0.2.0+1.21.0" + assert_output --regexp 'CHAOS.*false' + + # new deployment + assert_output --regexp 'VERSION.*' + "0.2.0+1.21.0" + assert_output --regexp 'CHAOS.*false' + + # env version + assert_output --regexp 'CURRENT VERSION.*' + "0.2.0+1.21.0" + assert_output --regexp 'NEW VERSION.*' + "0.2.0+1.21.0" + + run grep -q "TYPE=$TEST_RECIPE:0.2.0+1.21.0" \ + "$ABRA_DIR/servers/$TEST_SERVER/$TEST_APP_DOMAIN.env" + assert_success +} diff --git a/tests/integration/app_undeploy_overview.bats b/tests/integration/app_undeploy_overview.bats new file mode 100644 index 00000000..847def0e --- /dev/null +++ b/tests/integration/app_undeploy_overview.bats @@ -0,0 +1,102 @@ +#!/usr/bin/env bash + +setup_file(){ + load "$PWD/tests/integration/helpers/common" + _common_setup + _add_server + _new_app +} + +teardown_file(){ + _rm_app + _rm_server + _reset_recipe +} + +setup(){ + load "$PWD/tests/integration/helpers/common" + _common_setup + _ensure_catalogue +} + +teardown(){ + _reset_recipe + _undeploy_app + _reset_app +} + +@test "deploy and undeploy" { + run $ABRA app deploy "$TEST_APP_DOMAIN" "0.1.0+1.20.0" \ + --no-input --no-converge-checks + assert_success + + run $ABRA app undeploy "$TEST_APP_DOMAIN" --no-input + assert_success + + # current deployment + assert_output --regexp 'VERSION.*' + "0.1.0+1.20.0" + assert_output --regexp 'CHAOS.*false' + + # env version + assert_output --regexp 'CURRENT VERSION.*' + "0.1.0+1.20.0" + assert_output --regexp 'NEW VERSION.*' + "0.1.0+1.20.0" + + run grep -q "TYPE=$TEST_RECIPE:0.1.0+1.20.0" \ + "$ABRA_DIR/servers/$TEST_SERVER/$TEST_APP_DOMAIN.env" + assert_success +} + +@test "chaos deploy and undeploy" { + headHash=$(_get_head_hash) + latestRelease=$(_latest_release) + + run $ABRA app deploy "$TEST_APP_DOMAIN" \ + --no-input --no-converge-checks --chaos + assert_success + + run $ABRA app undeploy "$TEST_APP_DOMAIN" --no-input + assert_success + + # current deployment + assert_output --regexp 'VERSION.*' + "${latestRelease}" + assert_output --regexp 'CHAOS.*' + "${headHash:0:8}" + + # env version + assert_output --regexp 'CURRENT VERSION.*' + "${latestRelease}" + assert_output --regexp 'NEW VERSION.*' + "${headHash:0:8}" + + run grep -q "TYPE=$TEST_RECIPE:${headHash:0:8}" \ + "$ABRA_DIR/servers/$TEST_SERVER/$TEST_APP_DOMAIN.env" + assert_success +} + +@test "chaos deploy with unstaged commits and undeploy" { + headHash=$(_get_head_hash) + latestRelease=$(_latest_release) + + run bash -c 'echo "unstaged changes" >> "$ABRA_DIR/recipes/$TEST_RECIPE/foo"' + assert_success + assert_exists "$ABRA_DIR/recipes/$TEST_RECIPE/foo" + + run $ABRA app deploy "$TEST_APP_DOMAIN" \ + --no-input --no-converge-checks --chaos + assert_success + + run $ABRA app undeploy "$TEST_APP_DOMAIN" --no-input + assert_success + + # current deployment + assert_output --regexp 'VERSION.*' + "${latestRelease}" + assert_output --regexp 'CHAOS.*' + "${headHash:0:8}+U" + + # env version + assert_output --regexp 'CURRENT VERSION.*' + "${latestRelease}" + assert_output --regexp 'NEW VERSION.*' + "${headHash:0:8}+U" + + run grep -q "TYPE=$TEST_RECIPE:${headHash:0:8}" \ + "$ABRA_DIR/servers/$TEST_SERVER/$TEST_APP_DOMAIN.env" + assert_success + + run rm -rf "$ABRA_DIR/recipes/$TEST_RECIPE/foo" + assert_not_exists "$ABRA_DIR/recipes/$TEST_RECIPE/foo" +} diff --git a/tests/integration/app_upgrade_overview.bats b/tests/integration/app_upgrade_overview.bats new file mode 100644 index 00000000..a6bbc189 --- /dev/null +++ b/tests/integration/app_upgrade_overview.bats @@ -0,0 +1,75 @@ +#!/usr/bin/env bash + +setup_file(){ + load "$PWD/tests/integration/helpers/common" + _common_setup + _add_server + _new_app +} + +teardown_file(){ + _rm_app + _rm_server +} + +setup(){ + load "$PWD/tests/integration/helpers/common" + _common_setup +} + +teardown(){ + _undeploy_app + _reset_recipe +} + +@test "deploy then upgrade" { + run $ABRA app deploy "$TEST_APP_DOMAIN" "0.1.0+1.20.0" \ + --no-input --no-converge-checks + assert_success + + run $ABRA app upgrade "$TEST_APP_DOMAIN" "0.2.0+1.21.0" \ + --no-input --no-converge-checks + assert_success + + # current deployment + assert_output --regexp 'VERSION.*' + "0.1.0+1.20.0" + assert_output --regexp 'CHAOS.*false' + + # new deployment + assert_output --regexp 'VERSION.*' + "0.2.0+1.21.0" + assert_output --regexp 'CHAOS.*false' + + # env version + assert_output --regexp 'CURRENT VERSION.*' + "0.1.0+1.20.0" + assert_output --regexp 'NEW VERSION.*' + "0.2.0+1.21.0" + + run grep -q "TYPE=$TEST_RECIPE:0.2.0+1.21.0" \ + "$ABRA_DIR/servers/$TEST_SERVER/$TEST_APP_DOMAIN.env" + assert_success +} + +@test "force upgrade" { + run $ABRA app deploy "$TEST_APP_DOMAIN" "0.2.0+1.21.0" \ + --no-input --no-converge-checks + assert_success + + run $ABRA app upgrade "$TEST_APP_DOMAIN" "0.2.0+1.21.0" \ + --no-input --no-converge-checks --force + assert_success + + # current deployment + assert_output --regexp 'VERSION.*' + "0.2.0+1.21.0" + assert_output --regexp 'CHAOS.*false' + + # new deployment + assert_output --regexp 'VERSION.*' + "0.2.0+1.21.0" + assert_output --regexp 'CHAOS.*false' + + # env version + assert_output --regexp 'CURRENT VERSION.*' + "0.2.0+1.21.0" + assert_output --regexp 'NEW VERSION.*' + "0.2.0+1.21.0" + + run grep -q "TYPE=$TEST_RECIPE:0.2.0+1.21.0" \ + "$ABRA_DIR/servers/$TEST_SERVER/$TEST_APP_DOMAIN.env" + assert_success +}