Skip to content

Commit aa096eb

Browse files
committed
tests: frontend/dockerfile: add dockerfile lint tests for WCOW
A number of integration tests were initially skipped on Windows, waiting for their platform-specific translations. See moby#4485. This commit enables all the dockerfile linter tests that had been skipped before. Some of the tests did not need any platform specific change since the lint warning were being generated before actual image pull. Signed-off-by: Anthony Nandaa <[email protected]>
1 parent 3a70550 commit aa096eb

File tree

3 files changed

+118
-57
lines changed

3 files changed

+118
-57
lines changed

frontend/dockerfile/dockerfile_lint_test.go

Lines changed: 115 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -581,12 +581,16 @@ COPY Dockerfile /bar
581581
`)
582582
checkLinterWarnings(t, sb, &lintTestParams{Dockerfile: dockerfile})
583583

584-
dockerfile = []byte(`
585-
FROM alpine
584+
dockerfile = []byte(fmt.Sprintf(
585+
`
586+
FROM %s
586587
RUN <<'EOT'
587-
env
588+
%s
588589
EOT
589-
`)
590+
`,
591+
integration.UnixOrWindows("alpine", "nanoserver"),
592+
integration.UnixOrWindows("env", "set"),
593+
))
590594
checkLinterWarnings(t, sb, &lintTestParams{Dockerfile: dockerfile})
591595
}
592596

@@ -822,12 +826,24 @@ COPY Dockerfile .
822826
BuildErrLocation: 2,
823827
})
824828

825-
dockerfile = []byte(`
826-
ARG MY_OS=linux
829+
osName := integration.UnixOrWindows("linux", "windows")
830+
baseImg := integration.UnixOrWindows("busybox", "nanoserver")
831+
dockerfile = []byte(fmt.Sprintf(
832+
`
833+
ARG MY_OS=%s
827834
ARG MY_ARCH=amd64
828-
FROM --platform=linux/${MYARCH} busybox
835+
FROM --platform=%s/${MYARCH} %s
829836
COPY Dockerfile .
830-
`)
837+
`,
838+
osName, osName, baseImg))
839+
840+
osStr := integration.UnixOrWindows("linux", "windows")
841+
streamBuildErr := fmt.Sprintf(
842+
"failed to solve: failed to parse platform %s/${MYARCH}: \"\" is an invalid component of \"%s/\": platform specifier component must match \"^[A-Za-z0-9_-]+$\": invalid argument (did you mean MY_ARCH?)",
843+
osStr, osStr)
844+
unmarshalBuildErr := fmt.Sprintf(
845+
"failed to parse platform %s/${MYARCH}: \"\" is an invalid component of \"%s/\": platform specifier component must match \"^[A-Za-z0-9_-]+$\": invalid argument (did you mean MY_ARCH?)",
846+
osStr, osStr)
831847
checkLinterWarnings(t, sb, &lintTestParams{
832848
Dockerfile: dockerfile,
833849
Warnings: []expectedLintWarning{
@@ -840,16 +856,18 @@ COPY Dockerfile .
840856
Line: 4,
841857
},
842858
},
843-
StreamBuildErr: "failed to solve: failed to parse platform linux/${MYARCH}: \"\" is an invalid component of \"linux/\": platform specifier component must match \"^[A-Za-z0-9_-]+$\": invalid argument (did you mean MY_ARCH?)",
844-
UnmarshalBuildErr: "failed to parse platform linux/${MYARCH}: \"\" is an invalid component of \"linux/\": platform specifier component must match \"^[A-Za-z0-9_-]+$\": invalid argument (did you mean MY_ARCH?)",
859+
StreamBuildErr: streamBuildErr,
860+
UnmarshalBuildErr: unmarshalBuildErr,
845861
BuildErrLocation: 4,
846862
})
847863

848-
dockerfile = []byte(`
864+
dockerfile = []byte(fmt.Sprintf(
865+
`
849866
ARG tag=latest
850-
FROM busybox:${tag}${version} AS b
867+
FROM %s:${tag}${version} AS b
851868
COPY Dockerfile .
852-
`)
869+
`,
870+
baseImg))
853871
checkLinterWarnings(t, sb, &lintTestParams{
854872
Dockerfile: dockerfile,
855873
Warnings: []expectedLintWarning{
@@ -902,27 +920,34 @@ COPY Dockerfile${foo} .
902920
`)
903921
checkLinterWarnings(t, sb, &lintTestParams{Dockerfile: dockerfile})
904922

905-
dockerfile = []byte(`
906-
FROM alpine AS base
923+
baseImg := integration.UnixOrWindows("alpine", "nanoserver")
924+
dockerfile = []byte(fmt.Sprintf(
925+
`
926+
FROM %s AS base
907927
ARG foo=Dockerfile
908928
909929
FROM base
910930
COPY $foo .
911-
`)
931+
`,
932+
baseImg))
912933
checkLinterWarnings(t, sb, &lintTestParams{Dockerfile: dockerfile})
913934

914-
dockerfile = []byte(`
915-
FROM alpine
935+
dockerfile = []byte(fmt.Sprintf(
936+
`
937+
FROM %s
916938
RUN echo $PATH
917-
`)
939+
`,
940+
baseImg))
918941
checkLinterWarnings(t, sb, &lintTestParams{Dockerfile: dockerfile})
919942

