Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Honor ENTRYPOINT in image #322

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ RUN apt-get update && apt-get install -y \
e2fslibs-dev \
gawk \
gettext \
go-md2man \
iptables \
pkg-config \
libaio-dev \
Expand Down Expand Up @@ -96,6 +97,14 @@ RUN set -x \
&& cp "$GOPATH"/bin/crictl /usr/bin/ \
&& rm -rf "$GOPATH"

# Install buildah
RUN set -x \
&& export GOPATH=/go \
&& git clone https://github.com/projectatomic/buildah "$GOPATH/src/github.com/projectatomic/buildah" \
&& cd "$GOPATH/src/github.com/projectatomic/buildah" \
&& make \
&& make install

# Install ginkgo
RUN set -x \
&& export GOPATH=/go \
Expand Down
9 changes: 9 additions & 0 deletions Dockerfile.CentOS
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ RUN yum -y install btrfs-progs-devel \
glib2-devel \
gnupg \
golang \
golang-github-cpuguy83-go-md2man \
gpgme-devel \
libassuan-devel \
libseccomp-devel \
Expand All @@ -34,6 +35,14 @@ RUN set -x \
&& cp bin/* /usr/libexec/cni \
&& rm -rf "$GOPATH"

# Install buildah
RUN set -x \
&& export GOPATH=/go \
&& git clone https://github.com/projectatomic/buildah "$GOPATH/src/github.com/projectatomic/buildah" \
&& cd "$GOPATH/src/github.com/projectatomic/buildah" \
&& make \
&& make install

# Install ginkgo
RUN set -x \
&& export GOPATH=/go \
Expand Down
9 changes: 9 additions & 0 deletions Dockerfile.Fedora
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ RUN dnf -y install btrfs-progs-devel \
glib2-devel \
gnupg \
golang \
golang-github-cpuguy83-go-md2man \
gpgme-devel \
libassuan-devel \
libseccomp-devel \
Expand All @@ -36,6 +37,14 @@ RUN set -x \
&& cp bin/* /usr/libexec/cni \
&& rm -rf "$GOPATH"

# Install buildah
RUN set -x \
&& export GOPATH=/go \
&& git clone https://github.com/projectatomic/buildah "$GOPATH/src/github.com/projectatomic/buildah" \
&& cd "$GOPATH/src/github.com/projectatomic/buildah" \
&& make \
&& make install

# Install ginkgo
RUN set -x \
&& export GOPATH=/go \
Expand Down
2 changes: 1 addition & 1 deletion cmd/podman/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ var createFlags = []cli.Flag{
Name: "dns-search",
Usage: "Set custom DNS search domains",
},
cli.StringFlag{
cli.StringSliceFlag{
Name: "entrypoint",
Usage: "Overwrite the default ENTRYPOINT of the image",
},
Expand Down
31 changes: 20 additions & 11 deletions cmd/podman/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ type createConfig struct {
DNSOpt []string //dns-opt
DNSSearch []string //dns-search
DNSServers []string //dns
Entrypoint string //entrypoint
Entrypoint []string //entrypoint
Env map[string]string //env
ExposedPorts map[nat.Port]struct{}
GroupAdd []uint32 // group-add
Expand Down Expand Up @@ -419,14 +419,14 @@ func imageData(c *cli.Context, runtime *libpod.Runtime, image string) (string, s
// Parses CLI options related to container creation into a config which can be
// parsed into an OCI runtime spec
func parseCreateOpts(c *cli.Context, runtime *libpod.Runtime, imageName string, data *inspect.ImageData) (*createConfig, error) {
var command []string
var inputCommand, command []string
var memoryLimit, memoryReservation, memorySwap, memoryKernel int64
var blkioWeight uint16

imageID := data.ID

if len(c.Args()) > 1 {
command = c.Args()[1:]
inputCommand = c.Args()[1:]
}

sysctl, err := validateSysctl(c.StringSlice("sysctl"))
Expand Down Expand Up @@ -567,15 +567,24 @@ func parseCreateOpts(c *cli.Context, runtime *libpod.Runtime, imageName string,
workDir = data.Config.WorkingDir
}

// COMMAND
if len(command) == 0 {
command = data.Config.Cmd
}

// ENTRYPOINT
entrypoint := c.String("entrypoint")
if entrypoint == "" {
entrypoint = strings.Join(data.Config.Entrypoint, " ")
// User input entrypoint takes priority over image entrypoint
entrypoint := c.StringSlice("entrypoint")
if len(entrypoint) == 0 {
entrypoint = data.Config.Entrypoint
}

// Build the command
// If we have an entry point, it goes first
if len(entrypoint) > 0 {
command = entrypoint
}
if len(inputCommand) > 0 {
// User command overrides data CMD
command = append(command, inputCommand...)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this right? I thought user command overrode ENTRYPOINT as well?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's correct.

 2018-02-10 13:22:22 ⌚  localhost in ~/tmp/entrypoint
○ → cat Dockerfile 
FROM alpine
ENTRYPOINT ["ls"]

 2018-02-10 13:22:31 ⌚  localhost in ~/tmp/entrypoint
○ → docker run -it --rm entrycmd:latest top
ls: top: No such file or directory

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh, never knew that. Cool.

} else if len(data.Config.Cmd) > 0 && !c.IsSet("entrypoint") {
// If not user command, add CMD
command = append(command, data.Config.Cmd...)
}

// EXPOSED PORTS
Expand Down
3 changes: 2 additions & 1 deletion cmd/podman/inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"encoding/json"
"strings"

specs "github.com/opencontainers/runtime-spec/specs-go"
"github.com/pkg/errors"
Expand Down Expand Up @@ -223,7 +224,7 @@ func getCtrInspectInfo(ctr *libpod.Container, ctrInspectData *inspect.ContainerI
OpenStdin: config.Stdin,
StopSignal: config.StopSignal,
Cmd: config.Spec.Process.Args,
Entrypoint: createArtifact.Entrypoint,
Entrypoint: strings.Join(createArtifact.Entrypoint, " "),
},
}
return data, nil
Expand Down
11 changes: 11 additions & 0 deletions test/e2e/libpod_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Copy link
Member

@TomSweeneyRedHat TomSweeneyRedHat Feb 10, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fingers crossed that this will work, but ipbabble's been having some fun getting Buildah to run in a Docker container.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

works just fine

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))
}
100 changes: 100 additions & 0 deletions test/e2e/run_entrypoint_test.go
Original file line number Diff line number Diff line change
@@ -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())
})
})