From c0f313627bfd6cb9bb52394fd68ce1c13a1bc438 Mon Sep 17 00:00:00 2001 From: Forest Eckhardt Date: Wed, 16 Mar 2022 15:41:48 -0400 Subject: [PATCH] Adds --network flag for run command (#131) --- docker.go | 16 +++++++++++++--- docker_test.go | 21 +++++++++++++++++++++ 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/docker.go b/docker.go index 79abedd..0b15ae3 100644 --- a/docker.go +++ b/docker.go @@ -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 } @@ -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"} @@ -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) } diff --git a/docker_test.go b/docker_test.go index 0a3c64f..7e10e40 100644 --- a/docker_test.go +++ b/docker_test.go @@ -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() {