-
Notifications
You must be signed in to change notification settings - Fork 2
/
up.go
39 lines (37 loc) · 1.1 KB
/
up.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
package local
import (
"github.com/jawher/mow.cli"
)
func Up(fn func() *Client) func(cmd *cli.Cmd) {
return func(cmd *cli.Cmd) {
var (
force = cmd.BoolOpt("f force", false, "Force pull the Mesos image")
remove = cmd.BoolOpt("rm remove", false, "Remove any existing container")
envs = cmd.StringsOpt("e env", []string{"MESOS_LOGGING_LEVEL=INFO"}, "Environment variables")
)
cmd.Action = func() {
client := fn()
image, err := client.FindImage(Repository)
failOnErr(err)
if image == nil || *force {
failOnErr(client.PullImage(Repository))
image, err = client.FindImage(Repository)
failOnErr(err)
}
container, err := client.FindContainer(ContainerName, "")
failOnErr(err)
if *remove {
if container != nil {
failOnErr(client.RemoveContainer(container.ID, *force))
container, err = client.CreateContainer(ContainerName, Repository, *envs)
failOnErr(err)
}
}
if container == nil {
container, err = client.CreateContainer(ContainerName, Repository, *envs)
failOnErr(err)
}
failOnErr(client.StartContainer(container.ID))
}
}
}