Skip to content

Commit

Permalink
Adds --network flag for run command (#131)
Browse files Browse the repository at this point in the history
  • Loading branch information
ForestEckhardt authored Mar 16, 2022
1 parent 1afee13 commit c0f3136
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
16 changes: 13 additions & 3 deletions docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,13 @@ type DockerContainerRun struct {
inspect DockerContainerInspect

command string
entrypoint string
env map[string]string
memory string
tty bool
entrypoint string
publishPorts []string
network string
publishAll bool
publishPorts []string
tty bool
volumes []string
}

Expand Down Expand Up @@ -168,6 +169,11 @@ func (r DockerContainerRun) WithVolumes(volumes ...string) DockerContainerRun {
return r
}

func (r DockerContainerRun) WithNetwork(network string) DockerContainerRun {
r.network = network
return r
}

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

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

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

for _, volume := range r.volumes {
args = append(args, "--volume", volume)
}
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 optional entrypoint setting", func() {
it("sets the entrypoint flag on the run command", func() {
container, err := docker.Container.Run.
WithNetwork("host").
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",
"--network", "host",
"some-image-id",
}))
})
})

// TODO: remove this when WithVolume is deprecated.
context("when given optionial volume setting", func() {
it("sets the volume flag on the run command", func() {
Expand Down

0 comments on commit c0f3136

Please sign in to comment.