diff --git a/CHANGELOG.md b/CHANGELOG.md index fd723f128..e82e70b18 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ### To be Released +* feat(deploy): add --no-follow flag to detach deployment logs [#679](https://github.com/Scalingo/cli/pull/679) + ### 1.21.0 * fix(backup-download): Now download the last successful backup [#663](https://github.com/Scalingo/cli/pull/663) diff --git a/cmd/deployments.go b/cmd/deployments.go index 4a63260b2..496822f48 100644 --- a/cmd/deployments.go +++ b/cmd/deployments.go @@ -111,6 +111,7 @@ var ( Usage: "Trigger a deployment by archive", Flags: []cli.Flag{appFlag, cli.BoolFlag{Name: "war, w", Usage: "Specify that you want to deploy a WAR file"}, + cli.BoolFlag{Name: "no-follow", Usage: "Return immediately after the deployment is triggered"}, }, Description: ` Trigger the deployment of a custom archive for your application @@ -123,8 +124,11 @@ var ( $ scalingo -a myapp deploy archive.tar.gz v1.0.0 or $ scalingo -a myapp deploy http://example.com/archive.tar.gz v1.0.0 + or + $ scalingo --app my-app deploy --no-follow archive.tar.gz v1.0.0 + $ scalingo --app my-app deployment-follow - # See also commands 'deployments' + # See also commands 'deployments, deployment-follow' `, Action: func(c *cli.Context) { args := c.Args() @@ -138,15 +142,16 @@ var ( gitRef = args[1] } currentApp := appdetect.CurrentApp(c) + opts := deployments.DeployOpts{NoFollow: c.Bool("no-follow")} if c.Bool("war") || strings.HasSuffix(archivePath, ".war") { io.Status(fmt.Sprintf("Deploying WAR archive: %s", archivePath)) - err := deployments.DeployWar(currentApp, archivePath, gitRef) + err := deployments.DeployWar(currentApp, archivePath, gitRef, opts) if err != nil { errorQuit(err) } } else { io.Status(fmt.Sprintf("Deploying tarball archive: %s", archivePath)) - err := deployments.Deploy(currentApp, archivePath, gitRef) + err := deployments.Deploy(currentApp, archivePath, gitRef, opts) if err != nil { errorQuit(err) } diff --git a/deployments/deploy.go b/deployments/deploy.go index 7850a8395..cd42e6d39 100644 --- a/deployments/deploy.go +++ b/deployments/deploy.go @@ -19,7 +19,11 @@ type DeployRes struct { Deployment *scalingo.Deployment `json:"deployment"` } -func Deploy(app, archivePath, gitRef string) error { +type DeployOpts struct { + NoFollow bool +} + +func Deploy(app, archivePath, gitRef string, opts DeployOpts) error { c, err := config.ScalingoClient() if err != nil { return errgo.Notef(err, "fail to get Scalingo client") @@ -52,8 +56,12 @@ func Deploy(app, archivePath, gitRef string) error { scalingoio.Status("Your deployment has been queued and is going to start…") - go showQueuedWarnings(c, app, deployment.ID) + if opts.NoFollow { + scalingoio.Statusf("The no-follow flag is passed. You can check deployment logs with scalingo --app %s deployment-follow", app) + return nil + } + go showQueuedWarnings(c, app, deployment.ID) debug.Println("Streaming deployment logs of", app, ":", deployment.ID) err = Stream(&StreamOpts{ AppName: app, diff --git a/deployments/deploy_war.go b/deployments/deploy_war.go index bcaa0cab0..b2ea9a1c5 100644 --- a/deployments/deploy_war.go +++ b/deployments/deploy_war.go @@ -24,7 +24,7 @@ type DeployWarRes struct { Deployment *scalingo.Deployment `json:"deployment"` } -func DeployWar(appName, warPath, gitRef string) error { +func DeployWar(appName, warPath, gitRef string, opts DeployOpts) error { var warReadStream io.ReadCloser var warSize int64 @@ -92,7 +92,7 @@ func DeployWar(appName, warPath, gitRef string) error { return errgo.Newf("wrong status code after upload %s", res.Status) } - return Deploy(appName, sources.DownloadURL, gitRef) + return Deploy(appName, sources.DownloadURL, gitRef, opts) } func getURLInfo(warPath string) (warReadStream io.ReadCloser, warSize int64, err error) {