fix: ps/undeploy and WriteRecipeVersion #444
@ -258,7 +258,7 @@ EXAMPLE:
|
|||||||
app.Recipe.Version = chaosVersion
|
app.Recipe.Version = chaosVersion
|
||||||
}
|
}
|
||||||
log.Debugf("choosing %s as version to save to env file", app.Recipe.Version)
|
log.Debugf("choosing %s as version to save to env file", app.Recipe.Version)
|
||||||
if err := app.WriteRecipeVersion(app.Recipe.Version); err != nil {
|
if err := app.WriteRecipeVersion(app.Recipe.Version, false); err != nil {
|
||||||
log.Fatalf("writing new recipe version in env file: %s", err)
|
log.Fatalf("writing new recipe version in env file: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -219,7 +219,7 @@ var appNewCommand = cli.Command{
|
|||||||
}
|
}
|
||||||
|
|
||||||
log.Debugf("choosing %s as version to save to env file", version)
|
log.Debugf("choosing %s as version to save to env file", version)
|
||||||
if err := app.WriteRecipeVersion(version); err != nil {
|
if err := app.WriteRecipeVersion(version, false); err != nil {
|
||||||
log.Fatalf("writing new recipe version in env file: %s", err)
|
log.Fatalf("writing new recipe version in env file: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,12 +30,14 @@ var appPsCommand = cli.Command{
|
|||||||
Flags: []cli.Flag{
|
Flags: []cli.Flag{
|
||||||
internal.MachineReadableFlag,
|
internal.MachineReadableFlag,
|
||||||
internal.DebugFlag,
|
internal.DebugFlag,
|
||||||
|
internal.ChaosFlag,
|
||||||
|
internal.OfflineFlag,
|
||||||
},
|
},
|
||||||
Before: internal.SubCommandBefore,
|
Before: internal.SubCommandBefore,
|
||||||
BashComplete: autocomplete.AppNameComplete,
|
BashComplete: autocomplete.AppNameComplete,
|
||||||
Action: func(c *cli.Context) error {
|
Action: func(c *cli.Context) error {
|
||||||
app := internal.ValidateApp(c)
|
app := internal.ValidateApp(c)
|
||||||
if err := app.Recipe.Ensure(false, false); err != nil {
|
if err := app.Recipe.Ensure(internal.Chaos, internal.Offline); err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -56,12 +58,7 @@ var appPsCommand = cli.Command{
|
|||||||
chaosVersion := config.CHAOS_DEFAULT
|
chaosVersion := config.CHAOS_DEFAULT
|
||||||
statuses, err := appPkg.GetAppStatuses([]appPkg.App{app}, true)
|
statuses, err := appPkg.GetAppStatuses([]appPkg.App{app}, true)
|
||||||
if statusMeta, ok := statuses[app.StackName()]; ok {
|
if statusMeta, ok := statuses[app.StackName()]; ok {
|
||||||
isChaos, exists := statusMeta["chaos"]
|
if isChaos, exists := statusMeta["chaos"]; exists && isChaos == "true" {
|
||||||
if exists && isChaos == "false" {
|
|
||||||
if _, err := app.Recipe.EnsureVersion(deployMeta.Version); err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
chaosVersion, err = app.Recipe.ChaosVersion()
|
chaosVersion, err = app.Recipe.ChaosVersion()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
|
@ -225,7 +225,7 @@ EXAMPLE:
|
|||||||
|
|
||||||
app.Recipe.Version = chosenDowngrade
|
app.Recipe.Version = chosenDowngrade
|
||||||
log.Debugf("choosing %s as version to save to env file", app.Recipe.Version)
|
log.Debugf("choosing %s as version to save to env file", app.Recipe.Version)
|
||||||
if err := app.WriteRecipeVersion(app.Recipe.Version); err != nil {
|
if err := app.WriteRecipeVersion(app.Recipe.Version, false); err != nil {
|
||||||
log.Fatalf("writing new recipe version in env file: %s", err)
|
log.Fatalf("writing new recipe version in env file: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -68,6 +68,7 @@ var appUndeployCommand = cli.Command{
|
|||||||
Flags: []cli.Flag{
|
Flags: []cli.Flag{
|
||||||
internal.DebugFlag,
|
internal.DebugFlag,
|
||||||
internal.NoInputFlag,
|
internal.NoInputFlag,
|
||||||
|
internal.OfflineFlag,
|
||||||
pruneFlag,
|
pruneFlag,
|
||||||
},
|
},
|
||||||
Before: internal.SubCommandBefore,
|
Before: internal.SubCommandBefore,
|
||||||
@ -82,9 +83,6 @@ any previously attached volumes as eligible for pruning once undeployed.
|
|||||||
Passing "-p/--prune" does not remove those volumes.`,
|
Passing "-p/--prune" does not remove those volumes.`,
|
||||||
Action: func(c *cli.Context) error {
|
Action: func(c *cli.Context) error {
|
||||||
app := internal.ValidateApp(c)
|
app := internal.ValidateApp(c)
|
||||||
if err := app.Recipe.Ensure(internal.Chaos, internal.Offline); err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
stackName := app.StackName()
|
stackName := app.StackName()
|
||||||
|
|
||||||
cl, err := client.New(app.Server)
|
cl, err := client.New(app.Server)
|
||||||
|
@ -286,7 +286,7 @@ EXAMPLE:
|
|||||||
|
|
||||||
app.Recipe.Version = chosenUpgrade
|
app.Recipe.Version = chosenUpgrade
|
||||||
log.Debugf("choosing %s as version to save to env file", app.Recipe.Version)
|
log.Debugf("choosing %s as version to save to env file", app.Recipe.Version)
|
||||||
if err := app.WriteRecipeVersion(app.Recipe.Version); err != nil {
|
if err := app.WriteRecipeVersion(app.Recipe.Version, false); err != nil {
|
||||||
log.Fatalf("writing new recipe version in env file: %s", err)
|
log.Fatalf("writing new recipe version in env file: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -569,7 +569,7 @@ func ReadAbraShCmdNames(abraSh string) ([]string, error) {
|
|||||||
return cmdNames, nil
|
return cmdNames, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a App) WriteRecipeVersion(version string) error {
|
func (a App) WriteRecipeVersion(version string, dryRun bool) error {
|
||||||
file, err := os.Open(a.Path)
|
file, err := os.Open(a.Path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -581,7 +581,7 @@ func (a App) WriteRecipeVersion(version string) error {
|
|||||||
lines := []string{}
|
lines := []string{}
|
||||||
for scanner.Scan() {
|
for scanner.Scan() {
|
||||||
line := scanner.Text()
|
line := scanner.Text()
|
||||||
if !strings.Contains(line, "RECIPE=") && !strings.Contains(line, "TYPE") {
|
if !strings.HasPrefix(line, "RECIPE=") && !strings.HasPrefix(line, "TYPE=") {
|
||||||
lines = append(lines, line)
|
lines = append(lines, line)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@ -606,8 +606,12 @@ func (a App) WriteRecipeVersion(version string) error {
|
|||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := os.WriteFile(a.Path, []byte(strings.Join(lines, "\n")), os.ModePerm); err != nil {
|
if !dryRun {
|
||||||
log.Fatal(err)
|
if err := os.WriteFile(a.Path, []byte(strings.Join(lines, "\n")), os.ModePerm); err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
log.Debugf("skipping writing version %s because dry run", version)
|
||||||
}
|
}
|
||||||
|
|
||||||
if !skipped {
|
if !skipped {
|
||||||
|
@ -11,6 +11,7 @@ import (
|
|||||||
"coopcloud.tech/abra/pkg/envfile"
|
"coopcloud.tech/abra/pkg/envfile"
|
||||||
"coopcloud.tech/abra/pkg/recipe"
|
"coopcloud.tech/abra/pkg/recipe"
|
||||||
testPkg "coopcloud.tech/abra/pkg/test"
|
testPkg "coopcloud.tech/abra/pkg/test"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestGetAllFoldersInDirectory(t *testing.T) {
|
func TestGetAllFoldersInDirectory(t *testing.T) {
|
||||||
@ -43,13 +44,7 @@ func TestReadEnv(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
if !reflect.DeepEqual(env, testPkg.ExpectedAppEnv) {
|
if !reflect.DeepEqual(env, testPkg.ExpectedAppEnv) {
|
||||||
t.Fatalf(
|
t.Fatal("did not get expected application settings")
|
||||||
"did not get expected application settings. Expected: DOMAIN=%s RECIPE=%s; Got: DOMAIN=%s RECIPE=%s",
|
|
||||||
testPkg.ExpectedAppEnv["DOMAIN"],
|
|
||||||
testPkg.ExpectedAppEnv["RECIPE"],
|
|
||||||
env["DOMAIN"],
|
|
||||||
env["RECIPE"],
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -228,3 +223,21 @@ func TestEnvVarModifiersIncluded(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestNoOverwriteNonVersionEnvVars(t *testing.T) {
|
||||||
|
app, err := appPkg.GetApp(testPkg.ExpectedAppFiles, testPkg.AppName)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := app.WriteRecipeVersion("1.3.12", true); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
app, err = appPkg.GetApp(testPkg.ExpectedAppFiles, testPkg.AppName)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.NotEqual(t, app.Env["SMTP_AUTHTYPE"], "login:1.3.12")
|
||||||
|
}
|
||||||
|
@ -27,8 +27,9 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var ExpectedAppEnv = envfile.AppEnv{
|
var ExpectedAppEnv = envfile.AppEnv{
|
||||||
"DOMAIN": "ecloud.evil.corp",
|
"DOMAIN": "ecloud.evil.corp",
|
||||||
"RECIPE": "ecloud",
|
"RECIPE": "ecloud",
|
||||||
|
"SMTP_AUTHTYPE": "login",
|
||||||
}
|
}
|
||||||
|
|
||||||
var ExpectedApp = appPkg.App{
|
var ExpectedApp = appPkg.App{
|
||||||
|
@ -31,6 +31,84 @@ teardown(){
|
|||||||
assert_output --partial 'cannot find app'
|
assert_output --partial 'cannot find app'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# bats test_tags=slow
|
||||||
|
@test "retrieve recipe if missing" {
|
||||||
|
_deploy_app
|
||||||
|
|
||||||
|
run rm -rf "$ABRA_DIR/recipes/$TEST_RECIPE"
|
||||||
|
assert_success
|
||||||
|
assert_not_exists "$ABRA_DIR/recipes/$TEST_RECIPE"
|
||||||
|
|
||||||
|
run $ABRA app ps "$TEST_APP_DOMAIN"
|
||||||
|
assert_success
|
||||||
|
|
||||||
|
assert_exists "$ABRA_DIR/recipes/$TEST_RECIPE"
|
||||||
|
}
|
||||||
|
|
||||||
|
# bats test_tags=slow
|
||||||
|
@test "bail if unstaged changes and no --chaos" {
|
||||||
|
_deploy_app
|
||||||
|
|
||||||
|
run bash -c "echo foo >> $ABRA_DIR/recipes/$TEST_RECIPE/foo"
|
||||||
|
assert_success
|
||||||
|
assert_exists "$ABRA_DIR/recipes/$TEST_RECIPE/foo"
|
||||||
|
|
||||||
|
run $ABRA app ps "$TEST_APP_DOMAIN"
|
||||||
|
assert_failure
|
||||||
|
assert_output --partial 'locally unstaged changes'
|
||||||
|
|
||||||
|
run rm -rf "$ABRA_DIR/recipes/$TEST_RECIPE/foo"
|
||||||
|
assert_not_exists "$ABRA_DIR/recipes/$TEST_RECIPE/foo"
|
||||||
|
}
|
||||||
|
|
||||||
|
# bats test_tags=slow
|
||||||
|
@test "do not bail if unstaged changes and --chaos" {
|
||||||
|
_deploy_app
|
||||||
|
|
||||||
|
run bash -c "echo foo >> $ABRA_DIR/recipes/$TEST_RECIPE/foo"
|
||||||
|
assert_success
|
||||||
|
assert_exists "$ABRA_DIR/recipes/$TEST_RECIPE/foo"
|
||||||
|
|
||||||
|
run $ABRA app ps --chaos "$TEST_APP_DOMAIN"
|
||||||
|
assert_success
|
||||||
|
|
||||||
|
run rm -rf "$ABRA_DIR/recipes/$TEST_RECIPE/foo"
|
||||||
|
assert_not_exists "$ABRA_DIR/recipes/$TEST_RECIPE/foo"
|
||||||
|
}
|
||||||
|
|
||||||
|
# bats test_tags=slow
|
||||||
|
@test "ensure recipe up to date if no --offline" {
|
||||||
|
_deploy_app
|
||||||
|
|
||||||
|
wantHash=$(_get_n_hash 3)
|
||||||
|
|
||||||
|
run git -C "$ABRA_DIR/recipes/$TEST_RECIPE" reset --hard HEAD~3
|
||||||
|
assert_success
|
||||||
|
|
||||||
|
assert_equal $(_get_current_hash) "$wantHash"
|
||||||
|
|
||||||
|
run $ABRA app ps "$TEST_APP_DOMAIN"
|
||||||
|
assert_success
|
||||||
|
|
||||||
|
assert_equal $(_get_head_hash) $(_get_current_hash)
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "ensure recipe not up to date if --offline" {
|
||||||
|
_deploy_app
|
||||||
|
|
||||||
|
_ensure_env_version "0.1.0+1.20.0"
|
||||||
|
latestRelease=$(_latest_release)
|
||||||
|
|
||||||
|
run git -C "$ABRA_DIR/recipes/$TEST_RECIPE" tag -d "$latestRelease"
|
||||||
|
assert_success
|
||||||
|
|
||||||
|
run $ABRA app ps --offline "$TEST_APP_DOMAIN"
|
||||||
|
assert_success
|
||||||
|
|
||||||
|
run git -C "$ABRA_DIR/recipes/$TEST_RECIPE" tag -l
|
||||||
|
refute_output --partial "$latestRelease"
|
||||||
|
}
|
||||||
|
|
||||||
@test "error if not deployed" {
|
@test "error if not deployed" {
|
||||||
run $ABRA app ps "$TEST_APP_DOMAIN"
|
run $ABRA app ps "$TEST_APP_DOMAIN"
|
||||||
assert_failure
|
assert_failure
|
||||||
|
@ -18,6 +18,7 @@ setup(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
teardown(){
|
teardown(){
|
||||||
|
_reset_recipe
|
||||||
_undeploy_app
|
_undeploy_app
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -31,12 +32,61 @@ teardown(){
|
|||||||
assert_output --partial 'cannot find app'
|
assert_output --partial 'cannot find app'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# bats test_tags=slow
|
||||||
|
@test "ensure recipe up to date if no --offline" {
|
||||||
|
_deploy_app
|
||||||
|
|
||||||
|
wantHash=$(_get_n_hash 3)
|
||||||
|
|
||||||
|
run git -C "$ABRA_DIR/recipes/$TEST_RECIPE" reset --hard HEAD~3
|
||||||
|
assert_success
|
||||||
|
|
||||||
|
assert_equal $(_get_current_hash) "$wantHash"
|
||||||
|
|
||||||
|
run $ABRA app undeploy "$TEST_APP_DOMAIN" --no-input
|
||||||
|
assert_success
|
||||||
|
|
||||||
|
assert_equal $(_get_head_hash) $(_get_current_hash)
|
||||||
|
}
|
||||||
|
|
||||||
|
# bats test_tags=slow
|
||||||
|
@test "ensure recipe not up to date if --offline" {
|
||||||
|
_deploy_app
|
||||||
|
|
||||||
|
_ensure_env_version "0.1.0+1.20.0"
|
||||||
|
latestRelease=$(_latest_release)
|
||||||
|
|
||||||
|
run git -C "$ABRA_DIR/recipes/$TEST_RECIPE" tag -d "$latestRelease"
|
||||||
|
assert_success
|
||||||
|
|
||||||
|
run $ABRA app undeploy "$TEST_APP_DOMAIN" --no-input --offline
|
||||||
|
assert_success
|
||||||
|
|
||||||
|
run git -C "$ABRA_DIR/recipes/$TEST_RECIPE" tag -l
|
||||||
|
refute_output --partial "$latestRelease"
|
||||||
|
}
|
||||||
|
|
||||||
@test "error if not deployed" {
|
@test "error if not deployed" {
|
||||||
run $ABRA app undeploy "$TEST_APP_DOMAIN"
|
run $ABRA app undeploy "$TEST_APP_DOMAIN"
|
||||||
assert_failure
|
assert_failure
|
||||||
assert_output --partial 'is not deployed'
|
assert_output --partial 'is not deployed'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# bats test_tags=slow
|
||||||
|
@test "do not bail if unstaged changes (only query runtime)" {
|
||||||
|
_deploy_app
|
||||||
|
|
||||||
|
run bash -c "echo foo >> $ABRA_DIR/recipes/$TEST_RECIPE/foo"
|
||||||
|
assert_success
|
||||||
|
assert_exists "$ABRA_DIR/recipes/$TEST_RECIPE/foo"
|
||||||
|
|
||||||
|
run $ABRA app undeploy "$TEST_APP_DOMAIN" --no-input
|
||||||
|
assert_success
|
||||||
|
|
||||||
|
run rm -rf "$ABRA_DIR/recipes/$TEST_RECIPE/foo"
|
||||||
|
assert_not_exists "$ABRA_DIR/recipes/$TEST_RECIPE/foo"
|
||||||
|
}
|
||||||
|
|
||||||
# bats test_tags=slow
|
# bats test_tags=slow
|
||||||
@test "undeploy app" {
|
@test "undeploy app" {
|
||||||
run $ABRA app deploy "$TEST_APP_DOMAIN" --no-input
|
run $ABRA app deploy "$TEST_APP_DOMAIN" --no-input
|
||||||
|
@ -1,2 +1,3 @@
|
|||||||
RECIPE=ecloud
|
RECIPE=ecloud
|
||||||
DOMAIN=ecloud.evil.corp
|
DOMAIN=ecloud.evil.corp
|
||||||
|
SMTP_AUTHTYPE=login
|
||||||
|
Loading…
x
Reference in New Issue
Block a user