forked from toolshed/abra
.
This commit is contained in:
parent
9827f9d470
commit
51ea98a910
@ -64,10 +64,8 @@ checkout as-is. Recipe commit hashes are also supported as values for
|
|||||||
},
|
},
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
var (
|
var (
|
||||||
deployWarnMessages []string
|
deployWarnMessages []string
|
||||||
toDeployVersion string
|
toDeployVersion string
|
||||||
isChaosCommit bool
|
|
||||||
toDeployChaosVersion = config.CHAOS_DEFAULT
|
|
||||||
)
|
)
|
||||||
|
|
||||||
app := internal.ValidateApp(args)
|
app := internal.ValidateApp(args)
|
||||||
@ -100,28 +98,16 @@ checkout as-is. Recipe commit hashes are also supported as values for
|
|||||||
log.Fatalf("%s is already deployed", app.Name)
|
log.Fatalf("%s is already deployed", app.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
toDeployVersion, toDeployChaosVersion, err = getDeployVersion(args, deployMeta, app)
|
toDeployVersion, err = getDeployVersion(args, deployMeta, app)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if !internal.Chaos {
|
if !internal.Chaos {
|
||||||
isChaosCommit, err = app.Recipe.EnsureVersion(toDeployVersion)
|
_, err = app.Recipe.EnsureVersion(toDeployVersion)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if isChaosCommit {
|
|
||||||
log.Debugf("assuming chaos commit: %s", toDeployVersion)
|
|
||||||
|
|
||||||
internal.Chaos = true
|
|
||||||
toDeployChaosVersion = toDeployVersion
|
|
||||||
|
|
||||||
toDeployVersion, err = app.Recipe.GetVersionLabelLocal()
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := validateSecrets(cl, app); err != nil {
|
if err := validateSecrets(cl, app); err != nil {
|
||||||
@ -154,16 +140,11 @@ checkout as-is. Recipe commit hashes are also supported as values for
|
|||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
toDeployChaosVersionLabel := toDeployChaosVersion
|
|
||||||
if app.Recipe.Dirty {
|
|
||||||
toDeployChaosVersionLabel = formatter.AddDirtyMarker(toDeployChaosVersionLabel)
|
|
||||||
}
|
|
||||||
|
|
||||||
appPkg.ExposeAllEnv(stackName, compose, app.Env)
|
appPkg.ExposeAllEnv(stackName, compose, app.Env)
|
||||||
appPkg.SetRecipeLabel(compose, stackName, app.Recipe.Name)
|
appPkg.SetRecipeLabel(compose, stackName, app.Recipe.Name)
|
||||||
appPkg.SetChaosLabel(compose, stackName, internal.Chaos)
|
appPkg.SetChaosLabel(compose, stackName, internal.Chaos)
|
||||||
if internal.Chaos {
|
if internal.Chaos {
|
||||||
appPkg.SetChaosVersionLabel(compose, stackName, toDeployChaosVersionLabel)
|
appPkg.SetChaosVersionLabel(compose, stackName, toDeployVersion)
|
||||||
}
|
}
|
||||||
appPkg.SetUpdateLabel(compose, stackName, app.Env)
|
appPkg.SetUpdateLabel(compose, stackName, app.Env)
|
||||||
|
|
||||||
@ -197,19 +178,11 @@ checkout as-is. Recipe commit hashes are also supported as values for
|
|||||||
deployedVersion = deployMeta.Version
|
deployedVersion = deployMeta.Version
|
||||||
}
|
}
|
||||||
|
|
||||||
toWriteVersion := toDeployVersion
|
|
||||||
if internal.Chaos || isChaosCommit {
|
|
||||||
toWriteVersion = toDeployChaosVersion
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := internal.DeployOverview(
|
if err := internal.DeployOverview(
|
||||||
app,
|
app,
|
||||||
deployWarnMessages,
|
deployWarnMessages,
|
||||||
deployedVersion,
|
deployedVersion,
|
||||||
deployMeta.ChaosVersion,
|
|
||||||
toDeployVersion,
|
toDeployVersion,
|
||||||
toDeployChaosVersion,
|
|
||||||
toWriteVersion,
|
|
||||||
); err != nil {
|
); err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
@ -233,7 +206,7 @@ checkout as-is. Recipe commit hashes are also supported as values for
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := app.WriteRecipeVersion(toWriteVersion, false); err != nil {
|
if err := app.WriteRecipeVersion(toDeployVersion, false); err != nil {
|
||||||
log.Fatalf("writing recipe version failed: %s", err)
|
log.Fatalf("writing recipe version failed: %s", err)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -254,22 +227,22 @@ func getChaosVersion(app app.App, toDeployVersion, toDeployChaosVersion *string)
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getLatestVersionOrCommit(app app.App) (string, string, error) {
|
func getLatestVersionOrCommit(app app.App) (string, error) {
|
||||||
versions, err := app.Recipe.Tags()
|
versions, err := app.Recipe.Tags()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(versions) > 0 && !internal.Chaos {
|
if len(versions) > 0 && !internal.Chaos {
|
||||||
return versions[len(versions)-1], "", nil
|
return versions[len(versions)-1], nil
|
||||||
}
|
}
|
||||||
|
|
||||||
head, err := app.Recipe.Head()
|
head, err := app.Recipe.Head()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
return "", formatter.SmallSHA(head.String()), nil
|
return formatter.SmallSHA(head.String()), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// validateArgsAndFlags ensures compatible args/flags.
|
// validateArgsAndFlags ensures compatible args/flags.
|
||||||
@ -296,49 +269,41 @@ func validateSecrets(cl *dockerClient.Client, app app.App) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getDeployVersion(cliArgs []string, deployMeta stack.DeployMeta, app app.App) (string, string, error) {
|
func getDeployVersion(cliArgs []string, deployMeta stack.DeployMeta, app app.App) (string, error) {
|
||||||
// Chaos mode overrides everything
|
// Chaos mode overrides everything
|
||||||
if internal.Chaos {
|
if internal.Chaos {
|
||||||
v, err := app.Recipe.ChaosVersion()
|
v, err := app.Recipe.ChaosVersion()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", "", err
|
return "", err
|
||||||
}
|
}
|
||||||
// TODO: This seems wrong!?
|
log.Debugf("version: taking chaos version: %s", v)
|
||||||
cv, err := app.Recipe.GetVersionLabelLocal()
|
return v, nil
|
||||||
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
|
// Check if the deploy version is set with a cli argument
|
||||||
if len(cliArgs) == 2 && cliArgs[1] != "" {
|
if len(cliArgs) == 2 && cliArgs[1] != "" {
|
||||||
log.Debugf("version: taking version from cli arg: %s", cliArgs[1])
|
log.Debugf("version: taking version from cli arg: %s", cliArgs[1])
|
||||||
return cliArgs[1], "", nil
|
return cliArgs[1], nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if the recipe has a version in the .env file
|
// Check if the recipe has a version in the .env file
|
||||||
if app.Recipe.EnvVersion != "" && !internal.IgnoreEnvVersion {
|
if app.Recipe.EnvVersion != "" && !internal.IgnoreEnvVersion {
|
||||||
log.Debugf("version: taking version from .env file: %s", app.Recipe.EnvVersion)
|
log.Debugf("version: taking version from .env file: %s", app.Recipe.EnvVersion)
|
||||||
return app.Recipe.EnvVersion, "", nil
|
return app.Recipe.EnvVersion, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Take deployed version
|
// Take deployed version
|
||||||
if deployMeta.IsDeployed {
|
if deployMeta.IsDeployed {
|
||||||
log.Debugf("version: taking deployed version: %s", deployMeta.Version)
|
log.Debugf("version: taking deployed version: %s", deployMeta.Version)
|
||||||
return deployMeta.Version, "", nil
|
return deployMeta.Version, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
v, vc, err := getLatestVersionOrCommit(app)
|
v, err := getLatestVersionOrCommit(app)
|
||||||
log.Debugf("version: taking new recipe versio: %s, %s", v, vc)
|
log.Debugf("version: taking new recipe version: %s", v)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
if v == "" {
|
return v, nil
|
||||||
return vc, vc, nil
|
|
||||||
}
|
|
||||||
return v, vc, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
@ -209,16 +209,7 @@ var AppNewCommand = &cobra.Command{
|
|||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := app.Recipe.IsDirty(); err != nil {
|
if err := app.WriteRecipeVersion(recipeVersion, false); err != nil {
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
toWriteVersion := recipeVersion
|
|
||||||
if internal.Chaos || app.Recipe.Dirty {
|
|
||||||
toWriteVersion = chaosVersion
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := app.WriteRecipeVersion(toWriteVersion, false); err != nil {
|
|
||||||
log.Fatalf("writing recipe version failed: %s", err)
|
log.Fatalf("writing recipe version failed: %s", err)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -132,10 +132,7 @@ func DeployOverview(
|
|||||||
app appPkg.App,
|
app appPkg.App,
|
||||||
warnMessages []string,
|
warnMessages []string,
|
||||||
deployedVersion string,
|
deployedVersion string,
|
||||||
deployedChaosVersion string,
|
toDeployVersion string,
|
||||||
toDeployVersion,
|
|
||||||
toDeployChaosVersion string,
|
|
||||||
toWriteVersion string,
|
|
||||||
) error {
|
) error {
|
||||||
deployConfig := "compose.yml"
|
deployConfig := "compose.yml"
|
||||||
if composeFiles, ok := app.Env["COMPOSE_FILE"]; ok {
|
if composeFiles, ok := app.Env["COMPOSE_FILE"]; ok {
|
||||||
@ -152,11 +149,6 @@ func DeployOverview(
|
|||||||
domain = config.NO_DOMAIN_DEFAULT
|
domain = config.NO_DOMAIN_DEFAULT
|
||||||
}
|
}
|
||||||
|
|
||||||
if app.Recipe.Dirty {
|
|
||||||
toWriteVersion = formatter.AddDirtyMarker(toWriteVersion)
|
|
||||||
toDeployChaosVersion = formatter.AddDirtyMarker(toDeployChaosVersion)
|
|
||||||
}
|
|
||||||
|
|
||||||
envVersion := app.Recipe.EnvVersionRaw
|
envVersion := app.Recipe.EnvVersionRaw
|
||||||
if envVersion == "" {
|
if envVersion == "" {
|
||||||
envVersion = config.NO_VERSION_DEFAULT
|
envVersion = config.NO_VERSION_DEFAULT
|
||||||
@ -170,15 +162,12 @@ func DeployOverview(
|
|||||||
|
|
||||||
{"CURRENT DEPLOYMENT", "---"},
|
{"CURRENT DEPLOYMENT", "---"},
|
||||||
{"VERSION", formatter.BoldDirtyDefault(deployedVersion)},
|
{"VERSION", formatter.BoldDirtyDefault(deployedVersion)},
|
||||||
{"CHAOS", formatter.BoldDirtyDefault(deployedChaosVersion)},
|
|
||||||
|
{"CURRENT ENV VERSION", "---"},
|
||||||
|
{"ENV VERSION", formatter.BoldDirtyDefault(envVersion)},
|
||||||
|
|
||||||
{"NEW DEPLOYMENT", "---"},
|
{"NEW DEPLOYMENT", "---"},
|
||||||
{"VERSION", formatter.BoldDirtyDefault(toDeployVersion)},
|
{"VERSION", formatter.BoldDirtyDefault(toDeployVersion)},
|
||||||
{"CHAOS", formatter.BoldDirtyDefault(toDeployChaosVersion)},
|
|
||||||
|
|
||||||
{fmt.Sprintf("%s.ENV", strings.ToUpper(app.Name)), "---"},
|
|
||||||
{"CURRENT VERSION", formatter.BoldDirtyDefault(envVersion)},
|
|
||||||
{"NEW VERSION", formatter.BoldDirtyDefault(toWriteVersion)},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
overview := formatter.CreateOverview("DEPLOY OVERVIEW", rows)
|
overview := formatter.CreateOverview("DEPLOY OVERVIEW", rows)
|
||||||
|
@ -7,6 +7,7 @@ import (
|
|||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"coopcloud.tech/abra/pkg/config"
|
||||||
"coopcloud.tech/abra/pkg/formatter"
|
"coopcloud.tech/abra/pkg/formatter"
|
||||||
gitPkg "coopcloud.tech/abra/pkg/git"
|
gitPkg "coopcloud.tech/abra/pkg/git"
|
||||||
"coopcloud.tech/abra/pkg/log"
|
"coopcloud.tech/abra/pkg/log"
|
||||||
@ -274,19 +275,14 @@ func (r Recipe) EnsureUpToDate() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsDirty checks whether a recipe is dirty or not. N.B., if you call IsDirty
|
// IsDirty checks whether a recipe is dirty or not.
|
||||||
// from another Recipe method, you should propagate the pointer reference (*).
|
func (r *Recipe) IsDirty() (bool, error) {
|
||||||
func (r *Recipe) IsDirty() error {
|
|
||||||
isClean, err := gitPkg.IsClean(r.Dir)
|
isClean, err := gitPkg.IsClean(r.Dir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return false, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if !isClean {
|
return !isClean, nil
|
||||||
r.Dirty = true
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ChaosVersion constructs a chaos mode recipe version.
|
// ChaosVersion constructs a chaos mode recipe version.
|
||||||
@ -300,8 +296,12 @@ func (r *Recipe) ChaosVersion() (string, error) {
|
|||||||
|
|
||||||
version = formatter.SmallSHA(head.String())
|
version = formatter.SmallSHA(head.String())
|
||||||
|
|
||||||
if err := r.IsDirty(); err != nil {
|
dirty, err := r.IsDirty()
|
||||||
return version, err
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
if dirty {
|
||||||
|
return fmt.Sprintf("%s%s", version, config.DIRTY_DEFAULT), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return version, nil
|
return version, nil
|
||||||
|
@ -2,7 +2,6 @@ package recipe
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/url"
|
"net/url"
|
||||||
@ -20,7 +19,6 @@ import (
|
|||||||
"coopcloud.tech/abra/pkg/log"
|
"coopcloud.tech/abra/pkg/log"
|
||||||
"coopcloud.tech/abra/pkg/web"
|
"coopcloud.tech/abra/pkg/web"
|
||||||
"coopcloud.tech/tagcmp"
|
"coopcloud.tech/tagcmp"
|
||||||
"github.com/go-git/go-git/v5"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// RecipeCatalogueURL is the only current recipe catalogue available.
|
// RecipeCatalogueURL is the only current recipe catalogue available.
|
||||||
@ -122,7 +120,6 @@ type Features struct {
|
|||||||
func Get(name string) Recipe {
|
func Get(name string) Recipe {
|
||||||
version := ""
|
version := ""
|
||||||
versionRaw := ""
|
versionRaw := ""
|
||||||
dirty := false
|
|
||||||
if strings.Contains(name, ":") {
|
if strings.Contains(name, ":") {
|
||||||
split := strings.Split(name, ":")
|
split := strings.Split(name, ":")
|
||||||
if len(split) > 2 {
|
if len(split) > 2 {
|
||||||
@ -134,7 +131,6 @@ func Get(name string) Recipe {
|
|||||||
versionRaw = version
|
versionRaw = version
|
||||||
if strings.HasSuffix(version, config.DIRTY_DEFAULT) {
|
if strings.HasSuffix(version, config.DIRTY_DEFAULT) {
|
||||||
version = strings.Replace(split[1], config.DIRTY_DEFAULT, "", 1)
|
version = strings.Replace(split[1], config.DIRTY_DEFAULT, "", 1)
|
||||||
dirty = true
|
|
||||||
log.Debugf("removed dirty suffix from .env version: %s -> %s", split[1], version)
|
log.Debugf("removed dirty suffix from .env version: %s -> %s", split[1], version)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -160,7 +156,6 @@ func Get(name string) Recipe {
|
|||||||
Name: name,
|
Name: name,
|
||||||
EnvVersion: version,
|
EnvVersion: version,
|
||||||
EnvVersionRaw: versionRaw,
|
EnvVersionRaw: versionRaw,
|
||||||
Dirty: dirty,
|
|
||||||
Dir: dir,
|
Dir: dir,
|
||||||
GitURL: gitURL,
|
GitURL: gitURL,
|
||||||
SSHURL: sshURL,
|
SSHURL: sshURL,
|
||||||
@ -171,9 +166,11 @@ func Get(name string) Recipe {
|
|||||||
AbraShPath: path.Join(dir, "abra.sh"),
|
AbraShPath: path.Join(dir, "abra.sh"),
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := r.IsDirty(); err != nil && !errors.Is(err, git.ErrRepositoryNotExists) {
|
dirty, err := r.IsDirty()
|
||||||
|
if err != nil {
|
||||||
log.Fatalf("failed to check git status of %s: %s", r.Name, err)
|
log.Fatalf("failed to check git status of %s: %s", r.Name, err)
|
||||||
}
|
}
|
||||||
|
r.Dirty = dirty
|
||||||
|
|
||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user