Skip to content

Commit

Permalink
FAB-15666 Pass NetworkMode in DockerBuildOptions
Browse files Browse the repository at this point in the history
NetworkMode was being passed when laucnching containers but not when
building images.

FAB-15666 #done

Change-Id: Id097594bd587bed131cf9c4b7131af66ea380973
Signed-off-by: Gari Singh <gari.r.singh@gmail.com>
Signed-off-by: Matthew Sykes <sykesmat@us.ibm.com>
  • Loading branch information
mastersingh24 authored and sykesm committed Sep 24, 2019
1 parent 003c8c5 commit 7775c13
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
2 changes: 2 additions & 0 deletions core/container/dockercontroller/dockercontroller.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,12 +200,14 @@ func (vm *DockerVM) deployImage(client dockerClient, ccid ccintf.CCID, reader io
return err
}

networkMode := getDockerHostConfig().NetworkMode
outputbuf := bytes.NewBuffer(nil)
opts := docker.BuildImageOptions{
Name: id,
Pull: viper.GetBool("chaincode.pull"),
InputStream: reader,
OutputStream: outputbuf,
NetworkMode: networkMode,
}

startTime := time.Now()
Expand Down
18 changes: 14 additions & 4 deletions core/container/dockercontroller/dockercontroller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -420,14 +420,24 @@ func Test_deployImage(t *testing.T) {
Pull: viper.GetBool("chaincode.pull"),
InputStream: nil,
OutputStream: bytes.NewBuffer(nil),
NetworkMode: "host",
}

client.BuildImageStub = func(buildOpts docker.BuildImageOptions) error {
gt.Expect(buildOpts).To(Equal(expectedOpts))
return nil
}
err = dockerVM.deployImage(client, ccid, nil)
gt.Expect(err).NotTo(HaveOccurred())
gt.Expect(client.BuildImageCallCount()).To(Equal(1))
gt.Expect(client.BuildImageArgsForCall(0)).To(Equal(expectedOpts))

// set network mode
hostConfig = getDockerHostConfig()
hostConfig.NetworkMode = "bridge"
expectedOpts.NetworkMode = "bridge"
err = dockerVM.deployImage(client, ccid, nil)

gt.Expect(err).NotTo(HaveOccurred())
gt.Expect(client.BuildImageCallCount()).To(Equal(2))
gt.Expect(client.BuildImageArgsForCall(1)).To(Equal(expectedOpts))
hostConfig = nil
}

type InMemBuilder struct{}
Expand Down

0 comments on commit 7775c13

Please sign in to comment.