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
/**
@@ -172,6 +173,86 @@ public abstract class BuildImageMojo extends AbstractPackagerMojo {
172
173
@ Parameter (property = "spring-boot.build-image.applicationDirectory" , readonly = true )
173
174
String applicationDirectory ;
174
175
176
+ /**
177
+ * Alias for the builder registry {@link DockerRegistry#username} to support configuration through
178
+ * command-line property
179
+ * @since 3.3.11
180
+ */
181
+ @ Parameter (property = "spring-boot.build-image.docker.builderRegistry.username" , readonly = true )
182
+ String builderRegistryUsername ;
183
+
184
+ /**
185
+ * Alias for the builder registry {@link DockerRegistry#password} to support configuration through
186
+ * command-line property
187
+ * @since 3.3.11
188
+ */
189
+ @ Parameter (property = "spring-boot.build-image.docker.builderRegistry.password" , readonly = true )
190
+ String builderRegistryPassword ;
191
+
192
+ /**
193
+ * Alias for the builder registry {@link DockerRegistry#username} to support configuration through
194
+ * command-line property
195
+ * @since 3.3.11
196
+ */
197
+ @ Parameter (property = "spring-boot.build-image.docker.builderRegistry.email" , readonly = true )
198
+ String builderRegistryEmail ;
199
+
200
+ /**
201
+ * Alias for the builder registry {@link DockerRegistry#token} to support configuration through
202
+ * command-line property
203
+ * @since 3.3.11
204
+ */
205
+ @ Parameter (property = "spring-boot.build-image.docker.builderRegistry.token" , readonly = true )
206
+ String builderRegistryToken ;
207
+
208
+ /**
209
+ * Alias for the builder registry {@link DockerRegistry#url} to support configuration through
210
+ * command-line property
211
+ * @since 3.3.11
212
+ */
213
+ @ Parameter (property = "spring-boot.build-image.docker.builderRegistry.url" , readonly = true )
214
+ String builderRegistryUrl ;
215
+
216
+ /**
217
+ * Alias for the publish registry {@link DockerRegistry#username} to support configuration through
218
+ * command-line property
219
+ * @since 3.3.11
220
+ */
221
+ @ Parameter (property = "spring-boot.build-image.docker.publishRegistry.username" , readonly = true )
222
+ String publishRegistryUsername ;
223
+
224
+ /**
225
+ * Alias for the publish registry {@link DockerRegistry#password} to support configuration through
226
+ * command-line property
227
+ * @since 3.3.11
228
+ */
229
+ @ Parameter (property = "spring-boot.build-image.docker.publishRegistry.password" , readonly = true )
230
+ String publishRegistryPassword ;
231
+
232
+ /**
233
+ * Alias for the publish registry {@link DockerRegistry#username} to support configuration through
234
+ * command-line property
235
+ * @since 3.3.11
236
+ */
237
+ @ Parameter (property = "spring-boot.build-image.docker.publishRegistry.email" , readonly = true )
238
+ String publishRegistryEmail ;
239
+
240
+ /**
241
+ * Alias for the publish registry {@link DockerRegistry#token} to support configuration through
242
+ * command-line property
243
+ * @since 3.3.11
244
+ */
245
+ @ Parameter (property = "spring-boot.build-image.docker.publishRegistry.token" , readonly = true )
246
+ String publishRegistryToken ;
247
+
248
+ /**
249
+ * Alias for the publish registry {@link DockerRegistry#url} to support configuration through
250
+ * command-line property
251
+ * @since 3.3.11
252
+ */
253
+ @ Parameter (property = "spring-boot.build-image.docker.publishRegistry.url" , readonly = true )
254
+ String publishRegistryUrl ;
255
+
175
256
/**
176
257
* Docker configuration options.
177
258
* @since 2.4.0
@@ -247,9 +328,15 @@ private void buildImage() throws MojoExecutionException {
247
328
Libraries libraries = getLibraries (Collections .emptySet ());
248
329
try {
249
330
BuildRequest request = getBuildRequest (libraries );
250
- DockerConfiguration dockerConfiguration = (this .docker != null )
251
- ? this .docker .asDockerConfiguration (request .isPublish ())
252
- : new Docker ().asDockerConfiguration (request .isPublish ());
331
+ if (this .docker == null ) {
332
+ this .docker = new Docker ();
333
+ }
334
+ DockerRegistry builderRegistry = configureBuilderRegistry (this .docker .getBuilderRegistry ());
335
+ DockerRegistry publisherRegistry = configurePublishRegistry (this .docker .getPublishRegistry ());
336
+ this .docker .setBuilderRegistry (builderRegistry );
337
+ this .docker .setPublishRegistry (publisherRegistry );
338
+
339
+ DockerConfiguration dockerConfiguration = this .docker .asDockerConfiguration (request .isPublish ());
253
340
Builder builder = new Builder (new MojoBuildLog (this ::getLog ), dockerConfiguration );
254
341
builder .build (request );
255
342
}
@@ -258,6 +345,36 @@ private void buildImage() throws MojoExecutionException {
258
345
}
259
346
}
260
347
348
+ private DockerRegistry configurePublishRegistry (DockerRegistry dockerRegistry ) {
349
+ if (dockerRegistry == null ) {
350
+ dockerRegistry = new DockerRegistry ();
351
+ }
352
+ checkAndSetDockerRegistry (this .publishRegistryEmail , dockerRegistry .getEmail (), dockerRegistry ::setEmail );
353
+ checkAndSetDockerRegistry (this .publishRegistryPassword , dockerRegistry .getPassword (), dockerRegistry ::setPassword );
354
+ checkAndSetDockerRegistry (this .publishRegistryToken , dockerRegistry .getToken (), dockerRegistry ::setToken );
355
+ checkAndSetDockerRegistry (this .publishRegistryUrl , dockerRegistry .getUrl (), dockerRegistry ::setUrl );
356
+ checkAndSetDockerRegistry (this .publishRegistryUsername , dockerRegistry .getUsername (), dockerRegistry ::setUsername );
357
+ return dockerRegistry ;
358
+ }
359
+
360
+ private DockerRegistry configureBuilderRegistry (DockerRegistry dockerRegistry ) {
361
+ if (dockerRegistry == null ) {
362
+ dockerRegistry = new DockerRegistry ();
363
+ }
364
+ checkAndSetDockerRegistry (this .builderRegistryEmail , dockerRegistry .getEmail (), dockerRegistry ::setEmail );
365
+ checkAndSetDockerRegistry (this .builderRegistryPassword , dockerRegistry .getPassword (), dockerRegistry ::setPassword );
366
+ checkAndSetDockerRegistry (this .builderRegistryToken , dockerRegistry .getToken (), dockerRegistry ::setToken );
367
+ checkAndSetDockerRegistry (this .builderRegistryUrl , dockerRegistry .getUrl (), dockerRegistry ::setUrl );
368
+ checkAndSetDockerRegistry (this .builderRegistryUsername , dockerRegistry .getUsername (), dockerRegistry ::setUsername );
369
+ return dockerRegistry ;
370
+ }
371
+
372
+ private void checkAndSetDockerRegistry (String value , String currentValue , Consumer <String > setter ) {
373
+ if (StringUtils .hasText (value ) && !StringUtils .hasText (currentValue )) {
374
+ setter .accept (value );
375
+ }
376
+ }
377
+
261
378
private BuildRequest getBuildRequest (Libraries libraries ) {
262
379
ImagePackager imagePackager = new ImagePackager (getArchiveFile (), getBackupFile ());
263
380
Function <Owner , TarArchive > content = (owner ) -> getApplicationContent (owner , libraries , imagePackager );
0 commit comments