Skip to content

Commit 8e5c34f

Browse files
tonistiigibillywr
authored andcommitted
Updated tests in frontend/dockerfile/dockerfile_test.go to run on Windows.
Partially addressing moby#4485 Signed-off-by: Billy Owire <[email protected]>
2 parents 605c469 + 3b35fc3 commit 8e5c34f

File tree

1 file changed

+97
-46
lines changed

1 file changed

+97
-46
lines changed

frontend/dockerfile/dockerfile_test.go

Lines changed: 97 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,17 +1028,28 @@ RUN e="300:400"; p="/file" ; a=` + "`" + `stat -c "%u:%g
10281028
}
10291029

10301030
func testCopyWildcardCache(t *testing.T, sb integration.Sandbox) {
1031-
integration.SkipOnPlatform(t, "windows")
10321031
f := getFrontend(t, sb)
10331032

1034-
dockerfile := []byte(`
1033+
dockerfile := []byte(integration.UnixOrWindows(
1034+
`
10351035
FROM busybox AS base
10361036
COPY foo* files/
10371037
RUN cat /dev/urandom | head -c 100 | sha256sum > unique
10381038
COPY bar files/
10391039
FROM scratch
10401040
COPY --from=base unique /
1041-
`)
1041+
`,
1042+
`
1043+
FROM nanoserver AS base
1044+
USER ContainerAdministrator
1045+
WORKDIR /files
1046+
COPY foo* /files/
1047+
RUN echo test> /unique
1048+
COPY bar /files/
1049+
FROM nanoserver
1050+
COPY --from=base /unique /
1051+
`,
1052+
))
10421053

10431054
dir := integration.Tmpdir(
10441055
t,
@@ -1114,8 +1125,9 @@ COPY --from=base unique /
11141125
require.NoError(t, err)
11151126

11161127
dt2, err = os.ReadFile(filepath.Join(destDir, "unique"))
1128+
expectedStr := string(dt)
11171129
require.NoError(t, err)
1118-
require.NotEqual(t, string(dt), string(dt2))
1130+
require.NotEqual(t, integration.UnixOrWindows(expectedStr, expectedStr+"\r\n"), string(dt2))
11191131
}
11201132

11211133
func testEmptyWildcard(t *testing.T, sb integration.Sandbox) {
@@ -2788,7 +2800,6 @@ ADD %s /dest/
27882800
}
27892801

27902802
func testDockerfileAddArchive(t *testing.T, sb integration.Sandbox) {
2791-
integration.SkipOnPlatform(t, "windows")
27922803
f := getFrontend(t, sb)
27932804
f.RequiresBuildctl(t)
27942805

@@ -2807,10 +2818,12 @@ func testDockerfileAddArchive(t *testing.T, sb integration.Sandbox) {
28072818
err = tw.Close()
28082819
require.NoError(t, err)
28092820

2810-
dockerfile := []byte(`
2811-
FROM scratch
2821+
baseImage := integration.UnixOrWindows("scratch", "nanoserver")
2822+
2823+
dockerfile := []byte(fmt.Sprintf(`
2824+
FROM %s
28122825
ADD t.tar /
2813-
`)
2826+
`, baseImage))
28142827

28152828
dir := integration.Tmpdir(
28162829
t,
@@ -2838,10 +2851,10 @@ ADD t.tar /
28382851
err = gz.Close()
28392852
require.NoError(t, err)
28402853

2841-
dockerfile = []byte(`
2842-
FROM scratch
2854+
dockerfile = []byte(fmt.Sprintf(`
2855+
FROM %s
28432856
ADD t.tar.gz /
2844-
`)
2857+
`, baseImage))
28452858

28462859
dir = integration.Tmpdir(
28472860
t,
@@ -2862,10 +2875,10 @@ ADD t.tar.gz /
28622875
require.Equal(t, expectedContent, dt)
28632876

28642877
// COPY doesn't extract
2865-
dockerfile = []byte(`
2866-
FROM scratch
2878+
dockerfile = []byte(fmt.Sprintf(`
2879+
FROM %s
28672880
COPY t.tar.gz /
2868-
`)
2881+
`, baseImage))
28692882

28702883
dir = integration.Tmpdir(
28712884
t,
@@ -2897,9 +2910,9 @@ COPY t.tar.gz /
28972910
defer server.Close()
28982911

28992912
dockerfile = []byte(fmt.Sprintf(`
2900-
FROM scratch
2913+
FROM %s
29012914
ADD %s /
2902-
`, server.URL+"/t.tar.gz"))
2915+
`, baseImage, server.URL+"/t.tar.gz"))
29032916

29042917
dir = integration.Tmpdir(
29052918
t,
@@ -2920,9 +2933,9 @@ ADD %s /
29202933

29212934
// https://github.com/moby/buildkit/issues/386
29222935
dockerfile = []byte(fmt.Sprintf(`
2923-
FROM scratch
2936+
FROM %s
29242937
ADD %s /newname.tar.gz
2925-
`, server.URL+"/t.tar.gz"))
2938+
`, baseImage, server.URL+"/t.tar.gz"))
29262939

