Skip to content

Commit

Permalink
Add ability to save a default target deployment in config
Browse files Browse the repository at this point in the history
  • Loading branch information
andscoop committed Aug 21, 2018
1 parent a647d4a commit ff43fa7
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 36 deletions.
10 changes: 8 additions & 2 deletions airflow/docker.go
Expand Up @@ -247,7 +247,7 @@ func PS(airflowHome string) error {
}

// Deploy pushes a new docker image
func Deploy(path, name, wsId string) error {
func Deploy(path, name, wsId string, prompt bool) error {
deployments, err := api.GetDeployments(wsId)
if err != nil {
return err
Expand All @@ -263,7 +263,13 @@ func Deploy(path, name, wsId string) error {
return errors.New("No domain set, re-authenticate.")
}

if name == "" {
// Use config deployment if provided
if len(name) == 0 {
name = config.CFG.ProjectDeployment.GetProjectString()
}

// Prompt user for deployment if no deployment passed in
if len(name) == 0 || prompt {
if len(deployments) == 0 {
return errors.New(messages.HOUSTON_NO_DEPLOYMENTS_ERROR)
}
Expand Down
18 changes: 15 additions & 3 deletions cmd/airflow.go
Expand Up @@ -22,8 +22,10 @@ import (
)

var (
projectName string
forceDeploy bool
projectName string
forceDeploy bool
saveDeployConfig bool
forcePrompt bool

airflowRootCmd = &cobra.Command{
Use: "airflow",
Expand Down Expand Up @@ -91,6 +93,8 @@ func init() {
// Airflow deploy
airflowRootCmd.AddCommand(airflowDeployCmd)
airflowDeployCmd.Flags().BoolVarP(&forceDeploy, "force", "f", false, "Force deploy if uncommited changes")
airflowDeployCmd.Flags().BoolVarP(&forcePrompt, "prompt", "p", false, "Force prompt to choose target deployment")
airflowDeployCmd.Flags().BoolVarP(&saveDeployConfig, "save", "s", false, "Save deployment in config for future deploys")
airflowDeployCmd.Flags().StringVar(&workspaceId, "workspace-id", "", "workspace assigned to deployment")

// Airflow start
Expand Down Expand Up @@ -159,14 +163,22 @@ func airflowDeploy(cmd *cobra.Command, args []string) error {
ws := workspaceValidator()

releaseName := ""

// Get release name from args, if passed
if len(args) > 0 {
releaseName = args[0]
}

// Save releasename in config if specified
if len(releaseName) > 0 && saveDeployConfig {
config.CFG.ProjectDeployment.SetProjectString(releaseName)
}

if git.HasUncommitedChanges() && !forceDeploy {
fmt.Println(messages.REGISTRY_UNCOMMITTED_CHANGES)
return nil
}
return airflow.Deploy(config.WorkingPath, releaseName, ws)
return airflow.Deploy(config.WorkingPath, releaseName, ws, forcePrompt)
}

// Start an airflow cluster
Expand Down
29 changes: 15 additions & 14 deletions config/config.go
Expand Up @@ -36,20 +36,21 @@ var (

// CFG Houses configuration meta
CFG = cfgs{
Contexts: newCfg("contexts", ""),
CloudAPIProtocol: newCfg("cloud.api.protocol", "https"),
CloudAPIPort: newCfg("cloud.api.port", "443"),
CloudAPIToken: newCfg("cloud.api.token", ""),
Context: newCfg("context", ""),
LocalEnabled: newCfg("local.enabled", ""),
LocalHouston: newCfg("local.houston", ""),
LocalOrbit: newCfg("local.orbit", ""),
PostgresUser: newCfg("postgres.user", "postgres"),
PostgresPassword: newCfg("postgres.password", "postgres"),
PostgresHost: newCfg("postgres.host", "postgres"),
PostgresPort: newCfg("postgres.port", "5432"),
ProjectName: newCfg("project.name", ""),
ProjectWorkspace: newCfg("project.workspace", ""),
Contexts: newCfg("contexts", ""),
CloudAPIProtocol: newCfg("cloud.api.protocol", "https"),
CloudAPIPort: newCfg("cloud.api.port", "443"),
CloudAPIToken: newCfg("cloud.api.token", ""),
Context: newCfg("context", ""),
LocalEnabled: newCfg("local.enabled", ""),
LocalHouston: newCfg("local.houston", ""),
LocalOrbit: newCfg("local.orbit", ""),
PostgresUser: newCfg("postgres.user", "postgres"),
PostgresPassword: newCfg("postgres.password", "postgres"),
PostgresHost: newCfg("postgres.host", "postgres"),
PostgresPort: newCfg("postgres.port", "5432"),
ProjectDeployment: newCfg("project.deployment", ""),
ProjectName: newCfg("project.name", ""),
ProjectWorkspace: newCfg("project.workspace", ""),
}

// viperHome is the viper object in the users home directory
Expand Down
29 changes: 15 additions & 14 deletions config/types.go
Expand Up @@ -8,20 +8,21 @@ type cfg struct {

// cfgs houses all configurations for an astro project
type cfgs struct {
Contexts cfg
CloudAPIProtocol cfg
CloudAPIPort cfg
CloudAPIToken cfg
Context cfg
LocalEnabled cfg
LocalHouston cfg
LocalOrbit cfg
PostgresUser cfg
PostgresPassword cfg
PostgresHost cfg
PostgresPort cfg
ProjectName cfg
ProjectWorkspace cfg
Contexts cfg
CloudAPIProtocol cfg
CloudAPIPort cfg
CloudAPIToken cfg
Context cfg
LocalEnabled cfg
LocalHouston cfg
LocalOrbit cfg
PostgresUser cfg
PostgresPassword cfg
PostgresHost cfg
PostgresPort cfg
ProjectName cfg
ProjectDeployment cfg
ProjectWorkspace cfg
}

// Creates a new cfg struct
Expand Down
6 changes: 3 additions & 3 deletions deployment/deployment.go
Expand Up @@ -53,7 +53,7 @@ func Delete(uuid string) error {

// List all airflow deployments
func List(ws string) error {
r := " %-30s %-50s"
r := " %-30s %-50s %-30s"
// colorFmt := "\033[33;m"
// colorTrm := "\033[0m"

Expand All @@ -62,11 +62,11 @@ func List(ws string) error {
return err
}

h := fmt.Sprintf(r, "NAME", "UUID")
h := fmt.Sprintf(r, "NAME", "UUID", "RELEASE NAME")
fmt.Println(h)

for _, d := range deployments {
fullStr := fmt.Sprintf(r, d.Label, d.Id)
fullStr := fmt.Sprintf(r, d.Label, d.Id, d.ReleaseName)
fmt.Println(fullStr)
}
return nil
Expand Down

0 comments on commit ff43fa7

Please sign in to comment.