Skip to content

Commit

Permalink
Add direct option to docker run.
Browse files Browse the repository at this point in the history
Signed-off-by: Frankie Gallina-Jones <frankieg@vmware.com>
  • Loading branch information
robdimsdale authored and ForestEckhardt committed May 20, 2022
1 parent 0ee06c8 commit 01471d4
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
11 changes: 11 additions & 0 deletions docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ type DockerContainerRun struct {

command string
commandArgs []string
direct bool
entrypoint string
env map[string]string
memory string
Expand Down Expand Up @@ -143,6 +144,12 @@ func (r DockerContainerRun) WithCommandArgs(commandArgs []string) DockerContaine
r.commandArgs = commandArgs
return r
}

func (r DockerContainerRun) WithDirect() DockerContainerRun {
r.direct = true
return r
}

func (r DockerContainerRun) WithTTY() DockerContainerRun {
r.tty = true
return r
Expand Down Expand Up @@ -227,6 +234,10 @@ func (r DockerContainerRun) Execute(imageID string) (Container, error) {

args = append(args, imageID)

if r.direct {
args = append(args, "--")
}

if r.command != "" {
args = append(args, r.command)
}
Expand Down
22 changes: 22 additions & 0 deletions docker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,28 @@ func testDocker(t *testing.T, context spec.G, it spec.S) {
})
})

context("when given optional direct setting", func() {
it("runs the command directly (i.e. with '--' before command)", func() {
container, err := docker.Container.Run.
WithCommand("/some/command").
WithDirect().
Execute("some-image-id")

Expect(err).NotTo(HaveOccurred())
Expect(container).To(Equal(occam.Container{
ID: "some-container-id",
}))

Expect(executeArgs).To(HaveLen(2))
Expect(executeArgs[0]).To(Equal([]string{
"container", "run",
"--detach",
"some-image-id",
"--",
"/some/command",
}))
})
})
context("when given optional tty setting", func() {
it("sets the tty flag on the run command", func() {
container, err := docker.Container.Run.
Expand Down

0 comments on commit 01471d4

Please sign in to comment.