@@ -178,7 +178,7 @@ FROM ubuntu:latest as dev
178178 const info = await internalGetImageBuildInfoFromDockerfile ( async ( imageName ) => {
179179 assert . strictEqual ( imageName , 'ubuntu:latest' ) ;
180180 return details ;
181- } , dockerfile , { } , undefined , testSubstitute , nullLog , false ) ;
181+ } , dockerfile , { } , undefined , testSubstitute , nullLog , false , { os : 'linux' , arch : 'amd64' } ) ;
182182 assert . strictEqual ( info . user , 'imageUser' ) ;
183183 assert . strictEqual ( info . metadata . config . length , 1 ) ;
184184 assert . strictEqual ( info . metadata . config [ 0 ] . id , 'testid-substituted' ) ;
@@ -206,7 +206,7 @@ USER dockerfileUserB
206206 const info = await internalGetImageBuildInfoFromDockerfile ( async ( imageName ) => {
207207 assert . strictEqual ( imageName , 'ubuntu:latest' ) ;
208208 return details ;
209- } , dockerfile , { } , undefined , testSubstitute , nullLog , false ) ;
209+ } , dockerfile , { } , undefined , testSubstitute , nullLog , false , { os : 'linux' , arch : 'amd64' } ) ;
210210 assert . strictEqual ( info . user , 'dockerfileUserB' ) ;
211211 assert . strictEqual ( info . metadata . config . length , 0 ) ;
212212 assert . strictEqual ( info . metadata . raw . length , 0 ) ;
@@ -220,7 +220,7 @@ describe('findBaseImage', () => {
220220USER user1
221221` ;
222222 const extracted = extractDockerfile ( dockerfile ) ;
223- const image = findBaseImage ( extracted , { } , undefined ) ;
223+ const image = findBaseImage ( extracted , { } , undefined , { os : 'linux' , arch : 'amd64' } ) ;
224224 assert . strictEqual ( image , 'image1' ) ;
225225 } ) ;
226226
@@ -231,7 +231,7 @@ ARG IMAGE_USER=user2
231231USER $IMAGE_USER
232232` ;
233233 const extracted = extractDockerfile ( dockerfile ) ;
234- const image = findBaseImage ( extracted , { } , undefined ) ;
234+ const image = findBaseImage ( extracted , { } , undefined , { os : 'linux' , arch : 'amd64' } ) ;
235235 assert . strictEqual ( image , 'image2' ) ;
236236 } ) ;
237237
@@ -244,7 +244,7 @@ USER $IMAGE_USER
244244 const extracted = extractDockerfile ( dockerfile ) ;
245245 const image = findBaseImage ( extracted , {
246246 'BASE_IMAGE' : 'image3'
247- } , undefined ) ;
247+ } , undefined , { os : 'linux' , arch : 'amd64' } ) ;
248248 assert . strictEqual ( image , 'image3' ) ;
249249 } ) ;
250250
@@ -256,7 +256,7 @@ FROM image3 as stage3
256256FROM image4 as stage4
257257` ;
258258 const extracted = extractDockerfile ( dockerfile ) ;
259- const image = findBaseImage ( extracted , { } , 'stage2' ) ;
259+ const image = findBaseImage ( extracted , { } , 'stage2' , { os : 'linux' , arch : 'amd64' } ) ;
260260 assert . strictEqual ( image , 'image3' ) ;
261261 } ) ;
262262
@@ -268,7 +268,7 @@ FROM "\${BASE_IMAGE}"
268268` ;
269269 const extracted = extractDockerfile ( dockerfile ) ;
270270 assert . strictEqual ( extracted . stages . length , 1 ) ;
271- const image = findBaseImage ( extracted , { } , undefined ) ;
271+ const image = findBaseImage ( extracted , { } , undefined , { os : 'linux' , arch : 'amd64' } ) ;
272272 assert . strictEqual ( image , 'ubuntu:latest' ) ;
273273 } ) ;
274274
@@ -282,7 +282,7 @@ FROM \${cloud:+mcr.microsoft.com/}azure-cli:latest
282282 assert . strictEqual ( extracted . stages . length , 1 ) ;
283283 const image = findBaseImage ( extracted , {
284284 'cloud' : 'true'
285- } , undefined ) ;
285+ } , undefined , { os : 'linux' , arch : 'amd64' } ) ;
286286 assert . strictEqual ( image , 'mcr.microsoft.com/azure-cli:latest' ) ;
287287 } ) ;
288288
@@ -293,7 +293,7 @@ FROM \${cloud:+mcr.microsoft.com/}azure-cli:latest
293293` ;
294294 const extracted = extractDockerfile ( dockerfile ) ;
295295 assert . strictEqual ( extracted . stages . length , 1 ) ;
296- const image = findBaseImage ( extracted , { } , undefined ) ;
296+ const image = findBaseImage ( extracted , { } , undefined , { os : 'linux' , arch : 'amd64' } ) ;
297297 assert . strictEqual ( image , 'azure-cli:latest' ) ;
298298 } ) ;
299299
@@ -306,7 +306,7 @@ FROM \${cloud:-mcr.microsoft.com/}azure-cli:latest
306306 assert . strictEqual ( extracted . stages . length , 1 ) ;
307307 const image = findBaseImage ( extracted , {
308308 'cloud' : 'ghcr.io/'
309- } , undefined ) ;
309+ } , undefined , { os : 'linux' , arch : 'amd64' } ) ;
310310 assert . strictEqual ( image , 'ghcr.io/azure-cli:latest' ) ;
311311 } ) ;
312312
@@ -317,7 +317,7 @@ FROM \${cloud:-mcr.microsoft.com/}azure-cli:latest
317317` ;
318318 const extracted = extractDockerfile ( dockerfile ) ;
319319 assert . strictEqual ( extracted . stages . length , 1 ) ;
320- const image = findBaseImage ( extracted , { } , undefined ) ;
320+ const image = findBaseImage ( extracted , { } , undefined , { os : 'linux' , arch : 'amd64' } ) ;
321321 assert . strictEqual ( image , 'mcr.microsoft.com/azure-cli:latest' ) ;
322322 } ) ;
323323
@@ -334,7 +334,8 @@ FROM \${cloud:+"mcr.microsoft.com/"}azure-cli:latest"
334334 {
335335 cloud : 'true' ,
336336 } ,
337- undefined
337+ undefined ,
338+ { os : 'linux' , arch : 'amd64' }
338339 ) ;
339340 assert . strictEqual ( image , 'mcr.microsoft.com/azure-cli:latest' ) ;
340341 } ) ;
@@ -347,7 +348,7 @@ FROM "\${cloud:+"mcr.microsoft.com/"}azure-cli:latest"
347348
348349 const extracted = extractDockerfile ( dockerfile ) ;
349350 assert . strictEqual ( extracted . stages . length , 1 ) ;
350- const image = findBaseImage ( extracted , { } , undefined ) ;
351+ const image = findBaseImage ( extracted , { } , undefined , { os : 'linux' , arch : 'amd64' } ) ;
351352 assert . strictEqual ( image , 'azure-cli:latest' ) ;
352353 } ) ;
353354
@@ -364,7 +365,8 @@ FROM "\${cloud:-"mcr.microsoft.com/"}azure-cli:latest"
364365 {
365366 cloud : 'ghcr.io/' ,
366367 } ,
367- undefined
368+ undefined ,
369+ { os : 'linux' , arch : 'amd64' }
368370 ) ;
369371 assert . strictEqual ( image , 'ghcr.io/azure-cli:latest' ) ;
370372 } ) ;
@@ -377,9 +379,33 @@ FROM \${cloud:-"mcr.microsoft.com/"}azure-cli:latest as label
377379
378380 const extracted = extractDockerfile ( dockerfile ) ;
379381 assert . strictEqual ( extracted . stages . length , 1 ) ;
380- const image = findBaseImage ( extracted , { } , undefined ) ;
382+ const image = findBaseImage ( extracted , { } , undefined , { os : 'linux' , arch : 'amd64' } ) ;
381383 assert . strictEqual ( image , 'mcr.microsoft.com/azure-cli:latest' ) ;
382384 } ) ;
385+
386+ it ( 'Multi-platform build' , async ( ) => {
387+ const dockerfile = `
388+ ARG TARGETARCH
389+ FROM image1 AS base-1
390+
391+ FROM image2 AS base-2
392+
393+ FROM --platform=amd64 base-1 AS amd64-base
394+ LABEL Architecture="amd64"
395+
396+ FROM --platform=arm64 base-2 AS arm64-base
397+ LABEL Architecture="arm64"
398+
399+ FROM \${TARGETARCH}-base AS final
400+ ` ;
401+
402+ const extracted = extractDockerfile ( dockerfile ) ;
403+ assert . strictEqual ( extracted . stages . length , 5 ) ;
404+ const amd64BaseImage = findBaseImage ( extracted , { } , undefined , { os : 'linux' , arch : 'amd64' } ) ;
405+ assert . strictEqual ( amd64BaseImage , 'image1' ) ;
406+ const arm64BaseImage = findBaseImage ( extracted , { } , undefined , { os : 'linux' , arch : 'arm64' } ) ;
407+ assert . strictEqual ( arm64BaseImage , 'image2' ) ;
408+ } ) ;
383409 } ) ;
384410 } ) ;
385411} ) ;
0 commit comments