Skip to content

Commit

Permalink
Adds explicit docker-host opt default
Browse files Browse the repository at this point in the history
- Avoids nil-like empty default value

Signed-off-by: Micah Young <[email protected]>
  • Loading branch information
Micah Young committed Mar 15, 2021
1 parent 8759cb6 commit 11b0a1f
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 9 deletions.
6 changes: 3 additions & 3 deletions internal/build/lifecycle_execution_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ func testLifecycleExecution(t *testing.T, when spec.G, it spec.S) {
lifecycle := newTestLifecycleExec(t, false)
fakePhaseFactory := fakes.NewFakePhaseFactory()

err := lifecycle.Create(context.Background(), false, "", false, "test", "test", "test", fakeBuildCache, fakeLaunchCache, []string{}, []string{}, fakePhaseFactory)
err := lifecycle.Create(context.Background(), false, "host-socket", false, "test", "test", "test", fakeBuildCache, fakeLaunchCache, []string{}, []string{}, fakePhaseFactory)
h.AssertNil(t, err)

lastCallIndex := len(fakePhaseFactory.NewCalledWithProvider) - 1
Expand Down Expand Up @@ -1030,7 +1030,7 @@ func testLifecycleExecution(t *testing.T, when spec.G, it spec.S) {
lifecycle := newTestLifecycleExec(t, false)
fakePhaseFactory := fakes.NewFakePhaseFactory()

err := lifecycle.Analyze(context.Background(), "test", "test", false, "", false, fakeCache, fakePhaseFactory)
err := lifecycle.Analyze(context.Background(), "test", "test", false, "host-socket", false, fakeCache, fakePhaseFactory)
h.AssertNil(t, err)

lastCallIndex := len(fakePhaseFactory.NewCalledWithProvider) - 1
Expand Down Expand Up @@ -1656,7 +1656,7 @@ func testLifecycleExecution(t *testing.T, when spec.G, it spec.S) {
lifecycle := newTestLifecycleExec(t, false)
fakePhaseFactory := fakes.NewFakePhaseFactory()

err := lifecycle.Export(context.Background(), "test", "test", false, "", "test", fakeBuildCache, fakeLaunchCache, []string{}, fakePhaseFactory)
err := lifecycle.Export(context.Background(), "test", "test", false, "host-socket", "test", fakeBuildCache, fakeLaunchCache, []string{}, fakePhaseFactory)
h.AssertNil(t, err)

lastCallIndex := len(fakePhaseFactory.NewCalledWithProvider) - 1
Expand Down
2 changes: 1 addition & 1 deletion internal/build/phase_config_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ func WithDaemonAccess(dockerHost string) PhaseConfigProviderOperation {
dockerHost = os.Getenv("DOCKER_HOST")
}
var bind string
if dockerHost == "" {
if dockerHost == "host-socket" {
bind = "/var/run/docker.sock:/var/run/docker.sock"
if provider.os == "windows" {
bind = `\\.\pipe\docker_engine:\\.\pipe\docker_engine`
Expand Down
4 changes: 2 additions & 2 deletions internal/build/phase_config_provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ func testPhaseConfigProvider(t *testing.T, when spec.G, it spec.S) {
phaseConfigProvider := build.NewPhaseConfigProvider(
"some-name",
lifecycle,
build.WithDaemonAccess(""),
build.WithDaemonAccess("host-socket"),
)

h.AssertEq(t, phaseConfigProvider.ContainerConfig().User, "root")
Expand All @@ -152,7 +152,7 @@ func testPhaseConfigProvider(t *testing.T, when spec.G, it spec.S) {
phaseConfigProvider := build.NewPhaseConfigProvider(
"some-name",
lifecycle,
build.WithDaemonAccess(""),
build.WithDaemonAccess("host-socket"),
)

h.AssertEq(t, phaseConfigProvider.ContainerConfig().User, "ContainerAdministrator")
Expand Down
2 changes: 1 addition & 1 deletion internal/build/phase_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ func testPhase(t *testing.T, when spec.G, it spec.S) {
when("#WithDaemonAccess", func() {
when("with standard docker socket", func() {
it("allows daemon access inside the container", func() {
configProvider := build.NewPhaseConfigProvider(phaseName, lifecycleExec, build.WithArgs("daemon"), build.WithDaemonAccess(""))
configProvider := build.NewPhaseConfigProvider(phaseName, lifecycleExec, build.WithArgs("daemon"), build.WithDaemonAccess("host-socket"))
phase := phaseFactory.New(configProvider)
assertRunSucceeds(t, phase, &outBuf, &errBuf)
h.AssertContains(t, outBuf.String(), "daemon test")
Expand Down
4 changes: 2 additions & 2 deletions internal/commands/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,9 @@ func buildCommandFlags(cmd *cobra.Command, buildFlags *BuildFlags, cfg config.Co
cmd.Flags().StringArrayVar(&buildFlags.EnvFiles, "env-file", []string{}, "Build-time environment variables file\nOne variable per line, of the form 'VAR=VALUE' or 'VAR'\nWhen using latter value-less form, value will be taken from current\n environment at the time this command is executed\nNOTE: These are NOT available at image runtime.\"")
cmd.Flags().StringVar(&buildFlags.Network, "network", "", "Connect detect and build containers to network")
cmd.Flags().BoolVar(&buildFlags.Publish, "publish", false, "Publish to registry")
cmd.Flags().StringVar(&buildFlags.DockerHost, "docker-host", "",
cmd.Flags().StringVar(&buildFlags.DockerHost, "docker-host", "host-socket",
`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.
If not set (or set to 'host-socket') the standard socket location will be used.
Special value 'inherit' may be used in which case DOCKER_HOST environment variable will be used.
This option may set DOCKER_HOST environment variable for the build container if needed.
`)
Expand Down

0 comments on commit 11b0a1f

Please sign in to comment.