feat: support deploying with chaos mode
continuous-integration/drone/push Build is failing
Details
continuous-integration/drone/push Build is failing
Details
This commit is contained in:
parent
6d42e72f16
commit
2f9b11f389
|
@ -10,6 +10,7 @@ import (
|
||||||
"coopcloud.tech/abra/pkg/client"
|
"coopcloud.tech/abra/pkg/client"
|
||||||
stack "coopcloud.tech/abra/pkg/client/stack"
|
stack "coopcloud.tech/abra/pkg/client/stack"
|
||||||
"coopcloud.tech/abra/pkg/config"
|
"coopcloud.tech/abra/pkg/config"
|
||||||
|
"coopcloud.tech/abra/pkg/git"
|
||||||
"coopcloud.tech/abra/pkg/recipe"
|
"coopcloud.tech/abra/pkg/recipe"
|
||||||
"github.com/AlecAivazis/survey/v2"
|
"github.com/AlecAivazis/survey/v2"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
|
@ -22,6 +23,7 @@ var appDeployCommand = &cli.Command{
|
||||||
Usage: "Deploy an app",
|
Usage: "Deploy an app",
|
||||||
Flags: []cli.Flag{
|
Flags: []cli.Flag{
|
||||||
internal.ForceFlag,
|
internal.ForceFlag,
|
||||||
|
internal.ChaosFlag,
|
||||||
},
|
},
|
||||||
Description: `
|
Description: `
|
||||||
This command deploys a new instance of an app. It does not support changing the
|
This command deploys a new instance of an app. It does not support changing the
|
||||||
|
@ -50,14 +52,16 @@ hacking.
|
||||||
|
|
||||||
if isDeployed {
|
if isDeployed {
|
||||||
if internal.Force {
|
if internal.Force {
|
||||||
logrus.Infof("continuing with deployment due to '--force/-f' being set")
|
logrus.Warnf("'%s' already deployed but continuing (--force)", stackName)
|
||||||
|
} else if internal.Chaos {
|
||||||
|
logrus.Warnf("'%s' already deployed but continuing (--chaos)", stackName)
|
||||||
} else {
|
} else {
|
||||||
logrus.Fatalf("'%s' is already deployed", stackName)
|
logrus.Fatalf("'%s' is already deployed", stackName)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
version := deployedVersion
|
version := deployedVersion
|
||||||
if version == "" {
|
if version == "" && !internal.Chaos {
|
||||||
versions, err := catalogue.GetRecipeCatalogueVersions(app.Type)
|
versions, err := catalogue.GetRecipeCatalogueVersions(app.Type)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Fatal(err)
|
logrus.Fatal(err)
|
||||||
|
@ -70,13 +74,32 @@ hacking.
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
version = "latest commit"
|
version = "latest commit"
|
||||||
logrus.Warning("no versions detected, using latest commit")
|
logrus.Warn("no versions detected, using latest commit")
|
||||||
if err := recipe.EnsureLatest(app.Type); err != nil {
|
if err := recipe.EnsureLatest(app.Type); err != nil {
|
||||||
logrus.Fatal(err)
|
logrus.Fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if internal.Chaos {
|
||||||
|
logrus.Warnf("chaos mode engaged")
|
||||||
|
head, err := git.GetRecipeHead(app.Type)
|
||||||
|
if err != nil {
|
||||||
|
logrus.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
version = head.String()[:8]
|
||||||
|
|
||||||
|
isClean, err := git.IsClean(app.Type)
|
||||||
|
if err != nil {
|
||||||
|
logrus.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if !isClean {
|
||||||
|
version = fmt.Sprintf("%s + unstaged changes", version)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
abraShPath := fmt.Sprintf("%s/%s/%s", config.APPS_DIR, app.Type, "abra.sh")
|
abraShPath := fmt.Sprintf("%s/%s/%s", config.APPS_DIR, app.Type, "abra.sh")
|
||||||
abraShEnv, err := config.ReadAbraShEnvVars(abraShPath)
|
abraShEnv, err := config.ReadAbraShEnvVars(abraShPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -49,3 +49,15 @@ var ForceFlag = &cli.BoolFlag{
|
||||||
Aliases: []string{"f"},
|
Aliases: []string{"f"},
|
||||||
Destination: &Force,
|
Destination: &Force,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Chaos engages chaos mode.
|
||||||
|
var Chaos bool
|
||||||
|
|
||||||
|
// ChaosFlag turns on/off chaos functionality.
|
||||||
|
var ChaosFlag = &cli.BoolFlag{
|
||||||
|
Name: "chaos",
|
||||||
|
Value: false,
|
||||||
|
Aliases: []string{"ch"},
|
||||||
|
Usage: "Deploy uncommitted recipes changes. Use with care!",
|
||||||
|
Destination: &Chaos,
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,48 @@
|
||||||
|
package git
|
||||||
|
|
||||||
|
import (
|
||||||
|
"path"
|
||||||
|
|
||||||
|
"coopcloud.tech/abra/pkg/config"
|
||||||
|
"github.com/go-git/go-git/v5"
|
||||||
|
"github.com/go-git/go-git/v5/plumbing"
|
||||||
|
)
|
||||||
|
|
||||||
|
// GetRecipeHead retrieves latest HEAD metadata.
|
||||||
|
func GetRecipeHead(recipeName string) (*plumbing.Reference, error) {
|
||||||
|
recipeDir := path.Join(config.ABRA_DIR, "apps", recipeName)
|
||||||
|
|
||||||
|
repo, err := git.PlainOpen(recipeDir)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
head, err := repo.Head()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return head, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsClean checks if a repo has unstaged changes
|
||||||
|
func IsClean(recipeName string) (bool, error) {
|
||||||
|
recipeDir := path.Join(config.ABRA_DIR, "apps", recipeName)
|
||||||
|
|
||||||
|
repo, err := git.PlainOpen(recipeDir)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
worktree, err := repo.Worktree()
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
status, err := worktree.Status()
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return status.IsClean(), nil
|
||||||
|
}
|
Loading…
Reference in New Issue