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

Implemented deploy --no-follow flag #679

Merged
merged 1 commit into from
Sep 24, 2021
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 8 additions & 3 deletions cmd/deployments.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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()
Expand All @@ -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)
}
Expand Down
12 changes: 10 additions & 2 deletions deployments/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions deployments/deploy_war.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down