@@ -581,12 +581,16 @@ COPY Dockerfile /bar
581
581
` )
582
582
checkLinterWarnings (t , sb , & lintTestParams {Dockerfile : dockerfile })
583
583
584
- dockerfile = []byte (`
585
- FROM alpine
584
+ dockerfile = []byte (fmt .Sprintf (
585
+ `
586
+ FROM %s
586
587
RUN <<'EOT'
587
- env
588
+ %s
588
589
EOT
589
- ` )
590
+ ` ,
591
+ integration .UnixOrWindows ("alpine" , "nanoserver" ),
592
+ integration .UnixOrWindows ("env" , "set" ),
593
+ ))
590
594
checkLinterWarnings (t , sb , & lintTestParams {Dockerfile : dockerfile })
591
595
}
592
596
@@ -822,12 +826,24 @@ COPY Dockerfile .
822
826
BuildErrLocation : 2 ,
823
827
})
824
828
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
827
834
ARG MY_ARCH=amd64
828
- FROM --platform=linux /${MYARCH} busybox
835
+ FROM --platform=%s /${MYARCH} %s
829
836
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 )
831
847
checkLinterWarnings (t , sb , & lintTestParams {
832
848
Dockerfile : dockerfile ,
833
849
Warnings : []expectedLintWarning {
@@ -840,16 +856,18 @@ COPY Dockerfile .
840
856
Line : 4 ,
841
857
},
842
858
},
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 ,
845
861
BuildErrLocation : 4 ,
846
862
})
847
863
848
- dockerfile = []byte (`
864
+ dockerfile = []byte (fmt .Sprintf (
865
+ `
849
866
ARG tag=latest
850
- FROM busybox :${tag}${version} AS b
867
+ FROM %s :${tag}${version} AS b
851
868
COPY Dockerfile .
852
- ` )
869
+ ` ,
870
+ baseImg ))
853
871
checkLinterWarnings (t , sb , & lintTestParams {
854
872
Dockerfile : dockerfile ,
855
873
Warnings : []expectedLintWarning {
@@ -902,27 +920,34 @@ COPY Dockerfile${foo} .
902
920
` )
903
921
checkLinterWarnings (t , sb , & lintTestParams {Dockerfile : dockerfile })
904
922
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
907
927
ARG foo=Dockerfile
908
928
909
929
FROM base
910
930
COPY $foo .
911
- ` )
931
+ ` ,
932
+ baseImg ))
912
933
checkLinterWarnings (t , sb , & lintTestParams {Dockerfile : dockerfile })
913
934
914
- dockerfile = []byte (`
915
- FROM alpine
935
+ dockerfile = []byte (fmt .Sprintf (
936
+ `
937
+ FROM %s
916
938
RUN echo $PATH
917
- ` )
939
+ ` ,
940
+ baseImg ))
918
941
checkLinterWarnings (t , sb , & lintTestParams {Dockerfile : dockerfile })
919
942
920
- dockerfile = []byte (`
921
- FROM alpine
943
+ dockerfile = []byte (fmt .Sprintf (
944
+ `
945
+ FROM %s
922
946
COPY $foo .
923
947
ARG foo=bar
924
948
RUN echo $foo
925
- ` )
949
+ ` ,
950
+ baseImg ))
926
951
checkLinterWarnings (t , sb , & lintTestParams {
927
952
Dockerfile : dockerfile ,
928
953
Warnings : []expectedLintWarning {
@@ -937,13 +962,15 @@ RUN echo $foo
937
962
},
938
963
})
939
964
940
- dockerfile = []byte (`
941
- FROM alpine
965
+ dockerfile = []byte (fmt .Sprintf (
966
+ `
967
+ FROM %s
942
968
ARG DIR_BINARIES=binaries/
943
969
ARG DIR_ASSETS=assets/
944
970
ARG DIR_CONFIG=config/
945
971
COPY $DIR_ASSET .
946
- ` )
972
+ ` ,
973
+ baseImg ))
947
974
checkLinterWarnings (t , sb , & lintTestParams {
948
975
Dockerfile : dockerfile ,
949
976
Warnings : []expectedLintWarning {
@@ -958,10 +985,12 @@ COPY $DIR_ASSET .
958
985
},
959
986
})
960
987
961
- dockerfile = []byte (`
962
- FROM alpine
988
+ dockerfile = []byte (fmt .Sprintf (
989
+ `
990
+ FROM %s
963
991
ENV PATH=$PAHT:/tmp/bin
964
- ` )
992
+ ` ,
993
+ baseImg ))
965
994
checkLinterWarnings (t , sb , & lintTestParams {
966
995
Dockerfile : dockerfile ,
967
996
Warnings : []expectedLintWarning {
@@ -1150,10 +1179,13 @@ FROM --platform=${TARGETPLATFORM} scratch
1150
1179
}
1151
1180
1152
1181
func testInvalidDefaultArgInFrom (t * testing.T , sb integration.Sandbox ) {
1153
- dockerfile := []byte (`
1182
+ baseImg := integration .UnixOrWindows ("busybox" , "nanoserver" )
1183
+ dockerfile := []byte (fmt .Sprintf (
1184
+ `
1154
1185
ARG VERSION
1155
- FROM busybox:$VERSION
1156
- ` )
1186
+ FROM %s:$VERSION
1187
+ ` ,
1188
+ baseImg ))
1157
1189
checkLinterWarnings (t , sb , & lintTestParams {
1158
1190
Dockerfile : dockerfile ,
1159
1191
FrontendAttrs : map [string ]string {
@@ -1164,9 +1196,12 @@ FROM busybox:$VERSION
1164
1196
RuleName : "InvalidDefaultArgInFrom" ,
1165
1197
Description : "Default value for global ARG results in an empty or invalid base image name" ,
1166
1198
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 ,
1170
1205
},
1171
1206
},
1172
1207
})
@@ -1178,7 +1213,7 @@ FROM $IMAGE
1178
1213
checkLinterWarnings (t , sb , & lintTestParams {
1179
1214
Dockerfile : dockerfile ,
1180
1215
FrontendAttrs : map [string ]string {
1181
- "build-arg:IMAGE" : "busybox:latest" ,
1216
+ "build-arg:IMAGE" : integration . UnixOrWindows ( "busybox:latest" , "nanoserver:latest" ) ,
1182
1217
},
1183
1218
Warnings : []expectedLintWarning {
1184
1219
{
@@ -1192,57 +1227,80 @@ FROM $IMAGE
1192
1227
},
1193
1228
})
1194
1229
1195
- dockerfile = []byte (`
1230
+ dockerfile = []byte (integration .UnixOrWindows (
1231
+ `
1196
1232
ARG SFX="box:"
1197
1233
FROM busy${SFX}
1198
- ` )
1234
+ ` ,
1235
+ `
1236
+ ARG SFX="server:"
1237
+ FROM nano${SFX}
1238
+ ` ,
1239
+ ))
1199
1240
checkLinterWarnings (t , sb , & lintTestParams {
1200
1241
Dockerfile : dockerfile ,
1201
1242
FrontendAttrs : map [string ]string {
1202
- "build-arg:SFX" : "box:latest" ,
1243
+ "build-arg:SFX" : integration . UnixOrWindows ( "box:latest" , "server:latest" ) ,
1203
1244
},
1204
1245
Warnings : []expectedLintWarning {
1205
1246
{
1206
1247
RuleName : "InvalidDefaultArgInFrom" ,
1207
1248
Description : "Default value for global ARG results in an empty or invalid base image name" ,
1208
1249
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 ,
1212
1256
},
1213
1257
},
1214
1258
})
1215
1259
1216
- dockerfile = []byte (`
1260
+ dockerfile = []byte (fmt .Sprintf (
1261
+ `
1217
1262
ARG VERSION="latest"
1218
- FROM busybox:${VERSION}
1219
- ` )
1263
+ FROM %s:${VERSION}
1264
+ ` ,
1265
+ baseImg ))
1220
1266
checkLinterWarnings (t , sb , & lintTestParams {
1221
1267
Dockerfile : dockerfile ,
1222
1268
FrontendAttrs : map [string ]string {
1223
1269
"build-arg:VERSION" : "latest" ,
1224
1270
},
1225
1271
})
1226
1272
1227
- dockerfile = []byte (`
1273
+ dockerfile = []byte (integration .UnixOrWindows (
1274
+ `
1228
1275
ARG BUSYBOX_VARIANT=""
1229
1276
FROM busybox:stable${BUSYBOX_VARIANT}
1230
- ` )
1277
+ ` ,
1278
+ `
1279
+ ARG BUSYBOX_VARIANT=""
1280
+ FROM nanoserver:plus${BUSYBOX_VARIANT}
1281
+ ` ,
1282
+ ))
1231
1283
checkLinterWarnings (t , sb , & lintTestParams {
1232
1284
Dockerfile : dockerfile ,
1233
1285
FrontendAttrs : map [string ]string {
1234
- "build-arg:BUSYBOX_VARIANT" : "-musl" ,
1286
+ "build-arg:BUSYBOX_VARIANT" : integration . UnixOrWindows ( "-musl" , "-busybox" ) ,
1235
1287
},
1236
1288
})
1237
1289
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
+ ))
1242
1300
checkLinterWarnings (t , sb , & lintTestParams {
1243
1301
Dockerfile : dockerfile ,
1244
1302
FrontendAttrs : map [string ]string {
1245
- "build-arg:BUSYBOX_VARIANT" : "-musl" ,
1303
+ "build-arg:BUSYBOX_VARIANT" : integration . UnixOrWindows ( "-musl" , "-busybox" ) ,
1246
1304
},
1247
1305
})
1248
1306
}
@@ -1376,10 +1434,14 @@ func checkProgressStream(t *testing.T, sb integration.Sandbox, lintTest *lintTes
1376
1434
1377
1435
f := getFrontend (t , sb )
1378
1436
1437
+ platformStr := integration .UnixOrWindows (
1438
+ "linux/amd64,linux/arm64" ,
1439
+ "windows/amd64" ,
1440
+ )
1379
1441
attrs := lintTest .FrontendAttrs
1380
1442
if attrs == nil {
1381
1443
attrs = map [string ]string {
1382
- "platform" : "linux/amd64,linux/arm64" ,
1444
+ "platform" : platformStr ,
1383
1445
}
1384
1446
}
1385
1447
@@ -1428,8 +1490,6 @@ func checkLinterWarnings(t *testing.T, sb integration.Sandbox, lintTest *lintTes
1428
1490
return lintTest .Warnings [i ].Line < lintTest .Warnings [j ].Line
1429
1491
})
1430
1492
1431
- integration .SkipOnPlatform (t , "windows" )
1432
-
1433
1493
if lintTest .TmpDir == nil {
1434
1494
testfiles := []fstest.Applier {
1435
1495
fstest .CreateFile ("Dockerfile" , lintTest .Dockerfile , 0600 ),
0 commit comments