26
26
import org .springframework .boot .buildpack .platform .docker .TotalProgressPullListener ;
27
27
import org .springframework .boot .buildpack .platform .docker .TotalProgressPushListener ;
28
28
import 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 ;
30
31
import org .springframework .boot .buildpack .platform .docker .configuration .ResolvedDockerHost ;
31
32
import org .springframework .boot .buildpack .platform .docker .transport .DockerEngineException ;
32
33
import org .springframework .boot .buildpack .platform .docker .type .Binding ;
@@ -54,7 +55,7 @@ public class Builder {
54
55
55
56
private final DockerApi docker ;
56
57
57
- private final DockerConfiguration dockerConfiguration ;
58
+ private final BuilderDockerConfiguration dockerConfiguration ;
58
59
59
60
/**
60
61
* Create a new builder instance.
@@ -67,8 +68,22 @@ public Builder() {
67
68
* Create a new builder instance.
68
69
* @param dockerConfiguration the docker configuration
69
70
* @since 2.4.0
71
+ * @deprecated since 3.5.0 for removal in 4.0.0 in favor of
72
+ * {@link #Builder(BuilderDockerConfiguration)}
70
73
*/
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 ) {
72
87
this (BuildLog .toSystemOut (), dockerConfiguration );
73
88
}
74
89
@@ -85,17 +100,45 @@ public Builder(BuildLog log) {
85
100
* @param log a logger used to record output
86
101
* @param dockerConfiguration the docker configuration
87
102
* @since 2.4.0
103
+ * @deprecated since 3.5.0 for removal in 4.0.0 in favor of
104
+ * {@link #Builder(BuildLog, BuilderDockerConfiguration)}
88
105
*/
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 ,
91
133
BuildLogAdapter .get (log )), dockerConfiguration );
92
134
}
93
135
94
- Builder (BuildLog log , DockerApi docker , DockerConfiguration dockerConfiguration ) {
136
+ Builder (BuildLog log , DockerApi docker , BuilderDockerConfiguration dockerConfiguration ) {
95
137
Assert .notNull (log , "'log' must not be null" );
96
138
this .log = log ;
97
139
this .docker = docker ;
98
- this .dockerConfiguration = dockerConfiguration ;
140
+ this .dockerConfiguration = (dockerConfiguration != null ) ? dockerConfiguration
141
+ : new BuilderDockerConfiguration ();
99
142
}
100
143
101
144
public void build (BuildRequest request ) throws DockerEngineException , IOException {
@@ -104,8 +147,8 @@ public void build(BuildRequest request) throws DockerEngineException, IOExceptio
104
147
validateBindings (request .getBindings ());
105
148
String domain = request .getBuilder ().getDomain ();
106
149
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 ());
109
152
Image builderImage = imageFetcher .fetchImage (ImageType .BUILDER , request .getBuilder ());
110
153
BuilderMetadata builderMetadata = BuilderMetadata .fromImage (builderImage );
111
154
request = withRunImageIfNeeded (request , builderMetadata );
@@ -182,8 +225,8 @@ private void executeLifecycle(EphemeralBuilder builder, Lifecycle lifecycle) thr
182
225
}
183
226
184
227
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 ;
187
230
}
188
231
189
232
private void tagImage (ImageReference sourceReference , List <ImageReference > tags ) throws IOException {
@@ -203,18 +246,13 @@ private void pushImages(ImageReference name, List<ImageReference> tags) throws I
203
246
private void pushImage (ImageReference reference ) throws IOException {
204
247
Consumer <TotalProgressEvent > progressConsumer = this .log .pushingImage (reference );
205
248
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 );
207
251
this .log .pushedImage (reference );
208
252
}
209
253
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 ;
218
256
}
219
257
220
258
/**
@@ -224,23 +262,25 @@ private class ImageFetcher {
224
262
225
263
private final String domain ;
226
264
227
- private final String authHeader ;
265
+ private final DockerRegistryAuthentication registryAuthentication ;
228
266
229
267
private final PullPolicy pullPolicy ;
230
268
231
269
private ImagePlatform defaultPlatform ;
232
270
233
- ImageFetcher (String domain , String authHeader , PullPolicy pullPolicy , ImagePlatform platform ) {
271
+ ImageFetcher (String domain , DockerRegistryAuthentication registryAuthentication , PullPolicy pullPolicy ,
272
+ ImagePlatform platform ) {
234
273
this .domain = domain ;
235
- this .authHeader = authHeader ;
274
+ this .registryAuthentication = registryAuthentication ;
236
275
this .pullPolicy = pullPolicy ;
237
276
this .defaultPlatform = platform ;
238
277
}
239
278
240
279
Image fetchImage (ImageType type , ImageReference reference ) throws IOException {
241
280
Assert .notNull (type , "'type' must not be null" );
242
281
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 ),
244
284
() -> String .format ("%s '%s' must be pulled from the '%s' authenticated registry" ,
245
285
StringUtils .capitalize (type .getDescription ()), reference , this .domain ));
246
286
if (this .pullPolicy == PullPolicy .ALWAYS ) {
@@ -260,7 +300,8 @@ Image fetchImage(ImageType type, ImageReference reference) throws IOException {
260
300
private Image pullImage (ImageReference reference , ImageType imageType ) throws IOException {
261
301
TotalProgressPullListener listener = new TotalProgressPullListener (
262
302
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 );
264
305
Builder .this .log .pulledImage (image , imageType );
265
306
if (this .defaultPlatform == null ) {
266
307
this .defaultPlatform = ImagePlatform .from (image );
0 commit comments