2626import org .springframework .boot .buildpack .platform .docker .TotalProgressPullListener ;
2727import org .springframework .boot .buildpack .platform .docker .TotalProgressPushListener ;
2828import org .springframework .boot .buildpack .platform .docker .UpdateListener ;
29- import org .springframework .boot .buildpack .platform .docker .configuration .DockerConfiguration ;
29+ import org .springframework .boot .buildpack .platform .docker .configuration .DockerConnectionConfiguration ;
30+ import org .springframework .boot .buildpack .platform .docker .configuration .DockerRegistryAuthentication ;
3031import org .springframework .boot .buildpack .platform .docker .configuration .ResolvedDockerHost ;
3132import org .springframework .boot .buildpack .platform .docker .transport .DockerEngineException ;
3233import org .springframework .boot .buildpack .platform .docker .type .Binding ;
@@ -54,7 +55,7 @@ public class Builder {
5455
5556 private final DockerApi docker ;
5657
57- private final DockerConfiguration dockerConfiguration ;
58+ private final BuilderDockerConfiguration dockerConfiguration ;
5859
5960 /**
6061 * Create a new builder instance.
@@ -67,8 +68,22 @@ public Builder() {
6768 * Create a new builder instance.
6869 * @param dockerConfiguration the docker configuration
6970 * @since 2.4.0
71+ * @deprecated since 3.5.0 for removal in 4.0.0 in favor of
72+ * {@link #Builder(BuilderDockerConfiguration)}
7073 */
71- public Builder (DockerConfiguration dockerConfiguration ) {
74+ @ Deprecated (since = "3.5.0" , forRemoval = true )
75+ @ SuppressWarnings ("removal" )
76+ public Builder (
77+ org .springframework .boot .buildpack .platform .docker .configuration .DockerConfiguration dockerConfiguration ) {
78+ this (BuildLog .toSystemOut (), dockerConfiguration );
79+ }
80+
81+ /**
82+ * Create a new builder instance.
83+ * @param dockerConfiguration the docker configuration
84+ * @since 3.5.0
85+ */
86+ public Builder (BuilderDockerConfiguration dockerConfiguration ) {
7287 this (BuildLog .toSystemOut (), dockerConfiguration );
7388 }
7489
@@ -85,17 +100,45 @@ public Builder(BuildLog log) {
85100 * @param log a logger used to record output
86101 * @param dockerConfiguration the docker configuration
87102 * @since 2.4.0
103+ * @deprecated since 3.5.0 for removal in 4.0.0 in favor of
104+ * {@link #Builder(BuildLog, BuilderDockerConfiguration)}
88105 */
89- public Builder (BuildLog log , DockerConfiguration dockerConfiguration ) {
90- this (log , new DockerApi ((dockerConfiguration != null ) ? dockerConfiguration .getHost () : null ,
106+ @ Deprecated (since = "3.5.0" , forRemoval = true )
107+ @ SuppressWarnings ("removal" )
108+ public Builder (BuildLog log ,
109+ org .springframework .boot .buildpack .platform .docker .configuration .DockerConfiguration dockerConfiguration ) {
110+ this (log , adaptDeprecatedConfiguration (dockerConfiguration ));
111+ }
112+
113+ @ SuppressWarnings ("removal" )
114+ private static BuilderDockerConfiguration adaptDeprecatedConfiguration (
115+ org .springframework .boot .buildpack .platform .docker .configuration .DockerConfiguration configuration ) {
116+ if (configuration == null ) {
117+ return null ;
118+ }
119+ DockerConnectionConfiguration connection = org .springframework .boot .buildpack .platform .docker .configuration .DockerConfiguration .DockerHostConfiguration
120+ .asConnectionConfiguration (configuration .getHost ());
121+ return new BuilderDockerConfiguration (connection , configuration .isBindHostToBuilder (),
122+ configuration .getBuilderRegistryAuthentication (), configuration .getPublishRegistryAuthentication ());
123+ }
124+
125+ /**
126+ * Create a new builder instance.
127+ * @param log a logger used to record output
128+ * @param dockerConfiguration the docker configuration
129+ * @since 3.5.0
130+ */
131+ public Builder (BuildLog log , BuilderDockerConfiguration dockerConfiguration ) {
132+ this (log , new DockerApi ((dockerConfiguration != null ) ? dockerConfiguration .connection () : null ,
91133 BuildLogAdapter .get (log )), dockerConfiguration );
92134 }
93135
94- Builder (BuildLog log , DockerApi docker , DockerConfiguration dockerConfiguration ) {
136+ Builder (BuildLog log , DockerApi docker , BuilderDockerConfiguration dockerConfiguration ) {
95137 Assert .notNull (log , "'log' must not be null" );
96138 this .log = log ;
97139 this .docker = docker ;
98- this .dockerConfiguration = dockerConfiguration ;
140+ this .dockerConfiguration = (dockerConfiguration != null ) ? dockerConfiguration
141+ : new BuilderDockerConfiguration ();
99142 }
100143
101144 public void build (BuildRequest request ) throws DockerEngineException , IOException {
@@ -104,8 +147,8 @@ public void build(BuildRequest request) throws DockerEngineException, IOExceptio
104147 validateBindings (request .getBindings ());
105148 String domain = request .getBuilder ().getDomain ();
106149 PullPolicy pullPolicy = request .getPullPolicy ();
107- ImageFetcher imageFetcher = new ImageFetcher (domain , getBuilderAuthHeader (), pullPolicy ,
108- request .getImagePlatform ());
150+ ImageFetcher imageFetcher = new ImageFetcher (domain , this . dockerConfiguration . builderRegistryAuthentication () ,
151+ pullPolicy , request .getImagePlatform ());
109152 Image builderImage = imageFetcher .fetchImage (ImageType .BUILDER , request .getBuilder ());
110153 BuilderMetadata builderMetadata = BuilderMetadata .fromImage (builderImage );
111154 request = withRunImageIfNeeded (request , builderMetadata );
@@ -182,8 +225,8 @@ private void executeLifecycle(EphemeralBuilder builder, Lifecycle lifecycle) thr
182225 }
183226
184227 private ResolvedDockerHost getDockerHost () {
185- boolean bindHostToBuilder = this .dockerConfiguration != null && this . dockerConfiguration . isBindHostToBuilder ();
186- return (bindHostToBuilder ) ? ResolvedDockerHost .from (this .dockerConfiguration .getHost ()) : null ;
228+ boolean bindToBuilder = this .dockerConfiguration . bindHostToBuilder ();
229+ return (bindToBuilder ) ? ResolvedDockerHost .from (this .dockerConfiguration .connection ()) : null ;
187230 }
188231
189232 private void tagImage (ImageReference sourceReference , List <ImageReference > tags ) throws IOException {
@@ -203,18 +246,13 @@ private void pushImages(ImageReference name, List<ImageReference> tags) throws I
203246 private void pushImage (ImageReference reference ) throws IOException {
204247 Consumer <TotalProgressEvent > progressConsumer = this .log .pushingImage (reference );
205248 TotalProgressPushListener listener = new TotalProgressPushListener (progressConsumer );
206- this .docker .image ().push (reference , listener , getPublishAuthHeader ());
249+ String authHeader = authHeader (this .dockerConfiguration .publishRegistryAuthentication ());
250+ this .docker .image ().push (reference , listener , authHeader );
207251 this .log .pushedImage (reference );
208252 }
209253
210- private String getBuilderAuthHeader () {
211- return (this .dockerConfiguration != null && this .dockerConfiguration .getBuilderRegistryAuthentication () != null )
212- ? this .dockerConfiguration .getBuilderRegistryAuthentication ().getAuthHeader () : null ;
213- }
214-
215- private String getPublishAuthHeader () {
216- return (this .dockerConfiguration != null && this .dockerConfiguration .getPublishRegistryAuthentication () != null )
217- ? this .dockerConfiguration .getPublishRegistryAuthentication ().getAuthHeader () : null ;
254+ private static String authHeader (DockerRegistryAuthentication authentication ) {
255+ return (authentication != null ) ? authentication .getAuthHeader () : null ;
218256 }
219257
220258 /**
@@ -224,23 +262,25 @@ private class ImageFetcher {
224262
225263 private final String domain ;
226264
227- private final String authHeader ;
265+ private final DockerRegistryAuthentication registryAuthentication ;
228266
229267 private final PullPolicy pullPolicy ;
230268
231269 private ImagePlatform defaultPlatform ;
232270
233- ImageFetcher (String domain , String authHeader , PullPolicy pullPolicy , ImagePlatform platform ) {
271+ ImageFetcher (String domain , DockerRegistryAuthentication registryAuthentication , PullPolicy pullPolicy ,
272+ ImagePlatform platform ) {
234273 this .domain = domain ;
235- this .authHeader = authHeader ;
274+ this .registryAuthentication = registryAuthentication ;
236275 this .pullPolicy = pullPolicy ;
237276 this .defaultPlatform = platform ;
238277 }
239278
240279 Image fetchImage (ImageType type , ImageReference reference ) throws IOException {
241280 Assert .notNull (type , "'type' must not be null" );
242281 Assert .notNull (reference , "'reference' must not be null" );
243- Assert .state (this .authHeader == null || reference .getDomain ().equals (this .domain ),
282+ String authHeader = authHeader (this .registryAuthentication );
283+ Assert .state (authHeader == null || reference .getDomain ().equals (this .domain ),
244284 () -> String .format ("%s '%s' must be pulled from the '%s' authenticated registry" ,
245285 StringUtils .capitalize (type .getDescription ()), reference , this .domain ));
246286 if (this .pullPolicy == PullPolicy .ALWAYS ) {
@@ -260,7 +300,8 @@ Image fetchImage(ImageType type, ImageReference reference) throws IOException {
260300 private Image pullImage (ImageReference reference , ImageType imageType ) throws IOException {
261301 TotalProgressPullListener listener = new TotalProgressPullListener (
262302 Builder .this .log .pullingImage (reference , this .defaultPlatform , imageType ));
263- Image image = Builder .this .docker .image ().pull (reference , this .defaultPlatform , listener , this .authHeader );
303+ String authHeader = authHeader (this .registryAuthentication );
304+ Image image = Builder .this .docker .image ().pull (reference , this .defaultPlatform , listener , authHeader );
264305 Builder .this .log .pulledImage (image , imageType );
265306 if (this .defaultPlatform == null ) {
266307 this .defaultPlatform = ImagePlatform .from (image );
0 commit comments