920-
dockerfile = []byte(`
921-
FROM alpine
943+
dockerfile = []byte(fmt.Sprintf(
944+
`
945+
FROM %s
922946
COPY $foo .
923947
ARG foo=bar
924948
RUN echo $foo
925-
`)
949+
`,
950+
baseImg))
926951
checkLinterWarnings(t, sb, &lintTestParams{
927952
Dockerfile: dockerfile,
928953
Warnings: []expectedLintWarning{
@@ -937,13 +962,15 @@ RUN echo $foo
937962
},
938963
})
939964

940-
dockerfile = []byte(`
941-
FROM alpine
965+
dockerfile = []byte(fmt.Sprintf(
966+
`
967+
FROM %s
942968
ARG DIR_BINARIES=binaries/
943969
ARG DIR_ASSETS=assets/
944970
ARG DIR_CONFIG=config/
945971
COPY $DIR_ASSET .
946-
`)
972+
`,
973+
baseImg))
947974
checkLinterWarnings(t, sb, &lintTestParams{
948975
Dockerfile: dockerfile,
949976
Warnings: []expectedLintWarning{
@@ -958,10 +985,12 @@ COPY $DIR_ASSET .
958985
},
959986
})
960987

961-
dockerfile = []byte(`
962-
FROM alpine
988+
dockerfile = []byte(fmt.Sprintf(
989+
`
990+
FROM %s
963991
ENV PATH=$PAHT:/tmp/bin
964-
`)
992+
`,
993+
baseImg))
965994
checkLinterWarnings(t, sb, &lintTestParams{
966995
Dockerfile: dockerfile,
967996
Warnings: []expectedLintWarning{
@@ -1150,10 +1179,13 @@ FROM --platform=${TARGETPLATFORM} scratch
11501179
}
11511180

11521181
func testInvalidDefaultArgInFrom(t *testing.T, sb integration.Sandbox) {
1153-
dockerfile := []byte(`
1182+
baseImg := integration.UnixOrWindows("busybox", "nanoserver")
1183+
dockerfile := []byte(fmt.Sprintf(
1184+
`
11541185
ARG VERSION
1155-
FROM busybox:$VERSION
1156-
`)
1186+
FROM %s:$VERSION
1187+
`,
1188+
baseImg))
11571189
checkLinterWarnings(t, sb, &lintTestParams{
11581190
Dockerfile: dockerfile,
11591191
FrontendAttrs: map[string]string{
@@ -1164,9 +1196,12 @@ FROM busybox:$VERSION
11641196
RuleName: "InvalidDefaultArgInFrom",
11651197
Description: "Default value for global ARG results in an empty or invalid base image name",
11661198
URL: "https://docs.docker.com/go/dockerfile/rule/invalid-default-arg-in-from/",
1167-
Detail: "Default value for ARG busybox:$VERSION results in empty or invalid base image name",
1168-
Line: 3,
1169-
Level: 1,
1199+
Detail: fmt.Sprintf(
1200+
"Default value for ARG %s:$VERSION results in empty or invalid base image name",
1201+
integration.UnixOrWindows("busybox", "nanoserver"),
1202+
),
1203+
Line: 3,
1204+
Level: 1,
11701205
},
11711206
},
11721207
})
@@ -1178,7 +1213,7 @@ FROM $IMAGE
11781213
checkLinterWarnings(t, sb, &lintTestParams{
11791214
Dockerfile: dockerfile,
11801215
FrontendAttrs: map[string]string{
1181-
"build-arg:IMAGE": "busybox:latest",
1216+
"build-arg:IMAGE": integration.UnixOrWindows("busybox:latest", "nanoserver:latest"),
11821217
},
11831218
Warnings: []expectedLintWarning{
11841219
{
@@ -1192,57 +1227,80 @@ FROM $IMAGE
11921227
},
11931228
})
11941229

1195-
dockerfile = []byte(`
1230+
dockerfile = []byte(integration.UnixOrWindows(
1231+
`
11961232
ARG SFX="box:"
11971233
FROM busy${SFX}
1198-
`)
1234+
`,
1235+
`
1236+
ARG SFX="server:"
1237+
FROM nano${SFX}
1238+
`,
1239+
))
11991240
checkLinterWarnings(t, sb, &lintTestParams{
12001241
Dockerfile: dockerfile,
12011242
FrontendAttrs: map[string]string{
1202-
"build-arg:SFX": "box:latest",
1243+
"build-arg:SFX": integration.UnixOrWindows("box:latest", "server:latest"),
12031244
},
12041245
Warnings: []expectedLintWarning{
12051246
{
12061247
RuleName: "InvalidDefaultArgInFrom",
12071248
Description: "Default value for global ARG results in an empty or invalid base image name",
12081249
URL: "https://docs.docker.com/go/dockerfile/rule/invalid-default-arg-in-from/",
1209-
Detail: "Default value for ARG busy${SFX} results in empty or invalid base image name",
1210-
Line: 3,
1211-
Level: 1,
1250+
Detail: fmt.Sprintf(
1251+
"Default value for ARG %s${SFX} results in empty or invalid base image name",
1252+
integration.UnixOrWindows("busy", "nano"),
1253+
),
1254+
Line: 3,
1255+
Level: 1,
12121256
},
12131257
},
12141258
})
12151259

1216-
dockerfile = []byte(`
1260+
dockerfile = []byte(fmt.Sprintf(
1261+
`
12171262
ARG VERSION="latest"
1218-
FROM busybox:${VERSION}
1219-
`)
1263+
FROM %s:${VERSION}
1264+
`,
1265+
baseImg))
12201266
checkLinterWarnings(t, sb, &lintTestParams{
12211267
Dockerfile: dockerfile,
12221268
FrontendAttrs: map[string]string{
12231269
"build-arg:VERSION": "latest",
12241270
},
12251271
})
12261272

