1
1
import json
2
2
import logging
3
3
import os
4
- import re
5
4
6
5
from .. import auth
7
6
from .. import constants
14
13
15
14
class BuildApiMixin (object ):
16
15
def build (self , path = None , tag = None , quiet = False , fileobj = None ,
17
- nocache = False , rm = False , stream = False , timeout = None ,
16
+ nocache = False , rm = False , timeout = None ,
18
17
custom_context = False , encoding = None , pull = False ,
19
18
forcerm = False , dockerfile = None , container_limits = None ,
20
19
decode = False , buildargs = None , gzip = False , shmsize = None ,
@@ -67,9 +66,6 @@ def build(self, path=None, tag=None, quiet=False, fileobj=None,
67
66
rm (bool): Remove intermediate containers. The ``docker build``
68
67
command now defaults to ``--rm=true``, but we have kept the old
69
68
default of `False` to preserve backward compatibility
70
- stream (bool): *Deprecated for API version > 1.8 (always True)*.
71
- Return a blocking generator you can iterate over to retrieve
72
- build output as it happens
73
69
timeout (int): HTTP timeout
74
70
custom_context (bool): Optional if using ``fileobj``
75
71
encoding (str): The encoding for a stream. Set to ``gzip`` for
@@ -154,17 +150,6 @@ def build(self, path=None, tag=None, quiet=False, fileobj=None,
154
150
)
155
151
encoding = 'gzip' if gzip else encoding
156
152
157
- if utils .compare_version ('1.8' , self ._version ) >= 0 :
158
- stream = True
159
-
160
- if dockerfile and utils .compare_version ('1.17' , self ._version ) < 0 :
161
- raise errors .InvalidVersion (
162
- 'dockerfile was only introduced in API version 1.17'
163
- )
164
-
165
- if utils .compare_version ('1.19' , self ._version ) < 0 :
166
- pull = 1 if pull else 0
167
-
168
153
u = self ._url ('/build' )
169
154
params = {
170
155
't' : tag ,
@@ -179,12 +164,7 @@ def build(self, path=None, tag=None, quiet=False, fileobj=None,
179
164
params .update (container_limits )
180
165
181
166
if buildargs :
182
- if utils .version_gte (self ._version , '1.21' ):
183
- params .update ({'buildargs' : json .dumps (buildargs )})
184
- else :
185
- raise errors .InvalidVersion (
186
- 'buildargs was only introduced in API version 1.21'
187
- )
167
+ params .update ({'buildargs' : json .dumps (buildargs )})
188
168
189
169
if shmsize :
190
170
if utils .version_gte (self ._version , '1.22' ):
@@ -256,30 +236,21 @@ def build(self, path=None, tag=None, quiet=False, fileobj=None,
256
236
if encoding :
257
237
headers ['Content-Encoding' ] = encoding
258
238
259
- if utils .compare_version ('1.9' , self ._version ) >= 0 :
260
- self ._set_auth_headers (headers )
239
+ self ._set_auth_headers (headers )
261
240
262
241
response = self ._post (
263
242
u ,
264
243
data = context ,
265
244
params = params ,
266
245
headers = headers ,
267
- stream = stream ,
246
+ stream = True ,
268
247
timeout = timeout ,
269
248
)
270
249
271
250
if context is not None and not custom_context :
272
251
context .close ()
273
252
274
- if stream :
275
- return self ._stream_helper (response , decode = decode )
276
- else :
277
- output = self ._result (response )
278
- srch = r'Successfully built ([0-9a-f]+)'
279
- match = re .search (srch , output )
280
- if not match :
281
- return None , output
282
- return match .group (1 ), output
253
+ return self ._stream_helper (response , decode = decode )
283
254
284
255
def _set_auth_headers (self , headers ):
285
256
log .debug ('Looking for auth config' )
@@ -316,13 +287,8 @@ def _set_auth_headers(self, headers):
316
287
)
317
288
)
318
289
319
- if utils .compare_version ('1.19' , self ._version ) >= 0 :
320
- headers ['X-Registry-Config' ] = auth .encode_header (
321
- auth_data
322
- )
323
- else :
324
- headers ['X-Registry-Config' ] = auth .encode_header ({
325
- 'configs' : auth_data
326
- })
290
+ headers ['X-Registry-Config' ] = auth .encode_header (
291
+ auth_data
292
+ )
327
293
else :
328
294
log .debug ('No auth config found' )
0 commit comments