1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Merge pull request #20011 from Microsoft/MinimalBaseImage

Move base image selection to a utility function
This commit is contained in:
David Calavera 2016-02-04 18:06:30 -08:00
commit d4c8d0519d
2 changed files with 22 additions and 93 deletions

View file

@ -114,18 +114,16 @@ func (s *DockerSuite) TestBuildEnvironmentReplacementUser(c *check.C) {
func (s *DockerSuite) TestBuildEnvironmentReplacementVolume(c *check.C) { func (s *DockerSuite) TestBuildEnvironmentReplacementVolume(c *check.C) {
name := "testbuildenvironmentreplacement" name := "testbuildenvironmentreplacement"
var baseImage, volumePath string var volumePath string
if daemonPlatform == "windows" { if daemonPlatform == "windows" {
baseImage = "windowsservercore"
volumePath = "c:/quux" volumePath = "c:/quux"
} else { } else {
baseImage = "scratch"
volumePath = "/quux" volumePath = "/quux"
} }
_, err := buildImage(name, ` _, err := buildImage(name, `
FROM `+baseImage+` FROM `+minimalBaseImage()+`
ENV volume `+volumePath+` ENV volume `+volumePath+`
VOLUME ${volume} VOLUME ${volume}
`, true) `, true)
@ -201,16 +199,8 @@ func (s *DockerSuite) TestBuildEnvironmentReplacementWorkdir(c *check.C) {
func (s *DockerSuite) TestBuildEnvironmentReplacementAddCopy(c *check.C) { func (s *DockerSuite) TestBuildEnvironmentReplacementAddCopy(c *check.C) {
name := "testbuildenvironmentreplacement" name := "testbuildenvironmentreplacement"
var baseImage string
if daemonPlatform == "windows" {
baseImage = "windowsservercore"
} else {
baseImage = "scratch"
}
ctx, err := fakeContext(` ctx, err := fakeContext(`
FROM `+baseImage+` FROM `+minimalBaseImage()+`
ENV baz foo ENV baz foo
ENV quux bar ENV quux bar
ENV dot . ENV dot .
@ -697,14 +687,7 @@ func (s *DockerSuite) TestBuildSixtySteps(c *check.C) {
// TP5 timeframe when perf is better. // TP5 timeframe when perf is better.
name := "foobuildsixtysteps" name := "foobuildsixtysteps"
var baseImage string ctx, err := fakeContext("FROM "+minimalBaseImage()+"\n"+strings.Repeat("ADD foo /\n", 60),
if daemonPlatform == "windows" {
baseImage = "windowsservercore"
} else {
baseImage = "scratch"
}
ctx, err := fakeContext("FROM "+baseImage+"\n"+strings.Repeat("ADD foo /\n", 60),
map[string]string{ map[string]string{
"foo": "test1", "foo": "test1",
}) })
@ -844,14 +827,7 @@ RUN [ $(ls -l /exists/exists_file | awk '{print $3":"$4}') = 'dockerio:dockerio'
func (s *DockerSuite) TestBuildAddMultipleFilesToFile(c *check.C) { func (s *DockerSuite) TestBuildAddMultipleFilesToFile(c *check.C) {
name := "testaddmultiplefilestofile" name := "testaddmultiplefilestofile"
var baseImage string ctx, err := fakeContext(`FROM `+minimalBaseImage()+`
if daemonPlatform == "windows" {
baseImage = "windowsservercore"
} else {
baseImage = "scratch"
}
ctx, err := fakeContext(`FROM `+baseImage+`
ADD file1.txt file2.txt test ADD file1.txt file2.txt test
`, `,
map[string]string{ map[string]string{
@ -873,14 +849,7 @@ func (s *DockerSuite) TestBuildAddMultipleFilesToFile(c *check.C) {
func (s *DockerSuite) TestBuildJSONAddMultipleFilesToFile(c *check.C) { func (s *DockerSuite) TestBuildJSONAddMultipleFilesToFile(c *check.C) {
name := "testjsonaddmultiplefilestofile" name := "testjsonaddmultiplefilestofile"
var baseImage string ctx, err := fakeContext(`FROM `+minimalBaseImage()+`
if daemonPlatform == "windows" {
baseImage = "windowsservercore"
} else {
baseImage = "scratch"
}
ctx, err := fakeContext(`FROM `+baseImage+`
ADD ["file1.txt", "file2.txt", "test"] ADD ["file1.txt", "file2.txt", "test"]
`, `,
map[string]string{ map[string]string{
@ -902,14 +871,7 @@ func (s *DockerSuite) TestBuildJSONAddMultipleFilesToFile(c *check.C) {
func (s *DockerSuite) TestBuildAddMultipleFilesToFileWild(c *check.C) { func (s *DockerSuite) TestBuildAddMultipleFilesToFileWild(c *check.C) {
name := "testaddmultiplefilestofilewild" name := "testaddmultiplefilestofilewild"
var baseImage string ctx, err := fakeContext(`FROM `+minimalBaseImage()+`
if daemonPlatform == "windows" {
baseImage = "windowsservercore"
} else {
baseImage = "scratch"
}
ctx, err := fakeContext(`FROM `+baseImage+`
ADD file*.txt test ADD file*.txt test
`, `,
map[string]string{ map[string]string{
@ -931,14 +893,7 @@ func (s *DockerSuite) TestBuildAddMultipleFilesToFileWild(c *check.C) {
func (s *DockerSuite) TestBuildJSONAddMultipleFilesToFileWild(c *check.C) { func (s *DockerSuite) TestBuildJSONAddMultipleFilesToFileWild(c *check.C) {
name := "testjsonaddmultiplefilestofilewild" name := "testjsonaddmultiplefilestofilewild"
var baseImage string ctx, err := fakeContext(`FROM `+minimalBaseImage()+`
if daemonPlatform == "windows" {
baseImage = "windowsservercore"
} else {
baseImage = "scratch"
}
ctx, err := fakeContext(`FROM `+baseImage+`
ADD ["file*.txt", "test"] ADD ["file*.txt", "test"]
`, `,
map[string]string{ map[string]string{
@ -960,14 +915,7 @@ func (s *DockerSuite) TestBuildJSONAddMultipleFilesToFileWild(c *check.C) {
func (s *DockerSuite) TestBuildCopyMultipleFilesToFile(c *check.C) { func (s *DockerSuite) TestBuildCopyMultipleFilesToFile(c *check.C) {
name := "testcopymultiplefilestofile" name := "testcopymultiplefilestofile"
var baseImage string ctx, err := fakeContext(`FROM `+minimalBaseImage()+`
if daemonPlatform == "windows" {
baseImage = "windowsservercore"
} else {
baseImage = "scratch"
}
ctx, err := fakeContext(`FROM `+baseImage+`
COPY file1.txt file2.txt test COPY file1.txt file2.txt test
`, `,
map[string]string{ map[string]string{
@ -989,14 +937,7 @@ func (s *DockerSuite) TestBuildCopyMultipleFilesToFile(c *check.C) {
func (s *DockerSuite) TestBuildJSONCopyMultipleFilesToFile(c *check.C) { func (s *DockerSuite) TestBuildJSONCopyMultipleFilesToFile(c *check.C) {
name := "testjsoncopymultiplefilestofile" name := "testjsoncopymultiplefilestofile"
var baseImage string ctx, err := fakeContext(`FROM `+minimalBaseImage()+`
if daemonPlatform == "windows" {
baseImage = "windowsservercore"
} else {
baseImage = "scratch"
}
ctx, err := fakeContext(`FROM `+baseImage+`
COPY ["file1.txt", "file2.txt", "test"] COPY ["file1.txt", "file2.txt", "test"]
`, `,
map[string]string{ map[string]string{
@ -1364,14 +1305,7 @@ RUN [ $(ls -l /exists | awk '{print $3":"$4}') = 'dockerio:dockerio' ]`, expecte
func (s *DockerSuite) TestBuildAddEtcToRoot(c *check.C) { func (s *DockerSuite) TestBuildAddEtcToRoot(c *check.C) {
name := "testaddetctoroot" name := "testaddetctoroot"
var baseImage string ctx, err := fakeContext(`FROM `+minimalBaseImage()+`
if daemonPlatform == "windows" {
baseImage = "windowsservercore"
} else {
baseImage = "scratch"
}
ctx, err := fakeContext(`FROM `+baseImage+`
ADD . /`, ADD . /`,
map[string]string{ map[string]string{
"etc/test_file": "test1", "etc/test_file": "test1",
@ -1593,14 +1527,7 @@ RUN [ $(ls -l /exists | awk '{print $3":"$4}') = 'dockerio:dockerio' ]`, expecte
func (s *DockerSuite) TestBuildCopyEtcToRoot(c *check.C) { func (s *DockerSuite) TestBuildCopyEtcToRoot(c *check.C) {
name := "testcopyetctoroot" name := "testcopyetctoroot"
var baseImage string ctx, err := fakeContext(`FROM `+minimalBaseImage()+`
if daemonPlatform == "windows" {
baseImage = "windowsservercore"
} else {
baseImage = "scratch"
}
ctx, err := fakeContext(`FROM `+baseImage+`
COPY . /`, COPY . /`,
map[string]string{ map[string]string{
"etc/test_file": "test1", "etc/test_file": "test1",
@ -1618,14 +1545,7 @@ COPY . /`,
func (s *DockerSuite) TestBuildCopyDisallowRemote(c *check.C) { func (s *DockerSuite) TestBuildCopyDisallowRemote(c *check.C) {
name := "testcopydisallowremote" name := "testcopydisallowremote"
var baseImage string _, out, err := buildImageWithOut(name, `FROM `+minimalBaseImage()+`
if daemonPlatform == "windows" {
baseImage = "windowsservercore"
} else {
baseImage = "scratch"
}
_, out, err := buildImageWithOut(name, `FROM `+baseImage+`
COPY https://index.docker.io/robots.txt /`, COPY https://index.docker.io/robots.txt /`,
true) true)
if err == nil || !strings.Contains(out, "Source can't be a URL for COPY") { if err == nil || !strings.Contains(out, "Source can't be a URL for COPY") {

View file

@ -1752,3 +1752,12 @@ func runSleepingContainerInImage(c *check.C, image string, extraArgs ...string)
args = append(args, defaultSleepCommand...) args = append(args, defaultSleepCommand...)
return dockerCmd(c, args...) return dockerCmd(c, args...)
} }
// minimalBaseImage returns the name of the minimal base image for the current
// daemon platform.
func minimalBaseImage() string {
if daemonPlatform == "windows" {
return WindowsBaseImage
}
return "scratch"
}