From d5c66020ad9a63c814d7a9faf39bb08080a8bf88 Mon Sep 17 00:00:00 2001 From: decentral1se Date: Fri, 29 Aug 2025 16:28:06 +0200 Subject: [PATCH] refactor!: --ignore-env-version is --latest *only* on deploy See https://git.coopcloud.tech/toolshed/abra/issues/617 --- cli/app/deploy.go | 20 +++- cli/internal/cli.go | 8 +- cli/internal/ensure.go | 2 +- cli/run.go | 8 -- pkg/i18n/locales/abra.pot | 56 +++++---- pkg/i18n/locales/es.po | 57 +++++---- tests/integration/app_deploy.bats | 110 ++++++++++++++---- tests/integration/app_deploy_env_version.bats | 3 +- tests/integration/app_deploy_overview.bats | 4 +- 9 files changed, 179 insertions(+), 89 deletions(-) diff --git a/cli/app/deploy.go b/cli/app/deploy.go index d88f5087..4176d7ca 100644 --- a/cli/app/deploy.go +++ b/cli/app/deploy.go @@ -262,6 +262,14 @@ func validateArgsAndFlags(args []string) error { return errors.New(i18n.G("cannot use [version] and --chaos together")) } + if len(args) == 2 && args[1] != "" && internal.DeployLatest { + return errors.New(i18n.G("cannot use [version] and --latest together")) + } + + if internal.DeployLatest && internal.Chaos { + return errors.New(i18n.G("cannot use --chaos and --latest together")) + } + return nil } @@ -298,7 +306,7 @@ func getDeployVersion(cliArgs []string, deployMeta stack.DeployMeta, app app.App } // Check if the recipe has a version in the .env file - if app.Recipe.EnvVersion != "" && !internal.IgnoreEnvVersion { + if app.Recipe.EnvVersion != "" && !internal.DeployLatest { if strings.HasSuffix(app.Recipe.EnvVersionRaw, "+U") { return "", errors.New(i18n.G("version: can not redeploy chaos version %s", app.Recipe.EnvVersionRaw)) } @@ -307,7 +315,7 @@ func getDeployVersion(cliArgs []string, deployMeta stack.DeployMeta, app app.App } // Take deployed version - if deployMeta.IsDeployed { + if deployMeta.IsDeployed && !internal.DeployLatest { log.Debug(i18n.G("version: taking deployed version: %s", deployMeta.Version)) return deployMeta.Version, nil } @@ -352,4 +360,12 @@ func init() { false, i18n.G("disable converge logic checks"), ) + + AppDeployCommand.PersistentFlags().BoolVarP( + &internal.DeployLatest, + "latest", + "l", + false, + i18n.G("deploy latest recipe version"), + ) } diff --git a/cli/internal/cli.go b/cli/internal/cli.go index 7c4825ad..e98ddb16 100644 --- a/cli/internal/cli.go +++ b/cli/internal/cli.go @@ -2,13 +2,13 @@ package internal var ( // NOTE(d1): global - Debug bool - NoInput bool - Offline bool - IgnoreEnvVersion bool + Debug bool + NoInput bool + Offline bool // NOTE(d1): sub-command specific Chaos bool + DeployLatest bool DontWaitConverge bool Dry bool Force bool diff --git a/cli/internal/ensure.go b/cli/internal/ensure.go index e0b09924..b239cd27 100644 --- a/cli/internal/ensure.go +++ b/cli/internal/ensure.go @@ -6,6 +6,6 @@ func GetEnsureContext() recipe.EnsureContext { return recipe.EnsureContext{ Chaos, Offline, - IgnoreEnvVersion, + DeployLatest, } } diff --git a/cli/run.go b/cli/run.go index beb3f454..01b490bd 100644 --- a/cli/run.go +++ b/cli/run.go @@ -137,14 +137,6 @@ func Run(version, commit string) { i18n.G("prefer offline & filesystem access"), ) - rootCmd.PersistentFlags().BoolVarP( - &internal.IgnoreEnvVersion, - "ignore-env-version", - "i", - false, - i18n.G("ignore .env version checkout"), - ) - catalogue.CatalogueCommand.AddCommand( catalogue.CatalogueGenerateCommand, catalogue.CatalogueSyncCommand, diff --git a/pkg/i18n/locales/abra.pot b/pkg/i18n/locales/abra.pot index 5a9d3d48..7ffbb978 100644 --- a/pkg/i18n/locales/abra.pot +++ b/pkg/i18n/locales/abra.pot @@ -7,7 +7,7 @@ msgid "" msgstr "Project-Id-Version: \n" "Report-Msgid-Bugs-To: EMAIL\n" - "POT-Creation-Date: 2025-08-29 09:54+0200\n" + "POT-Creation-Date: 2025-08-29 16:31+0200\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -552,7 +552,7 @@ msgstr "" msgid "Both local recipe and live deployment labels are shown." msgstr "" -#: ./cli/app/backup.go:298 ./cli/app/backup.go:314 ./cli/app/check.go:90 ./cli/app/cmd.go:277 ./cli/app/cp.go:381 ./cli/app/deploy.go:327 ./cli/app/labels.go:138 ./cli/app/new.go:368 ./cli/app/ps.go:209 ./cli/app/restart.go:157 ./cli/app/restore.go:134 ./cli/app/secret.go:553 ./cli/app/secret.go:593 ./cli/app/secret.go:617 ./cli/app/secret.go:625 ./cli/catalogue/catalogue.go:309 ./cli/recipe/lint.go:131 ./cli/updater/updater.go:544 +#: ./cli/app/backup.go:298 ./cli/app/backup.go:314 ./cli/app/check.go:90 ./cli/app/cmd.go:277 ./cli/app/cp.go:381 ./cli/app/deploy.go:335 ./cli/app/labels.go:138 ./cli/app/new.go:368 ./cli/app/ps.go:209 ./cli/app/restart.go:157 ./cli/app/restore.go:134 ./cli/app/secret.go:553 ./cli/app/secret.go:593 ./cli/app/secret.go:617 ./cli/app/secret.go:625 ./cli/catalogue/catalogue.go:309 ./cli/recipe/lint.go:131 ./cli/updater/updater.go:544 msgid "C" msgstr "" @@ -693,7 +693,7 @@ msgid "Creates a new app from a default recipe.\n" "on your $PATH." msgstr "" -#: ./cli/app/deploy.go:343 ./cli/app/new.go:344 ./cli/app/rollback.go:332 ./cli/app/upgrade.go:443 +#: ./cli/app/deploy.go:351 ./cli/app/new.go:344 ./cli/app/rollback.go:332 ./cli/app/upgrade.go:443 msgid "D" msgstr "" @@ -1720,7 +1720,7 @@ msgstr "" msgid "broken symlink in your abra config folders: %s" msgstr "" -#: ./cli/app/backup.go:140 ./cli/app/cp.go:31 ./cli/app/deploy.go:351 ./cli/app/rollback.go:340 ./cli/app/upgrade.go:451 +#: ./cli/app/backup.go:140 ./cli/app/cp.go:31 ./cli/app/deploy.go:359 ./cli/app/rollback.go:340 ./cli/app/upgrade.go:451 msgid "c" msgstr "" @@ -1785,6 +1785,10 @@ msgstr "" msgid "cannot use '[secret] [version]' and '--all' together" msgstr "" +#: ./cli/app/deploy.go:270 +msgid "cannot use --chaos and --latest together" +msgstr "" + #: ./cli/app/cmd.go:103 msgid "cannot use --local & --user together" msgstr "" @@ -1809,6 +1813,10 @@ msgstr "" msgid "cannot use [version] and --chaos together" msgstr "" +#: ./cli/app/deploy.go:266 +msgid "cannot use [version] and --latest together" +msgstr "" + #: ./cli/run.go:32 msgid "catalogue" msgstr "" @@ -1834,7 +1842,7 @@ msgstr "" msgid "cfg" msgstr "" -#: ./cli/app/backup.go:297 ./cli/app/backup.go:313 ./cli/app/check.go:89 ./cli/app/cmd.go:276 ./cli/app/cp.go:380 ./cli/app/deploy.go:326 ./cli/app/labels.go:137 ./cli/app/new.go:367 ./cli/app/ps.go:208 ./cli/app/restart.go:156 ./cli/app/restore.go:133 ./cli/app/secret.go:552 ./cli/app/secret.go:592 ./cli/app/secret.go:616 ./cli/app/secret.go:624 ./cli/catalogue/catalogue.go:308 ./cli/recipe/lint.go:130 ./cli/updater/updater.go:543 +#: ./cli/app/backup.go:297 ./cli/app/backup.go:313 ./cli/app/check.go:89 ./cli/app/cmd.go:276 ./cli/app/cp.go:380 ./cli/app/deploy.go:334 ./cli/app/labels.go:137 ./cli/app/new.go:367 ./cli/app/ps.go:208 ./cli/app/restart.go:156 ./cli/app/restore.go:133 ./cli/app/secret.go:552 ./cli/app/secret.go:592 ./cli/app/secret.go:616 ./cli/app/secret.go:624 ./cli/catalogue/catalogue.go:308 ./cli/recipe/lint.go:130 ./cli/updater/updater.go:543 msgid "chaos" msgstr "" @@ -2155,6 +2163,10 @@ msgstr "" msgid "deploy labels stanza present" msgstr "" +#: ./cli/app/deploy.go:369 +msgid "deploy latest recipe version" +msgstr "" + #: ./pkg/upstream/stack/stack.go:637 msgid "deploy succeeded 🟢" msgstr "" @@ -2228,11 +2240,11 @@ msgstr "" msgid "dirty: %v, " msgstr "" -#: ./cli/app/deploy.go:353 ./cli/app/rollback.go:342 ./cli/app/upgrade.go:453 +#: ./cli/app/deploy.go:361 ./cli/app/rollback.go:342 ./cli/app/upgrade.go:453 msgid "disable converge logic checks" msgstr "" -#: ./cli/app/deploy.go:345 ./cli/app/rollback.go:334 ./cli/app/upgrade.go:445 +#: ./cli/app/deploy.go:353 ./cli/app/rollback.go:334 ./cli/app/upgrade.go:445 msgid "disable public DNS checks" msgstr "" @@ -2452,7 +2464,7 @@ msgstr "" msgid "expected 1 service but found %v: %s" msgstr "" -#: ./cli/app/deploy.go:335 ./cli/app/remove.go:158 ./cli/app/rollback.go:324 ./cli/app/secret.go:577 ./cli/app/upgrade.go:435 ./cli/app/volume.go:204 ./cli/recipe/fetch.go:20 ./cli/recipe/fetch.go:133 +#: ./cli/app/deploy.go:343 ./cli/app/remove.go:158 ./cli/app/rollback.go:324 ./cli/app/secret.go:577 ./cli/app/upgrade.go:435 ./cli/app/volume.go:204 ./cli/recipe/fetch.go:20 ./cli/recipe/fetch.go:133 msgid "f" msgstr "" @@ -2648,7 +2660,7 @@ msgstr "" msgid "for %s read env %s with value: %s from docker service" msgstr "" -#: ./cli/app/deploy.go:334 ./cli/app/remove.go:157 ./cli/app/rollback.go:323 ./cli/app/upgrade.go:434 ./cli/app/volume.go:203 ./cli/recipe/fetch.go:132 +#: ./cli/app/deploy.go:342 ./cli/app/remove.go:157 ./cli/app/rollback.go:323 ./cli/app/upgrade.go:434 ./cli/app/volume.go:203 ./cli/recipe/fetch.go:132 msgid "force" msgstr "" @@ -2845,11 +2857,7 @@ msgstr "" msgid "id: %s, " msgstr "" -#: ./cli/run.go:145 -msgid "ignore .env version checkout" -msgstr "" - -#: ./cli/app/backup.go:300 ./cli/app/backup.go:316 ./cli/app/check.go:92 ./cli/app/cmd.go:279 ./cli/app/cp.go:383 ./cli/app/deploy.go:329 ./cli/app/labels.go:140 ./cli/app/new.go:370 ./cli/app/ps.go:211 ./cli/app/restart.go:159 ./cli/app/restore.go:136 ./cli/app/secret.go:555 ./cli/app/secret.go:595 ./cli/app/secret.go:619 ./cli/app/secret.go:627 ./cli/catalogue/catalogue.go:311 ./cli/recipe/lint.go:133 ./cli/updater/updater.go:546 +#: ./cli/app/backup.go:300 ./cli/app/backup.go:316 ./cli/app/check.go:92 ./cli/app/cmd.go:279 ./cli/app/cp.go:383 ./cli/app/deploy.go:337 ./cli/app/labels.go:140 ./cli/app/new.go:370 ./cli/app/ps.go:211 ./cli/app/restart.go:159 ./cli/app/restore.go:136 ./cli/app/secret.go:555 ./cli/app/secret.go:595 ./cli/app/secret.go:619 ./cli/app/secret.go:627 ./cli/catalogue/catalogue.go:311 ./cli/recipe/lint.go:133 ./cli/updater/updater.go:546 msgid "ignore uncommitted recipes changes" msgstr "" @@ -3454,11 +3462,11 @@ msgstr "" msgid "no volumes to remove" msgstr "" -#: ./cli/app/deploy.go:350 ./cli/app/rollback.go:339 ./cli/app/upgrade.go:450 +#: ./cli/app/deploy.go:358 ./cli/app/rollback.go:339 ./cli/app/upgrade.go:450 msgid "no-converge-checks" msgstr "" -#: ./cli/app/deploy.go:342 ./cli/app/rollback.go:331 ./cli/app/upgrade.go:442 +#: ./cli/app/deploy.go:350 ./cli/app/rollback.go:331 ./cli/app/upgrade.go:442 msgid "no-domain-checks" msgstr "" @@ -3590,7 +3598,7 @@ msgstr "" msgid "pattern" msgstr "" -#: ./cli/app/deploy.go:337 ./cli/app/remove.go:160 ./cli/app/rollback.go:326 ./cli/app/upgrade.go:437 ./cli/app/volume.go:206 +#: ./cli/app/deploy.go:345 ./cli/app/remove.go:160 ./cli/app/rollback.go:326 ./cli/app/upgrade.go:437 ./cli/app/volume.go:206 msgid "perform action without further prompt" msgstr "" @@ -4130,7 +4138,7 @@ msgstr "" msgid "secret not found: %s" msgstr "" -#: ./cli/app/deploy.go:276 +#: ./cli/app/deploy.go:284 #, c-format msgid "secret not generated: %s" msgstr "" @@ -5004,32 +5012,32 @@ msgstr "" msgid "version wiped from %s.env" msgstr "" -#: ./cli/app/deploy.go:303 +#: ./cli/app/deploy.go:311 #, c-format msgid "version: can not redeploy chaos version %s" msgstr "" -#: ./cli/app/deploy.go:290 +#: ./cli/app/deploy.go:298 #, c-format msgid "version: taking chaos version: %s" msgstr "" -#: ./cli/app/deploy.go:311 +#: ./cli/app/deploy.go:319 #, c-format msgid "version: taking deployed version: %s" msgstr "" -#: ./cli/app/deploy.go:316 +#: ./cli/app/deploy.go:324 #, c-format msgid "version: taking new recipe version: %s" msgstr "" -#: ./cli/app/deploy.go:305 +#: ./cli/app/deploy.go:313 #, c-format msgid "version: taking version from .env file: %s" msgstr "" -#: ./cli/app/deploy.go:296 +#: ./cli/app/deploy.go:304 #, c-format msgid "version: taking version from cli arg: %s" msgstr "" diff --git a/pkg/i18n/locales/es.po b/pkg/i18n/locales/es.po index 2bb5e0af..13c94f48 100644 --- a/pkg/i18n/locales/es.po +++ b/pkg/i18n/locales/es.po @@ -2,7 +2,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: EMAIL\n" -"POT-Creation-Date: 2025-08-29 09:54+0200\n" +"POT-Creation-Date: 2025-08-29 16:31+0200\n" "PO-Revision-Date: 2025-08-29 08:00+0000\n" "Last-Translator: chasqui \n" "Language-Team: Spanish > $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 + + _reset_recipe + assert_not_exists "$ABRA_DIR/recipes/$TEST_RECIPE/foo" + + run $ABRA app deploy "$TEST_APP_DOMAIN" \ + --no-input --no-converge-checks --force --latest + assert_success + assert_output --partial "$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 latest after undeployed chaos deploy" { + latestRelease=$(_latest_release) + + run bash -c "echo foo >> $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 + + _reset_recipe + assert_not_exists "$ABRA_DIR/recipes/$TEST_RECIPE/foo" + + _undeploy_app + + run $ABRA app deploy "$TEST_APP_DOMAIN" \ + --no-input --no-converge-checks --latest + assert_success + assert_output --partial "$latestRelease" + + run grep -q "TYPE=$TEST_RECIPE:$latestRelease" \ + "$ABRA_DIR/servers/$TEST_SERVER/$TEST_APP_DOMAIN.env" + assert_success +} + @test "chaos version label includes dirty marker" { run bash -c "echo foo >> $ABRA_DIR/recipes/$TEST_RECIPE/foo" assert_success @@ -408,28 +493,7 @@ teardown(){ } # bats test_tags=slow -@test "ignore env version checkout after deploy" { - tagHash=$(_get_tag_hash "0.1.0+1.20.0") - - run $ABRA app deploy "$TEST_APP_DOMAIN" "0.1.0+1.20.0" \ - --no-input --no-converge-checks - assert_success - - assert_equal $(_get_current_hash) "$tagHash" - - run $ABRA app check --ignore-env-version "$TEST_APP_DOMAIN" - assert_success - - assert_equal $(_get_current_hash) "$(_get_head_hash)" - - run $ABRA app check "$TEST_APP_DOMAIN" - assert_success - - assert_equal $(_get_current_hash) "$tagHash" -} - -# bats test_tags=slow -@test "ignore env version on new deploy" { +@test "deploy latest on new deploy" { run $ABRA app deploy "$TEST_APP_DOMAIN" "0.1.0+1.20.0" \ --no-input --no-converge-checks assert_success @@ -439,7 +503,7 @@ teardown(){ latestRelease=$(_latest_release) run $ABRA app deploy "$TEST_APP_DOMAIN" \ - --no-input --no-converge-checks --ignore-env-version + --no-input --no-converge-checks --latest assert_success assert_output --partial "$latestRelease" } diff --git a/tests/integration/app_deploy_env_version.bats b/tests/integration/app_deploy_env_version.bats index e89b79f9..3deea61b 100644 --- a/tests/integration/app_deploy_env_version.bats +++ b/tests/integration/app_deploy_env_version.bats @@ -107,7 +107,8 @@ teardown(){ # bats test_tags=slow @test "takes deployed version when no .env version is present " { - run $ABRA app deploy "$TEST_APP_DOMAIN" "0.1.0+1.20.0" --no-input --no-converge-checks --ignore-env-version + run $ABRA app deploy "$TEST_APP_DOMAIN" "0.1.0+1.20.0" \ + --no-input --no-converge-checks assert_success run grep -q "TYPE=$TEST_RECIPE:0.1.0+1.20.0" \ diff --git a/tests/integration/app_deploy_overview.bats b/tests/integration/app_deploy_overview.bats index 8d5355c8..475c657a 100644 --- a/tests/integration/app_deploy_overview.bats +++ b/tests/integration/app_deploy_overview.bats @@ -86,7 +86,7 @@ teardown(){ assert_success } -@test "deploy, re-deploy, ignore env version" { +@test "deploy, re-deploy, deploy latest" { latestRelease=$(_latest_release) run $ABRA app deploy "$TEST_APP_DOMAIN" "0.1.1+1.20.2" \ @@ -96,7 +96,7 @@ teardown(){ _undeploy_app run $ABRA app deploy "$TEST_APP_DOMAIN" \ - --no-input --no-converge-checks --ignore-env-version + --no-input --no-converge-checks --latest assert_success assert_output --partial 'NEW DEPLOY OVERVIEW'