Skip to content
This repository has been archived by the owner on Dec 4, 2018. It is now read-only.

Commit

Permalink
Support -s flag for push
Browse files Browse the repository at this point in the history
  • Loading branch information
davewalter authored and xoebus committed Sep 5, 2018
1 parent 68cd32e commit 88f7a1d
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 18 deletions.
29 changes: 17 additions & 12 deletions autopilot.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func venerableAppName(appName string) string {
return fmt.Sprintf("%s-venerable", appName)
}

func getActionsForApp(appRepo *ApplicationRepo, appName, manifestPath, appPath string, vars []string, varsFiles []string, showLogs bool) []rewind.Action {
func getActionsForApp(appRepo *ApplicationRepo, appName, manifestPath, appPath, stackName string, vars []string, varsFiles []string, showLogs bool) []rewind.Action {
venName := venerableAppName(appName)
var err error
var curApp, venApp *AppEntity
Expand Down Expand Up @@ -97,7 +97,7 @@ func getActionsForApp(appRepo *ApplicationRepo, appName, manifestPath, appPath s
// push
{
Forward: func() error {
return appRepo.PushApplication(appName, manifestPath, appPath, vars, varsFiles, showLogs)
return appRepo.PushApplication(appName, manifestPath, appPath, stackName, vars, varsFiles, showLogs)
},
ReversePrevious: func() error {
if !haveVenToCleanup {
Expand All @@ -123,12 +123,12 @@ func getActionsForApp(appRepo *ApplicationRepo, appName, manifestPath, appPath s
}
}

func getActionsForNewApp(appRepo *ApplicationRepo, appName, manifestPath, appPath string, vars []string, varsFiles []string, showLogs bool) []rewind.Action {
func getActionsForNewApp(appRepo *ApplicationRepo, appName, manifestPath, appPath, stackName string, vars []string, varsFiles []string, showLogs bool) []rewind.Action {
return []rewind.Action{
// push
{
Forward: func() error {
return appRepo.PushApplication(appName, manifestPath, appPath, vars, varsFiles, showLogs)
return appRepo.PushApplication(appName, manifestPath, appPath, stackName, vars, varsFiles, showLogs)
},
},
}
Expand All @@ -141,11 +141,11 @@ func (plugin AutopilotPlugin) Run(cliConnection plugin.CliConnection, args []str
}

appRepo := NewApplicationRepo(cliConnection)
appName, manifestPath, appPath, vars, varsFiles, showLogs, err := ParseArgs(args)
appName, manifestPath, appPath, stackName, vars, varsFiles, showLogs, err := ParseArgs(args)
fatalIf(err)

fatalIf((&rewind.Actions{
Actions: getActionsForApp(appRepo, appName, manifestPath, appPath, vars, varsFiles, showLogs),
Actions: getActionsForApp(appRepo, appName, manifestPath, appPath, stackName, vars, varsFiles, showLogs),
RewindFailureMessage: "Oh no. Something's gone wrong. I've tried to roll back but you should check to see if everything is OK.",
}).Execute())

Expand Down Expand Up @@ -187,33 +187,34 @@ func (s *StringSlice) Set(value string) error {
return nil
}

func ParseArgs(args []string) (string, string, string, []string, []string, bool, error) {
func ParseArgs(args []string) (string, string, string, string, []string, []string, bool, error) {
flags := flag.NewFlagSet("zero-downtime-push", flag.ContinueOnError)

var vars StringSlice
var varsFiles StringSlice

manifestPath := flags.String("f", "", "path to an application manifest")
appPath := flags.String("p", "", "path to application files")
stackName := flags.String("s", "", "name of the stack to use")
showLogs := flags.Bool("show-app-log", false, "tail and show application log during application start")
flags.Var(&vars, "var", "Variable key value pair for variable substitution, (e.g., name=app1); can specify multiple times")
flags.Var(&varsFiles, "vars-file", "Path to a variable substitution file for manifest; can specify multiple times")

if len(args) < 2 || strings.HasPrefix(args[1], "-") {
return "", "", "", []string{}, []string{}, false, ErrNoArgs
return "", "", "", "", []string{}, []string{}, false, ErrNoArgs
}
err := flags.Parse(args[2:])
if err != nil {
return "", "", "", []string{}, []string{}, false, err
return "", "", "", "", []string{}, []string{}, false, err
}

appName := args[1]

if *manifestPath == "" {
return "", "", "", []string{}, []string{}, false, ErrNoManifest
return "", "", "", "", []string{}, []string{}, false, ErrNoManifest
}

return appName, *manifestPath, *appPath, vars, varsFiles, *showLogs, nil
return appName, *manifestPath, *appPath, *stackName, vars, varsFiles, *showLogs, nil
}

var (
Expand All @@ -236,13 +237,17 @@ func (repo *ApplicationRepo) RenameApplication(oldName, newName string) error {
return err
}

func (repo *ApplicationRepo) PushApplication(appName, manifestPath, appPath string, vars []string, varsFiles []string, showLogs bool) error {
func (repo *ApplicationRepo) PushApplication(appName, manifestPath, appPath, stackName string, vars []string, varsFiles []string, showLogs bool) error {
args := []string{"push", appName, "-f", manifestPath, "--no-start"}

if appPath != "" {
args = append(args, "-p", appPath)
}

if stackName != "" {
args = append(args, "-s", stackName)
}

for _, varPair := range vars {
args = append(args, "--var", varPair)
}
Expand Down
30 changes: 24 additions & 6 deletions autopilot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@ func TestAutopilot(t *testing.T) {

var _ = Describe("Flag Parsing", func() {
It("parses a complete set of args", func() {
appName, manifestPath, appPath, vars, varsFiles, showLogs, err := ParseArgs(
appName, manifestPath, appPath, stackName, vars, varsFiles, showLogs, err := ParseArgs(
[]string{
"zero-downtime-push",
"appname",
"-f", "manifest-path",
"-p", "app-path",
"-s", "stack-name",
"-var", "foo=bar",
"-var", "baz=bob",
"-vars-file", "vars.yml",
Expand All @@ -37,13 +38,14 @@ var _ = Describe("Flag Parsing", func() {
Expect(appName).To(Equal("appname"))
Expect(manifestPath).To(Equal("manifest-path"))
Expect(appPath).To(Equal("app-path"))
Expect(stackName).To(Equal("stack-name"))
Expect(vars).To(Equal([]string{"foo=bar", "baz=bob"}))
Expect(varsFiles).To(Equal([]string{"vars.yml"}))
Expect(showLogs).To(Equal(false))
})

It("requires a manifest", func() {
_, _, _, _, _, _, err := ParseArgs(
_, _, _, _, _, _, _, err := ParseArgs(
[]string{
"zero-downtime-push",
"appname",
Expand Down Expand Up @@ -171,7 +173,7 @@ var _ = Describe("ApplicationRepo", func() {

Describe("PushApplication", func() {
It("pushes an application with both a manifest and a path", func() {
err := repo.PushApplication("appName", "/path/to/a/manifest.yml", "/path/to/the/app", []string{}, []string{}, false)
err := repo.PushApplication("appName", "/path/to/a/manifest.yml", "/path/to/the/app", "", []string{}, []string{}, false)
Expect(err).ToNot(HaveOccurred())

Expect(cliConn.CliCommandCallCount()).To(Equal(2))
Expand All @@ -186,7 +188,7 @@ var _ = Describe("ApplicationRepo", func() {
})

It("pushes an application with only a manifest", func() {
err := repo.PushApplication("appName", "/path/to/a/manifest.yml", "", []string{}, []string{}, false)
err := repo.PushApplication("appName", "/path/to/a/manifest.yml", "", "", []string{}, []string{}, false)
Expect(err).ToNot(HaveOccurred())

Expect(cliConn.CliCommandCallCount()).To(Equal(2))
Expand All @@ -199,8 +201,24 @@ var _ = Describe("ApplicationRepo", func() {
}))
})

It("pushes an application with a stack", func() {
err := repo.PushApplication("appName", "/path/to/a/manifest.yml", "/path/to/the/app", "stackName", []string{}, []string{}, false)
Expect(err).ToNot(HaveOccurred())

Expect(cliConn.CliCommandCallCount()).To(Equal(2))
args := cliConn.CliCommandArgsForCall(0)
Expect(args).To(Equal([]string{
"push",
"appName",
"-f", "/path/to/a/manifest.yml",
"--no-start",
"-p", "/path/to/the/app",
"-s", "stackName",
}))
})

It("pushes an application with variables", func() {
err := repo.PushApplication("appName", "/path/to/a/manifest.yml", "", []string{"foo=bar", "baz=bob"}, []string{"vars.yml"}, false)
err := repo.PushApplication("appName", "/path/to/a/manifest.yml", "", "", []string{"foo=bar", "baz=bob"}, []string{"vars.yml"}, false)
Expect(err).ToNot(HaveOccurred())

Expect(cliConn.CliCommandCallCount()).To(Equal(2))
Expand All @@ -219,7 +237,7 @@ var _ = Describe("ApplicationRepo", func() {
It("returns errors from the push", func() {
cliConn.CliCommandReturns([]string{}, errors.New("bad app"))

err := repo.PushApplication("appName", "/path/to/a/manifest.yml", "/path/to/the/app", []string{}, []string{}, false)
err := repo.PushApplication("appName", "/path/to/a/manifest.yml", "/path/to/the/app", "", []string{}, []string{}, false)
Expect(err).To(MatchError("bad app"))
})
})
Expand Down

0 comments on commit 88f7a1d

Please sign in to comment.