forked from remind101/empire
-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy.go
85 lines (69 loc) · 2.05 KB
/
deploy.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package main
import (
"fmt"
"io"
"os"
"github.com/docker/docker/pkg/jsonmessage"
"github.com/docker/docker/pkg/term"
"github.com/remind101/empire/pkg/heroku"
)
var stream bool
var cmdDeploy = &Command{
Run: maybeMessage(runDeploy),
Usage: "deploy [<registry>]<image>:[<tag>] [-s]",
OptionalApp: true,
OptionalMessage: true,
Category: "deploy",
Short: "deploy a docker image",
Long: `
Deploy is used to deploy a docker image to an app.
Options:
-s enable the status stream during the deployment. If this is enabled, the
command will wait until the scheduler has finished deploying the new
release.
Examples:
$ emp deploy remind101/acme-inc:latest
Pulling repository remind101/acme-inc
345c7524bc96: Download complete
a1dd7097a8e8: Download complete
23debee88b99: Download complete
31862d352883: Download complete
c7388ff7ab91: Download complete
78fb106ed050: Download complete
133fcef559c4: Download complete
Status: Image is up to date for remind101/acme-inc:latest
Status: Created new release v1 for acme-inc
$ emp releases
v1 Jan 1 12:55 Deploy remind101/acme-inc:latest
`,
}
func init() {
cmdDeploy.Flag.BoolVarP(&stream, "stream", "s", false, "boolean to enable the status stream")
}
type PostDeployForm struct {
Image string `json:"image"`
Stream bool `json:"stream"`
}
func runDeploy(cmd *Command, args []string) {
r, w := io.Pipe()
if len(args) < 1 {
printFatal("You must specify an image to deploy")
}
image := args[0]
message := getMessage()
form := &PostDeployForm{Image: image, Stream: stream}
var endpoint string
appName, _ := app()
if appName != "" {
endpoint = fmt.Sprintf("/apps/%s/deploys", appName)
} else {
endpoint = "/deploys"
}
rh := heroku.RequestHeaders{CommitMessage: message}
go func() {
must(client.PostWithHeaders(w, endpoint, form, rh.Headers()))
must(w.Close())
}()
outFd, isTerminalOut := term.GetFdInfo(os.Stdout)
must(jsonmessage.DisplayJSONMessagesStream(r, os.Stdout, outFd, isTerminalOut, nil))
}