Skip to content

Commit

Permalink
Merge pull request containers#21312 from albertofaria/no-entrypoint
Browse files Browse the repository at this point in the history
Allow passing the OCI runtime an empty command
  • Loading branch information
openshift-merge-bot[bot] authored Jan 23, 2024
2 parents d084146 + 5cc83da commit fcac504
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 9 deletions.
5 changes: 1 addition & 4 deletions pkg/specgen/generate/container_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,10 +226,7 @@ func MakeContainer(ctx context.Context, rt *libpod.Runtime, s *specgen.SpecGener
options = append(options, libpod.WithHostUsers(s.HostUsers))
}

command, err := makeCommand(s, imageData)
if err != nil {
return nil, nil, nil, err
}
command := makeCommand(s, imageData)

infraVol := len(compatibleOptions.Mounts) > 0 || len(compatibleOptions.Volumes) > 0 || len(compatibleOptions.ImageVolumes) > 0 || len(compatibleOptions.OverlayVolumes) > 0
opts, err := createContainerOptions(rt, s, pod, finalVolumes, finalOverlays, imageData, command, infraVol, *compatibleOptions)
Expand Down
9 changes: 5 additions & 4 deletions pkg/specgen/generate/oci.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
package generate

import (
"fmt"
"strings"

"github.com/containers/common/libimage"
"github.com/containers/podman/v4/libpod/define"
"github.com/containers/podman/v4/pkg/specgen"
"github.com/opencontainers/runtime-tools/generate"
"github.com/sirupsen/logrus"
)

func addRlimits(s *specgen.SpecGenerator, g *generate.Generator) {
Expand All @@ -23,7 +23,7 @@ func addRlimits(s *specgen.SpecGenerator, g *generate.Generator) {
}

// Produce the final command for the container.
func makeCommand(s *specgen.SpecGenerator, imageData *libimage.ImageData) ([]string, error) {
func makeCommand(s *specgen.SpecGenerator, imageData *libimage.ImageData) []string {
finalCommand := []string{}

entrypoint := s.Entrypoint
Expand All @@ -46,13 +46,14 @@ func makeCommand(s *specgen.SpecGenerator, imageData *libimage.ImageData) ([]str
finalCommand = append(finalCommand, command...)

if len(finalCommand) == 0 {
return nil, fmt.Errorf("no command or entrypoint provided, and no CMD or ENTRYPOINT from image")
logrus.Debug("no command or entrypoint provided, and no CMD or ENTRYPOINT from image: defaulting to empty string")
finalCommand = []string{""}
}

if s.Init {
// bind mount for this binary is added in addContainerInitBinary()
finalCommand = append([]string{define.ContainerInitPath, "--"}, finalCommand...)
}

return finalCommand, nil
return finalCommand
}
2 changes: 1 addition & 1 deletion test/e2e/run_entrypoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ CMD []
podmanTest.BuildImage(dockerfile, "foobar.com/entrypoint:latest", "false")
session := podmanTest.Podman([]string{"run", "foobar.com/entrypoint:latest"})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(125))
Expect(session).Should(Or(Exit(126), Exit(127)))
})

It("podman run entrypoint == [\"\"]", func() {
Expand Down
16 changes: 16 additions & 0 deletions test/system/030-run.bats
Original file line number Diff line number Diff line change
Expand Up @@ -1415,4 +1415,20 @@ search | $IMAGE |
run_podman rmi $(pause_image)
}

@test "podman run - no entrypoint" {
run_podman 127 run --rm --rootfs "$PODMAN_TMPDIR"

# runc and crun emit different diagnostics
runtime=$(podman_runtime)
case "$runtime" in
crun) expect='crun: executable file `` not found in $PATH: No such file or directory: OCI runtime attempted to invoke a command that was not found' ;;
runc) expect='runc: runc create failed: unable to start container process: exec: "": executable file not found in $PATH: OCI runtime attempted to invoke a command that was not found' ;;
*) skip "Unknown runtime '$runtime'" ;;
esac

# The '.*' in the error below is for dealing with podman-remote, which
# includes "error preparing container <sha> for attach" in output.
is "$output" "Error.*: $expect" "podman emits useful diagnostic when no entrypoint is set"
}

# vim: filetype=sh

0 comments on commit fcac504

Please sign in to comment.