Skip to content

Commit

Permalink
update: use DOCKER_HOST as the default
Browse files Browse the repository at this point in the history
related: #1338
Signed-off-by: till <till@php.net>
  • Loading branch information
till committed Sep 20, 2023
1 parent 3a994bd commit 9833d11
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 4 deletions.
2 changes: 1 addition & 1 deletion internal/build/phase_config_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ func WithDaemonAccess(dockerHost string) PhaseConfigProviderOperation {
return func(provider *PhaseConfigProvider) {
WithRoot()(provider)
if dockerHost == "inherit" {
dockerHost = os.Getenv("DOCKER_HOST")
dockerHost = strings.TrimSpace(os.Getenv("DOCKER_HOST"))
}
var bind string
if dockerHost == "" {
Expand Down
41 changes: 41 additions & 0 deletions internal/build/phase_config_provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,47 @@ func testPhaseConfigProvider(t *testing.T, when spec.G, it spec.S) {
h.AssertSliceContains(t, phaseConfigProvider.HostConfig().Binds, `\\.\pipe\docker_engine:\\.\pipe\docker_engine`)
})
})

when("DOCKER_HOST is set", func() {
it("should use the value", func() {
t.Setenv("DOCKER_HOST", "tcp://127.0.0.1:2375")

fakeBuilderImage := ifakes.NewImage("fake-builder", "", nil)
h.AssertNil(t, fakeBuilderImage.SetOS("osx"))

fakeBuilder, err := fakes.NewFakeBuilder(fakes.WithImage(fakeBuilderImage))
h.AssertNil(t, err)

lifecycle := newTestLifecycleExec(t, false, "some-temp-dir", fakes.WithBuilder(fakeBuilder))

phaseConfigProvider := build.NewPhaseConfigProvider(
"some-name",
lifecycle,
build.WithDaemonAccess("inherit"),
)
h.AssertSliceContains(t, phaseConfigProvider.ContainerConfig().Env, "DOCKER_HOST=tcp://127.0.0.1:2375")
h.AssertSliceNotContains(t, phaseConfigProvider.HostConfig().Binds, "/var/run/docker.sock:/var/run/docker.sock")
})
})

when("DOCKER_HOST is empty", func() {
it("falls back to /var/run/docker.sock", func() {
fakeBuilderImage := ifakes.NewImage("fake-builder", "", nil)
h.AssertNil(t, fakeBuilderImage.SetOS("osx"))

fakeBuilder, err := fakes.NewFakeBuilder(fakes.WithImage(fakeBuilderImage))
h.AssertNil(t, err)

lifecycle := newTestLifecycleExec(t, false, "some-temp-dir", fakes.WithBuilder(fakeBuilder))

phaseConfigProvider := build.NewPhaseConfigProvider(
"some-name",
lifecycle,
build.WithDaemonAccess("inherit"),
)
h.AssertSliceContains(t, phaseConfigProvider.HostConfig().Binds, "/var/run/docker.sock:/var/run/docker.sock")
})
})
})

when("called with WithEnv", func() {
Expand Down
6 changes: 3 additions & 3 deletions internal/commands/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,10 +242,10 @@ func buildCommandFlags(cmd *cobra.Command, buildFlags *BuildFlags, cfg config.Co
cmd.Flags().StringArrayVar(&buildFlags.PreBuildpacks, "pre-buildpack", []string{}, "Buildpacks to prepend to the groups in the builder's order")
cmd.Flags().StringArrayVar(&buildFlags.PostBuildpacks, "post-buildpack", []string{}, "Buildpacks to append to the groups in the builder's order")
cmd.Flags().BoolVar(&buildFlags.Publish, "publish", false, "Publish to registry")
cmd.Flags().StringVar(&buildFlags.DockerHost, "docker-host", "",
cmd.Flags().StringVar(&buildFlags.DockerHost, "docker-host", "inherit",
`Address to docker daemon that will be exposed to the build container.
If not set (or set to empty string) the standard socket location will be used.
Special value 'inherit' may be used in which case DOCKER_HOST environment variable will be used.
By default it's set to inherit and the DOCKER_HOST environment variable will be used.
If set to empty string the standard socket location will be used.
This option may set DOCKER_HOST environment variable for the build container if needed.
`)
cmd.Flags().StringVar(&buildFlags.LifecycleImage, "lifecycle-image", cfg.LifecycleImage, `Custom lifecycle image to use for analysis, restore, and export when builder is untrusted.`)
Expand Down

0 comments on commit 9833d11

Please sign in to comment.