Browse code

Windows: Support ARG in builder

Signed-off-by: John Howard <jhoward@microsoft.com>

John Howard authored on 2016/05/05 03:06:54
Showing 3 changed files
... ...
@@ -6,7 +6,7 @@ import "fmt"
6 6
 // a command not supported on the platform.
7 7
 func platformSupports(command string) error {
8 8
 	switch command {
9
-	case "user", "stopsignal", "arg":
9
+	case "user", "stopsignal":
10 10
 		return fmt.Errorf("The daemon on this platform does not support the command '%s'", command)
11 11
 	}
12 12
 	return nil
... ...
@@ -7,6 +7,7 @@ import (
7 7
 	"os"
8 8
 	"path/filepath"
9 9
 
10
+	"github.com/docker/docker/utils"
10 11
 	"github.com/docker/docker/volume"
11 12
 	containertypes "github.com/docker/engine-api/types/container"
12 13
 )
... ...
@@ -30,8 +31,10 @@ type ExitStatus struct {
30 30
 
31 31
 // CreateDaemonEnvironment creates a new environment variable slice for this container.
32 32
 func (container *Container) CreateDaemonEnvironment(linkedEnv []string) []string {
33
-	// On Windows, nothing to link. Just return the container environment.
34
-	return container.Config.Env
33
+	// because the env on the container can override certain default values
34
+	// we need to replace the 'env' keys where they match and append anything
35
+	// else.
36
+	return utils.ReplaceOrAppendEnvValues(linkedEnv, container.Config.Env)
35 37
 }
36 38
 
37 39
 // UnmountIpcMounts unmount Ipc related mounts.
... ...
@@ -6171,17 +6171,24 @@ func (s *DockerSuite) TestBuildStopSignal(c *check.C) {
6171 6171
 }
6172 6172
 
6173 6173
 func (s *DockerSuite) TestBuildBuildTimeArg(c *check.C) {
6174
-	testRequires(c, DaemonIsLinux) // Windows does not support ARG
6175 6174
 	imgName := "bldargtest"
6176 6175
 	envKey := "foo"
6177 6176
 	envVal := "bar"
6178
-	args := []string{
6179
-		"--build-arg", fmt.Sprintf("%s=%s", envKey, envVal),
6177
+	args := []string{"--build-arg", fmt.Sprintf("%s=%s", envKey, envVal)}
6178
+	var dockerfile string
6179
+	if daemonPlatform == "windows" {
6180
+		// Bugs in Windows busybox port - use the default base image and native cmd stuff
6181
+		dockerfile = fmt.Sprintf(`FROM `+minimalBaseImage()+`
6182
+			ARG %s
6183
+			RUN echo %%%s%%
6184
+			CMD setlocal enableextensions && if defined %s (echo %%%s%%)`, envKey, envKey, envKey, envKey)
6185
+	} else {
6186
+		dockerfile = fmt.Sprintf(`FROM busybox
6187
+			ARG %s
6188
+			RUN echo $%s
6189
+			CMD echo $%s`, envKey, envKey, envKey)
6190
+
6180 6191
 	}
6181
-	dockerfile := fmt.Sprintf(`FROM busybox
6182
-		ARG %s
6183
-		RUN echo $%s
6184
-		CMD echo $%s`, envKey, envKey, envKey)
6185 6192
 
6186 6193
 	if _, out, err := buildImageWithOut(imgName, dockerfile, true, args...); err != nil || !strings.Contains(out, envVal) {
6187 6194
 		if err != nil {
... ...
@@ -6191,7 +6198,9 @@ func (s *DockerSuite) TestBuildBuildTimeArg(c *check.C) {
6191 6191
 	}
6192 6192
 
6193 6193
 	containerName := "bldargCont"
6194
-	if out, _ := dockerCmd(c, "run", "--name", containerName, imgName); out != "\n" {
6194
+	out, _ := dockerCmd(c, "run", "--name", containerName, imgName)
6195
+	out = strings.Trim(out, " \r\n'")
6196
+	if out != "" {
6195 6197
 		c.Fatalf("run produced invalid output: %q, expected empty string", out)
6196 6198
 	}
6197 6199
 }