forked from toolshed/abra
@ -6,9 +6,11 @@ import (
|
||||
|
||||
abraFormatter "coopcloud.tech/abra/cli/formatter"
|
||||
"coopcloud.tech/abra/cli/internal"
|
||||
"coopcloud.tech/abra/pkg/catalogue"
|
||||
"coopcloud.tech/abra/pkg/client"
|
||||
stack "coopcloud.tech/abra/pkg/client/stack"
|
||||
"coopcloud.tech/abra/pkg/config"
|
||||
"coopcloud.tech/abra/pkg/recipe"
|
||||
"github.com/AlecAivazis/survey/v2"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/urfave/cli/v2"
|
||||
@ -18,14 +20,55 @@ var appDeployCommand = &cli.Command{
|
||||
Name: "deploy",
|
||||
Aliases: []string{"d"},
|
||||
Usage: "Deploy an app",
|
||||
Flags: []cli.Flag{
|
||||
internal.ForceFlag,
|
||||
},
|
||||
Description: `
|
||||
This command deploys a new instance of an app. It does not support changing the
|
||||
version of an existing deployed app, for this you need to look at the "abra app
|
||||
upgrade <app>" command. You may pass "--force" to re-deploy the same version.
|
||||
`,
|
||||
Action: func(c *cli.Context) error {
|
||||
app := internal.ValidateApp(c)
|
||||
stackName := app.StackName()
|
||||
|
||||
cl, err := client.New(app.Server)
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
|
||||
logrus.Debugf("checking whether '%s' is already deployed", stackName)
|
||||
|
||||
isDeployed, deployedVersion, err := stack.IsDeployed(c.Context, cl, stackName)
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
|
||||
if isDeployed {
|
||||
if internal.Force {
|
||||
logrus.Infof("continuing with deployment due to '--force/-f' being set")
|
||||
} else {
|
||||
logrus.Fatalf("'%s' is already deployed", stackName)
|
||||
}
|
||||
}
|
||||
|
||||
version := deployedVersion
|
||||
if version == "" {
|
||||
versions, err := catalogue.GetRecipeCatalogueVersions(app.Type)
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
if len(versions) > 0 {
|
||||
version = versions[len(versions)-1]
|
||||
logrus.Infof("choosing '%s' as version to deploy", version)
|
||||
recipe.EnsureVersion(app.Type, version)
|
||||
} else {
|
||||
version = "latest commit"
|
||||
logrus.Warning("no versions detected, using latest commit")
|
||||
recipe.EnsureLatest(app.Type)
|
||||
}
|
||||
}
|
||||
|
||||
abraShPath := fmt.Sprintf("%s/%s/%s", config.APPS_DIR, app.Type, "abra.sh")
|
||||
abraShEnv, err := config.ReadAbraShEnvVars(abraShPath)
|
||||
if err != nil {
|
||||
@ -41,7 +84,7 @@ var appDeployCommand = &cli.Command{
|
||||
}
|
||||
deployOpts := stack.Deploy{
|
||||
Composefiles: composeFiles,
|
||||
Namespace: app.StackName(),
|
||||
Namespace: stackName,
|
||||
Prune: false,
|
||||
ResolveImage: stack.ResolveImageAlways,
|
||||
}
|
||||
@ -50,7 +93,7 @@ var appDeployCommand = &cli.Command{
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
|
||||
if err := DeployOverview(app); err != nil {
|
||||
if err := DeployOverview(app, version); err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
|
||||
@ -75,7 +118,7 @@ var appDeployCommand = &cli.Command{
|
||||
}
|
||||
|
||||
// DeployOverview shows a deployment overview
|
||||
func DeployOverview(app config.App) error {
|
||||
func DeployOverview(app config.App, version string) error {
|
||||
tableCol := []string{"server", "compose", "domain", "stack", "version"}
|
||||
table := abraFormatter.CreateTable(tableCol)
|
||||
|
||||
@ -84,7 +127,7 @@ func DeployOverview(app config.App) error {
|
||||
deployConfig = strings.Join(strings.Split(composeFiles, ":"), "\n")
|
||||
}
|
||||
|
||||
table.Append([]string{app.Server, deployConfig, app.Domain, app.StackName(), "unknown"})
|
||||
table.Append([]string{app.Server, deployConfig, app.Domain, app.StackName(), version})
|
||||
table.Render()
|
||||
|
||||
response := false
|
||||
|
Reference in New Issue
Block a user