This commit is contained in:
parent
e5a6dea10c
commit
8b8e158664
@ -64,7 +64,7 @@ EXAMPLE:
|
||||
app.Recipe.Version = specificVersion
|
||||
}
|
||||
|
||||
if specificVersion == "" && app.Recipe.Version != "" {
|
||||
if specificVersion == "" && app.Recipe.Version != "" && !internal.Chaos {
|
||||
log.Debugf("retrieved %s as version from env file", app.Recipe.Version)
|
||||
specificVersion = app.Recipe.Version
|
||||
}
|
||||
|
@ -160,6 +160,7 @@ var appSecretInsertCommand = cli.Command{
|
||||
internal.PassFlag,
|
||||
internal.FileFlag,
|
||||
internal.TrimFlag,
|
||||
internal.ChaosFlag,
|
||||
},
|
||||
Before: internal.SubCommandBefore,
|
||||
ArgsUsage: "<domain> <secret-name> <version> <data>",
|
||||
|
@ -61,7 +61,6 @@ var recipeVersionCommand = cli.Command{
|
||||
log.Fatalf("%s has no published versions?", recipe.Name)
|
||||
}
|
||||
|
||||
var allRows [][]string
|
||||
for i := len(recipeMeta.Versions) - 1; i >= 0; i-- {
|
||||
table, err := formatter.CreateTable()
|
||||
if err != nil {
|
||||
@ -71,6 +70,7 @@ var recipeVersionCommand = cli.Command{
|
||||
table.Headers("SERVICE", "NAME", "TAG")
|
||||
|
||||
for version, meta := range recipeMeta.Versions[i] {
|
||||
var allRows [][]string
|
||||
var rows [][]string
|
||||
|
||||
for service, serviceMeta := range meta {
|
||||
@ -86,6 +86,18 @@ var recipeVersionCommand = cli.Command{
|
||||
fmt.Println(table)
|
||||
log.Infof("VERSION: %s", version)
|
||||
fmt.Println()
|
||||
continue
|
||||
}
|
||||
|
||||
if internal.MachineReadable {
|
||||
sort.Slice(allRows, sortServiceByName(allRows))
|
||||
headers := []string{"VERSION", "SERVICE", "NAME", "TAG"}
|
||||
out, err := formatter.ToJSON(headers, allRows)
|
||||
if err != nil {
|
||||
log.Fatal("unable to render to JSON: %s", err)
|
||||
}
|
||||
fmt.Println(out)
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -96,17 +108,6 @@ var recipeVersionCommand = cli.Command{
|
||||
}
|
||||
}
|
||||
|
||||
if internal.MachineReadable {
|
||||
sort.Slice(allRows, sortServiceByName(allRows))
|
||||
headers := []string{"VERSION", "SERVICE", "NAME", "TAG"}
|
||||
out, err := formatter.ToJSON(headers, allRows)
|
||||
if err != nil {
|
||||
log.Fatal("unable to render to JSON: %s", err)
|
||||
}
|
||||
fmt.Println(out)
|
||||
return nil
|
||||
}
|
||||
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
@ -576,6 +576,7 @@ func (a App) WriteRecipeVersion(version string) error {
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
skipped := false
|
||||
scanner := bufio.NewScanner(file)
|
||||
lines := []string{}
|
||||
for scanner.Scan() {
|
||||
@ -590,6 +591,12 @@ func (a App) WriteRecipeVersion(version string) error {
|
||||
continue
|
||||
}
|
||||
|
||||
if strings.Contains(line, version) {
|
||||
skipped = true
|
||||
lines = append(lines, line)
|
||||
continue
|
||||
}
|
||||
|
||||
splitted := strings.Split(line, ":")
|
||||
line = fmt.Sprintf("%s:%s", splitted[0], version)
|
||||
lines = append(lines, line)
|
||||
@ -603,7 +610,11 @@ func (a App) WriteRecipeVersion(version string) error {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
log.Infof("version %s saved to %s.env", version, a.Domain)
|
||||
if !skipped {
|
||||
log.Infof("version %s saved to %s.env", version, a.Domain)
|
||||
} else {
|
||||
log.Debugf("skipping version %s write as already exists in %s.env", version, a.Domain)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -69,7 +69,7 @@ func ToJSON(headers []string, rows [][]string) (string, error) {
|
||||
|
||||
buff.Write([]byte("["))
|
||||
|
||||
for _, row := range rows {
|
||||
for idx, row := range rows {
|
||||
payload := make(map[string]string)
|
||||
|
||||
for idx, header := range headers {
|
||||
@ -82,6 +82,10 @@ func ToJSON(headers []string, rows [][]string) (string, error) {
|
||||
}
|
||||
|
||||
buff.Write(serialized)
|
||||
|
||||
if idx < (len(rows) - 1) {
|
||||
buff.Write([]byte(","))
|
||||
}
|
||||
}
|
||||
|
||||
buff.Write([]byte("]"))
|
||||
|
@ -26,21 +26,26 @@ func (r Recipe) Ensure(chaos bool, offline bool) error {
|
||||
if err := r.EnsureIsClean(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if !offline {
|
||||
if err := r.EnsureUpToDate(); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
if r.Version != "" {
|
||||
log.Debugf("ensuring version %s", r.Version)
|
||||
if _, err := r.EnsureVersion(r.Version); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
if err := r.EnsureLatest(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
if err := r.EnsureLatest(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -20,6 +20,7 @@ setup(){
|
||||
|
||||
teardown(){
|
||||
_reset_recipe
|
||||
_reset_tags
|
||||
}
|
||||
|
||||
@test "validate app argument" {
|
||||
@ -82,19 +83,17 @@ teardown(){
|
||||
}
|
||||
|
||||
@test "ensure recipe not up to date if --offline" {
|
||||
wantHash=$(_get_n_hash 1)
|
||||
_ensure_env_version "0.1.0+1.20.0"
|
||||
latestRelease=$(_latest_release)
|
||||
|
||||
run git -C "$ABRA_DIR/recipes/$TEST_RECIPE" reset --hard HEAD~1
|
||||
run git -C "$ABRA_DIR/recipes/$TEST_RECIPE" tag -d "$latestRelease"
|
||||
assert_success
|
||||
|
||||
assert_equal $(_get_current_hash) "$wantHash"
|
||||
|
||||
# NOTE(d1): we can't quite tell if this will fail or not in the future, so,
|
||||
# since it isn't an important part of what we're testing here, we don't check
|
||||
# it
|
||||
# NOTE(d1): don't assert success because it might flake
|
||||
run $ABRA app check "$TEST_APP_DOMAIN" --offline
|
||||
|
||||
assert_equal $(_get_current_hash) "$wantHash"
|
||||
run git -C "$ABRA_DIR/recipes/$TEST_RECIPE" tag -l
|
||||
refute_output --partial "$latestRelease"
|
||||
}
|
||||
|
||||
@test "error if missing .env.sample" {
|
||||
|
@ -19,8 +19,9 @@ setup(){
|
||||
}
|
||||
|
||||
teardown(){
|
||||
_undeploy_app
|
||||
_reset_recipe
|
||||
_reset_tags
|
||||
_undeploy_app
|
||||
}
|
||||
|
||||
# bats test_tags=slow
|
||||
@ -105,20 +106,18 @@ test_cmd_export"
|
||||
}
|
||||
|
||||
@test "ensure recipe not up to date if --offline" {
|
||||
wantHash=$(_get_n_hash 3)
|
||||
_ensure_env_version "0.1.0+1.20.0"
|
||||
latestRelease=$(_latest_release)
|
||||
|
||||
run git -C "$ABRA_DIR/recipes/$TEST_RECIPE" reset --hard HEAD~3
|
||||
run git -C "$ABRA_DIR/recipes/$TEST_RECIPE" tag -d "$latestRelease"
|
||||
assert_success
|
||||
|
||||
assert_equal $(_get_current_hash) "$wantHash"
|
||||
|
||||
run $ABRA app cmd --local --offline "$TEST_APP_DOMAIN" test_cmd
|
||||
assert_success
|
||||
assert_output --partial 'baz'
|
||||
|
||||
assert_equal $(_get_current_hash) $wantHash
|
||||
|
||||
_reset_recipe "$TEST_RECIPE"
|
||||
run git -C "$ABRA_DIR/recipes/$TEST_RECIPE" tag -l
|
||||
refute_output --partial "$latestRelease"
|
||||
}
|
||||
|
||||
@test "error if missing arguments without passing --local" {
|
||||
|
@ -87,19 +87,18 @@ teardown(){
|
||||
|
||||
# bats test_tags=slow
|
||||
@test "ensure recipe not up to date if --offline" {
|
||||
wantHash=$(_get_n_hash 3)
|
||||
_ensure_env_version "0.1.0+1.20.0"
|
||||
latestRelease=$(_latest_release)
|
||||
|
||||
run git -C "$ABRA_DIR/recipes/$TEST_RECIPE" reset --hard HEAD~3
|
||||
run git -C "$ABRA_DIR/recipes/$TEST_RECIPE" tag -d "$latestRelease"
|
||||
assert_success
|
||||
|
||||
assert_equal $(_get_current_hash) "$wantHash"
|
||||
|
||||
# NOTE(d1): need to use --chaos to force same commit
|
||||
run $ABRA app deploy "$TEST_APP_DOMAIN" \
|
||||
--no-input --no-converge-checks --chaos --offline
|
||||
--no-input --no-converge-checks --offline
|
||||
assert_success
|
||||
|
||||
assert_equal $(_get_current_hash) "$wantHash"
|
||||
run git -C "$ABRA_DIR/recipes/$TEST_RECIPE" tag -l
|
||||
refute_output --partial "$latestRelease"
|
||||
}
|
||||
|
||||
# bats test_tags=slow
|
||||
@ -107,6 +106,7 @@ teardown(){
|
||||
latestCommit="$(git -C "$ABRA_DIR/recipes/$TEST_RECIPE" rev-parse --short HEAD)"
|
||||
|
||||
_remove_tags
|
||||
_wipe_env_version
|
||||
|
||||
# NOTE(d1): need to pass --offline to stop tags being pulled again
|
||||
run $ABRA app deploy "$TEST_APP_DOMAIN" \
|
||||
@ -126,6 +126,8 @@ teardown(){
|
||||
|
||||
assert_equal $(_get_current_hash) "$wantHash"
|
||||
|
||||
_wipe_env_version
|
||||
|
||||
run $ABRA app deploy "$TEST_APP_DOMAIN" \
|
||||
--no-input --no-converge-checks --chaos
|
||||
assert_success
|
||||
|
@ -67,8 +67,7 @@ teardown(){
|
||||
run $ABRA app deploy "$TEST_APP_DOMAIN" --no-input --no-converge-checks
|
||||
assert_success
|
||||
|
||||
latestRelease=$(git -C "$ABRA_DIR/recipes/$TEST_RECIPE" tag -l | tail -n 1)
|
||||
run grep -q "TYPE=git.coopcloud.tech\/coop-cloud\/abra-test-recipe:$latestRelease" \
|
||||
run grep -q "TYPE=git.coopcloud.tech\/coop-cloud\/abra-test-recipe:$(_latest_release)" \
|
||||
"$ABRA_DIR/servers/$TEST_SERVER/$TEST_APP_DOMAIN.env"
|
||||
assert_success
|
||||
}
|
||||
|
@ -62,8 +62,8 @@ teardown(){
|
||||
|
||||
run $ABRA app ls --server foo.com
|
||||
assert_success
|
||||
refute_output --partial "server: $TEST_SERVER |"
|
||||
assert_output --partial "server: foo.com |"
|
||||
refute_output --partial "SERVER: $TEST_SERVER"
|
||||
assert_output --partial "SERVER: foo.com"
|
||||
|
||||
run rm -rf "$ABRA_DIR/servers/foo.com"
|
||||
assert_success
|
||||
@ -97,8 +97,8 @@ teardown(){
|
||||
@test "server stats are correct" {
|
||||
run $ABRA app ls
|
||||
assert_success
|
||||
assert_output --partial "server: $TEST_SERVER"
|
||||
assert_output --partial "total apps: 1"
|
||||
assert_output --partial "SERVER: $TEST_SERVER"
|
||||
assert_output --partial "TOTAL APPS: 1"
|
||||
|
||||
run mkdir -p "$ABRA_DIR/servers/foo.com"
|
||||
assert_success
|
||||
@ -113,8 +113,8 @@ teardown(){
|
||||
assert_success
|
||||
assert_output --partial "$TEST_SERVER"
|
||||
assert_output --partial "foo.com"
|
||||
assert_output --partial "total servers: 2"
|
||||
assert_output --partial "total apps: 2"
|
||||
assert_output --partial "TOTAL SERVERS: 2"
|
||||
assert_output --partial "TOTAL APPS: 2"
|
||||
|
||||
run rm -rf "$ABRA_DIR/servers/foo.com"
|
||||
assert_success
|
||||
|
@ -40,8 +40,7 @@ teardown(){
|
||||
_get_current_hash
|
||||
assert_equal "$headHash" "$currentHash"
|
||||
|
||||
latestRelease=$(git -C "$ABRA_DIR/recipes/$TEST_RECIPE" tag -l | tail -n 1)
|
||||
run grep -q "TYPE=$TEST_RECIPE:$latestRelease" \
|
||||
run grep -q "TYPE=$TEST_RECIPE:$(_latest_release)" \
|
||||
"$ABRA_DIR/servers/$TEST_SERVER/$TEST_APP_DOMAIN.env"
|
||||
assert_success
|
||||
}
|
||||
|
@ -41,13 +41,11 @@ teardown(){
|
||||
@test "show ps report" {
|
||||
_deploy_app
|
||||
|
||||
latestRelease=$(git -C "$ABRA_DIR/recipes/$TEST_RECIPE" tag -l | tail -n 1)
|
||||
|
||||
run $ABRA app ps "$TEST_APP_DOMAIN"
|
||||
assert_success
|
||||
assert_output --partial 'app'
|
||||
assert_output --partial 'healthy'
|
||||
assert_output --partial "$latestRelease"
|
||||
assert_output --partial $(_latest_release)
|
||||
assert_output --partial 'false' # not a chaos deploy
|
||||
}
|
||||
|
||||
|
@ -58,18 +58,18 @@ teardown(){
|
||||
}
|
||||
|
||||
@test "ensure recipe not up to date if --offline" {
|
||||
wantHash=$(_get_n_hash 3)
|
||||
_ensure_env_version "0.1.0+1.20.0"
|
||||
latestRelease=$(_latest_release)
|
||||
|
||||
run git -C "$ABRA_DIR/recipes/$TEST_RECIPE" reset --hard HEAD~3
|
||||
run git -C "$ABRA_DIR/recipes/$TEST_RECIPE" tag -d "$latestRelease"
|
||||
assert_success
|
||||
|
||||
assert_equal $(_get_current_hash) "$wantHash"
|
||||
|
||||
run $ABRA app rollback "$TEST_APP_DOMAIN" \
|
||||
--no-input --no-converge-checks --offline
|
||||
assert_failure
|
||||
|
||||
assert_equal $(_get_current_hash) $wantHash
|
||||
run git -C "$ABRA_DIR/recipes/$TEST_RECIPE" tag -l
|
||||
refute_output --partial "$latestRelease"
|
||||
}
|
||||
|
||||
@test "error if not already deployed" {
|
||||
|
@ -217,7 +217,8 @@ teardown(){
|
||||
run bash -c "echo bar >> $ABRA_DIR/recipes/$TEST_RECIPE/foo"
|
||||
|
||||
run $ABRA app secret insert \
|
||||
--file "$TEST_APP_DOMAIN" test_pass_one v1 "$ABRA_DIR/recipes/$TEST_RECIPE/foo"
|
||||
--chaos \
|
||||
--file "$TEST_APP_DOMAIN" test_pass_one v1 "$ABRA_DIR/recipes/$TEST_RECIPE/foo"
|
||||
assert_success
|
||||
assert_output --partial 'successfully stored on server'
|
||||
|
||||
@ -317,9 +318,10 @@ teardown(){
|
||||
run $ABRA app secret generate "$TEST_APP_DOMAIN" --all
|
||||
assert_success
|
||||
|
||||
run $ABRA app secret ls "$TEST_APP_DOMAIN" --machine
|
||||
run bash -c '$ABRA app secret ls "$TEST_APP_DOMAIN" --machine \
|
||||
| jq -r ".[] | select(.name==\"test_pass_two\") | .version"'
|
||||
assert_success
|
||||
assert_output --partial '"created-on-server":"true"'
|
||||
assert_output --partial 'v1'
|
||||
}
|
||||
|
||||
@test "ls: bail if unstaged changes and no --chaos" {
|
||||
|
@ -64,8 +64,8 @@ teardown(){
|
||||
|
||||
run sed -i 's/TYPE=abra-test-recipe:.*/TYPE=abra-test-recipe:0.2.0+1.21.0/g' \
|
||||
"$ABRA_DIR/servers/$TEST_SERVER/$TEST_APP_DOMAIN.env"
|
||||
|
||||
assert_success
|
||||
|
||||
run $ABRA app secret generate "$TEST_APP_DOMAIN" --all
|
||||
assert_success
|
||||
|
||||
@ -80,6 +80,7 @@ teardown(){
|
||||
|
||||
run sed -i 's/TYPE=abra-test-recipe:.*/TYPE=abra-test-recipe:0.2.0+1.21.0/g' \
|
||||
"$ABRA_DIR/servers/$TEST_SERVER/$TEST_APP_DOMAIN.env"
|
||||
assert_success
|
||||
|
||||
run $ABRA app secret generate "$TEST_APP_DOMAIN" --all
|
||||
assert_success
|
||||
|
@ -18,8 +18,9 @@ setup(){
|
||||
}
|
||||
|
||||
teardown(){
|
||||
_undeploy_app
|
||||
_reset_recipe
|
||||
_reset_app
|
||||
_undeploy_app
|
||||
}
|
||||
|
||||
@test "validate app argument" {
|
||||
@ -123,11 +124,9 @@ teardown(){
|
||||
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 "$(_latest_release)"
|
||||
}
|
||||
|
||||
# bats test_tags=slow
|
||||
@ -136,11 +135,9 @@ teardown(){
|
||||
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 "$(_latest_release)"
|
||||
assert_output --partial 'release notes baz' # 0.2.0+1.21.0
|
||||
refute_output --partial 'release notes bar' # 0.1.1+1.20.2
|
||||
}
|
||||
@ -164,11 +161,9 @@ teardown(){
|
||||
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 "$(_latest_release)"
|
||||
assert_output --partial 'release notes bar' # 0.1.1+1.20.2
|
||||
assert_output --partial 'release notes baz' # 0.2.0+1.21.0
|
||||
}
|
||||
|
@ -1,5 +1,9 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
_latest_release(){
|
||||
echo $(git -C "$ABRA_DIR/recipes/$TEST_RECIPE" tag -l | tail -n 1)
|
||||
}
|
||||
|
||||
_fetch_recipe() {
|
||||
if [[ ! -d "$ABRA_DIR/recipes/$TEST_RECIPE" ]]; then
|
||||
run mkdir -p "$ABRA_DIR/recipes"
|
||||
@ -19,7 +23,7 @@ _reset_recipe(){
|
||||
}
|
||||
|
||||
_ensure_latest_version(){
|
||||
latestRelease=$(git -C "$ABRA_DIR/recipes/$TEST_RECIPE" tag -l | tail -n 1)
|
||||
latestRelease=$(_latest_release)
|
||||
|
||||
if [ ! $latestRelease = "$1" ]; then
|
||||
echo "expected latest recipe version of '$1', saw: $latestRelease"
|
||||
@ -33,3 +37,15 @@ _ensure_catalogue(){
|
||||
assert_success
|
||||
fi
|
||||
}
|
||||
|
||||
_ensure_env_version(){
|
||||
run sed -i 's/TYPE=abra-test-recipe:.*/TYPE=abra-test-recipe:$1/g' \
|
||||
"$ABRA_DIR/servers/$TEST_SERVER/$TEST_APP_DOMAIN.env"
|
||||
assert_success
|
||||
}
|
||||
|
||||
_wipe_env_version(){
|
||||
run sed -i 's/TYPE=abra-test-recipe:.*/TYPE=abra-test-recipe/g' \
|
||||
"$ABRA_DIR/servers/$TEST_SERVER/$TEST_APP_DOMAIN.env"
|
||||
assert_success
|
||||
}
|
||||
|
@ -1,10 +1,17 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
setup_file(){
|
||||
load "$PWD/tests/integration/helpers/common"
|
||||
_common_setup
|
||||
_ensure_catalogue
|
||||
}
|
||||
|
||||
setup() {
|
||||
load "$PWD/tests/integration/helpers/common"
|
||||
_common_setup
|
||||
}
|
||||
|
||||
|
||||
@test "recipe versions" {
|
||||
run $ABRA recipe versions gitea
|
||||
assert_success
|
||||
@ -12,11 +19,9 @@ setup() {
|
||||
}
|
||||
|
||||
@test "local tags used if no catalogue entry" {
|
||||
latestRelease=$(git -C "$ABRA_DIR/recipes/$TEST_RECIPE" tag -l | tail -n 1)
|
||||
|
||||
run $ABRA recipe versions "$TEST_RECIPE"
|
||||
assert_success
|
||||
assert_output --partial "$latestRelease"
|
||||
assert_output --partial "$(_latest_release)"
|
||||
}
|
||||
|
||||
@test "versions listed in correct order" {
|
||||
|
@ -66,7 +66,6 @@ teardown(){
|
||||
fi
|
||||
|
||||
output=$("$ABRA" server ls --machine)
|
||||
|
||||
run diff \
|
||||
<(jq -S "." <(echo "$output")) \
|
||||
<(jq -S "." <(echo '[{"host":"local","name":"default"}]'))
|
||||
|
Loading…
x
Reference in New Issue
Block a user