Merge pull request #21312 from albertofaria/no-entrypoint

Allow passing the OCI runtime an empty command
This commit is contained in:
openshift-merge-bot[bot]
2024-01-23 12:48:52 +00:00
committed by GitHub
4 changed files with 23 additions and 9 deletions

View File

@ -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)

View File

@ -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) {
@ -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
@ -46,7 +46,8 @@ 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 {
@ -54,5 +55,5 @@ func makeCommand(s *specgen.SpecGenerator, imageData *libimage.ImageData) ([]str
finalCommand = append([]string{define.ContainerInitPath, "--"}, finalCommand...)
}
return finalCommand, nil
return finalCommand
}

View File

@ -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() {

View File

@ -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