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

Created the keep-old-app flag #54

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ $ cf install-plugin path/to/downloaded/binary
```
$ cf zero-downtime-push application-to-replace \
-f path/to/new_manifest.yml \
-p path/to/new/path
-p path/to/new/path \
[-keep-old-app]
```

## warning
Expand Down
19 changes: 10 additions & 9 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, showLogs bool) []rewind.Action {
func getActionsForApp(appRepo *ApplicationRepo, appName, manifestPath, appPath string, showLogs bool, keepOldApp bool) []rewind.Action {
venName := venerableAppName(appName)
var err error
var curApp, venApp *AppEntity
Expand Down Expand Up @@ -114,7 +114,7 @@ func getActionsForApp(appRepo *ApplicationRepo, appName, manifestPath, appPath s
// delete
{
Forward: func() error {
if !haveVenToCleanup {
if !haveVenToCleanup || keepOldApp {
return nil
}
return appRepo.DeleteApplication(venName)
Expand All @@ -141,11 +141,11 @@ func (plugin AutopilotPlugin) Run(cliConnection plugin.CliConnection, args []str
}

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

fatalIf((&rewind.Actions{
Actions: getActionsForApp(appRepo, appName, manifestPath, appPath, showLogs),
Actions: getActionsForApp(appRepo, appName, manifestPath, appPath, showLogs, keepOldApp),
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 @@ -176,27 +176,28 @@ func (AutopilotPlugin) GetMetadata() plugin.PluginMetadata {
}
}

func ParseArgs(args []string) (string, string, string, bool, error) {
func ParseArgs(args []string) (string, string, string, bool, bool, error) {
flags := flag.NewFlagSet("zero-downtime-push", flag.ContinueOnError)
manifestPath := flags.String("f", "", "path to an application manifest")
appPath := flags.String("p", "", "path to application files")
showLogs := flags.Bool("show-app-log", false, "tail and show application log during application start")
keepOldApp := flags.Bool("keep-old-app", false, "do not remove the old application")

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

appName := args[1]

if *manifestPath == "" {
return "", "", "", false, ErrNoManifest
return "", "", "", false, true, ErrNoManifest
}

return appName, *manifestPath, *appPath, *showLogs, nil
return appName, *manifestPath, *appPath, *showLogs, *keepOldApp, nil
}

var (
Expand Down
6 changes: 4 additions & 2 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, showLogs, err := ParseArgs(
appName, manifestPath, appPath, showLogs, keepOldApp, err := ParseArgs(
[]string{
"zero-downtime-push",
"appname",
"-f", "manifest-path",
"-p", "app-path",
"-keep-old-app",
},
)
Expect(err).ToNot(HaveOccurred())
Expand All @@ -35,10 +36,11 @@ var _ = Describe("Flag Parsing", func() {
Expect(manifestPath).To(Equal("manifest-path"))
Expect(appPath).To(Equal("app-path"))
Expect(showLogs).To(Equal(false))
Expect(keepOldApp).To(Equal(true))
})

It("requires a manifest", func() {
_, _, _, _, err := ParseArgs(
_, _, _, _, _, err := ParseArgs(
[]string{
"zero-downtime-push",
"appname",
Expand Down
Empty file added manifest.yml
Empty file.