forked from toolshed/abra
		
	Compare commits
	
		
			2 Commits
		
	
	
		
			fix-deploy
			...
			app-new-ch
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| f4cadb5ad2 | |||
| cee0fa7c8e | 
| @ -261,7 +261,7 @@ func init() { | ||||
| 	AppCmdCommand.Flags().BoolVarP( | ||||
| 		&requestTTY, | ||||
| 		"tty", | ||||
| 		"t", | ||||
| 		"T", | ||||
| 		false, | ||||
| 		"request remote TTY", | ||||
| 	) | ||||
|  | ||||
| @ -46,8 +46,7 @@ checkout as-is. Recipe commit hashes are also supported as values for | ||||
| 	ValidArgsFunction: func( | ||||
| 		cmd *cobra.Command, | ||||
| 		args []string, | ||||
| 		toComplete string, | ||||
| 	) ([]string, cobra.ShellCompDirective) { | ||||
| 		toComplete string) ([]string, cobra.ShellCompDirective) { | ||||
| 		switch l := len(args); l { | ||||
| 		case 0: | ||||
| 			return autocomplete.AppNameComplete() | ||||
| @ -100,9 +99,27 @@ checkout as-is. Recipe commit hashes are also supported as values for | ||||
| 			log.Fatalf("%s is already deployed", app.Name) | ||||
| 		} | ||||
|  | ||||
| 		toDeployVersion, toDeployChaosVersion, err = getDeployVersion(args, deployMeta, app) | ||||
| 		if err != nil { | ||||
| 			log.Fatal(err) | ||||
| 		if len(args) == 2 && args[1] != "" { | ||||
| 			toDeployVersion = args[1] | ||||
| 		} | ||||
|  | ||||
| 		if !deployMeta.IsDeployed && | ||||
| 			toDeployVersion == "" && | ||||
| 			app.Recipe.EnvVersion != "" && !internal.IgnoreEnvVersion { | ||||
| 			log.Debugf("new deployment, choosing .env version: %s", app.Recipe.EnvVersion) | ||||
| 			toDeployVersion = app.Recipe.EnvVersion | ||||
| 		} | ||||
|  | ||||
| 		if !internal.Chaos && toDeployVersion == "" { | ||||
| 			if err := getLatestVersionOrCommit(app, &toDeployVersion); err != nil { | ||||
| 				log.Fatal(err) | ||||
| 			} | ||||
| 		} | ||||
|  | ||||
| 		if internal.Chaos { | ||||
| 			if err := getChaosVersion(app, &toDeployVersion, &toDeployChaosVersion); err != nil { | ||||
| 				log.Fatal(err) | ||||
| 			} | ||||
| 		} | ||||
|  | ||||
| 		if !internal.Chaos { | ||||
| @ -254,22 +271,32 @@ func getChaosVersion(app app.App, toDeployVersion, toDeployChaosVersion *string) | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
| func getLatestVersionOrCommit(app app.App) (string, string, error) { | ||||
| func getLatestVersionOrCommit(app app.App, toDeployVersion *string) error { | ||||
| 	versions, err := app.Recipe.Tags() | ||||
| 	if err != nil { | ||||
| 		return "", "", err | ||||
| 		return err | ||||
| 	} | ||||
|  | ||||
| 	if len(versions) > 0 && !internal.Chaos { | ||||
| 		return versions[len(versions)-1], "", nil | ||||
| 		*toDeployVersion = versions[len(versions)-1] | ||||
|  | ||||
| 		log.Debugf("choosing %s as version to deploy", *toDeployVersion) | ||||
|  | ||||
| 		if _, err := app.Recipe.EnsureVersion(*toDeployVersion); err != nil { | ||||
| 			return err | ||||
| 		} | ||||
|  | ||||
| 		return nil | ||||
| 	} | ||||
|  | ||||
| 	head, err := app.Recipe.Head() | ||||
| 	if err != nil { | ||||
| 		return "", "", err | ||||
| 		return err | ||||
| 	} | ||||
|  | ||||
| 	return "", formatter.SmallSHA(head.String()), nil | ||||
| 	*toDeployVersion = formatter.SmallSHA(head.String()) | ||||
|  | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
| // validateArgsAndFlags ensures compatible args/flags. | ||||
| @ -296,50 +323,6 @@ func validateSecrets(cl *dockerClient.Client, app app.App) error { | ||||
| 	return nil | ||||
| } | ||||
|  | ||||
| func getDeployVersion(cliArgs []string, deployMeta stack.DeployMeta, app app.App) (string, string, error) { | ||||
| 	// Chaos mode overrides everything | ||||
| 	if internal.Chaos { | ||||
| 		v, err := app.Recipe.ChaosVersion() | ||||
| 		if err != nil { | ||||
| 			return "", "", err | ||||
| 		} | ||||
| 		cv, err := app.Recipe.GetVersionLabelLocal() | ||||
| 		if err != nil { | ||||
| 			return "", "", err | ||||
| 		} | ||||
| 		log.Debugf("version: taking chaos version: %s, %s", v, cv) | ||||
| 		return v, cv, nil | ||||
| 	} | ||||
|  | ||||
| 	// Check if the deploy version is set with a cli argument | ||||
| 	if len(cliArgs) == 2 && cliArgs[1] != "" { | ||||
| 		log.Debugf("version: taking version from cli arg: %s", cliArgs[1]) | ||||
| 		return cliArgs[1], "", nil | ||||
| 	} | ||||
|  | ||||
| 	// Check if the recipe has a version in the .env file | ||||
| 	if app.Recipe.EnvVersion != "" && !internal.IgnoreEnvVersion { | ||||
| 		log.Debugf("version: taking version from .env file: %s", app.Recipe.EnvVersion) | ||||
| 		return app.Recipe.EnvVersion, "", nil | ||||
| 	} | ||||
|  | ||||
| 	// Take deployed version | ||||
| 	if deployMeta.IsDeployed { | ||||
| 		log.Debugf("version: taking deployed version: %s", deployMeta.Version) | ||||
| 		return deployMeta.Version, "", nil | ||||
| 	} | ||||
|  | ||||
| 	v, vc, err := getLatestVersionOrCommit(app) | ||||
| 	log.Debugf("version: taking new recipe versio: %s, %s", v, vc) | ||||
| 	if err != nil { | ||||
| 		log.Fatal(err) | ||||
| 	} | ||||
| 	if v == "" { | ||||
| 		return vc, vc, nil | ||||
| 	} | ||||
| 	return v, vc, nil | ||||
| } | ||||
|  | ||||
| func init() { | ||||
| 	AppDeployCommand.Flags().BoolVarP( | ||||
| 		&internal.Chaos, | ||||
|  | ||||
| @ -81,35 +81,8 @@ var AppNewCommand = &cobra.Command{ | ||||
| 				log.Fatal(err) | ||||
| 			} | ||||
|  | ||||
| 			// NOTE(d1): rely on tags as there is no recipe.EnvVersion yet because | ||||
| 			// the app has not been fully created. we rely on the local git state of | ||||
| 			// the repository | ||||
| 			tags, err := recipe.Tags() | ||||
| 			if err != nil { | ||||
| 				log.Fatal(err) | ||||
| 			} | ||||
|  | ||||
| 			internal.SortVersionsDesc(tags) | ||||
|  | ||||
| 			if len(tags) == 0 { | ||||
| 				// NOTE(d1): this is a new recipe with no released versions | ||||
| 				recipeVersion = config.UNKNOWN_DEFAULT | ||||
| 			} else { | ||||
| 				recipeVersion = tags[len(tags)-1] | ||||
| 			} | ||||
|  | ||||
| 			if err := recipe.IsDirty(); err != nil { | ||||
| 				log.Fatal(err) | ||||
| 			} | ||||
|  | ||||
| 			if !internal.Offline && !recipe.Dirty { | ||||
| 				if err := recipe.EnsureUpToDate(); err != nil { | ||||
| 					log.Fatal(err) | ||||
| 				} | ||||
| 			} | ||||
| 		} | ||||
|  | ||||
| 		if !internal.Chaos { | ||||
| 			recipeVersion = chaosVersion | ||||
| 		} else { | ||||
| 			if err := recipe.EnsureIsClean(); err != nil { | ||||
| 				log.Fatal(err) | ||||
| 			} | ||||
|  | ||||
| @ -123,13 +123,6 @@ Pass "--all-services/-a" to restart all services.`, | ||||
| var allServices bool | ||||
|  | ||||
| func init() { | ||||
| 	AppRestartCommand.Flags().BoolVarP( | ||||
| 		&internal.Chaos, | ||||
| 		"chaos", | ||||
| 		"C", | ||||
| 		false, | ||||
| 		"ignore uncommitted recipes changes", | ||||
| 	) | ||||
| 	AppRestartCommand.Flags().BoolVarP( | ||||
| 		&allServices, | ||||
| 		"all-services", | ||||
|  | ||||
| @ -4,13 +4,11 @@ import ( | ||||
| 	"fmt" | ||||
| 	"os" | ||||
| 	"slices" | ||||
| 	"sort" | ||||
| 	"strings" | ||||
|  | ||||
| 	"coopcloud.tech/abra/pkg/formatter" | ||||
| 	gitPkg "coopcloud.tech/abra/pkg/git" | ||||
| 	"coopcloud.tech/abra/pkg/log" | ||||
| 	"coopcloud.tech/tagcmp" | ||||
| 	"github.com/distribution/reference" | ||||
| 	"github.com/go-git/go-git/v5" | ||||
| 	"github.com/go-git/go-git/v5/plumbing" | ||||
| @ -347,18 +345,6 @@ func (r Recipe) Tags() ([]string, error) { | ||||
| 		return tags, err | ||||
| 	} | ||||
|  | ||||
| 	sort.Slice(tags, func(i, j int) bool { | ||||
| 		version1, err := tagcmp.Parse(tags[i]) | ||||
| 		if err != nil { | ||||
| 			return false | ||||
| 		} | ||||
| 		version2, err := tagcmp.Parse(tags[j]) | ||||
| 		if err != nil { | ||||
| 			return false | ||||
| 		} | ||||
| 		return version1.IsLessThan(version2) | ||||
| 	}) | ||||
|  | ||||
| 	log.Debugf("detected %s as tags for recipe %s", strings.Join(tags, ", "), r.Name) | ||||
|  | ||||
| 	return tags, nil | ||||
|  | ||||
| @ -54,21 +54,13 @@ teardown(){ | ||||
| } | ||||
|  | ||||
| # bats test_tags=slow | ||||
| @test "deploy commit written to env and redeploy keeps that version" { | ||||
| @test "chaos commit written to env" { | ||||
|   run $ABRA app deploy "$TEST_APP_DOMAIN" "1e83340e" --no-input --no-converge-checks | ||||
|   assert_success | ||||
|  | ||||
|   run grep -q "TYPE=$TEST_RECIPE:1e83340e" \ | ||||
|     "$ABRA_DIR/servers/$TEST_SERVER/$TEST_APP_DOMAIN.env" | ||||
|   assert_success | ||||
|  | ||||
|   run $ABRA app deploy "$TEST_APP_DOMAIN" \ | ||||
|     --force --no-input --no-converge-checks | ||||
|   assert_success | ||||
|  | ||||
|   run grep -q "TYPE=$TEST_RECIPE:1e83340e" \ | ||||
|     "$ABRA_DIR/servers/$TEST_SERVER/$TEST_APP_DOMAIN.env" | ||||
|   assert_success | ||||
| } | ||||
|  | ||||
| # bats test_tags=slow | ||||
| @ -106,15 +98,12 @@ 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 | ||||
| @test "deploy overwrites chaos deploy" { | ||||
|   run $ABRA app deploy "$TEST_APP_DOMAIN" "1e83340e" \ | ||||
|     --no-input --no-converge-checks | ||||
|   assert_success | ||||
|  | ||||
|   run grep -q "TYPE=$TEST_RECIPE:0.1.0+1.20.0" \ | ||||
|     "$ABRA_DIR/servers/$TEST_SERVER/$TEST_APP_DOMAIN.env" | ||||
|   assert_success | ||||
|  | ||||
|   run sed -i 's/TYPE=abra-test-recipe:.*/TYPE=abra-test-recipe/g' \ | ||||
|   run grep -q "TYPE=$TEST_RECIPE:1e83340e" \ | ||||
|     "$ABRA_DIR/servers/$TEST_SERVER/$TEST_APP_DOMAIN.env" | ||||
|   assert_success | ||||
|  | ||||
| @ -122,7 +111,7 @@ teardown(){ | ||||
|     --force --no-input --no-converge-checks | ||||
|   assert_success | ||||
|  | ||||
|   run grep -q "TYPE=$TEST_RECIPE:0.1.0+1.20.0" \ | ||||
|   run grep -q "TYPE=$TEST_RECIPE:1e83340e" \ | ||||
|     "$ABRA_DIR/servers/$TEST_SERVER/$TEST_APP_DOMAIN.env" | ||||
|   assert_success | ||||
|   assert_failure | ||||
| } | ||||
|  | ||||
| @ -56,7 +56,7 @@ teardown(){ | ||||
|   assert_success | ||||
| } | ||||
|  | ||||
| @test "create new app with chaos commit" { | ||||
| @test "create new app with version commit" { | ||||
|   tagHash=$(_get_tag_hash "0.3.0+1.21.0") | ||||
|  | ||||
|   run $ABRA app new "$TEST_RECIPE" "$tagHash" \ | ||||
| @ -129,6 +129,10 @@ teardown(){ | ||||
|   assert_exists "$ABRA_DIR/recipes/$TEST_RECIPE/foo" | ||||
|   assert_equal "$(_git_status)" "?? foo" | ||||
|  | ||||
|   run git -C "$ABRA_DIR/recipes/$TEST_RECIPE" status | ||||
|   assert_success | ||||
|   assert_output --partial 'foo' | ||||
|  | ||||
|   run rm -rf "$ABRA_DIR/recipes/$TEST_RECIPE/foo" | ||||
|   assert_not_exists "$ABRA_DIR/recipes/$TEST_RECIPE/foo" | ||||
| } | ||||
| @ -210,7 +214,7 @@ teardown(){ | ||||
|     --chaos | ||||
|   assert_success | ||||
|   assert_exists "$ABRA_DIR/servers/$TEST_SERVER/$TEST_APP_DOMAIN.env" | ||||
|   assert_output --partial "version: $latestRelease" | ||||
|   assert_output --partial "version: ${currentHash:0:8}" | ||||
|   assert_output --partial "chaos: ${currentHash:0:8}" | ||||
|  | ||||
|   assert_exists "$ABRA_DIR/recipes/$TEST_RECIPE/foo" | ||||
| @ -238,7 +242,7 @@ teardown(){ | ||||
|     --chaos | ||||
|   assert_success | ||||
|   assert_exists "$ABRA_DIR/servers/$TEST_SERVER/$TEST_APP_DOMAIN.env" | ||||
|   assert_output --partial "version: unknown" | ||||
|   assert_output --partial "version: ${currentHash:0:8}" | ||||
|   assert_output --partial "chaos: ${currentHash:0:8}" | ||||
|  | ||||
|   assert_exists "$ABRA_DIR/recipes/$TEST_RECIPE/foo" | ||||
|  | ||||
		Reference in New Issue
	
	Block a user