1227-
dockerfile = []byte(`
1273+
dockerfile = []byte(integration.UnixOrWindows(
1274+
`
12281275
ARG BUSYBOX_VARIANT=""
12291276
FROM busybox:stable${BUSYBOX_VARIANT}
1230-
`)
1277+
`,
1278+
`
1279+
ARG BUSYBOX_VARIANT=""
1280+
FROM nanoserver:plus${BUSYBOX_VARIANT}
1281+
`,
1282+
))
12311283
checkLinterWarnings(t, sb, &lintTestParams{
12321284
Dockerfile: dockerfile,
12331285
FrontendAttrs: map[string]string{
1234-
"build-arg:BUSYBOX_VARIANT": "-musl",
1286+
"build-arg:BUSYBOX_VARIANT": integration.UnixOrWindows("-musl", "-busybox"),
12351287
},
12361288
})
12371289

1238-
dockerfile = []byte(`
1239-
ARG BUSYBOX_VARIANT
1240-
FROM busybox:stable${BUSYBOX_VARIANT}
1241-
`)
1290+
dockerfile = []byte(integration.UnixOrWindows(
1291+
`
1292+
ARG BUSYBOX_VARIANT
1293+
FROM busybox:stable${BUSYBOX_VARIANT}
1294+
`,
1295+
`
1296+
ARG BUSYBOX_VARIANT
1297+
FROM nanoserver:plus${BUSYBOX_VARIANT}
1298+
`,
1299+
))
12421300
checkLinterWarnings(t, sb, &lintTestParams{
12431301
Dockerfile: dockerfile,
12441302
FrontendAttrs: map[string]string{
1245-
"build-arg:BUSYBOX_VARIANT": "-musl",
1303+
"build-arg:BUSYBOX_VARIANT": integration.UnixOrWindows("-musl", "-busybox"),
12461304
},
12471305
})
12481306
}
@@ -1376,10 +1434,14 @@ func checkProgressStream(t *testing.T, sb integration.Sandbox, lintTest *lintTes
13761434

13771435
f := getFrontend(t, sb)
13781436

1437+
platformStr := integration.UnixOrWindows(
1438+
"linux/amd64,linux/arm64",
1439+
"windows/amd64",
1440+
)
13791441
attrs := lintTest.FrontendAttrs
13801442
if attrs == nil {
13811443
attrs = map[string]string{
1382-
"platform": "linux/amd64,linux/arm64",
1444+
"platform": platformStr,
13831445
}
13841446
}
13851447

@@ -1428,8 +1490,6 @@ func checkLinterWarnings(t *testing.T, sb integration.Sandbox, lintTest *lintTes
14281490
return lintTest.Warnings[i].Line < lintTest.Warnings[j].Line
14291491
})
14301492

