github.com/beornf/libcompose@v0.4.1-0.20210215180846-a59802c0f07c/cli/docker/app/commands.go (about)

     1  package app
     2  
     3  import (
     4  	"github.com/docker/libcompose/cli/command"
     5  	"github.com/docker/libcompose/docker/client"
     6  	"github.com/docker/libcompose/docker/ctx"
     7  	"github.com/sirupsen/logrus"
     8  	"github.com/urfave/cli"
     9  )
    10  
    11  // DockerClientFlags defines the flags that are specific to the docker client,
    12  // like configdir or tls related flags.
    13  func DockerClientFlags() []cli.Flag {
    14  	return []cli.Flag{
    15  		cli.BoolFlag{
    16  			Name:  "tls",
    17  			Usage: "Use TLS; implied by --tlsverify",
    18  		},
    19  		cli.BoolFlag{
    20  			Name:   "tlsverify",
    21  			Usage:  "Use TLS and verify the remote",
    22  			EnvVar: "DOCKER_TLS_VERIFY",
    23  		},
    24  		cli.StringFlag{
    25  			Name:  "tlscacert",
    26  			Usage: "Trust certs signed only by this CA",
    27  		},
    28  		cli.StringFlag{
    29  			Name:  "tlscert",
    30  			Usage: "Path to TLS certificate file",
    31  		},
    32  		cli.StringFlag{
    33  			Name:  "tlskey",
    34  			Usage: "Path to TLS key file",
    35  		},
    36  		cli.StringFlag{
    37  			Name:  "configdir",
    38  			Usage: "Path to docker config dir, default ${HOME}/.docker",
    39  		},
    40  	}
    41  }
    42  
    43  // Populate updates the specified docker context based on command line arguments and subcommands.
    44  func Populate(context *ctx.Context, c *cli.Context) {
    45  	command.Populate(&context.Context, c)
    46  
    47  	context.ConfigDir = c.String("configdir")
    48  
    49  	opts := client.Options{}
    50  	opts.TLS = c.GlobalBool("tls")
    51  	opts.TLSVerify = c.GlobalBool("tlsverify")
    52  	opts.TLSOptions.CAFile = c.GlobalString("tlscacert")
    53  	opts.TLSOptions.CertFile = c.GlobalString("tlscert")
    54  	opts.TLSOptions.KeyFile = c.GlobalString("tlskey")
    55  
    56  	clientFactory, err := client.NewDefaultFactory(opts)
    57  	if err != nil {
    58  		logrus.Fatalf("Failed to construct Docker client: %v", err)
    59  	}
    60  
    61  	context.ClientFactory = clientFactory
    62  }