49
49
import org .springframework .boot .loader .tools .LayoutFactory ;
50
50
import org .springframework .boot .loader .tools .Libraries ;
51
51
import org .springframework .boot .loader .tools .LoaderImplementation ;
52
+ import org .springframework .boot .maven .Docker .DockerRegistry ;
52
53
import org .springframework .util .StringUtils ;
53
54
54
55
/**
@@ -187,6 +188,86 @@ public abstract class BuildImageMojo extends AbstractPackagerMojo {
187
188
@ Parameter (property = "spring-boot.build-image.imagePlatform" )
188
189
String imagePlatform ;
189
190
191
+ /**
192
+ * Alias for the builder registry {@link DockerRegistry#username} to support
193
+ * configuration through command-line property.
194
+ * @since 3.5.0
195
+ */
196
+ @ Parameter (property = "spring-boot.build-image.docker.builderRegistry.username" )
197
+ String builderRegistryUsername ;
198
+
199
+ /**
200
+ * Alias for the builder registry {@link DockerRegistry#password} to support
201
+ * configuration through command-line property.
202
+ * @since 3.5.0
203
+ */
204
+ @ Parameter (property = "spring-boot.build-image.docker.builderRegistry.password" )
205
+ String builderRegistryPassword ;
206
+
207
+ /**
208
+ * Alias for the builder registry {@link DockerRegistry#username} to support
209
+ * configuration through command-line property.
210
+ * @since 3.5.0
211
+ */
212
+ @ Parameter (property = "spring-boot.build-image.docker.builderRegistry.email" )
213
+ String builderRegistryEmail ;
214
+
215
+ /**
216
+ * Alias for the builder registry {@link DockerRegistry#token} to support
217
+ * configuration through command-line property.
218
+ * @since 3.5.0
219
+ */
220
+ @ Parameter (property = "spring-boot.build-image.docker.builderRegistry.token" )
221
+ String builderRegistryToken ;
222
+
223
+ /**
224
+ * Alias for the builder registry {@link DockerRegistry#url} to support configuration
225
+ * through command-line property.
226
+ * @since 3.5.0
227
+ */
228
+ @ Parameter (property = "spring-boot.build-image.docker.builderRegistry.url" )
229
+ String builderRegistryUrl ;
230
+
231
+ /**
232
+ * Alias for the publish registry {@link DockerRegistry#username} to support
233
+ * configuration through command-line property.
234
+ * @since 3.5.0
235
+ */
236
+ @ Parameter (property = "spring-boot.build-image.docker.publishRegistry.username" )
237
+ String publishRegistryUsername ;
238
+
239
+ /**
240
+ * Alias for the publish registry {@link DockerRegistry#password} to support
241
+ * configuration through command-line property.
242
+ * @since 3.5.0
243
+ */
244
+ @ Parameter (property = "spring-boot.build-image.docker.publishRegistry.password" )
245
+ String publishRegistryPassword ;
246
+
247
+ /**
248
+ * Alias for the publish registry {@link DockerRegistry#username} to support
249
+ * configuration through command-line property.
250
+ * @since 3.5.0
251
+ */
252
+ @ Parameter (property = "spring-boot.build-image.docker.publishRegistry.email" )
253
+ String publishRegistryEmail ;
254
+
255
+ /**
256
+ * Alias for the publish registry {@link DockerRegistry#token} to support
257
+ * configuration through command-line property.
258
+ * @since 3.5.0
259
+ */
260
+ @ Parameter (property = "spring-boot.build-image.docker.publishRegistry.token" )
261
+ String publishRegistryToken ;
262
+
263
+ /**
264
+ * Alias for the publish registry {@link DockerRegistry#url} to support configuration
265
+ * through command-line property.
266
+ * @since 3.5.0
267
+ */
268
+ @ Parameter (property = "spring-boot.build-image.docker.publishRegistry.url" )
269
+ String publishRegistryUrl ;
270
+
190
271
/**
191
272
* Docker configuration options.
192
273
* @since 2.4.0
@@ -262,9 +343,15 @@ private void buildImage() throws MojoExecutionException {
262
343
Libraries libraries = getLibraries (Collections .emptySet ());
263
344
try {
264
345
BuildRequest request = getBuildRequest (libraries );
265
- DockerConfiguration dockerConfiguration = (this .docker != null )
266
- ? this .docker .asDockerConfiguration (request .isPublish ())
267
- : new Docker ().asDockerConfiguration (request .isPublish ());
346
+ if (this .docker == null ) {
347
+ this .docker = new Docker ();
348
+ }
349
+ DockerRegistry builderRegistry = configureBuilderRegistry (this .docker .getBuilderRegistry ());
350
+ DockerRegistry publisherRegistry = configurePublishRegistry (this .docker .getPublishRegistry ());
351
+ this .docker .setBuilderRegistry (builderRegistry );
352
+ this .docker .setPublishRegistry (publisherRegistry );
353
+
354
+ DockerConfiguration dockerConfiguration = this .docker .asDockerConfiguration (request .isPublish ());
268
355
Builder builder = new Builder (new MojoBuildLog (this ::getLog ), dockerConfiguration );
269
356
builder .build (request );
270
357
}
@@ -273,6 +360,40 @@ private void buildImage() throws MojoExecutionException {
273
360
}
274
361
}
275
362
363
+ private DockerRegistry configurePublishRegistry (DockerRegistry dockerRegistry ) {
364
+ if (dockerRegistry == null ) {
365
+ dockerRegistry = new DockerRegistry ();
366
+ }
367
+ checkAndSetDockerRegistry (this .publishRegistryEmail , dockerRegistry .getEmail (), dockerRegistry ::setEmail );
368
+ checkAndSetDockerRegistry (this .publishRegistryPassword , dockerRegistry .getPassword (),
369
+ dockerRegistry ::setPassword );
370
+ checkAndSetDockerRegistry (this .publishRegistryToken , dockerRegistry .getToken (), dockerRegistry ::setToken );
371
+ checkAndSetDockerRegistry (this .publishRegistryUrl , dockerRegistry .getUrl (), dockerRegistry ::setUrl );
372
+ checkAndSetDockerRegistry (this .publishRegistryUsername , dockerRegistry .getUsername (),
373
+ dockerRegistry ::setUsername );
374
+ return dockerRegistry ;
375
+ }
376
+
377
+ private DockerRegistry configureBuilderRegistry (DockerRegistry dockerRegistry ) {
378
+ if (dockerRegistry == null ) {
379
+ dockerRegistry = new DockerRegistry ();
380
+ }
381
+ checkAndSetDockerRegistry (this .builderRegistryEmail , dockerRegistry .getEmail (), dockerRegistry ::setEmail );
382
+ checkAndSetDockerRegistry (this .builderRegistryPassword , dockerRegistry .getPassword (),
383
+ dockerRegistry ::setPassword );
384
+ checkAndSetDockerRegistry (this .builderRegistryToken , dockerRegistry .getToken (), dockerRegistry ::setToken );
385
+ checkAndSetDockerRegistry (this .builderRegistryUrl , dockerRegistry .getUrl (), dockerRegistry ::setUrl );
386
+ checkAndSetDockerRegistry (this .builderRegistryUsername , dockerRegistry .getUsername (),
387
+ dockerRegistry ::setUsername );
388
+ return dockerRegistry ;
389
+ }
390
+
391
+ private void checkAndSetDockerRegistry (String value , String currentValue , Consumer <String > setter ) {
392
+ if (StringUtils .hasText (value ) && !StringUtils .hasText (currentValue )) {
393
+ setter .accept (value );
394
+ }
395
+ }
396
+
276
397
private BuildRequest getBuildRequest (Libraries libraries ) {
277
398
ImagePackager imagePackager = new ImagePackager (getArchiveFile (), getBackupFile ());
278
399
Function <Owner , TarArchive > content = (owner ) -> getApplicationContent (owner , libraries , imagePackager );
0 commit comments