29272940
dir = integration.Tmpdir(
29282941
t,
@@ -4409,13 +4422,21 @@ COPY foo bar
44094422
}
44104423

44114424
func testMultiStageImplicitFrom(t *testing.T, sb integration.Sandbox) {
4412-
integration.SkipOnPlatform(t, "windows")
44134425
f := getFrontend(t, sb)
44144426

4415-
dockerfile := []byte(`
4427+
dockerfile := []byte(integration.UnixOrWindows(
4428+
`
44164429
FROM scratch
44174430
COPY --from=busybox /etc/passwd test
4418-
`)
4431+
`, `
4432+
FROM nanoserver AS build
4433+
USER ContainerAdministrator
4434+
RUN echo test> test
4435+
4436+
FROM nanoserver
4437+
COPY --from=build /test /test
4438+
`,
4439+
))
44194440

44204441
dir := integration.Tmpdir(
44214442
t,
@@ -4444,17 +4465,26 @@ COPY --from=busybox /etc/passwd test
44444465

44454466
dt, err := os.ReadFile(filepath.Join(destDir, "test"))
44464467
require.NoError(t, err)
4447-
require.Contains(t, string(dt), "root")
4468+
require.Contains(t, string(dt), integration.UnixOrWindows("root", "test"))
44484469

44494470
// testing masked image will load actual stage
44504471

4451-
dockerfile = []byte(`
4472+
dockerfile = []byte(integration.UnixOrWindows(
4473+
`
44524474
FROM busybox AS golang
44534475
RUN mkdir -p /usr/bin && echo -n foo > /usr/bin/go
44544476
44554477
FROM scratch
44564478
COPY --from=golang /usr/bin/go go
4457-
`)
4479+
`, `
4480+
FROM nanoserver AS golang
4481+
USER ContainerAdministrator
4482+
RUN echo foo> go
4483+
4484+
FROM nanoserver
4485+
COPY --from=golang /go /go
4486+
`,
4487+
))
44584488

44594489
dir = integration.Tmpdir(
44604490
t,
@@ -4482,17 +4512,18 @@ COPY --from=golang /usr/bin/go go
44824512
}
44834513

