4949import org .springframework .boot .loader .tools .LayoutFactory ;
5050import org .springframework .boot .loader .tools .Libraries ;
5151import org .springframework .boot .loader .tools .LoaderImplementation ;
52+ import org .springframework .boot .maven .Docker .DockerRegistry ;
5253import org .springframework .util .StringUtils ;
5354
5455/**
@@ -172,6 +173,86 @@ public abstract class BuildImageMojo extends AbstractPackagerMojo {
172173 @ Parameter (property = "spring-boot.build-image.applicationDirectory" , readonly = true )
173174 String applicationDirectory ;
174175
176+ /**
177+ * Alias for the builder registry {@link DockerRegistry#username} to support
178+ * configuration through 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
186+ * configuration through 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
194+ * configuration through 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
202+ * configuration through 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
210+ * through 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
218+ * configuration through 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
226+ * configuration through 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
234+ * configuration through 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
242+ * configuration through 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
250+ * through 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+
175256 /**
176257 * Docker configuration options.
177258 * @since 2.4.0
@@ -247,9 +328,15 @@ private void buildImage() throws MojoExecutionException {
247328 Libraries libraries = getLibraries (Collections .emptySet ());
248329 try {
249330 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 ());
253340 Builder builder = new Builder (new MojoBuildLog (this ::getLog ), dockerConfiguration );
254341 builder .build (request );
255342 }
@@ -258,6 +345,40 @@ private void buildImage() throws MojoExecutionException {
258345 }
259346 }
260347
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 (),
354+ dockerRegistry ::setPassword );
355+ checkAndSetDockerRegistry (this .publishRegistryToken , dockerRegistry .getToken (), dockerRegistry ::setToken );
356+ checkAndSetDockerRegistry (this .publishRegistryUrl , dockerRegistry .getUrl (), dockerRegistry ::setUrl );
357+ checkAndSetDockerRegistry (this .publishRegistryUsername , dockerRegistry .getUsername (),
358+ dockerRegistry ::setUsername );
359+ return dockerRegistry ;
360+ }
361+
362+ private DockerRegistry configureBuilderRegistry (DockerRegistry dockerRegistry ) {
363+ if (dockerRegistry == null ) {
364+ dockerRegistry = new DockerRegistry ();
365+ }
366+ checkAndSetDockerRegistry (this .builderRegistryEmail , dockerRegistry .getEmail (), dockerRegistry ::setEmail );
367+ checkAndSetDockerRegistry (this .builderRegistryPassword , dockerRegistry .getPassword (),
368+ dockerRegistry ::setPassword );
369+ checkAndSetDockerRegistry (this .builderRegistryToken , dockerRegistry .getToken (), dockerRegistry ::setToken );
370+ checkAndSetDockerRegistry (this .builderRegistryUrl , dockerRegistry .getUrl (), dockerRegistry ::setUrl );
371+ checkAndSetDockerRegistry (this .builderRegistryUsername , dockerRegistry .getUsername (),
372+ dockerRegistry ::setUsername );
373+ return dockerRegistry ;
374+ }
375+
376+ private void checkAndSetDockerRegistry (String value , String currentValue , Consumer <String > setter ) {
377+ if (StringUtils .hasText (value ) && !StringUtils .hasText (currentValue )) {
378+ setter .accept (value );
379+ }
380+ }
381+
261382 private BuildRequest getBuildRequest (Libraries libraries ) {
262383 ImagePackager imagePackager = new ImagePackager (getArchiveFile (), getBackupFile ());
263384 Function <Owner , TarArchive > content = (owner ) -> getApplicationContent (owner , libraries , imagePackager );
0 commit comments