Skip to content

Commit 82e57a4

Browse files
authored
Merge pull request #1887 from docker/cleanup_deprecated
Cleanup / remove deprecated features
2 parents 42b2548 + df8422d commit 82e57a4

24 files changed

+150
-638
lines changed

docker/api/build.py

Lines changed: 8 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import json
22
import logging
33
import os
4-
import re
54

65
from .. import auth
76
from .. import constants
@@ -14,7 +13,7 @@
1413

1514
class BuildApiMixin(object):
1615
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,
1817
custom_context=False, encoding=None, pull=False,
1918
forcerm=False, dockerfile=None, container_limits=None,
2019
decode=False, buildargs=None, gzip=False, shmsize=None,
@@ -67,9 +66,6 @@ def build(self, path=None, tag=None, quiet=False, fileobj=None,
6766
rm (bool): Remove intermediate containers. The ``docker build``
6867
command now defaults to ``--rm=true``, but we have kept the old
6968
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
7369
timeout (int): HTTP timeout
7470
custom_context (bool): Optional if using ``fileobj``
7571
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,
154150
)
155151
encoding = 'gzip' if gzip else encoding
156152

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-
168153
u = self._url('/build')
169154
params = {
170155
't': tag,
@@ -179,12 +164,7 @@ def build(self, path=None, tag=None, quiet=False, fileobj=None,
179164
params.update(container_limits)
180165

181166
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)})
188168

189169
if shmsize:
190170
if utils.version_gte(self._version, '1.22'):
@@ -256,30 +236,21 @@ def build(self, path=None, tag=None, quiet=False, fileobj=None,
256236
if encoding:
257237
headers['Content-Encoding'] = encoding
258238

259-
if utils.compare_version('1.9', self._version) >= 0:
260-
self._set_auth_headers(headers)
239+
self._set_auth_headers(headers)
261240

262241
response = self._post(
263242
u,
264243
data=context,
265244
params=params,
266245
headers=headers,
267-
stream=stream,
246+
stream=True,
268247
timeout=timeout,
269248
)
270249

271250
if context is not None and not custom_context:
272251
context.close()
273252

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)
283254

284255
def _set_auth_headers(self, headers):
285256
log.debug('Looking for auth config')
@@ -316,13 +287,8 @@ def _set_auth_headers(self, headers):
316287
)
317288
)
318289

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+
)
327293
else:
328294
log.debug('No auth config found')

docker/api/client.py

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import json
22
import struct
3-
import warnings
43
from functools import partial
54

65
import requests
@@ -27,7 +26,7 @@
2726
MINIMUM_DOCKER_API_VERSION
2827
)
2928
from ..errors import (
30-
DockerException, TLSParameterError,
29+
DockerException, InvalidVersion, TLSParameterError,
3130
create_api_error_from_http_exception
3231
)
3332
from ..tls import TLSConfig
@@ -160,11 +159,9 @@ def __init__(self, base_url=None, version=None,
160159
)
161160
)
162161
if utils.version_lt(self._version, MINIMUM_DOCKER_API_VERSION):
163-
warnings.warn(
164-
'The minimum API version supported is {}, but you are using '
165-
'version {}. It is recommended you either upgrade Docker '
166-
'Engine or use an older version of Docker SDK for '
167-
'Python.'.format(MINIMUM_DOCKER_API_VERSION, self._version)
162+
raise InvalidVersion(
163+
'API versions below {} are no longer supported by this '
164+
'library.'.format(MINIMUM_DOCKER_API_VERSION)
168165
)
169166

170167
def _retrieve_server_version(self):
@@ -353,17 +350,8 @@ def _multiplexed_response_stream_helper(self, response):
353350
break
354351
yield data
355352

356-
def _stream_raw_result_old(self, response):
357-
''' Stream raw output for API versions below 1.6 '''
358-
self._raise_for_status(response)
359-
for line in response.iter_lines(chunk_size=1,
360-
decode_unicode=True):
361-
# filter out keep-alive new lines
362-
if line:
363-
yield line
364-
365353
def _stream_raw_result(self, response):
366-
''' Stream result for TTY-enabled container above API 1.6 '''
354+
''' Stream result for TTY-enabled container '''
367355
self._raise_for_status(response)
368356
for out in response.iter_content(chunk_size=1, decode_unicode=True):
369357
yield out
@@ -419,11 +407,6 @@ def _get_result(self, container, stream, res):
419407
return self._get_result_tty(stream, res, self._check_is_tty(container))
420408

421409
def _get_result_tty(self, stream, res, is_tty):
422-
# Stream multi-plexing was only introduced in API v1.6. Anything
423-
# before that needs old-style streaming.
424-
if utils.compare_version('1.6', self._version) < 0:
425-
return self._stream_raw_result_old(res)
426-
427410
# We should also use raw streaming (without keep-alives)
428411
# if we're dealing with a tty-enabled container.
429412
if is_tty:

0 commit comments

Comments
 (0)