feat: auto-deploy traefik prototype
continuous-integration/drone/push Build is passing Details

Closes coop-cloud/organising#212.
This commit is contained in:
decentral1se 2021-11-03 09:41:20 +01:00
parent c227972c12
commit 04e24022f5
No known key found for this signature in database
GPG Key ID: 5E2EF5A63E3718CC
3 changed files with 43 additions and 10 deletions

View File

@ -72,7 +72,7 @@ func createSecrets(sanitisedAppName string) (AppSecrets, error) {
// ensureDomainFlag checks if the domain flag was used. if not, asks the user for it/
func ensureDomainFlag(recipe recipe.Recipe, server string) error {
if Domain == "" {
if Domain == "" && !NoInput {
prompt := &survey.Input{
Message: "Specify app domain",
Default: fmt.Sprintf("%s.%s", recipe.Name, server),
@ -81,6 +81,11 @@ func ensureDomainFlag(recipe recipe.Recipe, server string) error {
return err
}
}
if Domain == "" {
return fmt.Errorf("no domain provided")
}
return nil
}
@ -91,7 +96,7 @@ func ensureServerFlag() error {
return err
}
if NewAppServer == "" {
if NewAppServer == "" && !NoInput {
prompt := &survey.Select{
Message: "Select app server:",
Options: servers,
@ -101,12 +106,16 @@ func ensureServerFlag() error {
}
}
if NewAppServer == "" {
return fmt.Errorf("no server provided")
}
return nil
}
// ensureServerFlag checks if the AppName flag was used. if not, asks the user for it.
func ensureAppNameFlag() error {
if NewAppName == "" {
if NewAppName == "" && !NoInput {
prompt := &survey.Input{
Message: "Specify app name:",
Default: config.SanitiseAppName(Domain),
@ -115,6 +124,11 @@ func ensureAppNameFlag() error {
return err
}
}
if NewAppName == "" {
return fmt.Errorf("no app name provided")
}
return nil
}
@ -174,7 +188,7 @@ func NewAction(c *cli.Context) error {
table.Append([]string{sanitisedAppName, Domain, recipe.Name, NewAppServer})
fmt.Println("")
fmt.Println(fmt.Sprintf("New '%s' created! Here is your new app overview:", recipe.Name))
fmt.Println(fmt.Sprintf("A new %s app has been created! Here is an overview:", recipe.Name))
fmt.Println("")
table.Render()
fmt.Println("")

View File

@ -57,7 +57,7 @@ func ValidateRecipeWithPrompt(c *cli.Context) recipe.Recipe {
}
}
if recipeName == "" && RecipeName != "" {
if RecipeName != "" {
recipeName = RecipeName
logrus.Debugf("programmatically setting recipe name to %s", recipeName)
}
@ -80,7 +80,7 @@ func ValidateRecipeWithPrompt(c *cli.Context) recipe.Recipe {
func ValidateApp(c *cli.Context) config.App {
appName := c.Args().First()
if appName == "" && AppName != "" {
if AppName != "" {
appName = AppName
logrus.Debugf("programmatically setting app name to %s", appName)
}

View File

@ -8,10 +8,12 @@ import (
"os"
"os/exec"
"os/user"
"path"
"path/filepath"
"strings"
"time"
abraFormatter "coopcloud.tech/abra/cli/formatter"
"coopcloud.tech/abra/cli/internal"
"coopcloud.tech/abra/pkg/client"
"coopcloud.tech/abra/pkg/config"
@ -331,14 +333,31 @@ func createServerDir(domainName string) error {
func deployTraefik(c *cli.Context, cl *dockerClient.Client, domainName string) error {
internal.NoInput = true
internal.RecipeName = "traefik"
internal.NewAppServer = domainName
internal.NewAppName = config.SanitiseAppName(domainName)
if err := internal.NewAction(c); err != nil {
logrus.Fatal(err)
internal.Domain = fmt.Sprintf("%s.%s", "traefik", domainName)
internal.NewAppName = fmt.Sprintf("%s_%s", "traefik", config.SanitiseAppName(domainName))
appEnvPath := path.Join(config.ABRA_DIR, "servers", internal.Domain, fmt.Sprintf("%s.env", internal.NewAppName))
if _, err := os.Stat(appEnvPath); !os.IsNotExist(err) {
fmt.Println(fmt.Sprintf(`
You specified "--traefik/-t" and that means that Abra will now try to
automatically create a new Traefik app on %s.
`, internal.NewAppServer))
tableCol := []string{"recipe", "domain", "server", "name"}
table := abraFormatter.CreateTable(tableCol)
table.Append([]string{internal.RecipeName, internal.Domain, internal.NewAppServer, internal.NewAppName})
if err := internal.NewAction(c); err != nil {
logrus.Fatal(err)
}
} else {
logrus.Infof("%s already exists, not creating again", appEnvPath)
}
internal.AppName = domainName
internal.AppName = internal.NewAppName
if err := internal.DeployAction(c); err != nil {
logrus.Fatal(err)
}