2021-08-02 01:10:41 +00:00
|
|
|
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"
|
2021-08-02 01:10:41 +00:00
|
|
|
"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-08-02 06:36:35 +00:00
|
|
|
|
2021-09-01 12:03:39 +00:00
|
|
|
appFiles, err := config.LoadAppFiles("")
|
|
|
|
if err != nil {
|
|
|
|
logrus.Fatal(err)
|
|
|
|
}
|
2021-08-02 06:36:35 +00:00
|
|
|
|
2021-09-01 12:03:39 +00:00
|
|
|
appEnv, err := config.GetApp(appFiles, appName)
|
|
|
|
if err != nil {
|
|
|
|
logrus.Fatal(err)
|
|
|
|
}
|
2021-08-02 06:36:35 +00:00
|
|
|
|
2021-09-04 22:41:31 +00:00
|
|
|
server := appFiles[appName].Server
|
|
|
|
cl, err := client.New(server)
|
2021-09-01 12:03:39 +00:00
|
|
|
if err != nil {
|
|
|
|
logrus.Fatal(err)
|
|
|
|
}
|
2021-08-02 06:36:35 +00:00
|
|
|
|
2021-09-03 09:46:40 +00:00
|
|
|
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()
|
|
|
|
|
2021-09-04 20:02:49 +00:00
|
|
|
composeFiles, err := config.GetAppComposeFiles(appEnv.Type, appEnv.Env)
|
|
|
|
if err != nil {
|
|
|
|
logrus.Fatal(err)
|
|
|
|
}
|
2021-09-04 19:08:14 +00:00
|
|
|
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,
|
|
|
|
}
|
2021-09-04 20:02:49 +00:00
|
|
|
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
|
2021-08-02 01:10:41 +00:00
|
|
|
},
|
|
|
|
}
|