mirror of
				https://github.com/moby/moby.git
				synced 2022-11-09 12:21:53 -05:00 
			
		
		
		
	Windows: Support ARG in builder
Signed-off-by: John Howard <jhoward@microsoft.com>
This commit is contained in:
		
							parent
							
								
									973d6f0820
								
							
						
					
					
						commit
						6b5c83bf18
					
				
					 3 changed files with 23 additions and 11 deletions
				
			
		| 
						 | 
					@ -6,7 +6,7 @@ import "fmt"
 | 
				
			||||||
// a command not supported on the platform.
 | 
					// a command not supported on the platform.
 | 
				
			||||||
func platformSupports(command string) error {
 | 
					func platformSupports(command string) error {
 | 
				
			||||||
	switch command {
 | 
						switch command {
 | 
				
			||||||
	case "user", "stopsignal", "arg":
 | 
						case "user", "stopsignal":
 | 
				
			||||||
		return fmt.Errorf("The daemon on this platform does not support the command '%s'", command)
 | 
							return fmt.Errorf("The daemon on this platform does not support the command '%s'", command)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return nil
 | 
						return nil
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -7,6 +7,7 @@ import (
 | 
				
			||||||
	"os"
 | 
						"os"
 | 
				
			||||||
	"path/filepath"
 | 
						"path/filepath"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"github.com/docker/docker/utils"
 | 
				
			||||||
	"github.com/docker/docker/volume"
 | 
						"github.com/docker/docker/volume"
 | 
				
			||||||
	containertypes "github.com/docker/engine-api/types/container"
 | 
						containertypes "github.com/docker/engine-api/types/container"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
| 
						 | 
					@ -30,8 +31,10 @@ type ExitStatus struct {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// CreateDaemonEnvironment creates a new environment variable slice for this container.
 | 
					// CreateDaemonEnvironment creates a new environment variable slice for this container.
 | 
				
			||||||
func (container *Container) CreateDaemonEnvironment(linkedEnv []string) []string {
 | 
					func (container *Container) CreateDaemonEnvironment(linkedEnv []string) []string {
 | 
				
			||||||
	// On Windows, nothing to link. Just return the container environment.
 | 
						// because the env on the container can override certain default values
 | 
				
			||||||
	return container.Config.Env
 | 
						// we need to replace the 'env' keys where they match and append anything
 | 
				
			||||||
 | 
						// else.
 | 
				
			||||||
 | 
						return utils.ReplaceOrAppendEnvValues(linkedEnv, container.Config.Env)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// UnmountIpcMounts unmount Ipc related mounts.
 | 
					// UnmountIpcMounts unmount Ipc related mounts.
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -6171,17 +6171,24 @@ func (s *DockerSuite) TestBuildStopSignal(c *check.C) {
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (s *DockerSuite) TestBuildBuildTimeArg(c *check.C) {
 | 
					func (s *DockerSuite) TestBuildBuildTimeArg(c *check.C) {
 | 
				
			||||||
	testRequires(c, DaemonIsLinux) // Windows does not support ARG
 | 
					 | 
				
			||||||
	imgName := "bldargtest"
 | 
						imgName := "bldargtest"
 | 
				
			||||||
	envKey := "foo"
 | 
						envKey := "foo"
 | 
				
			||||||
	envVal := "bar"
 | 
						envVal := "bar"
 | 
				
			||||||
	args := []string{
 | 
						args := []string{"--build-arg", fmt.Sprintf("%s=%s", envKey, envVal)}
 | 
				
			||||||
		"--build-arg", fmt.Sprintf("%s=%s", envKey, envVal),
 | 
						var dockerfile string
 | 
				
			||||||
 | 
						if daemonPlatform == "windows" {
 | 
				
			||||||
 | 
							// Bugs in Windows busybox port - use the default base image and native cmd stuff
 | 
				
			||||||
 | 
							dockerfile = fmt.Sprintf(`FROM `+minimalBaseImage()+`
 | 
				
			||||||
 | 
								ARG %s
 | 
				
			||||||
 | 
								RUN echo %%%s%%
 | 
				
			||||||
 | 
								CMD setlocal enableextensions && if defined %s (echo %%%s%%)`, envKey, envKey, envKey, envKey)
 | 
				
			||||||
 | 
						} else {
 | 
				
			||||||
 | 
							dockerfile = fmt.Sprintf(`FROM busybox
 | 
				
			||||||
 | 
								ARG %s
 | 
				
			||||||
 | 
								RUN echo $%s
 | 
				
			||||||
 | 
								CMD echo $%s`, envKey, envKey, envKey)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	dockerfile := fmt.Sprintf(`FROM busybox
 | 
					 | 
				
			||||||
		ARG %s
 | 
					 | 
				
			||||||
		RUN echo $%s
 | 
					 | 
				
			||||||
		CMD echo $%s`, envKey, envKey, envKey)
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if _, out, err := buildImageWithOut(imgName, dockerfile, true, args...); err != nil || !strings.Contains(out, envVal) {
 | 
						if _, out, err := buildImageWithOut(imgName, dockerfile, true, args...); err != nil || !strings.Contains(out, envVal) {
 | 
				
			||||||
		if err != nil {
 | 
							if err != nil {
 | 
				
			||||||
| 
						 | 
					@ -6191,7 +6198,9 @@ func (s *DockerSuite) TestBuildBuildTimeArg(c *check.C) {
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	containerName := "bldargCont"
 | 
						containerName := "bldargCont"
 | 
				
			||||||
	if out, _ := dockerCmd(c, "run", "--name", containerName, imgName); out != "\n" {
 | 
						out, _ := dockerCmd(c, "run", "--name", containerName, imgName)
 | 
				
			||||||
 | 
						out = strings.Trim(out, " \r\n'")
 | 
				
			||||||
 | 
						if out != "" {
 | 
				
			||||||
		c.Fatalf("run produced invalid output: %q, expected empty string", out)
 | 
							c.Fatalf("run produced invalid output: %q, expected empty string", out)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue