Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update: use DOCKER_HOST as the default #1910

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading