diff --git a/cli/app/deploy.go b/cli/app/deploy.go index 81fd780a..f4bfb390 100644 --- a/cli/app/deploy.go +++ b/cli/app/deploy.go @@ -23,7 +23,7 @@ var appDeployCommand = cli.Command{ Name: "deploy", Aliases: []string{"d"}, Usage: "Deploy an app", - ArgsUsage: "", + ArgsUsage: " []", Flags: []cli.Flag{ internal.DebugFlag, internal.NoInputFlag, @@ -99,9 +99,17 @@ recipes. } } - isLatestHash := false version := deployedVersion - if !internal.Chaos { + specificVersion := c.Args().Get(1) + if specificVersion != "" { + version = specificVersion + logrus.Debugf("choosing %s as version to deploy", version) + if err := recipe.EnsureVersion(app.Recipe, version); err != nil { + logrus.Fatal(err) + } + } + + if !internal.Chaos && specificVersion == "" { catl, err := recipe.ReadRecipeCatalogue(internal.Offline) if err != nil { logrus.Fatal(err) @@ -110,7 +118,21 @@ recipes. if err != nil { logrus.Fatal(err) } - if len(versions) > 0 { + + if len(versions) == 0 && !internal.Chaos { + logrus.Warn("no published versions in catalogue, trying local recipe repository") + recipeVersions, err := recipe.GetRecipeVersions(app.Recipe, internal.Offline) + if err != nil { + logrus.Warn(err) + } + for _, recipeVersion := range recipeVersions { + for version := range recipeVersion { + versions = append(versions, version) + } + } + } + + if len(versions) > 0 && !internal.Chaos { version = versions[len(versions)-1] logrus.Debugf("choosing %s as version to deploy", version) if err := recipe.EnsureVersion(app.Recipe, version); err != nil { @@ -121,19 +143,11 @@ recipes. if err != nil { logrus.Fatal(err) } - isLatestHash = true version = formatter.SmallSHA(head.String()) logrus.Warn("no versions detected, using latest commit") } } - if version != "unknown" && !internal.Chaos && !isLatestHash { - logrus.Debugf("choosing %s as version to deploy", version) - if err := recipe.EnsureVersion(app.Recipe, version); err != nil { - logrus.Fatal(err) - } - } - if internal.Chaos { logrus.Warnf("chaos mode engaged") var err error diff --git a/cli/app/rollback.go b/cli/app/rollback.go index afb70b9e..feec6b78 100644 --- a/cli/app/rollback.go +++ b/cli/app/rollback.go @@ -22,7 +22,7 @@ var appRollbackCommand = cli.Command{ Name: "rollback", Aliases: []string{"rl"}, Usage: "Roll an app back to a previous version", - ArgsUsage: "", + ArgsUsage: " []", Flags: []cli.Flag{ internal.DebugFlag, internal.NoInputFlag, @@ -107,16 +107,41 @@ recipes. } if len(versions) == 0 && !internal.Chaos { - logrus.Fatalf("no published releases for %s in the recipe catalogue?", app.Recipe) + logrus.Warn("no published versions in catalogue, trying local recipe repository") + recipeVersions, err := recipe.GetRecipeVersions(app.Recipe, internal.Offline) + if err != nil { + logrus.Warn(err) + } + for _, recipeVersion := range recipeVersions { + for version := range recipeVersion { + versions = append(versions, version) + } + } } var availableDowngrades []string if deployedVersion == "unknown" { availableDowngrades = versions - logrus.Warnf("failed to determine version of deployed %s", app.Name) + logrus.Warnf("failed to determine deployed version of %s", app.Name) } - if deployedVersion != "unknown" && !internal.Chaos { + specificVersion := c.Args().Get(1) + if specificVersion != "" { + parsedDeployedVersion, err := tagcmp.Parse(deployedVersion) + if err != nil { + logrus.Fatal(err) + } + parsedSpecificVersion, err := tagcmp.Parse(specificVersion) + if err != nil { + logrus.Fatal(err) + } + if parsedSpecificVersion.IsGreaterThan(parsedDeployedVersion) || parsedSpecificVersion.Equals(parsedDeployedVersion) { + logrus.Fatalf("%s is not a downgrade for %s?", deployedVersion, specificVersion) + } + availableDowngrades = append(availableDowngrades, specificVersion) + } + + if deployedVersion != "unknown" && !internal.Chaos && specificVersion == "" { for _, version := range versions { parsedDeployedVersion, err := tagcmp.Parse(deployedVersion) if err != nil { @@ -126,12 +151,12 @@ recipes. if err != nil { logrus.Fatal(err) } - if parsedVersion != parsedDeployedVersion && parsedVersion.IsLessThan(parsedDeployedVersion) { + if parsedVersion.IsLessThan(parsedDeployedVersion) && !(parsedVersion.Equals(parsedDeployedVersion)) { availableDowngrades = append(availableDowngrades, version) } } - if len(availableDowngrades) == 0 { + if len(availableDowngrades) == 0 && !internal.Force { logrus.Info("no available downgrades, you're on oldest ✌️") return nil } @@ -139,7 +164,7 @@ recipes. var chosenDowngrade string if len(availableDowngrades) > 0 && !internal.Chaos { - if internal.Force || internal.NoInput { + if internal.Force || internal.NoInput || specificVersion != "" { chosenDowngrade = availableDowngrades[len(availableDowngrades)-1] logrus.Debugf("choosing %s as version to downgrade to (--force/--no-input)", chosenDowngrade) } else { @@ -197,6 +222,7 @@ recipes. config.SetChaosVersionLabel(compose, stackName, chosenDowngrade) config.SetUpdateLabel(compose, stackName, app.Env) + // NOTE(d1): no release notes implemeneted for rolling back if err := internal.NewVersionOverview(app, deployedVersion, chosenDowngrade, ""); err != nil { logrus.Fatal(err) } diff --git a/cli/app/upgrade.go b/cli/app/upgrade.go index 7bb85fbf..bc31f484 100644 --- a/cli/app/upgrade.go +++ b/cli/app/upgrade.go @@ -22,7 +22,7 @@ var appUpgradeCommand = cli.Command{ Name: "upgrade", Aliases: []string{"up"}, Usage: "Upgrade an app", - ArgsUsage: "", + ArgsUsage: " []", Flags: []cli.Flag{ internal.DebugFlag, internal.NoInputFlag, @@ -108,26 +108,52 @@ recipes. } if len(versions) == 0 && !internal.Chaos { - logrus.Fatalf("no published releases for %s in the recipe catalogue?", app.Recipe) + logrus.Warn("no published versions in catalogue, trying local recipe repository") + recipeVersions, err := recipePkg.GetRecipeVersions(app.Recipe, internal.Offline) + if err != nil { + logrus.Warn(err) + } + for _, recipeVersion := range recipeVersions { + for version := range recipeVersion { + versions = append(versions, version) + } + } } var availableUpgrades []string if deployedVersion == "unknown" { availableUpgrades = versions - logrus.Warnf("failed to determine version of deployed %s", app.Name) + logrus.Warnf("failed to determine deployed version of %s", app.Name) } - if deployedVersion != "unknown" && !internal.Chaos { + specificVersion := c.Args().Get(1) + if specificVersion != "" { + parsedDeployedVersion, err := tagcmp.Parse(deployedVersion) + if err != nil { + logrus.Fatal(err) + } + parsedSpecificVersion, err := tagcmp.Parse(specificVersion) + if err != nil { + logrus.Fatal(err) + } + if parsedSpecificVersion.IsLessThan(parsedDeployedVersion) || parsedSpecificVersion.Equals(parsedDeployedVersion) { + logrus.Fatalf("%s is not an upgrade for %s?", deployedVersion, specificVersion) + } + availableUpgrades = append(availableUpgrades, specificVersion) + } + + parsedDeployedVersion, err := tagcmp.Parse(deployedVersion) + if err != nil { + logrus.Fatal(err) + } + + if deployedVersion != "unknown" && !internal.Chaos && specificVersion == "" { for _, version := range versions { - parsedDeployedVersion, err := tagcmp.Parse(deployedVersion) - if err != nil { - logrus.Fatal(err) - } parsedVersion, err := tagcmp.Parse(version) if err != nil { logrus.Fatal(err) } - if parsedVersion.IsGreaterThan(parsedDeployedVersion) { + if parsedVersion.IsGreaterThan(parsedDeployedVersion) && !(parsedVersion.Equals(parsedDeployedVersion)) { availableUpgrades = append(availableUpgrades, version) } } @@ -140,7 +166,7 @@ recipes. var chosenUpgrade string if len(availableUpgrades) > 0 && !internal.Chaos { - if internal.Force || internal.NoInput { + if internal.Force || internal.NoInput || specificVersion != "" { chosenUpgrade = availableUpgrades[len(availableUpgrades)-1] logrus.Debugf("choosing %s as version to upgrade to", chosenUpgrade) } else { @@ -162,9 +188,26 @@ recipes. // if release notes written after git tag published, read them before we // check out the tag and then they'll appear to be missing. this covers // when we obviously will forget to write release notes before publishing - releaseNotes, err := internal.GetReleaseNotes(app.Recipe, chosenUpgrade) - if err != nil { - return err + var releaseNotes string + for _, version := range versions { + parsedVersion, err := tagcmp.Parse(version) + if err != nil { + logrus.Fatal(err) + } + parsedChosenUpgrade, err := tagcmp.Parse(chosenUpgrade) + if err != nil { + logrus.Fatal(err) + } + + if !(parsedVersion.Equals(parsedDeployedVersion)) && parsedVersion.IsLessThan(parsedChosenUpgrade) { + note, err := internal.GetReleaseNotes(app.Recipe, version) + if err != nil { + return err + } + if note != "" { + releaseNotes += fmt.Sprintf("%s\n", note) + } + } } if !internal.Chaos { diff --git a/cli/internal/deploy.go b/cli/internal/deploy.go index 410fa97d..ca30aa57 100644 --- a/cli/internal/deploy.go +++ b/cli/internal/deploy.go @@ -32,17 +32,9 @@ func NewVersionOverview(app config.App, currentVersion, newVersion, releaseNotes table.Append([]string{server, app.Recipe, deployConfig, app.Domain, currentVersion, newVersion}) table.Render() - if releaseNotes == "" { - var err error - releaseNotes, err = GetReleaseNotes(app.Recipe, newVersion) - if err != nil { - return err - } - } - if releaseNotes != "" && newVersion != "" { fmt.Println() - fmt.Println(fmt.Sprintf("%s release notes:\n\n%s", newVersion, releaseNotes)) + fmt.Print(releaseNotes) } else { logrus.Warnf("no release notes available for %s", newVersion) } @@ -80,7 +72,8 @@ func GetReleaseNotes(recipeName, version string) (string, error) { if err != nil { return "", err } - return string(releaseNotes), nil + withTitle := fmt.Sprintf("%s release notes:\n%s", version, string(releaseNotes)) + return withTitle, nil } return "", nil diff --git a/pkg/recipe/recipe.go b/pkg/recipe/recipe.go index 0959c6be..aed3da4e 100644 --- a/pkg/recipe/recipe.go +++ b/pkg/recipe/recipe.go @@ -298,7 +298,10 @@ func EnsureVersion(recipeName, version string) error { return err } - logrus.Debugf("read %s as tags for recipe %s", strings.Join(parsedTags, ", "), recipeName) + joinedTags := strings.Join(parsedTags, ", ") + if joinedTags != "" { + logrus.Debugf("read %s as tags for recipe %s", joinedTags, recipeName) + } if tagRef.String() == "" { return fmt.Errorf("the local copy of %s doesn't seem to have version %s available?", recipeName, version) diff --git a/pkg/upstream/stack/stack.go b/pkg/upstream/stack/stack.go index d7772161..c2d1e214 100644 --- a/pkg/upstream/stack/stack.go +++ b/pkg/upstream/stack/stack.go @@ -415,7 +415,7 @@ func deployServices( return nil } - logrus.Infof("Starting to poll for deployment status for: %s", appName) + logrus.Infof("Waiting for %s to deploy... please hold 🤚", appName) ch := make(chan error, len(serviceIDs)) for serviceID, serviceName := range serviceIDs { logrus.Debugf("waiting on %s to converge", serviceName) @@ -472,12 +472,10 @@ func WaitOnService(ctx context.Context, cl *dockerClient.Client, serviceID, appN return err case <-sigintChannel: return fmt.Errorf(fmt.Sprintf(` -Cancelling polling for %s, deployment is still continuing. +Not waiting for %s to deploy. The deployment is ongoing... -If you want to stop the deployment try: - abra app undeploy %s - -`, appName, appName)) +If you want to stop the deployment, try: + abra app undeploy %s`, appName, appName)) case <-time.After(timeout): return fmt.Errorf(fmt.Sprintf(` %s has not converged (%s second timeout reached). diff --git a/tests/integration/app_backup.bats b/tests/integration/app_backup.bats index 4f10772a..a91d6e13 100644 --- a/tests/integration/app_backup.bats +++ b/tests/integration/app_backup.bats @@ -17,6 +17,13 @@ setup() { _common_setup } +teardown(){ + # https://github.com/bats-core/bats-core/issues/383#issuecomment-738628888 + if [[ -z "${BATS_TEST_COMPLETED}" ]]; then + _undeploy_app + fi +} + @test "retrieve recipe if missing" { assert_exists "$ABRA_DIR/recipes/$TEST_RECIPE" diff --git a/tests/integration/app_cmd.bats b/tests/integration/app_cmd.bats index 26fc4052..3dd50ee3 100644 --- a/tests/integration/app_cmd.bats +++ b/tests/integration/app_cmd.bats @@ -17,6 +17,13 @@ setup(){ _common_setup } +teardown(){ + # https://github.com/bats-core/bats-core/issues/383#issuecomment-738628888 + if [[ -z "${BATS_TEST_COMPLETED}" ]]; then + _undeploy_app + fi +} + @test "validate app argument" { run $ABRA app cmd assert_failure diff --git a/tests/integration/app_cp.bats b/tests/integration/app_cp.bats index 4123b530..2687e9d4 100644 --- a/tests/integration/app_cp.bats +++ b/tests/integration/app_cp.bats @@ -17,6 +17,13 @@ setup(){ _common_setup } +teardown(){ + # https://github.com/bats-core/bats-core/issues/383#issuecomment-738628888 + if [[ -z "${BATS_TEST_COMPLETED}" ]]; then + _undeploy_app + fi +} + @test "validate app argument" { run $ABRA app cp assert_failure diff --git a/tests/integration/app_deploy.bats b/tests/integration/app_deploy.bats index 5c04f49a..edee25d9 100644 --- a/tests/integration/app_deploy.bats +++ b/tests/integration/app_deploy.bats @@ -17,6 +17,13 @@ setup(){ _common_setup } +teardown(){ + # https://github.com/bats-core/bats-core/issues/383#issuecomment-738628888 + if [[ -z "${BATS_TEST_COMPLETED}" ]]; then + _undeploy_app + fi +} + @test "validate app argument" { run $ABRA app deploy assert_failure @@ -43,6 +50,8 @@ setup(){ run rm -rf "$ABRA_DIR/recipes/$TEST_RECIPE/foo" assert_not_exists "$ABRA_DIR/recipes/$TEST_RECIPE/foo" + + _checkout_recipe "$TEST_RECIPE" } # bats test_tags=slow @@ -77,25 +86,26 @@ setup(){ run $ABRA app deploy "$TEST_APP_DOMAIN" --no-input --no-converge-checks assert_success - run git -C "$ABRA_DIR/recipes/$TEST_RECIPE" status - refute_output --partial 'behind 3' + # NOTE(d1): nuke it to ensure clean git state + run rm -rf "$ABRA_DIR/recipes/$TEST_RECIPE" + assert_success + assert_not_exists "$ABRA_DIR/recipes/$TEST_RECIPE" + _fetch_recipe "$TEST_RECIPE" _undeploy_app } # bats test_tags=slow @test "ensure recipe not up to date if --offline" { - latestCommit="$(git -C "$ABRA_DIR/recipes/$TEST_RECIPE" rev-parse --short HEAD)" - refute [ -z "$latestCommit" ]; - run git -C "$ABRA_DIR/recipes/$TEST_RECIPE" reset --hard HEAD~3 assert_success run git -C "$ABRA_DIR/recipes/$TEST_RECIPE" status assert_output --partial 'behind 3' + # NOTE(d1): need to use --chaos to force same commit run $ABRA app deploy "$TEST_APP_DOMAIN" \ - --no-input --no-converge-checks --offline + --no-input --no-converge-checks --chaos --offline assert_success run git -C "$ABRA_DIR/recipes/$TEST_RECIPE" status @@ -103,23 +113,46 @@ setup(){ _undeploy_app - run git -C "$ABRA_DIR/recipes/$TEST_RECIPE" checkout "$latestCommit" + # NOTE(d1): nuke it to ensure clean git state + run rm -rf "$ABRA_DIR/recipes/$TEST_RECIPE" assert_success - - run git -C "$ABRA_DIR/recipes/$TEST_RECIPE" status - refute_output --partial 'behind 3' + assert_not_exists "$ABRA_DIR/recipes/$TEST_RECIPE" + _fetch_recipe "$TEST_RECIPE" } # bats test_tags=slow @test "deploy latest commit if no published versions and no --chaos" { latestCommit="$(git -C "$ABRA_DIR/recipes/$TEST_RECIPE" rev-parse --short HEAD)" - run $ABRA app deploy "$TEST_APP_DOMAIN" --no-input --no-converge-checks + run bash -c 'git -C "$ABRA_DIR/recipes/$TEST_RECIPE" tag -l | wc -l' + assert_success + refute_output '0' + + run bash -c 'git -C "$ABRA_DIR/recipes/$TEST_RECIPE" tag -l | \ + xargs -I{} git -C "$ABRA_DIR/recipes/$TEST_RECIPE" tag -d {}' + assert_success + assert_output --partial 'Deleted tag' + + run bash -c 'git -C "$ABRA_DIR/recipes/$TEST_RECIPE" tag -l | wc -l' + assert_success + assert_output '0' + + # NOTE(d1): need to pass --offline to stop tags being pulled again + run $ABRA app deploy "$TEST_APP_DOMAIN" \ + --no-input --no-converge-checks --offline assert_success assert_output --partial "$latestCommit" + assert_output --partial 'using latest commit' refute_output --partial 'chaos' _undeploy_app + + run git -C "$ABRA_DIR/recipes/$TEST_RECIPE" fetch --all + assert_success + + run bash -c 'git -C "$ABRA_DIR/recipes/$TEST_RECIPE" tag -l | wc -l' + assert_success + refute_output '0' } # bats test_tags=slow @@ -143,9 +176,11 @@ setup(){ _undeploy_app - run git -C "$ABRA_DIR/recipes/$TEST_RECIPE" checkout "$latestCommit" + # NOTE(d1): nuke it to ensure clean git state + run rm -rf "$ABRA_DIR/recipes/$TEST_RECIPE" assert_success - refute_output --partial 'behind 3' + assert_not_exists "$ABRA_DIR/recipes/$TEST_RECIPE" + _fetch_recipe "$TEST_RECIPE" } # bats test_tags=slow @@ -274,3 +309,18 @@ setup(){ _undeploy_app } + +@test "error if specific version does not exist" { + run $ABRA app deploy "$TEST_APP_DOMAIN" DOESNTEXIST --no-input --no-converge-checks + assert_failure + assert_output --partial "doesn't seem to have version DOESNTEXIST available" +} + +# bats test_tags=slow +@test "deploy specific version" { + run $ABRA app deploy "$TEST_APP_DOMAIN" "0.2.0+1.21.0" --no-input + assert_success + assert_output --partial "0.2.0+1.21.0" + + _undeploy_app +} diff --git a/tests/integration/app_list.bats b/tests/integration/app_list.bats index 0f62e1ee..dd38d10f 100644 --- a/tests/integration/app_list.bats +++ b/tests/integration/app_list.bats @@ -17,6 +17,13 @@ setup(){ _common_setup } +teardown(){ + # https://github.com/bats-core/bats-core/issues/383#issuecomment-738628888 + if [[ -z "${BATS_TEST_COMPLETED}" ]]; then + _undeploy_app + fi +} + @test "list without status" { run $ABRA app ls assert_success diff --git a/tests/integration/app_new.bats b/tests/integration/app_new.bats index 282b24cc..4ce67680 100644 --- a/tests/integration/app_new.bats +++ b/tests/integration/app_new.bats @@ -16,6 +16,13 @@ setup(){ _common_setup } +teardown(){ + # https://github.com/bats-core/bats-core/issues/383#issuecomment-738628888 + if [[ -z "${BATS_TEST_COMPLETED}" ]]; then + _undeploy_app + fi +} + @test "create new app" { run $ABRA app new "$TEST_RECIPE" \ --no-input \ diff --git a/tests/integration/app_ps.bats b/tests/integration/app_ps.bats index edc60cb5..b2a9987c 100644 --- a/tests/integration/app_ps.bats +++ b/tests/integration/app_ps.bats @@ -17,6 +17,13 @@ setup(){ _common_setup } +teardown(){ + # https://github.com/bats-core/bats-core/issues/383#issuecomment-738628888 + if [[ -z "${BATS_TEST_COMPLETED}" ]]; then + _undeploy_app + fi +} + @test "validate app argument" { run $ABRA app ps assert_failure diff --git a/tests/integration/app_remove.bats b/tests/integration/app_remove.bats index 63626fd0..e9595db9 100644 --- a/tests/integration/app_remove.bats +++ b/tests/integration/app_remove.bats @@ -17,6 +17,13 @@ setup(){ _common_setup } +teardown(){ + # https://github.com/bats-core/bats-core/issues/383#issuecomment-738628888 + if [[ -z "${BATS_TEST_COMPLETED}" ]]; then + _undeploy_app + fi +} + @test "validate app argument" { run $ABRA app deploy assert_failure diff --git a/tests/integration/app_restart.bats b/tests/integration/app_restart.bats index 18ee570f..b01bb7b3 100644 --- a/tests/integration/app_restart.bats +++ b/tests/integration/app_restart.bats @@ -17,6 +17,13 @@ setup(){ _common_setup } +teardown(){ + # https://github.com/bats-core/bats-core/issues/383#issuecomment-738628888 + if [[ -z "${BATS_TEST_COMPLETED}" ]]; then + _undeploy_app + fi +} + @test "validate app argument" { run $ABRA app restart assert_failure diff --git a/tests/integration/app_restore.bats b/tests/integration/app_restore.bats index ed0d6d63..de477230 100644 --- a/tests/integration/app_restore.bats +++ b/tests/integration/app_restore.bats @@ -17,6 +17,13 @@ setup(){ _common_setup } +teardown(){ + # https://github.com/bats-core/bats-core/issues/383#issuecomment-738628888 + if [[ -z "${BATS_TEST_COMPLETED}" ]]; then + _undeploy_app + fi +} + @test "validate app argument" { run $ABRA app restore assert_failure diff --git a/tests/integration/app_rollback.bats b/tests/integration/app_rollback.bats index 2f2c246e..b3601741 100644 --- a/tests/integration/app_rollback.bats +++ b/tests/integration/app_rollback.bats @@ -8,6 +8,7 @@ setup_file(){ } teardown_file(){ + _rm_app _rm_server } @@ -16,8 +17,12 @@ setup(){ _common_setup } -# TODO(d1): test "no available downgrades" when this is implemented -# https://git.coopcloud.tech/coop-cloud/organising/issues/204 +teardown(){ + # https://github.com/bats-core/bats-core/issues/383#issuecomment-738628888 + if [[ -z "${BATS_TEST_COMPLETED}" ]]; then + _undeploy_app + fi +} @test "validate app argument" { run $ABRA app rollback @@ -73,8 +78,11 @@ setup(){ run git -C "$ABRA_DIR/recipes/$TEST_RECIPE" checkout "$latestCommit" assert_success - run git -C "$ABRA_DIR/recipes/$TEST_RECIPE" status - refute_output --partial 'behind 3' + # NOTE(d1): nuke it to ensure clean git state + run rm -rf "$ABRA_DIR/recipes/$TEST_RECIPE" + assert_success + assert_not_exists "$ABRA_DIR/recipes/$TEST_RECIPE" + _fetch_recipe "$TEST_RECIPE" } @test "bail if unstaged changes and no --chaos" { @@ -123,38 +131,21 @@ setup(){ # bats test_tags=slow @test "ensure same commit if --chaos" { - run git -C "$ABRA_DIR/recipes/$TEST_RECIPE" checkout main - assert_success - latestCommit="$(git -C "$ABRA_DIR/recipes/$TEST_RECIPE" rev-parse --short HEAD)" - run git -C "$ABRA_DIR/recipes/$TEST_RECIPE" reset --hard HEAD~3 - assert_success - - run git -C "$ABRA_DIR/recipes/$TEST_RECIPE" status - assert_output --partial 'behind 3' - - threeCommitsBack="$(git -C "$ABRA_DIR/recipes/$TEST_RECIPE" rev-parse --short HEAD)" - run $ABRA app deploy "$TEST_APP_DOMAIN" \ --no-input --no-converge-checks --chaos assert_success - refute_output --partial "$latestCommit" - assert_output --partial "$threeCommitsBack" + assert_output --partial "$latestCommit" assert_output --partial 'chaos' run $ABRA app rollback "$TEST_APP_DOMAIN" \ --chaos --no-input --no-converge-checks assert_success - refute_output --partial "$latestCommit" - assert_output --partial "$threeCommitsBack" + assert_output --partial "$latestCommit" assert_output --partial 'chaos' _undeploy_app - - run git -C "$ABRA_DIR/recipes/$TEST_RECIPE" checkout "$latestCommit" - assert_success - refute_output --partial 'behind 3' } # bats test_tags=slow @@ -164,7 +155,8 @@ setup(){ run sed -i '/traefik.enable=.*/d' "$ABRA_DIR/recipes/$TEST_RECIPE/compose.yml" assert_success - run $ABRA app rollback "$TEST_APP_DOMAIN" --no-input --chaos + run $ABRA app rollback "$TEST_APP_DOMAIN" \ + --no-input --chaos --chaos --no-converge-checks assert_failure assert_output --partial 'failed lint checks' @@ -174,59 +166,59 @@ setup(){ } @test "error if not already deployed" { - run $ABRA app rollback "$TEST_APP_DOMAIN" --no-input --chaos + run $ABRA app rollback "$TEST_APP_DOMAIN" --no-input assert_failure assert_output --partial 'not deployed' } # bats test_tags=slow -@test "error if no published release and no --chaos" { - _deploy_app +@test "no rollback if on oldest version" { + run $ABRA app deploy "$TEST_APP_DOMAIN" "0.1.0+1.20.0" --no-input --no-converge-checks + assert_success + assert_output --partial '0.1.0+1.20.0' - run $ABRA app rollback "$TEST_APP_DOMAIN" --no-input + run $ABRA app rollback "$TEST_APP_DOMAIN" --no-input --no-converge-checks + assert_success + assert_output --partial "you're on oldest" + + _undeploy_app +} + +# bats test_tags=slow +@test "error if specific version is not downgrade" { + run $ABRA app deploy "$TEST_APP_DOMAIN" "0.1.0+1.20.0" --no-input --no-converge-checks + assert_success + assert_output --partial '0.1.0+1.20.0' + + run $ABRA app rollback "$TEST_APP_DOMAIN" "0.1.0+1.20.0" --no-input --no-converge-checks assert_failure - assert_output --partial 'no published releases' + assert_output --partial 'is not a downgrade' _undeploy_app } # bats test_tags=slow @test "rollback to previous version" { - latestVersion=$(jq -r '.gitea.versions[-1] | keys[0]' < "$ABRA_DIR/catalogue/recipes.json") - refute [ -z "$latestVersion" ]; - - rollbackVersion=$(jq -r '.gitea.versions[-2] | keys[0]' < "$ABRA_DIR/catalogue/recipes.json") - refute [ -z "$rollbackVersion" ]; - - run $ABRA app new gitea \ - --no-input \ - --server "$TEST_SERVER" \ - --domain "gitea.$TEST_SERVER" \ - --secrets + run $ABRA app deploy "$TEST_APP_DOMAIN" "0.1.1+1.20.2" --no-input --no-converge-checks assert_success - assert_exists "$ABRA_DIR/servers/$TEST_SERVER/gitea.$TEST_SERVER.env" + assert_output --partial '0.1.1+1.20.2' - run $ABRA app deploy "gitea.$TEST_SERVER" --no-input --no-converge-checks + run $ABRA app rollback "$TEST_APP_DOMAIN" --no-input --no-converge-checks assert_success - assert_output --partial "$latestVersion" + assert_output --partial "0.1.0+1.20.0" - run $ABRA app rollback "gitea.$TEST_SERVER" --no-input --no-converge-checks - assert_success - assert_output --partial "$rollbackVersion" - - run $ABRA app undeploy "gitea.$TEST_SERVER" --no-input - assert_success - - run $ABRA app secret remove "gitea.$TEST_SERVER" --all --no-input - assert_success - - # NOTE(d1): to let the stack come down before nuking volumes - sleep 5 - - run $ABRA app volume remove "gitea.$TEST_SERVER" --no-input - assert_success - - run $ABRA app remove "gitea.$TEST_SERVER" --no-input - assert_success - assert_not_exists "$ABRA_DIR/servers/$TEST_SERVER/gitea.$TEST_SERVER.env" + _undeploy_app +} + +# bats test_tags=slow +@test "rollback to a version 2 tags behind" { + run $ABRA app deploy "$TEST_APP_DOMAIN" "0.2.0+1.21.0" --no-input --no-converge-checks + assert_success + assert_output --partial "0.2.0+1.21.0" + + run $ABRA app rollback "$TEST_APP_DOMAIN" "0.1.0+1.20.0" --no-input --no-converge-checks + assert_success + assert_output --partial "0.1.0+1.20.0" + + _undeploy_app } diff --git a/tests/integration/app_run.bats b/tests/integration/app_run.bats index 8980abf4..abcd1aa0 100644 --- a/tests/integration/app_run.bats +++ b/tests/integration/app_run.bats @@ -17,6 +17,13 @@ setup(){ _common_setup } +teardown(){ + # https://github.com/bats-core/bats-core/issues/383#issuecomment-738628888 + if [[ -z "${BATS_TEST_COMPLETED}" ]]; then + _undeploy_app + fi +} + @test "validate app argument" { run $ABRA app run assert_failure diff --git a/tests/integration/app_secret.bats b/tests/integration/app_secret.bats index 79e529cc..2f629047 100644 --- a/tests/integration/app_secret.bats +++ b/tests/integration/app_secret.bats @@ -18,6 +18,13 @@ teardown_file(){ _rm_server } +teardown(){ + # https://github.com/bats-core/bats-core/issues/383#issuecomment-738628888 + if [[ -z "${BATS_TEST_COMPLETED}" ]]; then + _undeploy_app + fi +} + setup(){ load "$PWD/tests/integration/helpers/common" _common_setup diff --git a/tests/integration/app_services.bats b/tests/integration/app_services.bats index 9fee6b1d..c63ce2df 100644 --- a/tests/integration/app_services.bats +++ b/tests/integration/app_services.bats @@ -17,6 +17,13 @@ setup(){ _common_setup } +teardown(){ + # https://github.com/bats-core/bats-core/issues/383#issuecomment-738628888 + if [[ -z "${BATS_TEST_COMPLETED}" ]]; then + _undeploy_app + fi +} + @test "validate app argument" { run $ABRA app services assert_failure diff --git a/tests/integration/app_undeploy.bats b/tests/integration/app_undeploy.bats index 051eb458..9d435203 100644 --- a/tests/integration/app_undeploy.bats +++ b/tests/integration/app_undeploy.bats @@ -17,6 +17,13 @@ setup(){ _common_setup } +teardown(){ + # https://github.com/bats-core/bats-core/issues/383#issuecomment-738628888 + if [[ -z "${BATS_TEST_COMPLETED}" ]]; then + _undeploy_app + fi +} + @test "validate app argument" { run $ABRA app undeploy assert_failure diff --git a/tests/integration/app_upgrade.bats b/tests/integration/app_upgrade.bats index 2a660e36..a2575102 100644 --- a/tests/integration/app_upgrade.bats +++ b/tests/integration/app_upgrade.bats @@ -17,6 +17,13 @@ setup(){ _common_setup } +teardown(){ + # https://github.com/bats-core/bats-core/issues/383#issuecomment-738628888 + if [[ -z "${BATS_TEST_COMPLETED}" ]]; then + _undeploy_app + fi +} + @test "validate app argument" { run $ABRA app upgrade assert_failure @@ -28,49 +35,171 @@ setup(){ } # bats test_tags=slow -@test "upgrade app" { - latestVersion=$(jq -r '.gitea.versions[-1] | keys[0]' < "$ABRA_DIR/catalogue/recipes.json") - refute [ -z "$latestVersion" ]; +@test "error if specific version is not an upgrade" { + run $ABRA app deploy "$TEST_APP_DOMAIN" "0.1.0+1.20.0" --no-input --no-converge-checks + assert_success + assert_output --partial '0.1.0+1.20.0' - rollbackVersion=$(jq -r '.gitea.versions[-2] | keys[0]' < "$ABRA_DIR/catalogue/recipes.json") - refute [ -z "$rollbackVersion" ]; + run $ABRA app upgrade "$TEST_APP_DOMAIN" "0.1.0+1.20.0" --no-input + assert_failure + assert_output --partial 'is not an upgrade' - run $ABRA app new gitea \ + _undeploy_app +} + +# bats test_tags=slow +@test "no upgrade if lint error" { + _deploy_app + + run sed -i '/traefik.enable=.*/d' "$ABRA_DIR/recipes/$TEST_RECIPE/compose.yml" + assert_success + + run $ABRA app upgrade "$TEST_APP_DOMAIN" \ + --no-input --no-converge-checks --chaos + assert_failure + assert_output --partial 'failed lint checks' + + _checkout_recipe "$TEST_RECIPE" + + _undeploy_app +} + +# bats test_tags=slow +@test "no upgrade if on latest version" { + _deploy_app + + run $ABRA app upgrade "$TEST_APP_DOMAIN" --no-input --no-converge-checks + assert_success + assert_output --partial "you're on latest" + + _undeploy_app +} + +# bats test_tags=slow +@test "upgrade to latest catalogue published version" { + appDomain="custom-html.$TEST_SERVER" + + run $ABRA app new custom-html \ --no-input \ --server "$TEST_SERVER" \ - --domain "gitea.$TEST_SERVER" \ - --secrets - assert_success - assert_exists "$ABRA_DIR/servers/$TEST_SERVER/gitea.$TEST_SERVER.env" + --domain "$appDomain" - run $ABRA app deploy "gitea.$TEST_SERVER" --no-input + oneVersionBack=$(jq -r '."custom-html".versions[-2] | keys[0]' < "$ABRA_DIR/catalogue/recipes.json") + refute [ -z "$oneVersionBack" ]; + + run $ABRA app deploy "$appDomain" "$oneVersionBack" --no-input --no-converge-checks + assert_success + assert_output --partial "$oneVersionsBack" + + latestVersion=$(jq -r '."custom-html".versions[-1] | keys[0]' < "$ABRA_DIR/catalogue/recipes.json") + refute [ -z "$latestVersion" ]; + + run $ABRA app upgrade "$appDomain" --no-input --no-converge-checks assert_success assert_output --partial "$latestVersion" - run $ABRA app rollback "gitea.$TEST_SERVER" --no-input - assert_success - assert_output --partial "$rollbackVersion" - - # NOTE(d1): let runtime settle down before upgrade - sleep 5 - - run $ABRA app upgrade "gitea.$TEST_SERVER" --no-input - assert_success - assert_output --partial "$latestVersion" - - run $ABRA app undeploy "gitea.$TEST_SERVER" --no-input + run $ABRA app undeploy "$appDomain" --no-input assert_success - run $ABRA app secret remove "gitea.$TEST_SERVER" --all --no-input + # NOTE(d1): to let the stack come down before nuking volumes + sleep 3 + + run $ABRA app volume remove "$appDomain" --no-input assert_success - # NOTE(d1): to let the stack come down before nuking volumes - sleep 5 - - run $ABRA app volume remove "gitea.$TEST_SERVER" --no-input + run $ABRA app remove "$appDomain" --no-input assert_success - - run $ABRA app remove "gitea.$TEST_SERVER" --no-input - assert_success - assert_not_exists "$ABRA_DIR/servers/$TEST_SERVER/gitea.$TEST_SERVER.env" + assert_not_exists "$ABRA_DIR/servers/$TEST_SERVER/$appDomain.env" +} + +# bats test_tags=slow +@test "upgrade specific version" { + run $ABRA app deploy "$TEST_APP_DOMAIN" "0.1.0+1.20.0" --no-input --no-converge-checks + assert_success + assert_output --partial '0.1.0+1.20.0' + + run $ABRA app upgrade "$TEST_APP_DOMAIN" "0.2.0+1.21.0" --no-input --no-converge-checks + assert_success + assert_output --partial '0.2.0+1.21.0' + + _undeploy_app +} + +# bats test_tags=slow +@test "upgrade to latest" { + run $ABRA app deploy "$TEST_APP_DOMAIN" "0.1.0+1.20.0" --no-input --no-converge-checks + assert_success + assert_output --partial '0.1.0+1.20.0' + + latestRelease=$(git -C "$ABRA_DIR/recipes/$TEST_RECIPE" tag -l | tail -n 1) + + run $ABRA app upgrade "$TEST_APP_DOMAIN" --no-input --no-converge-checks + assert_success + assert_output --partial "$latestRelease" + + _undeploy_app +} + +# bats test_tags=slow +@test "show single release note" { + run $ABRA app deploy "$TEST_APP_DOMAIN" "0.1.1+1.20.2" --no-input --no-converge-checks + assert_success + assert_output --partial '0.1.1+1.20.2' + + latestRelease=$(git -C "$ABRA_DIR/recipes/$TEST_RECIPE" tag -l | tail -n 1) + + run $ABRA app upgrade "$TEST_APP_DOMAIN" --no-input --no-converge-checks + assert_success + assert_output --partial "$latestRelease" + assert_output --partial 'release notes baz' # 0.2.0+1.21.0 + refute_output --partial 'release notes bar' # 0.1.1+1.20.2 + + _undeploy_app +} + +# bats test_tags=slow +@test "show single release note for specific version" { + run $ABRA app deploy "$TEST_APP_DOMAIN" "0.1.0+1.20.0" --no-input --no-converge-checks + assert_success + assert_output --partial '0.1.0+1.20.0' + + run $ABRA app upgrade "$TEST_APP_DOMAIN" "0.1.1+1.20.2" --no-input --no-converge-checks + assert_success + assert_output --partial '0.1.1+1.20.2' + assert_output --partial 'release notes bar' # 0.1.1+1.20.2 + refute_output --partial 'release notes baz' # 0.2.0+1.21.0 + + _undeploy_app +} + +# bats test_tags=slow +@test "show multiple release notes" { + run $ABRA app deploy "$TEST_APP_DOMAIN" "0.1.0+1.20.0" --no-input --no-converge-checks + assert_success + assert_output --partial '0.1.0+1.20.0' + + latestRelease=$(git -C "$ABRA_DIR/recipes/$TEST_RECIPE" tag -l | tail -n 1) + + run $ABRA app upgrade "$TEST_APP_DOMAIN" --no-input --no-converge-checks + assert_success + assert_output --partial "$latestRelease" + assert_output --partial 'release notes bar' # 0.1.1+1.20.2 + assert_output --partial 'release notes baz' # 0.2.0+1.21.0 + + _undeploy_app +} + +# bats test_tags=slow +@test "show multiple release notes for specific version" { + run $ABRA app deploy "$TEST_APP_DOMAIN" "0.1.0+1.20.0" --no-input --no-converge-checks + assert_success + assert_output --partial '0.1.0+1.20.0' + + run $ABRA app upgrade "$TEST_APP_DOMAIN" "0.2.0+1.21.0" --no-input --no-converge-checks + assert_success + assert_output --partial '0.2.0+1.21.0' + assert_output --partial 'release notes bar' # 0.1.1+1.20.2 + assert_output --partial 'release notes baz' # 0.2.0+1.21.0 + + _undeploy_app } diff --git a/tests/integration/app_version.bats b/tests/integration/app_version.bats index b4cd3910..a8f95f6c 100644 --- a/tests/integration/app_version.bats +++ b/tests/integration/app_version.bats @@ -17,6 +17,13 @@ setup(){ _common_setup } +teardown(){ + # https://github.com/bats-core/bats-core/issues/383#issuecomment-738628888 + if [[ -z "${BATS_TEST_COMPLETED}" ]]; then + _undeploy_app + fi +} + @test "validate app argument" { run $ABRA app version assert_failure @@ -61,38 +68,16 @@ setup(){ _undeploy_app } +# bats test_tags=slow @test "list version" { - latestVersion=$(jq -r '.gitea.versions[-1] | keys[0]' < "$ABRA_DIR/catalogue/recipes.json") + _deploy_app + + latestVersion=$(git -C "$ABRA_DIR/recipes/$TEST_RECIPE" git tag | tail -n 1) refute [ -z "$latestVersion" ]; - run $ABRA app new gitea \ - --no-input \ - --server "$TEST_SERVER" \ - --domain "gitea.$TEST_SERVER" \ - --secrets - assert_success - - run $ABRA app deploy "gitea.$TEST_SERVER" \ - --no-input --no-converge-checks - assert_success - - run $ABRA app version "gitea.$TEST_SERVER" + run $ABRA app version "$TEST_APP_DOMAIN" assert_success assert_output --partial "$latestVersion" - run $ABRA app undeploy "gitea.$TEST_SERVER" --no-input - assert_success - - run $ABRA app secret remove "gitea.$TEST_SERVER" --all --no-input - assert_success - - # NOTE(d1): to let the stack come down before nuking volumes - sleep 5 - - run $ABRA app volume remove "gitea.$TEST_SERVER" --no-input - assert_success - - run $ABRA app remove "gitea.$TEST_SERVER" --no-input - assert_success - assert_not_exists "$ABRA_DIR/servers/$TEST_SERVER/gitea.$TEST_SERVER.env" + _undeploy_app } diff --git a/tests/integration/app_volume.bats b/tests/integration/app_volume.bats index 9c0c9d5b..5b4ff600 100644 --- a/tests/integration/app_volume.bats +++ b/tests/integration/app_volume.bats @@ -17,6 +17,13 @@ setup(){ _common_setup } +teardown(){ + # https://github.com/bats-core/bats-core/issues/383#issuecomment-738628888 + if [[ -z "${BATS_TEST_COMPLETED}" ]]; then + _undeploy_app + fi +} + @test "ls validate app argument" { run $ABRA app volume ls assert_failure diff --git a/tests/integration/setup_suite.bash b/tests/integration/setup_suite.bash index f0438864..c52b71b8 100644 --- a/tests/integration/setup_suite.bash +++ b/tests/integration/setup_suite.bash @@ -1,13 +1,13 @@ #!/usr/bin/env bash setup_suite(){ - if [[ -z "${TEST_SERVER}" ]]; then - echo 'set $TEST_SERVER before running the test suite' >&3 + if [[ -z "${ABRA_DIR}" ]]; then + echo 'set $ABRA_DIR before running the test suite' >&3 exit 1 fi - if [[ -z "${ABRA_DIR}" ]]; then - echo 'set $ABRA_DIR before running the test suite' >&3 + if [[ -z "${TEST_SERVER}" ]]; then + echo 'set $TEST_SERVER before running the test suite' >&3 exit 1 fi @@ -36,6 +36,11 @@ setup_suite(){ } teardown_suite(){ + if [[ -z "${ABRA_DIR}" ]]; then + echo 'set $ABRA_DIR before running the test suite' >&3 + exit 1 + fi + if [[ -d "$ABRA_DIR" ]]; then rm -rf "$ABRA_DIR" fi