44844514
func testMultiStageCaseInsensitive(t *testing.T, sb integration.Sandbox) {
4485-
integration.SkipOnPlatform(t, "windows")
44864515
f := getFrontend(t, sb)
44874516

4488-
dockerfile := []byte(`
4489-
FROM scratch AS STAge0
4517+
dockerfileStr := `
4518+
FROM %s AS STAge0
44904519
COPY foo bar
4491-
FROM scratch AS staGE1
4520+
FROM %s AS staGE1
44924521
COPY --from=staGE0 bar baz
4493-
FROM scratch
4522+
FROM %s
44944523
COPY --from=stage1 baz bax
4495-
`)
4524+
`
4525+
baseImage := integration.UnixOrWindows("scratch", "nanoserver")
4526+
dockerfile := []byte(fmt.Sprintf(dockerfileStr, baseImage, baseImage, baseImage))
44964527
dir := integration.Tmpdir(
44974528
t,
44984529
fstest.CreateFile("Dockerfile", dockerfile, 0600),
@@ -4652,7 +4683,6 @@ RUN dir file1
46524683
}
46534684

46544685
func testOnBuildCleared(t *testing.T, sb integration.Sandbox) {
4655-
integration.SkipOnPlatform(t, "windows")
46564686
workers.CheckFeatureCompat(t, sb, workers.FeatureDirectPush)
46574687
f := getFrontend(t, sb)
46584688

@@ -4662,10 +4692,16 @@ func testOnBuildCleared(t *testing.T, sb integration.Sandbox) {
46624692
}
46634693
require.NoError(t, err)
46644694

4665-
dockerfile := []byte(`
4695+
dockerfile := []byte(integration.UnixOrWindows(
4696+
`
46664697
FROM busybox
46674698
ONBUILD RUN mkdir -p /out && echo -n 11 >> /out/foo
4668-
`)
4699+
`, `
4700+
FROM nanoserver
4701+
USER ContainerAdministrator
4702+
ONBUILD RUN mkdir \out && echo 11>> \out\foo
4703+
`,
4704+
))
46694705

46704706
dir := integration.Tmpdir(
46714707
t,
@@ -4725,9 +4761,9 @@ ONBUILD RUN mkdir -p /out && echo -n 11 >> /out/foo
47254761

47264762
dockerfile = []byte(fmt.Sprintf(`
47274763
FROM %s AS base
4728-
FROM scratch
4764+
FROM %s
47294765
COPY --from=base /out /
4730-
`, target2))
4766+
`, target2, integration.UnixOrWindows("scratch", "nanoserver")))
47314767

47324768
dir = integration.Tmpdir(
47334769
t,
@@ -4751,7 +4787,7 @@ ONBUILD RUN mkdir -p /out && echo -n 11 >> /out/foo
47514787

47524788
dt, err := os.ReadFile(filepath.Join(destDir, "foo"))
47534789
require.NoError(t, err)
4754-
require.Equal(t, "11", string(dt))
4790+
require.Equal(t, integration.UnixOrWindows("11", "11\r\n"), string(dt))
47554791
}
47564792

47574793
func testOnBuildNamedContext(t *testing.T, sb integration.Sandbox) {
@@ -5820,10 +5856,10 @@ COPY --from=build out .
58205856
}
58215857

58225858
func testBuiltinArgs(t *testing.T, sb integration.Sandbox) {
5823-
integration.SkipOnPlatform(t, "windows")
58245859
f := getFrontend(t, sb)
58255860

5826-
dockerfile := []byte(`
5861+
dockerfile := []byte(integration.UnixOrWindows(
5862+
`
58275863
FROM busybox AS build
58285864
ARG FOO
58295865
ARG BAR
@@ -5832,7 +5868,18 @@ RUN echo -n $HTTP_PROXY::$NO_PROXY::$FOO::$BAR::$BAZ > /out
58325868
FROM scratch
58335869
COPY --from=build /out /
58345870
5835-
`)
5871+
`, `
5872+
FROM nanoserver AS build
5873+
USER ContainerAdministrator
5874+
ARG FOO
5875+
ARG BAR
5876+
ARG BAZ=bazcontent
5877+
RUN echo %HTTP_PROXY%::%NO_PROXY%::%FOO%::%BAR%::%BAZ%> out
5878+
FROM nanoserver
5879+
COPY --from=build out /
5880+
`,
5881+
))
5882+
58365883
dir := integration.Tmpdir(
58375884
t,
58385885
fstest.CreateFile("Dockerfile", dockerfile, 0600),
@@ -5867,7 +5914,9 @@ COPY --from=build /out /
58675914

58685915
dt, err := os.ReadFile(filepath.Join(destDir, "out"))
58695916
require.NoError(t, err)
5870-
require.Equal(t, "hpvalue::npvalue::foocontents::::bazcontent", string(dt))
5917+
// Windows can't interpret empty env variables, %BAR% handles empty values.
5918+
expectedStr := integration.UnixOrWindows(`hpvalue::npvalue::foocontents::::bazcontent`, "hpvalue::npvalue::foocontents::%BAR%::bazcontent\r\n")
5919+
require.Equal(t, expectedStr, string(dt))
58715920

58725921
// repeat with changed default args should match the old cache
58735922
destDir = t.TempDir()
@@ -5894,7 +5943,8 @@ COPY --from=build /out /
58945943

58955944
dt, err = os.ReadFile(filepath.Join(destDir, "out"))
58965945
require.NoError(t, err)
5897-
require.Equal(t, "hpvalue::npvalue::foocontents::::bazcontent", string(dt))
5946+
expectedStr = integration.UnixOrWindows("hpvalue::npvalue::foocontents::::bazcontent", "hpvalue::npvalue::foocontents::%BAR%::bazcontent\r\n")
5947+
require.Equal(t, expectedStr, string(dt))
58985948

58995949
// changing actual value invalidates cache
59005950
destDir = t.TempDir()
@@ -5921,7 +5971,8 @@ COPY --from=build /out /
59215971

59225972
dt, err = os.ReadFile(filepath.Join(destDir, "out"))
59235973
require.NoError(t, err)
5924-
require.Equal(t, "hpvalue2::::foocontents2::::bazcontent", string(dt))
5974+
expectedStr = integration.UnixOrWindows("hpvalue2::::foocontents2::::bazcontent", "hpvalue2::%NO_PROXY%::foocontents2::%BAR%::bazcontent\r\n")
5975+
require.Equal(t, expectedStr, string(dt))
59255976
}
59265977

59275978
func testTarContext(t *testing.T, sb integration.Sandbox) {
@@ -6037,15 +6088,15 @@ COPY foo bar
60376088
}
60386089

60396090
func testFrontendUseForwardedSolveResults(t *testing.T, sb integration.Sandbox) {
6040-
integration.SkipOnPlatform(t, "windows")
60416091
c, err := client.New(sb.Context(), sb.Address())
60426092
require.NoError(t, err)
60436093
defer c.Close()
60446094

6045-
dockerfile := []byte(`
6046-
FROM scratch
6095+
dockerfileStr := `
6096+
FROM %s
60476097
COPY foo foo2
6048-
`)
6098+
`
6099+
dockerfile := []byte(fmt.Sprintf(dockerfileStr, integration.UnixOrWindows("scratch", "nanoserver")))
60496100
dir := integration.Tmpdir(
60506101
t,
60516102
fstest.CreateFile("Dockerfile", dockerfile, 0600),

0 commit comments

Comments
 (0)