1431-
integration.SkipOnPlatform(t, "windows")
1432-
14331493
if lintTest.TmpDir == nil {
14341494
testfiles := []fstest.Applier{
14351495
fstest.CreateFile("Dockerfile", lintTest.Dockerfile, 0600),

frontend/dockerfile/dockerfile_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ func init() {
236236

237237
images := integration.UnixOrWindows(
238238
[]string{"busybox:latest", "alpine:latest"},
239-
[]string{"nanoserver:latest", "nanoserver:plus"})
239+
[]string{"nanoserver:latest", "nanoserver:plus", "nanoserver:plus-busybox"})
240240
opts = []integration.TestOpt{
241241
integration.WithMirroredImages(integration.OfficialImages(images...)),
242242
integration.WithMatrix("frontend", frontends),

util/testutil/integration/util_windows.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ var windowsImagesMirrorMap = map[string]string{
1919
// nanoserver with extra binaries, like fc.exe
2020
// TODO(profnandaa): get an approved/compliant repo, placeholder for now
2121
// see dockerfile here - https://github.com/microsoft/windows-container-tools/pull/178
22-
"nanoserver:plus": "docker.io/wintools/nanoserver:ltsc2022",
22+
"nanoserver:plus": "docker.io/wintools/nanoserver:ltsc2022",
23+
"nanoserver:plus-busybox": "docker.io/wintools/nanoserver:ltsc2022",
2324
}
2425

2526
// abstracted function to handle pipe dialing on windows.

0 commit comments

Comments
 (0)