github.com/xeptore/docker-cli@v20.10.14+incompatible/cli/command/stack/deploy.go (about) 1 package stack 2 3 import ( 4 "github.com/docker/cli/cli" 5 "github.com/docker/cli/cli/command" 6 "github.com/docker/cli/cli/command/stack/kubernetes" 7 "github.com/docker/cli/cli/command/stack/loader" 8 "github.com/docker/cli/cli/command/stack/options" 9 "github.com/docker/cli/cli/command/stack/swarm" 10 composetypes "github.com/docker/cli/cli/compose/types" 11 "github.com/spf13/cobra" 12 "github.com/spf13/pflag" 13 ) 14 15 func newDeployCommand(dockerCli command.Cli, common *commonOptions) *cobra.Command { 16 var opts options.Deploy 17 18 cmd := &cobra.Command{ 19 Use: "deploy [OPTIONS] STACK", 20 Aliases: []string{"up"}, 21 Short: "Deploy a new stack or update an existing stack", 22 Args: cli.ExactArgs(1), 23 RunE: func(cmd *cobra.Command, args []string) error { 24 opts.Namespace = args[0] 25 if err := validateStackName(opts.Namespace); err != nil { 26 return err 27 } 28 config, err := loader.LoadComposefile(dockerCli, opts) 29 if err != nil { 30 return err 31 } 32 return RunDeploy(dockerCli, cmd.Flags(), config, common.Orchestrator(), opts) 33 }, 34 } 35 36 flags := cmd.Flags() 37 flags.StringSliceVarP(&opts.Composefiles, "compose-file", "c", []string{}, `Path to a Compose file, or "-" to read from stdin`) 38 flags.SetAnnotation("compose-file", "version", []string{"1.25"}) 39 flags.BoolVar(&opts.SendRegistryAuth, "with-registry-auth", false, "Send registry authentication details to Swarm agents") 40 flags.SetAnnotation("with-registry-auth", "swarm", nil) 41 flags.BoolVar(&opts.Prune, "prune", false, "Prune services that are no longer referenced") 42 flags.SetAnnotation("prune", "version", []string{"1.27"}) 43 flags.SetAnnotation("prune", "swarm", nil) 44 flags.StringVar(&opts.ResolveImage, "resolve-image", swarm.ResolveImageAlways, 45 `Query the registry to resolve image digest and supported platforms ("`+swarm.ResolveImageAlways+`"|"`+swarm.ResolveImageChanged+`"|"`+swarm.ResolveImageNever+`")`) 46 flags.SetAnnotation("resolve-image", "version", []string{"1.30"}) 47 flags.SetAnnotation("resolve-image", "swarm", nil) 48 kubernetes.AddNamespaceFlag(flags) 49 return cmd 50 } 51 52 // RunDeploy performs a stack deploy against the specified orchestrator 53 func RunDeploy(dockerCli command.Cli, flags *pflag.FlagSet, config *composetypes.Config, commonOrchestrator command.Orchestrator, opts options.Deploy) error { 54 return runOrchestratedCommand(dockerCli, flags, commonOrchestrator, 55 func() error { return swarm.RunDeploy(dockerCli, opts, config) }, 56 func(kli *kubernetes.KubeCli) error { return kubernetes.RunDeploy(kli, opts, config) }) 57 }