fix: app version includes tags, sorts & tests
continuous-integration/drone/push Build is passing Details

See coop-cloud/organising#442
This commit is contained in:
decentral1se 2023-09-24 11:18:56 +02:00
parent bf648eeb5d
commit f3ded88ed8
Signed by: decentral1se
GPG Key ID: 03789458B3D0C410
2 changed files with 51 additions and 16 deletions

View File

@ -2,6 +2,7 @@ package app
import (
"context"
"sort"
"coopcloud.tech/abra/cli/internal"
"coopcloud.tech/abra/pkg/autocomplete"
@ -10,10 +11,21 @@ import (
"coopcloud.tech/abra/pkg/recipe"
"coopcloud.tech/abra/pkg/upstream/stack"
"github.com/docker/distribution/reference"
"github.com/olekukonko/tablewriter"
"github.com/sirupsen/logrus"
"github.com/urfave/cli"
)
func sortServiceByName(versions [][]string) func(i, j int) bool {
return func(i, j int) bool {
// NOTE(d1): corresponds to the `tableCol` definition below
if versions[i][1] == "app" {
return true
}
return versions[i][1] < versions[j][1]
}
}
// getImagePath returns the image name
func getImagePath(image string) (string, error) {
img, err := reference.ParseNormalizedNamed(image)
@ -39,13 +51,8 @@ var appVersionCommand = cli.Command{
internal.NoInputFlag,
internal.OfflineFlag,
},
Before: internal.SubCommandBefore,
Usage: "Show app versions",
Description: `
Show all information about versioning related to a deployed app. This includes
the individual image names, tags and digests. But also the Co-op Cloud recipe
version.
`,
Before: internal.SubCommandBefore,
Usage: "Show version info of a deployed app",
BashComplete: autocomplete.AppNameComplete,
Action: func(c *cli.Context) error {
app := internal.ValidateApp(c)
@ -87,14 +94,22 @@ version.
logrus.Fatalf("could not retrieve deployed version (%s) from recipe catalogue?", deployedVersion)
}
tableCol := []string{"version", "service", "image"}
tableCol := []string{"version", "service", "image", "tag"}
table := formatter.CreateTable(tableCol)
table.SetAutoMergeCellsByColumnIndex([]int{0})
var versions [][]string
for serviceName, versionMeta := range versionsMeta {
table.Append([]string{deployedVersion, serviceName, versionMeta.Image})
versions = append(versions, []string{deployedVersion, serviceName, versionMeta.Image, versionMeta.Tag})
}
sort.Slice(versions, sortServiceByName(versions))
for _, version := range versions {
table.Append(version)
}
table.SetAutoMergeCellsByColumnIndex([]int{0})
table.SetAlignment(tablewriter.ALIGN_LEFT)
table.Render()
return nil

View File

@ -58,26 +58,46 @@ teardown(){
}
# bats test_tags=slow
@test "error if no version in catalogue" {
@test "error if not in catalogue" {
_deploy_app
run $ABRA app version "$TEST_APP_DOMAIN"
assert_failure
assert_output --partial 'could not retrieve deployed version'
assert_output --partial 'does not exist'
_undeploy_app
}
# bats test_tags=slow
@test "list version" {
_deploy_app
appDomain="custom-html.$TEST_SERVER"
latestVersion=$(git -C "$ABRA_DIR/recipes/$TEST_RECIPE" tag | tail -n 1)
run $ABRA app new custom-html \
--no-input \
--server "$TEST_SERVER" \
--domain "$appDomain"
latestVersion=$(git -C "$ABRA_DIR/recipes/custom-html" tag | tail -n 1)
refute [ -z "$latestVersion" ];
run $ABRA app version "$TEST_APP_DOMAIN"
run $ABRA app deploy "$appDomain" --no-input --no-converge-checks
assert_success
assert_output --partial "$latestVersion"
_undeploy_app
run $ABRA app version "$appDomain"
assert_success
assert_output --partial "$latestVersion"
run $ABRA app undeploy "$appDomain" --no-input
assert_success
# NOTE(d1): to let the stack come down before nuking volumes
sleep 3
run $ABRA app volume remove "$appDomain" --no-input
assert_success
run $ABRA app remove "$appDomain" --no-input
assert_success
assert_not_exists "$ABRA_DIR/servers/$TEST_SERVER/$appDomain.env"
}