Skip to content

Commit df8422d

Browse files
committed
Refuse API version < 1.21 ; Remove associated code paths
Signed-off-by: Joffrey F <[email protected]>
1 parent b180b87 commit df8422d

20 files changed

+140
-519
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:

docker/api/container.py

Lines changed: 51 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -204,15 +204,13 @@ def containers(self, quiet=False, all=False, trunc=False, latest=False,
204204
return res
205205

206206
def create_container(self, image, command=None, hostname=None, user=None,
207-
detach=False, stdin_open=False, tty=False,
208-
mem_limit=None, ports=None, environment=None,
209-
dns=None, volumes=None, volumes_from=None,
207+
detach=False, stdin_open=False, tty=False, ports=None,
208+
environment=None, volumes=None,
210209
network_disabled=False, name=None, entrypoint=None,
211-
cpu_shares=None, working_dir=None, domainname=None,
212-
memswap_limit=None, cpuset=None, host_config=None,
213-
mac_address=None, labels=None, volume_driver=None,
214-
stop_signal=None, networking_config=None,
215-
healthcheck=None, stop_timeout=None, runtime=None):
210+
working_dir=None, domainname=None, host_config=None,
211+
mac_address=None, labels=None, stop_signal=None,
212+
networking_config=None, healthcheck=None,
213+
stop_timeout=None, runtime=None):
216214
"""
217215
Creates a container. Parameters are similar to those for the ``docker
218216
run`` command except it doesn't support the attach options (``-a``).
@@ -354,35 +352,24 @@ def create_container(self, image, command=None, hostname=None, user=None,
354352
return container ID
355353
stdin_open (bool): Keep STDIN open even if not attached
356354
tty (bool): Allocate a pseudo-TTY
357-
mem_limit (float or str): Memory limit. Accepts float values (which
358-
represent the memory limit of the created container in bytes)
359-
or a string with a units identification char (``100000b``,
360-
``1000k``, ``128m``, ``1g``). If a string is specified without
361-
a units character, bytes are assumed as an intended unit.
362355
ports (list of ints): A list of port numbers
363356
environment (dict or list): A dictionary or a list of strings in
364357
the following format ``["PASSWORD=xxx"]`` or
365358
``{"PASSWORD": "xxx"}``.
366-
dns (:py:class:`list`): DNS name servers. Deprecated since API
367-
version 1.10. Use ``host_config`` instead.
368359
volumes (str or list): List of paths inside the container to use
369360
as volumes.
370-
volumes_from (:py:class:`list`): List of container names or Ids to
371-
get volumes from.
372361
network_disabled (bool): Disable networking
373362
name (str): A name for the container
374363
entrypoint (str or list): An entrypoint
375364
working_dir (str): Path to the working directory
376365
domainname (str): The domain name to use for the container
377-
memswap_limit (int):
378366
host_config (dict): A dictionary created with
379367
:py:meth:`create_host_config`.
380368
mac_address (str): The Mac Address to assign the container
381369
labels (dict or list): A dictionary of name-value labels (e.g.
382370
``{"label1": "value1", "label2": "value2"}``) or a list of
383371
names of labels to set with empty values (e.g.
384372
``["label1", "label2"]``)
385-
volume_driver (str): The name of a volume driver/plugin.
386373
stop_signal (str): The stop signal to use to stop the container
387374
(e.g. ``SIGINT``).
388375
stop_timeout (int): Timeout to stop the container, in seconds.
@@ -405,17 +392,12 @@ def create_container(self, image, command=None, hostname=None, user=None,
405392
if isinstance(volumes, six.string_types):
406393
volumes = [volumes, ]
407394

408-
if host_config and utils.compare_version('1.15', self._version) < 0:
409-
raise errors.InvalidVersion(
410-
'host_config is not supported in API < 1.15'
411-
)
412-
413395
config = self.create_container_config(
414-
image, command, hostname, user, detach, stdin_open, tty, mem_limit,
415-
ports, dns, environment, volumes, volumes_from,
416-
network_disabled, entrypoint, cpu_shares, working_dir, domainname,
417-
memswap_limit, cpuset, host_config, mac_address, labels,
418-
volume_driver, stop_signal, networking_config, healthcheck,
396+
image, command, hostname, user, detach, stdin_open, tty,
397+
ports, environment, volumes,
398+
network_disabled, entrypoint, working_dir, domainname,
399+
host_config, mac_address, labels,
400+
stop_signal, networking_config, healthcheck,
419401
stop_timeout, runtime
420402
)
421403
return self.create_container_from_config(config, name)
@@ -681,7 +663,6 @@ def export(self, container):
681663
return self._stream_raw_result(res)
682664

683665
@utils.check_resource('container')
684-
@utils.minimum_version('1.20')
685666
def get_archive(self, container, path):
686667
"""
687668
Retrieve a file or folder from a container in the form of a tar
@@ -786,59 +767,46 @@ def logs(self, container, stdout=True, stderr=True, stream=False,
786767
:py:class:`docker.errors.APIError`
787768
If the server returns an error.
788769
"""
789-
if utils.compare_version('1.11', self._version) >= 0:
790-
if follow is None:
791-
follow = stream
792-
params = {'stderr': stderr and 1 or 0,
793-
'stdout': stdout and 1 or 0,
794-
'timestamps': timestamps and 1 or 0,
795-
'follow': follow and 1 or 0,
796-
}
797-
if utils.compare_version('1.13', self._version) >= 0:
798-
if tail != 'all' and (not isinstance(tail, int) or tail < 0):
799-
tail = 'all'
800-
params['tail'] = tail
801-
802-
if since is not None:
803-
if utils.version_lt(self._version, '1.19'):
804-
raise errors.InvalidVersion(
805-
'since is not supported for API version < 1.19'
806-
)
807-
if isinstance(since, datetime):
808-
params['since'] = utils.datetime_to_timestamp(since)
809-
elif (isinstance(since, int) and since > 0):
810-
params['since'] = since
811-
else:
812-
raise errors.InvalidArgument(
813-
'since value should be datetime or positive int, '
814-
'not {}'.format(type(since))
815-
)
816-
817-
if until is not None:
818-
if utils.version_lt(self._version, '1.35'):
819-
raise errors.InvalidVersion(
820-
'until is not supported for API version < 1.35'
821-
)
822-
if isinstance(until, datetime):
823-
params['until'] = utils.datetime_to_timestamp(until)
824-
elif (isinstance(until, int) and until > 0):
825-
params['until'] = until
826-
else:
827-
raise errors.InvalidArgument(
828-
'until value should be datetime or positive int, '
829-
'not {}'.format(type(until))
830-
)
831-
832-
url = self._url("/containers/{0}/logs", container)
833-
res = self._get(url, params=params, stream=stream)
834-
return self._get_result(container, stream, res)
835-
return self.attach(
836-
container,
837-
stdout=stdout,
838-
stderr=stderr,
839-
stream=stream,
840-
logs=True
841-
)
770+
if follow is None:
771+
follow = stream
772+
params = {'stderr': stderr and 1 or 0,
773+
'stdout': stdout and 1 or 0,
774+
'timestamps': timestamps and 1 or 0,
775+
'follow': follow and 1 or 0,
776+
}
777+
if tail != 'all' and (not isinstance(tail, int) or tail < 0):
778+
tail = 'all'
779+
params['tail'] = tail
780+
781+
if since is not None:
782+
if isinstance(since, datetime):
783+
params['since'] = utils.datetime_to_timestamp(since)
784+
elif (isinstance(since, int) and since > 0):
785+
params['since'] = since
786+
else:
787+
raise errors.InvalidArgument(
788+
'since value should be datetime or positive int, '
789+
'not {}'.format(type(since))
790+
)
791+
792+
if until is not None:
793+
if utils.version_lt(self._version, '1.35'):
794+
raise errors.InvalidVersion(
795+
'until is not supported for API version < 1.35'
796+
)
797+
if isinstance(until, datetime):
798+
params['until'] = utils.datetime_to_timestamp(until)
799+
elif (isinstance(until, int) and until > 0):
800+
params['until'] = until
801+
else:
802+
raise errors.InvalidArgument(
803+
'until value should be datetime or positive int, '
804+
'not {}'.format(type(until))
805+
)
806+
807+
url = self._url("/containers/{0}/logs", container)
808+
res = self._get(url, params=params, stream=stream)
809+
return self._get_result(container, stream, res)
842810

843811
@utils.check_resource('container')
844812
def pause(self, container):
@@ -906,7 +874,6 @@ def port(self, container, private_port):
906874
return h_ports
907875

908876
@utils.check_resource('container')
909-
@utils.minimum_version('1.20')
910877
def put_archive(self, container, path, data):
911878
"""
912879
Insert a file or folder in an existing container using a tar archive as
@@ -976,7 +943,6 @@ def remove_container(self, container, v=False, link=False, force=False):
976943
)
977944
self._raise_for_status(res)
978945

979-
@utils.minimum_version('1.17')
980946
@utils.check_resource('container')
981947
def rename(self, container, name):
982948
"""
@@ -1073,7 +1039,6 @@ def start(self, container, *args, **kwargs):
10731039
res = self._post(url)
10741040
self._raise_for_status(res)
10751041

1076-
@utils.minimum_version('1.17')
10771042
@utils.check_resource('container')
10781043
def stats(self, container, decode=None, stream=True):
10791044
"""

0 commit comments

Comments
 (0)