forked from docker/libcompose
-
Notifications
You must be signed in to change notification settings - Fork 0
/
commands.go
62 lines (55 loc) · 1.61 KB
/
commands.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
package app
import (
"github.com/Sirupsen/logrus"
"github.com/docker/libcompose/cli/command"
"github.com/docker/libcompose/docker/client"
"github.com/docker/libcompose/docker/ctx"
"github.com/urfave/cli"
)
// DockerClientFlags defines the flags that are specific to the docker client,
// like configdir or tls related flags.
func DockerClientFlags() []cli.Flag {
return []cli.Flag{
cli.BoolFlag{
Name: "tls",
Usage: "Use TLS; implied by --tlsverify",
},
cli.BoolFlag{
Name: "tlsverify",
Usage: "Use TLS and verify the remote",
EnvVar: "DOCKER_TLS_VERIFY",
},
cli.StringFlag{
Name: "tlscacert",
Usage: "Trust certs signed only by this CA",
},
cli.StringFlag{
Name: "tlscert",
Usage: "Path to TLS certificate file",
},
cli.StringFlag{
Name: "tlskey",
Usage: "Path to TLS key file",
},
cli.StringFlag{
Name: "configdir",
Usage: "Path to docker config dir, default ${HOME}/.docker",
},
}
}
// Populate updates the specified docker context based on command line arguments and subcommands.
func Populate(context *ctx.Context, c *cli.Context) {
command.Populate(&context.Context, c)
context.ConfigDir = c.String("configdir")
opts := client.Options{}
opts.TLS = c.GlobalBool("tls")
opts.TLSVerify = c.GlobalBool("tlsverify")
opts.TLSOptions.CAFile = c.GlobalString("tlscacert")
opts.TLSOptions.CertFile = c.GlobalString("tlscert")
opts.TLSOptions.KeyFile = c.GlobalString("tlskey")
clientFactory, err := client.NewDefaultFactory(opts)
if err != nil {
logrus.Fatalf("Failed to construct Docker client: %v", err)
}
context.ClientFactory = clientFactory
}