From d26266659d8649b36b91e8f8f78f8073007554ac Mon Sep 17 00:00:00 2001 From: baude Date: Sat, 10 Feb 2018 11:57:05 -0600 Subject: Honor ENTRYPOINT in image When an image has an ENTRYPOINT defined, we should be honoring it. The problem is described in issue #321. Also, added buildah binary to test runtimes for testing entrypoint and will also allow us to test podman build as well. Signed-off-by: baude Closes: #322 Approved by: rhatdan --- test/e2e/libpod_suite_test.go | 11 +++++ test/e2e/run_entrypoint_test.go | 100 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 111 insertions(+) create mode 100644 test/e2e/run_entrypoint_test.go (limited to 'test') diff --git a/test/e2e/libpod_suite_test.go b/test/e2e/libpod_suite_test.go index b8e650e30..afe91134e 100644 --- a/test/e2e/libpod_suite_test.go +++ b/test/e2e/libpod_suite_test.go @@ -449,3 +449,14 @@ func (p *PodmanTest) GetContainerStatus() string { session.WaitWithDefaultTimeout() return session.OutputToString() } + +// BuildImage uses podman build and buildah to build an image +// called imageName based on a string dockerfile +func (p *PodmanTest) BuildImage(dockerfile, imageName string) { + dockerfilePath := filepath.Join(p.TempDir, "Dockerfile") + err := ioutil.WriteFile(dockerfilePath, []byte(dockerfile), 0755) + Expect(err).To(BeNil()) + session := p.Podman([]string{"build", "-t", imageName, "--file", dockerfilePath, p.TempDir}) + session.Wait(120) + Expect(session.ExitCode()).To(Equal(0)) +} diff --git a/test/e2e/run_entrypoint_test.go b/test/e2e/run_entrypoint_test.go new file mode 100644 index 000000000..2ae282967 --- /dev/null +++ b/test/e2e/run_entrypoint_test.go @@ -0,0 +1,100 @@ +package integration + +import ( + "os" + + . "github.com/onsi/ginkgo" + . "github.com/onsi/gomega" +) + +var _ = Describe("Podman run entrypoint", func() { + var ( + tempdir string + err error + podmanTest PodmanTest + ) + + BeforeEach(func() { + tempdir, err = CreateTempDirInTempDir() + if err != nil { + os.Exit(1) + } + podmanTest = PodmanCreate(tempdir) + podmanTest.RestoreArtifact(ALPINE) + }) + + AfterEach(func() { + podmanTest.Cleanup() + + }) + + It("podman run entrypoint", func() { + dockerfile := `FROM docker.io/library/alpine:latest +ENTRYPOINT ["grep", "Alpine", "/etc/os-release"] +` + podmanTest.BuildImage(dockerfile, "foobar.com/entrypoint:latest") + session := podmanTest.Podman([]string{"run", "foobar.com/entrypoint:latest"}) + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(0)) + Expect(len(session.OutputToStringArray())).To(Equal(3)) + }) + + It("podman run entrypoint with cmd", func() { + dockerfile := `FROM docker.io/library/alpine:latest +CMD [ "-v"] +ENTRYPOINT ["grep", "Alpine", "/etc/os-release"] +` + podmanTest.BuildImage(dockerfile, "foobar.com/entrypoint:latest") + session := podmanTest.Podman([]string{"run", "foobar.com/entrypoint:latest"}) + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(0)) + Expect(len(session.OutputToStringArray())).To(Equal(5)) + }) + + It("podman run entrypoint with user cmd overrides image cmd", func() { + dockerfile := `FROM docker.io/library/alpine:latest +CMD [ "-v"] +ENTRYPOINT ["grep", "Alpine", "/etc/os-release"] +` + podmanTest.BuildImage(dockerfile, "foobar.com/entrypoint:latest") + session := podmanTest.Podman([]string{"run", "foobar.com/entrypoint:latest", "-i"}) + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(0)) + Expect(len(session.OutputToStringArray())).To(Equal(6)) + }) + + It("podman run entrypoint with user cmd no image cmd", func() { + dockerfile := `FROM docker.io/library/alpine:latest +ENTRYPOINT ["grep", "Alpine", "/etc/os-release"] +` + podmanTest.BuildImage(dockerfile, "foobar.com/entrypoint:latest") + session := podmanTest.Podman([]string{"run", "foobar.com/entrypoint:latest", "-i"}) + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(0)) + Expect(len(session.OutputToStringArray())).To(Equal(6)) + }) + + It("podman run user entrypoint overrides image entrypoint and image cmd", func() { + dockerfile := `FROM docker.io/library/alpine:latest +CMD ["-i"] +ENTRYPOINT ["grep", "Alpine", "/etc/os-release"] +` + podmanTest.BuildImage(dockerfile, "foobar.com/entrypoint:latest") + session := podmanTest.Podman([]string{"run", "--entrypoint=uname", "foobar.com/entrypoint:latest"}) + 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() { + dockerfile := `FROM docker.io/library/alpine:latest +CMD ["-i"] +ENTRYPOINT ["grep", "Alpine", "/etc/os-release"] +` + podmanTest.BuildImage(dockerfile, "foobar.com/entrypoint:latest") + session := podmanTest.Podman([]string{"run", "--entrypoint=uname", "foobar.com/entrypoint:latest", "-r"}) + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(0)) + Expect(session.LineInOuputStartsWith("Linux")).To(BeFalse()) + }) +}) -- cgit v1.2.3-54-g00ecf