Add entrypoint flags to service cli.

Signed-off-by: Daniel Nephin <dnephin@docker.com>
This commit is contained in:
Daniel Nephin 2016-12-07 14:37:55 -05:00
parent d14a4d4231
commit 951fdd11cd
2 changed files with 34 additions and 8 deletions

View File

@ -10,6 +10,7 @@ import (
"github.com/docker/docker/api/types/swarm" "github.com/docker/docker/api/types/swarm"
"github.com/docker/docker/opts" "github.com/docker/docker/opts"
runconfigopts "github.com/docker/docker/runconfig/opts" runconfigopts "github.com/docker/docker/runconfig/opts"
shlex "github.com/flynn-archive/go-shlex"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/spf13/pflag" "github.com/spf13/pflag"
) )
@ -157,6 +158,30 @@ func (opts *placementPrefOpts) Type() string {
return "pref" 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 { type updateOptions struct {
parallelism uint64 parallelism uint64
delay time.Duration delay time.Duration
@ -312,6 +337,7 @@ type serviceOptions struct {
labels opts.ListOpts labels opts.ListOpts
containerLabels opts.ListOpts containerLabels opts.ListOpts
image string image string
entrypoint ShlexOpt
args []string args []string
hostname string hostname string
env opts.ListOpts env opts.ListOpts
@ -427,6 +453,7 @@ func (opts *serviceOptions) ToService() (swarm.ServiceSpec, error) {
ContainerSpec: swarm.ContainerSpec{ ContainerSpec: swarm.ContainerSpec{
Image: opts.image, Image: opts.image,
Args: opts.args, Args: opts.args,
Command: opts.entrypoint.Value(),
Env: currentEnv, Env: currentEnv,
Hostname: opts.hostname, Hostname: opts.hostname,
Labels: runconfigopts.ConvertKVStringsToMap(opts.containerLabels.GetAll()), 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.StringVarP(&opts.user, flagUser, "u", "", "Username or UID (format: <name|uid>[:<group|gid>])")
flags.StringVar(&opts.hostname, flagHostname, "", "Container hostname") flags.StringVar(&opts.hostname, flagHostname, "", "Container hostname")
flags.SetAnnotation(flagHostname, "version", []string{"1.25"}) 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.limitCPU, flagLimitCPU, "Limit CPUs")
flags.Var(&opts.resources.limitMemBytes, flagLimitMemory, "Limit Memory") flags.Var(&opts.resources.limitMemBytes, flagLimitMemory, "Limit Memory")
@ -554,6 +582,7 @@ const (
flagDNSSearchRemove = "dns-search-rm" flagDNSSearchRemove = "dns-search-rm"
flagDNSSearchAdd = "dns-search-add" flagDNSSearchAdd = "dns-search-add"
flagEndpointMode = "endpoint-mode" flagEndpointMode = "endpoint-mode"
flagEntrypoint = "entrypoint"
flagHost = "host" flagHost = "host"
flagHostAdd = "host-add" flagHostAdd = "host-add"
flagHostRemove = "host-rm" flagHostRemove = "host-rm"

View File

@ -17,7 +17,6 @@ import (
"github.com/docker/docker/opts" "github.com/docker/docker/opts"
runconfigopts "github.com/docker/docker/runconfig/opts" runconfigopts "github.com/docker/docker/runconfig/opts"
"github.com/docker/go-connections/nat" "github.com/docker/go-connections/nat"
shlex "github.com/flynn-archive/go-shlex"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/spf13/pflag" "github.com/spf13/pflag"
@ -38,7 +37,7 @@ func newUpdateCommand(dockerCli *command.DockerCli) *cobra.Command {
flags := cmd.Flags() flags := cmd.Flags()
flags.String("image", "", "Service image tag") 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.Bool("rollback", false, "Rollback to previous specification")
flags.SetAnnotation("rollback", "version", []string{"1.25"}) flags.SetAnnotation("rollback", "version", []string{"1.25"})
flags.Bool("force", false, "Force update even if no changes require it") 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) updateContainerLabels(flags, &cspec.Labels)
updateString("image", &cspec.Image) updateString("image", &cspec.Image)
updateStringToSlice(flags, "args", &cspec.Args) updateStringToSlice(flags, "args", &cspec.Args)
updateStringToSlice(flags, flagEntrypoint, &cspec.Command)
updateEnvironment(flags, &cspec.Env) updateEnvironment(flags, &cspec.Env)
updateString(flagWorkdir, &cspec.Dir) updateString(flagWorkdir, &cspec.Dir)
updateString(flagUser, &cspec.User) updateString(flagUser, &cspec.User)
@ -409,15 +409,12 @@ func updateService(flags *pflag.FlagSet, spec *swarm.ServiceSpec) error {
return nil 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) { if !flags.Changed(flag) {
return nil return
} }
value, _ := flags.GetString(flag) *field = flags.Lookup(flag).Value.(*ShlexOpt).Value()
valueSlice, err := shlex.Split(value)
*field = valueSlice
return err
} }
func anyChanged(flags *pflag.FlagSet, fields ...string) bool { func anyChanged(flags *pflag.FlagSet, fields ...string) bool {