abra/cli/app/deploy.go

72 lines
1.6 KiB
Go
Raw Normal View History

package app
import (
2021-09-01 12:03:39 +00:00
"errors"
"fmt"
"coopcloud.tech/abra/cli/internal"
"coopcloud.tech/abra/client"
stack "coopcloud.tech/abra/client/stack"
"coopcloud.tech/abra/config"
"github.com/sirupsen/logrus"
"github.com/urfave/cli/v2"
)
2021-09-01 12:03:39 +00:00
var appDeployCommand = &cli.Command{
Name: "deploy",
Usage: "Deploy an app",
Action: func(c *cli.Context) error {
appName := c.Args().First()
if appName == "" {
internal.ShowSubcommandHelpAndError(c, errors.New("no app name provided"))
}
2021-09-01 12:03:39 +00:00
appFiles, err := config.LoadAppFiles("")
if err != nil {
logrus.Fatal(err)
}
2021-09-01 12:03:39 +00:00
appEnv, err := config.GetApp(appFiles, appName)
if err != nil {
logrus.Fatal(err)
}
server := appFiles[appName].Server
cl, err := client.New(server)
2021-09-01 12:03:39 +00:00
if err != nil {
logrus.Fatal(err)
}
abraShPath := fmt.Sprintf("%s/%s/%s", config.APPS_DIR, appEnv.Type, "abra.sh")
abraShEnv, err := config.ReadAbraShEnvVars(abraShPath)
if err != nil {
logrus.Fatal(err)
}
for k, v := range abraShEnv {
appEnv.Env[k] = v
}
appEnv.Env["STACK_NAME"] = appEnv.StackName()
composeFiles, err := config.GetAppComposeFiles(appEnv.Type, appEnv.Env)
if err != nil {
logrus.Fatal(err)
}
deployOpts := stack.Deploy{
2021-09-01 12:03:39 +00:00
Composefiles: composeFiles,
2021-09-02 17:49:41 +00:00
Namespace: appEnv.StackName(),
2021-09-01 12:03:39 +00:00
Prune: false,
ResolveImage: stack.ResolveImageAlways,
}
compose, err := config.GetAppComposeConfig(appName, deployOpts, appEnv.Env)
2021-09-01 12:03:39 +00:00
if err != nil {
logrus.Fatal(err)
}
if err := stack.RunDeploy(cl, deployOpts, compose); err != nil {
logrus.Fatal(err)
}
return nil
},
}