Skip to content

Commit

Permalink
WIP add WithVolume support
Browse files Browse the repository at this point in the history
  • Loading branch information
Andy Brown authored and ryanmoran committed Mar 3, 2021
1 parent edfe10f commit 5fc0f1a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
10 changes: 10 additions & 0 deletions docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ type DockerContainerRun struct {
entrypoint string
publishPorts []string
publishAll bool
volume string
}

func (r DockerContainerRun) WithEnv(env map[string]string) DockerContainerRun {
Expand Down Expand Up @@ -150,6 +151,11 @@ func (r DockerContainerRun) WithPublishAll() DockerContainerRun {
return r
}

func (r DockerContainerRun) WithVolume(volume string) DockerContainerRun {
r.volume = volume
return r
}

func (r DockerContainerRun) Execute(imageID string) (Container, error) {
args := []string{"container", "run", "--detach"}

Expand Down Expand Up @@ -188,6 +194,10 @@ func (r DockerContainerRun) Execute(imageID string) (Container, error) {
args = append(args, "--entrypoint", r.entrypoint)
}

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

args = append(args, imageID)

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

context("when given optionial volume setting", func() {
it("sets the volume flag on the run command", func() {
container, err := docker.Container.Run.
WithVolume("/tmp/host-source:/tmp/dir-on-container:rw").
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",
"--detect",
"--volume", "/tmp/host-source:/tmp/dir-on-container:rw",
"some-image-id",
}))
})
})

context("failure cases", func() {
context("when the executable fails", func() {
it.Before(func() {
Expand Down

0 comments on commit 5fc0f1a

Please sign in to comment.