From e956441fe0f5fedaa0ca18f80ea767c46432507f Mon Sep 17 00:00:00 2001 From: Michael Crosby Date: Fri, 27 Jul 2018 12:09:11 -0400 Subject: [PATCH] Add WithImageConfigArgs to replace CMD on image This allows users to provide args for the process arguments while creating the base spec with an image. It provides the same symantics as Docker where additional args replace the CMD while leaving the ENTRYPOINT the same. Signed-off-by: Michael Crosby --- oci/spec_opts_unix.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/oci/spec_opts_unix.go b/oci/spec_opts_unix.go index 27be93a20..9b01afa44 100644 --- a/oci/spec_opts_unix.go +++ b/oci/spec_opts_unix.go @@ -106,6 +106,12 @@ func WithLinuxNamespace(ns specs.LinuxNamespace) SpecOpts { // WithImageConfig configures the spec to from the configuration of an Image func WithImageConfig(image Image) SpecOpts { + return WithImageConfigArgs(image, nil) +} + +// WithImageConfigArgs configures the spec to from the configuration of an Image with additional args that +// replaces the CMD of the image +func WithImageConfigArgs(image Image, args []string) SpecOpts { return func(ctx context.Context, client Client, c *containers.Container, s *Spec) error { ic, err := image.Config(ctx) if err != nil { @@ -133,6 +139,9 @@ func WithImageConfig(image Image) SpecOpts { setProcess(s) s.Process.Env = append(s.Process.Env, config.Env...) cmd := config.Cmd + if len(args) > 0 { + cmd = args + } s.Process.Args = append(config.Entrypoint, cmd...) cwd := config.WorkingDir if cwd == "" {