@@ -86,7 +86,7 @@ void noSkipWhenNotPom() throws IOException, MojoExecutionException {
86
86
}
87
87
88
88
@ Test
89
- void buildUsingBuildx () throws IOException , MojoExecutionException {
89
+ void buildUsingBuildxWithDockerContainerDriver () throws IOException , MojoExecutionException {
90
90
givenBuildXService ();
91
91
92
92
givenMavenProject (buildMojo );
@@ -98,6 +98,20 @@ void buildUsingBuildx() throws IOException, MojoExecutionException {
98
98
thenBuildxRun (null , null , true , null );
99
99
}
100
100
101
+ @ Test
102
+ void buildUsingBuildxWithDefaultDriver () throws IOException , MojoExecutionException {
103
+ givenBuildXService ();
104
+
105
+ givenMavenProject (buildMojo );
106
+ ImageConfiguration imageConfiguration = singleBuildXImageWithDefaultBuilderName (null );
107
+ givenResolvedImages (buildMojo , Collections .singletonList (imageConfiguration ));
108
+ givenPackaging ("jar" );
109
+
110
+ whenMojoExecutes ();
111
+
112
+ thenBuildxRun (null , null , true , null , Collections .emptyList (), false );
113
+ }
114
+
101
115
@ Test
102
116
void buildUsingConfiguredBuildx () throws IOException , MojoExecutionException {
103
117
givenBuildXService ();
@@ -269,7 +283,7 @@ void buildWithTagByBuildx(boolean skipTag) throws IOException, MojoExecutionExce
269
283
List <String > fullTags = skipTag ? Collections .emptyList () : tags .stream ()
270
284
.map (tag -> new ImageName (imageConfiguration .getName (), tag ).getFullName ())
271
285
.collect (Collectors .toList ());
272
- thenBuildxRun (null , null , true , null , fullTags );
286
+ thenBuildxRun (null , null , true , null , fullTags , true );
273
287
}
274
288
275
289
@ ParameterizedTest
@@ -348,30 +362,39 @@ private void verifyBuild(int wantedNumberOfInvocations) throws DockerAccessExcep
348
362
349
363
private void thenBuildxRun (String relativeConfigFile , String contextDir , boolean nativePlatformIncluded ,
350
364
String attestation ) throws MojoExecutionException {
351
- thenBuildxRun (relativeConfigFile , contextDir , nativePlatformIncluded , attestation , Collections .emptyList ());
365
+ thenBuildxRun (relativeConfigFile , contextDir , nativePlatformIncluded , attestation , Collections .emptyList (), true );
352
366
}
353
367
354
368
private void thenBuildxRun (String relativeConfigFile , String contextDir ,
355
- boolean nativePlatformIncluded , String attestation , List <String > tags )
369
+ boolean nativePlatformIncluded , String attestation , List <String > tags , boolean useMavenBuilder )
356
370
throws MojoExecutionException {
357
371
Path buildPath = projectBaseDirectory .toPath ().resolve ("target/docker/example/latest" );
358
372
String config = getOsDependentBuild (buildPath , "docker" );
359
373
String configFile =
360
374
relativeConfigFile != null ? getOsDependentBuild (projectBaseDirectory .toPath (), relativeConfigFile ) :
361
375
null ;
362
376
363
- List <String > cmds =
364
- BuildXService .append (new ArrayList <>(), "docker" , "--config" , config , "buildx" ,
365
- "create" , "--driver" , "docker-container" , "--name" , "maven" , "--node" , "maven0" );
366
- if (configFile != null ) {
367
- BuildXService .append (cmds , "--config" , configFile .replace ('/' , File .separatorChar ));
377
+ if (useMavenBuilder ) {
378
+ List <String > cmds =
379
+ BuildXService .append (new ArrayList <>(), "docker" , "--config" , config , "buildx" , "create" ,
380
+ "--driver" , "docker-container" , "--name" , "maven" , "--node" , "maven0" );
381
+
382
+ if (configFile != null ) {
383
+ cmds = BuildXService .append (cmds , "--config" , configFile .replace ('/' , File .separatorChar ));
384
+ }
385
+ Mockito .verify (exec ).process (cmds );
368
386
}
369
- Mockito .verify (exec ).process (cmds );
370
387
371
388
if (nativePlatformIncluded ) {
372
- List <String > buildXLine = BuildXService .append (new ArrayList <>(), "docker" , "--config" , config , "buildx" ,
373
- "build" , "--progress=plain" , "--builder" , "maven" ,
374
- "--platform" , NATIVE_PLATFORM , "--tag" , "example:latest" );
389
+ List <String > buildXLineInitial = BuildXService .append (new ArrayList <>(), "docker" , "--config" , config , "buildx" ,
390
+ "build" , "--progress=plain" , "--builder" );
391
+ if (useMavenBuilder ) {
392
+ buildXLineInitial .add ("maven" );
393
+ } else {
394
+ buildXLineInitial .add ("default" );
395
+ }
396
+
397
+ List <String > buildXLine = BuildXService .append (buildXLineInitial ,"--platform" , NATIVE_PLATFORM , "--tag" , "example:latest" );
375
398
376
399
tags .forEach (tag -> {
377
400
buildXLine .add ("--tag" );
@@ -446,6 +469,11 @@ private ImageConfiguration singleBuildXImageWithAttestations(Boolean sbom, Strin
446
469
.build (), null );
447
470
}
448
471
472
+ private ImageConfiguration singleBuildXImageWithDefaultBuilderName (String configFile ) {
473
+ return singleImageConfiguration (getBuildXPlatforms (NATIVE_PLATFORM ).configFile (configFile )
474
+ .builderName ("default" ).build (), null );
475
+ }
476
+
449
477
protected ImageConfiguration singleImageWithAuthRegistry (String dockerFile ) {
450
478
BuildImageConfiguration buildImageConfiguration = new BuildImageConfiguration .Builder ()
451
479
.dockerFile (dockerFile )
0 commit comments