1919import com .google .cloud .tools .jib .Command ;
2020import com .google .cloud .tools .jib .api .buildplan .AbsoluteUnixPath ;
2121import com .google .cloud .tools .jib .api .buildplan .FileEntriesLayer ;
22+ import com .google .cloud .tools .jib .api .buildplan .Platform ;
2223import com .google .cloud .tools .jib .event .events .ProgressEvent ;
2324import com .google .cloud .tools .jib .event .progress .ProgressEventHandler ;
2425import com .google .cloud .tools .jib .global .JibSystemProperties ;
2526import com .google .cloud .tools .jib .registry .LocalRegistry ;
2627import com .google .common .base .Splitter ;
2728import com .google .common .collect .ImmutableList ;
2829import com .google .common .collect .ImmutableMap ;
30+ import com .google .common .collect .ImmutableSet ;
2931import com .google .common .io .Resources ;
3032import java .io .IOException ;
3133import java .net .URISyntaxException ;
3537import java .util .Arrays ;
3638import java .util .Collections ;
3739import java .util .List ;
40+ import java .util .Objects ;
41+ import java .util .Set ;
3842import java .util .concurrent .ExecutionException ;
3943import java .util .stream .Stream ;
4044import org .hamcrest .CoreMatchers ;
@@ -83,6 +87,8 @@ private void checkCompletion() {
8387 private static final Logger logger = LoggerFactory .getLogger (ContainerizerIntegrationTest .class );
8488 private static final String DISTROLESS_DIGEST =
8589 "sha256:f488c213f278bc5f9ffe3ddf30c5dbb2303a15a74146b738d12453088e662880" ;
90+ private static final String MULTI_PLATFORM_DIGEST =
91+ "sha256:c737fc29fc2556d3377d6a719a9842a500777fce35a7f1299acd569c73f65247" ;
8692 private static final double DOUBLE_ERROR_MARGIN = 1e-10 ;
8793
8894 public static ImmutableList <FileEntriesLayer > fakeLayerConfigurations ;
@@ -228,6 +234,30 @@ public void testSteps_forBuildToDockerRegistry_multipleTags()
228234 new Command ("docker" , "run" , "--rm" , imageReference3 ).run ());
229235 }
230236
237+ @ Test
238+ public void testSteps_forBuildToDockerRegistry_multiplePlatforms ()
239+ throws IOException , InterruptedException , ExecutionException , RegistryException ,
240+ CacheDirectoryCreationException , InvalidImageReferenceException {
241+ buildImage (
242+ ImageReference .of ("gcr.io" , "distroless/java17-debian11" , MULTI_PLATFORM_DIGEST ),
243+ Containerizer .to (RegistryImage .named (dockerHost + ":5000/testimage:testtag" )),
244+ Collections .singletonList ("testtag" ),
245+ ImmutableSet .of (new Platform ("amd64" , "linux" ), new Platform ("arm64" , "linux" )));
246+
247+ String imageReference = dockerHost + ":5000/testimage:testtag-amd64" ;
248+ localRegistry .pull (imageReference );
249+ assertDockerInspect (imageReference );
250+ Assert .assertEquals (
251+ "Hello, world. An argument.\n " , new Command ("docker" , "run" , "--rm" , imageReference ).run ());
252+
253+ String imageReference2 = dockerHost + ":5000/testimage:testtag-arm64" ;
254+ localRegistry .pull (imageReference2 );
255+ assertDockerInspect (imageReference2 );
256+ Assert .assertEquals (
257+ "Hello, world. An argument.\n " ,
258+ new Command ("docker" , "run" , "--rm" , imageReference2 ).run ());
259+ }
260+
231261 @ Test
232262 public void testSteps_forBuildToDockerRegistry_skipExistingDigest ()
233263 throws IOException , InterruptedException , ExecutionException , RegistryException ,
@@ -336,6 +366,16 @@ private JibContainer buildImage(
336366 ImageReference baseImage , Containerizer containerizer , List <String > additionalTags )
337367 throws IOException , InterruptedException , RegistryException , CacheDirectoryCreationException ,
338368 ExecutionException {
369+ return buildImage (baseImage , containerizer , additionalTags , null );
370+ }
371+
372+ private JibContainer buildImage (
373+ ImageReference baseImage ,
374+ Containerizer containerizer ,
375+ List <String > additionalTags ,
376+ Set <Platform > additionalPlatforms )
377+ throws IOException , InterruptedException , RegistryException , CacheDirectoryCreationException ,
378+ ExecutionException {
339379 JibContainerBuilder containerBuilder =
340380 Jib .from (baseImage )
341381 .setEntrypoint (
@@ -346,6 +386,9 @@ private JibContainer buildImage(
346386 .setExposedPorts (Ports .parse (Arrays .asList ("1000" , "2000-2002/tcp" , "3000/udp" )))
347387 .setLabels (ImmutableMap .of ("key1" , "value1" , "key2" , "value2" ))
348388 .setFileEntriesLayers (fakeLayerConfigurations );
389+ if (Objects .nonNull (additionalPlatforms )) {
390+ containerBuilder .setPlatforms (additionalPlatforms );
391+ }
349392
350393 containerizer
351394 .setAllowInsecureRegistries (true )
0 commit comments