feat: auto-deploy traefik prototype
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
Closes coop-cloud/organising#212.
This commit is contained in:
parent
c227972c12
commit
04e24022f5
@ -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/
|
// ensureDomainFlag checks if the domain flag was used. if not, asks the user for it/
|
||||||
func ensureDomainFlag(recipe recipe.Recipe, server string) error {
|
func ensureDomainFlag(recipe recipe.Recipe, server string) error {
|
||||||
if Domain == "" {
|
if Domain == "" && !NoInput {
|
||||||
prompt := &survey.Input{
|
prompt := &survey.Input{
|
||||||
Message: "Specify app domain",
|
Message: "Specify app domain",
|
||||||
Default: fmt.Sprintf("%s.%s", recipe.Name, server),
|
Default: fmt.Sprintf("%s.%s", recipe.Name, server),
|
||||||
@ -81,6 +81,11 @@ func ensureDomainFlag(recipe recipe.Recipe, server string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if Domain == "" {
|
||||||
|
return fmt.Errorf("no domain provided")
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -91,7 +96,7 @@ func ensureServerFlag() error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if NewAppServer == "" {
|
if NewAppServer == "" && !NoInput {
|
||||||
prompt := &survey.Select{
|
prompt := &survey.Select{
|
||||||
Message: "Select app server:",
|
Message: "Select app server:",
|
||||||
Options: servers,
|
Options: servers,
|
||||||
@ -101,12 +106,16 @@ func ensureServerFlag() error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if NewAppServer == "" {
|
||||||
|
return fmt.Errorf("no server provided")
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// ensureServerFlag checks if the AppName flag was used. if not, asks the user for it.
|
// ensureServerFlag checks if the AppName flag was used. if not, asks the user for it.
|
||||||
func ensureAppNameFlag() error {
|
func ensureAppNameFlag() error {
|
||||||
if NewAppName == "" {
|
if NewAppName == "" && !NoInput {
|
||||||
prompt := &survey.Input{
|
prompt := &survey.Input{
|
||||||
Message: "Specify app name:",
|
Message: "Specify app name:",
|
||||||
Default: config.SanitiseAppName(Domain),
|
Default: config.SanitiseAppName(Domain),
|
||||||
@ -115,6 +124,11 @@ func ensureAppNameFlag() error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if NewAppName == "" {
|
||||||
|
return fmt.Errorf("no app name provided")
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -174,7 +188,7 @@ func NewAction(c *cli.Context) error {
|
|||||||
table.Append([]string{sanitisedAppName, Domain, recipe.Name, NewAppServer})
|
table.Append([]string{sanitisedAppName, Domain, recipe.Name, NewAppServer})
|
||||||
|
|
||||||
fmt.Println("")
|
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("")
|
fmt.Println("")
|
||||||
table.Render()
|
table.Render()
|
||||||
fmt.Println("")
|
fmt.Println("")
|
||||||
|
@ -57,7 +57,7 @@ func ValidateRecipeWithPrompt(c *cli.Context) recipe.Recipe {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if recipeName == "" && RecipeName != "" {
|
if RecipeName != "" {
|
||||||
recipeName = RecipeName
|
recipeName = RecipeName
|
||||||
logrus.Debugf("programmatically setting recipe name to %s", 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 {
|
func ValidateApp(c *cli.Context) config.App {
|
||||||
appName := c.Args().First()
|
appName := c.Args().First()
|
||||||
|
|
||||||
if appName == "" && AppName != "" {
|
if AppName != "" {
|
||||||
appName = AppName
|
appName = AppName
|
||||||
logrus.Debugf("programmatically setting app name to %s", appName)
|
logrus.Debugf("programmatically setting app name to %s", appName)
|
||||||
}
|
}
|
||||||
|
@ -8,10 +8,12 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"os/user"
|
"os/user"
|
||||||
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
abraFormatter "coopcloud.tech/abra/cli/formatter"
|
||||||
"coopcloud.tech/abra/cli/internal"
|
"coopcloud.tech/abra/cli/internal"
|
||||||
"coopcloud.tech/abra/pkg/client"
|
"coopcloud.tech/abra/pkg/client"
|
||||||
"coopcloud.tech/abra/pkg/config"
|
"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 {
|
func deployTraefik(c *cli.Context, cl *dockerClient.Client, domainName string) error {
|
||||||
internal.NoInput = true
|
internal.NoInput = true
|
||||||
|
|
||||||
internal.RecipeName = "traefik"
|
internal.RecipeName = "traefik"
|
||||||
internal.NewAppServer = domainName
|
internal.NewAppServer = domainName
|
||||||
internal.NewAppName = config.SanitiseAppName(domainName)
|
internal.Domain = fmt.Sprintf("%s.%s", "traefik", domainName)
|
||||||
if err := internal.NewAction(c); err != nil {
|
internal.NewAppName = fmt.Sprintf("%s_%s", "traefik", config.SanitiseAppName(domainName))
|
||||||
logrus.Fatal(err)
|
|
||||||
|
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 {
|
if err := internal.DeployAction(c); err != nil {
|
||||||
logrus.Fatal(err)
|
logrus.Fatal(err)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user