Skip to content

Commit

Permalink
Merge pull request containers#6939 from rhatdan/entrypoint
Browse files Browse the repository at this point in the history
Fix handling of entrypoint
  • Loading branch information
openshift-merge-robot authored Jul 14, 2020
2 parents c078e93 + 6535c8b commit 50cd21e
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 9 deletions.
12 changes: 5 additions & 7 deletions cmd/podman/common/specgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -367,27 +367,25 @@ func FillOutSpecGen(s *specgen.SpecGenerator, c *ContainerCLIOpts, args []string
s.Annotations = annotations

s.WorkDir = c.Workdir
entrypoint := []string{}
userCommand := []string{}
var command []string
if c.Entrypoint != nil {
entrypoint := []string{}
if ep := *c.Entrypoint; len(ep) > 0 {
// Check if entrypoint specified is json
if err := json.Unmarshal([]byte(*c.Entrypoint), &entrypoint); err != nil {
entrypoint = append(entrypoint, ep)
}
}
s.Entrypoint = entrypoint
// Build the command
// If we have an entry point, it goes first
command = entrypoint
}
var command []string

// Include the command used to create the container.
s.ContainerCreateCommand = os.Args

// Build the command
// If we have an entry point, it goes first
if c.Entrypoint != nil {
command = entrypoint
}
if len(inputCommand) > 0 {
// User command overrides data CMD
command = append(command, inputCommand...)
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/handlers/compat/containers_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func makeCreateConfig(ctx context.Context, containerConfig *config.Config, input
workDir = input.WorkingDir
}

if len(input.Entrypoint) == 0 {
if input.Entrypoint == nil {
entrypointSlice, err := newImage.Entrypoint(ctx)
if err != nil {
return createconfig.CreateConfig{}, err
Expand Down
2 changes: 1 addition & 1 deletion pkg/specgen/generate/oci.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func makeCommand(ctx context.Context, s *specgen.SpecGenerator, img *image.Image
finalCommand := []string{}

entrypoint := s.Entrypoint
if len(entrypoint) == 0 && img != nil {
if entrypoint == nil && img != nil {
newEntry, err := img.Entrypoint(ctx)
if err != nil {
return nil, err
Expand Down
5 changes: 5 additions & 0 deletions test/e2e/run_entrypoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@ ENTRYPOINT ["grep", "Alpine", "/etc/os-release"]
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
Expect(session.LineInOuputStartsWith("Linux")).To(BeTrue())

session = podmanTest.Podman([]string{"run", "--entrypoint", "", "foobar.com/entrypoint:latest", "uname"})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
Expect(session.LineInOuputStartsWith("Linux")).To(BeTrue())
})

It("podman run user entrypoint with command overrides image entrypoint and image cmd", func() {
Expand Down

0 comments on commit 50cd21e

Please sign in to comment.