Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added deploy config for removing manual ALL option and forcing manual… #38

Merged
merged 1 commit into from
Nov 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions stim/prompt.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,14 @@ func (stim *Stim) PromptBool(label string, override bool, defaultvalue bool) (bo
return true, nil
}

defaultstring := "n"
y := "y"
n := "n"
if defaultvalue {
defaultstring = "y"
y = strings.ToUpper(y)
} else {
n = strings.ToUpper(n)
}
label = label + " (y/n) [" + defaultstring + "]"
label = label + " (" + y + "/" + n + ")"

prompt := promptui.Prompt{
Label: label,
Expand All @@ -54,7 +57,11 @@ func (stim *Stim) PromptBool(label string, override bool, defaultvalue bool) (bo
return false, err
}

if result == "" || strings.ToLower(strings.TrimSpace(result))[0:1] == "y" {
if result == "" {
return defaultvalue, nil
}

if strings.ToLower(strings.TrimSpace(result))[0:1] == "y" {
return true, nil
}

Expand Down
16 changes: 9 additions & 7 deletions stimpacks/deploy/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,10 @@ type Global struct {

// Spec contains the spec of a given environment/instance
type Spec struct {
Kubernetes Kubernetes `yaml:"kubernetes"`
Secrets []*v2e.SecretItem `yaml:"secrets"`
EnvironmentVars []*EnvironmentVar `yaml:"env"`
Kubernetes Kubernetes `yaml:"kubernetes"`
Secrets []*v2e.SecretItem `yaml:"secrets"`
EnvironmentVars []*EnvironmentVar `yaml:"env"`
AddConfermationPrompt bool `yaml:"addConfermationPrompt"`
}

// Kubernetes describes the Kubernetes configuration to use
Expand All @@ -64,10 +65,11 @@ type Kubernetes struct {

// Environment describes a deployment environment (i.e. dev, stage, prod, etc.)
type Environment struct {
Name string `yaml:"name"`
Spec *Spec `yaml:"spec"`
Instances []*Instance `yaml:"instances"`
instanceMap map[string]int
Name string `yaml:"name"`
Spec *Spec `yaml:"spec"`
Instances []*Instance `yaml:"instances"`
RemoveAllPrompt bool `yaml:"removeAllPrompt"`
instanceMap map[string]int
}

// Instance describes an instance of a deployment within an environment (i.e. us-west-2 for env prod)
Expand Down
46 changes: 41 additions & 5 deletions stimpacks/deploy/deploy.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package deploy

import (
"os"
"strings"

log "github.com/PremiereGlobal/stim/pkg/stimlog"
Expand Down Expand Up @@ -54,16 +55,28 @@ func (d *Deploy) Run() {
environmentList[i] = e.Name
}
selectedEnvironmentName, _ = d.stim.PromptList("Which environment?", environmentList, d.stim.ConfigGetString("deploy.environment"))
if selectedEnvironmentName == "" {
d.log.Info("No environment selected! exiting")
os.Exit(0)
}
}
selectedEnvironment := d.config.Environments[d.config.environmentMap[selectedEnvironmentName]]

// Determine the selected instance (via cli param) or prompt the user
instanceList := make([]string, len(selectedEnvironment.Instances)+1)
instanceList[0] = allOptionPrompt
for i, inst := range selectedEnvironment.Instances {
instanceList[i+1] = inst.Name
instanceList := make([]string, 0)

//Check if we should remove all prompt or not
if !selectedEnvironment.RemoveAllPrompt {
instanceList = append(instanceList, allOptionPrompt)
}
for _, inst := range selectedEnvironment.Instances {
instanceList = append(instanceList, inst.Name)
}
selectedInstanceName, _ := d.stim.PromptList("Which instance?", instanceList, d.stim.ConfigGetString("deploy.instance"))
if selectedInstanceName == "" {
d.log.Info("No instance selected! exiting")
os.Exit(0)
}
if strings.ToLower(selectedInstanceName) == strings.ToLower(allOptionPrompt) || strings.ToLower(selectedInstanceName) == strings.ToLower(allOptionCli) {
selectedInstanceName = allOptionCli
} else if _, ok := selectedEnvironment.instanceMap[selectedInstanceName]; !ok {
Expand All @@ -73,11 +86,34 @@ func (d *Deploy) Run() {
// Run the deployment(s)
if selectedInstanceName == allOptionCli {
d.log.Info("Deploying to all clusters in environment: {}", selectedEnvironment.Name)
//Check if confermation prompt is required
if selectedEnvironment.Spec.AddConfermationPrompt {
//Do AddConfermationPrompt, only if the instance is not passed on the cli
proceed, _ := d.stim.PromptBool("Proceed?", d.stim.ConfigGetString("deploy.instance") != "", false)
if !proceed {
os.Exit(1)
}
}
for _, inst := range selectedEnvironment.Instances {
if inst.Spec.AddConfermationPrompt {
//Do AddConfermationPrompt, only if the instance is not passed on the cli
proceed, _ := d.stim.PromptBool("Proceed?", d.stim.ConfigGetString("deploy.instance") != "", false)
if !proceed {
os.Exit(1)
}
}
d.Deploy(selectedEnvironment, inst)
}
} else {
d.Deploy(selectedEnvironment, selectedEnvironment.Instances[selectedEnvironment.instanceMap[selectedInstanceName]])
d.log.Info("Deploying to environment: {} and instance: {}", selectedInstanceName)
inst := selectedEnvironment.Instances[selectedEnvironment.instanceMap[selectedInstanceName]]
if selectedEnvironment.Spec.AddConfermationPrompt || inst.Spec.AddConfermationPrompt {
proceed, _ := d.stim.PromptBool("Proceed?", d.stim.ConfigGetString("deploy.instance") != "", false)
if !proceed {
os.Exit(1)
}
}
d.Deploy(selectedEnvironment, inst)
}

}
Expand Down