Merge pull request #29228 from dnephin/add-entrypoint-to-service-cli
Add entrypoint flags to service cli.
This commit is contained in:
commit
cf19bd44af
2 changed files with 34 additions and 8 deletions
|
@ -10,6 +10,7 @@ import (
|
|||
"github.com/docker/docker/api/types/swarm"
|
||||
"github.com/docker/docker/opts"
|
||||
runconfigopts "github.com/docker/docker/runconfig/opts"
|
||||
shlex "github.com/flynn-archive/go-shlex"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/spf13/pflag"
|
||||
)
|
||||
|
@ -157,6 +158,30 @@ func (opts *placementPrefOpts) Type() string {
|
|||
return "pref"
|
||||
}
|
||||
|
||||
// ShlexOpt is a flag Value which parses a string as a list of shell words
|
||||
type ShlexOpt []string
|
||||
|
||||
// Set the value
|
||||
func (s *ShlexOpt) Set(value string) error {
|
||||
valueSlice, err := shlex.Split(value)
|
||||
*s = ShlexOpt(valueSlice)
|
||||
return err
|
||||
}
|
||||
|
||||
// Type returns the tyep of the value
|
||||
func (s *ShlexOpt) Type() string {
|
||||
return "command"
|
||||
}
|
||||
|
||||
func (s *ShlexOpt) String() string {
|
||||
return fmt.Sprint(*s)
|
||||
}
|
||||
|
||||
// Value returns the value as a string slice
|
||||
func (s *ShlexOpt) Value() []string {
|
||||
return []string(*s)
|
||||
}
|
||||
|
||||
type updateOptions struct {
|
||||
parallelism uint64
|
||||
delay time.Duration
|
||||
|
@ -312,6 +337,7 @@ type serviceOptions struct {
|
|||
labels opts.ListOpts
|
||||
containerLabels opts.ListOpts
|
||||
image string
|
||||
entrypoint ShlexOpt
|
||||
args []string
|
||||
hostname string
|
||||
env opts.ListOpts
|
||||
|
@ -427,6 +453,7 @@ func (opts *serviceOptions) ToService() (swarm.ServiceSpec, error) {
|
|||
ContainerSpec: swarm.ContainerSpec{
|
||||
Image: opts.image,
|
||||
Args: opts.args,
|
||||
Command: opts.entrypoint.Value(),
|
||||
Env: currentEnv,
|
||||
Hostname: opts.hostname,
|
||||
Labels: runconfigopts.ConvertKVStringsToMap(opts.containerLabels.GetAll()),
|
||||
|
@ -473,6 +500,7 @@ func addServiceFlags(flags *pflag.FlagSet, opts *serviceOptions) {
|
|||
flags.StringVarP(&opts.user, flagUser, "u", "", "Username or UID (format: <name|uid>[:<group|gid>])")
|
||||
flags.StringVar(&opts.hostname, flagHostname, "", "Container hostname")
|
||||
flags.SetAnnotation(flagHostname, "version", []string{"1.25"})
|
||||
flags.Var(&opts.entrypoint, flagEntrypoint, "Overwrite the default ENTRYPOINT of the image")
|
||||
|
||||
flags.Var(&opts.resources.limitCPU, flagLimitCPU, "Limit CPUs")
|
||||
flags.Var(&opts.resources.limitMemBytes, flagLimitMemory, "Limit Memory")
|
||||
|
@ -554,6 +582,7 @@ const (
|
|||
flagDNSSearchRemove = "dns-search-rm"
|
||||
flagDNSSearchAdd = "dns-search-add"
|
||||
flagEndpointMode = "endpoint-mode"
|
||||
flagEntrypoint = "entrypoint"
|
||||
flagHost = "host"
|
||||
flagHostAdd = "host-add"
|
||||
flagHostRemove = "host-rm"
|
||||
|
|
|
@ -17,7 +17,6 @@ import (
|
|||
"github.com/docker/docker/opts"
|
||||
runconfigopts "github.com/docker/docker/runconfig/opts"
|
||||
"github.com/docker/go-connections/nat"
|
||||
shlex "github.com/flynn-archive/go-shlex"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/pflag"
|
||||
|
@ -38,7 +37,7 @@ func newUpdateCommand(dockerCli *command.DockerCli) *cobra.Command {
|
|||
|
||||
flags := cmd.Flags()
|
||||
flags.String("image", "", "Service image tag")
|
||||
flags.String("args", "", "Service command args")
|
||||
flags.Var(&ShlexOpt{}, "args", "Service command args")
|
||||
flags.Bool("rollback", false, "Rollback to previous specification")
|
||||
flags.SetAnnotation("rollback", "version", []string{"1.25"})
|
||||
flags.Bool("force", false, "Force update even if no changes require it")
|
||||
|
@ -258,6 +257,7 @@ func updateService(flags *pflag.FlagSet, spec *swarm.ServiceSpec) error {
|
|||
updateContainerLabels(flags, &cspec.Labels)
|
||||
updateString("image", &cspec.Image)
|
||||
updateStringToSlice(flags, "args", &cspec.Args)
|
||||
updateStringToSlice(flags, flagEntrypoint, &cspec.Command)
|
||||
updateEnvironment(flags, &cspec.Env)
|
||||
updateString(flagWorkdir, &cspec.Dir)
|
||||
updateString(flagUser, &cspec.User)
|
||||
|
@ -409,15 +409,12 @@ func updateService(flags *pflag.FlagSet, spec *swarm.ServiceSpec) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func updateStringToSlice(flags *pflag.FlagSet, flag string, field *[]string) error {
|
||||
func updateStringToSlice(flags *pflag.FlagSet, flag string, field *[]string) {
|
||||
if !flags.Changed(flag) {
|
||||
return nil
|
||||
return
|
||||
}
|
||||
|
||||
value, _ := flags.GetString(flag)
|
||||
valueSlice, err := shlex.Split(value)
|
||||
*field = valueSlice
|
||||
return err
|
||||
*field = flags.Lookup(flag).Value.(*ShlexOpt).Value()
|
||||
}
|
||||
|
||||
func anyChanged(flags *pflag.FlagSet, fields ...string) bool {
|
||||
|
|
Loading…
Reference in a new issue