Skip to content

Commit 706e2ca

Browse files
authored
Merge pull request #1665 from docker/2.4.0-release
2.4.0 release
2 parents 0832898 + 1ad6859 commit 706e2ca

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+629
-214
lines changed

docker/api/build.py

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def build(self, path=None, tag=None, quiet=False, fileobj=None,
1818
custom_context=False, encoding=None, pull=False,
1919
forcerm=False, dockerfile=None, container_limits=None,
2020
decode=False, buildargs=None, gzip=False, shmsize=None,
21-
labels=None, cache_from=None):
21+
labels=None, cache_from=None, target=None, network_mode=None):
2222
"""
2323
Similar to the ``docker build`` command. Either ``path`` or ``fileobj``
2424
needs to be set. ``path`` can be a local path (to a directory
@@ -88,12 +88,16 @@ def build(self, path=None, tag=None, quiet=False, fileobj=None,
8888
- cpusetcpus (str): CPUs in which to allow execution, e.g.,
8989
``"0-3"``, ``"0,1"``
9090
decode (bool): If set to ``True``, the returned stream will be
91-
decoded into dicts on the fly. Default ``False``.
91+
decoded into dicts on the fly. Default ``False``
9292
shmsize (int): Size of `/dev/shm` in bytes. The size must be
93-
greater than 0. If omitted the system uses 64MB.
94-
labels (dict): A dictionary of labels to set on the image.
93+
greater than 0. If omitted the system uses 64MB
94+
labels (dict): A dictionary of labels to set on the image
9595
cache_from (list): A list of images used for build cache
96-
resolution.
96+
resolution
97+
target (str): Name of the build-stage to build in a multi-stage
98+
Dockerfile
99+
network_mode (str): networking mode for the run commands during
100+
build
97101
98102
Returns:
99103
A generator for the build output.
@@ -198,6 +202,22 @@ def build(self, path=None, tag=None, quiet=False, fileobj=None,
198202
'cache_from was only introduced in API version 1.25'
199203
)
200204

205+
if target:
206+
if utils.version_gte(self._version, '1.29'):
207+
params.update({'target': target})
208+
else:
209+
raise errors.InvalidVersion(
210+
'target was only introduced in API version 1.29'
211+
)
212+
213+
if network_mode:
214+
if utils.version_gte(self._version, '1.25'):
215+
params.update({'networkmode': network_mode})
216+
else:
217+
raise errors.InvalidVersion(
218+
'network_mode was only introduced in API version 1.25'
219+
)
220+
201221
if context is not None:
202222
headers = {'Content-Type': 'application/tar'}
203223
if encoding:

docker/api/client.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,12 @@ class APIClient(
8383
configuration.
8484
user_agent (str): Set a custom user agent for requests to the server.
8585
"""
86+
87+
__attrs__ = requests.Session.__attrs__ + ['_auth_configs',
88+
'_version',
89+
'base_url',
90+
'timeout']
91+
8692
def __init__(self, base_url=None, version=None,
8793
timeout=DEFAULT_TIMEOUT_SECONDS, tls=False,
8894
user_agent=DEFAULT_USER_AGENT, num_pools=DEFAULT_NUM_POOLS):
@@ -248,7 +254,7 @@ def _attach_params(self, override=None):
248254
'stream': 1
249255
}
250256

251-
@check_resource
257+
@check_resource('container')
252258
def _attach_websocket(self, container, params=None):
253259
url = self._url("/containers/{0}/attach/ws", container)
254260
req = requests.Request("POST", url, params=self._attach_params(params))

docker/api/container.py

Lines changed: 37 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111

1212
class ContainerApiMixin(object):
13-
@utils.check_resource
13+
@utils.check_resource('container')
1414
def attach(self, container, stdout=True, stderr=True,
1515
stream=False, logs=False):
1616
"""
@@ -54,7 +54,7 @@ def attach(self, container, stdout=True, stderr=True,
5454

5555
return self._read_from_socket(response, stream)
5656

57-
@utils.check_resource
57+
@utils.check_resource('container')
5858
def attach_socket(self, container, params=None, ws=False):
5959
"""
6060
Like ``attach``, but returns the underlying socket-like object for the
@@ -93,7 +93,7 @@ def attach_socket(self, container, params=None, ws=False):
9393
)
9494
)
9595

96-
@utils.check_resource
96+
@utils.check_resource('container')
9797
def commit(self, container, repository=None, tag=None, message=None,
9898
author=None, changes=None, conf=None):
9999
"""
@@ -195,7 +195,7 @@ def containers(self, quiet=False, all=False, trunc=False, latest=False,
195195
x['Id'] = x['Id'][:12]
196196
return res
197197

198-
@utils.check_resource
198+
@utils.check_resource('container')
199199
def copy(self, container, resource):
200200
"""
201201
Identical to the ``docker cp`` command. Get files/folders from the
@@ -238,7 +238,7 @@ def create_container(self, image, command=None, hostname=None, user=None,
238238
memswap_limit=None, cpuset=None, host_config=None,
239239
mac_address=None, labels=None, volume_driver=None,
240240
stop_signal=None, networking_config=None,
241-
healthcheck=None, stop_timeout=None):
241+
healthcheck=None, stop_timeout=None, runtime=None):
242242
"""
243243
Creates a container. Parameters are similar to those for the ``docker
244244
run`` command except it doesn't support the attach options (``-a``).
@@ -391,8 +391,6 @@ def create_container(self, image, command=None, hostname=None, user=None,
391391
``{"PASSWORD": "xxx"}``.
392392
dns (:py:class:`list`): DNS name servers. Deprecated since API
393393
version 1.10. Use ``host_config`` instead.
394-
dns_opt (:py:class:`list`): Additional options to be added to the
395-
container's ``resolv.conf`` file
396394
volumes (str or list): List of paths inside the container to use
397395
as volumes.
398396
volumes_from (:py:class:`list`): List of container names or Ids to
@@ -417,6 +415,9 @@ def create_container(self, image, command=None, hostname=None, user=None,
417415
Default: 10
418416
networking_config (dict): A networking configuration generated
419417
by :py:meth:`create_networking_config`.
418+
runtime (str): Runtime to use with this container.
419+
healthcheck (dict): Specify a test to perform to check that the
420+
container is healthy.
420421
421422
Returns:
422423
A dictionary with an image 'Id' key and a 'Warnings' key.
@@ -441,7 +442,7 @@ def create_container(self, image, command=None, hostname=None, user=None,
441442
network_disabled, entrypoint, cpu_shares, working_dir, domainname,
442443
memswap_limit, cpuset, host_config, mac_address, labels,
443444
volume_driver, stop_signal, networking_config, healthcheck,
444-
stop_timeout
445+
stop_timeout, runtime
445446
)
446447
return self.create_container_from_config(config, name)
447448

@@ -495,6 +496,8 @@ def create_host_config(self, *args, **kwargs):
495496
to have read-write access to the host's ``/dev/sda`` via a
496497
node named ``/dev/xvda`` inside the container.
497498
dns (:py:class:`list`): Set custom DNS servers.
499+
dns_opt (:py:class:`list`): Additional options to be added to the
500+
container's ``resolv.conf`` file
498501
dns_search (:py:class:`list`): DNS search domains.
499502
extra_hosts (dict): Addtional hostnames to resolve inside the
500503
container, as a mapping of hostname to IP address.
@@ -576,6 +579,7 @@ def create_host_config(self, *args, **kwargs):
576579
values are: ``host``
577580
volumes_from (:py:class:`list`): List of container names or IDs to
578581
get volumes from.
582+
runtime (str): Runtime to use with this container.
579583
580584
581585
Returns:
@@ -659,7 +663,7 @@ def create_endpoint_config(self, *args, **kwargs):
659663
"""
660664
return EndpointConfig(self._version, *args, **kwargs)
661665

662-
@utils.check_resource
666+
@utils.check_resource('container')
663667
def diff(self, container):
664668
"""
665669
Inspect changes on a container's filesystem.
@@ -678,7 +682,7 @@ def diff(self, container):
678682
self._get(self._url("/containers/{0}/changes", container)), True
679683
)
680684

681-
@utils.check_resource
685+
@utils.check_resource('container')
682686
def export(self, container):
683687
"""
684688
Export the contents of a filesystem as a tar archive.
@@ -699,7 +703,7 @@ def export(self, container):
699703
self._raise_for_status(res)
700704
return res.raw
701705

702-
@utils.check_resource
706+
@utils.check_resource('container')
703707
@utils.minimum_version('1.20')
704708
def get_archive(self, container, path):
705709
"""
@@ -730,7 +734,7 @@ def get_archive(self, container, path):
730734
utils.decode_json_header(encoded_stat) if encoded_stat else None
731735
)
732736

733-
@utils.check_resource
737+
@utils.check_resource('container')
734738
def inspect_container(self, container):
735739
"""
736740
Identical to the `docker inspect` command, but only for containers.
@@ -750,7 +754,7 @@ def inspect_container(self, container):
750754
self._get(self._url("/containers/{0}/json", container)), True
751755
)
752756

753-
@utils.check_resource
757+
@utils.check_resource('container')
754758
def kill(self, container, signal=None):
755759
"""
756760
Kill a container or send a signal to a container.
@@ -773,7 +777,7 @@ def kill(self, container, signal=None):
773777

774778
self._raise_for_status(res)
775779

776-
@utils.check_resource
780+
@utils.check_resource('container')
777781
def logs(self, container, stdout=True, stderr=True, stream=False,
778782
timestamps=False, tail='all', since=None, follow=None):
779783
"""
@@ -825,6 +829,11 @@ def logs(self, container, stdout=True, stderr=True, stream=False,
825829
params['since'] = utils.datetime_to_timestamp(since)
826830
elif (isinstance(since, int) and since > 0):
827831
params['since'] = since
832+
else:
833+
raise errors.InvalidArgument(
834+
'since value should be datetime or int, not {}'.
835+
format(type(since))
836+
)
828837
url = self._url("/containers/{0}/logs", container)
829838
res = self._get(url, params=params, stream=stream)
830839
return self._get_result(container, stream, res)
@@ -836,7 +845,7 @@ def logs(self, container, stdout=True, stderr=True, stream=False,
836845
logs=True
837846
)
838847

839-
@utils.check_resource
848+
@utils.check_resource('container')
840849
def pause(self, container):
841850
"""
842851
Pauses all processes within a container.
@@ -852,7 +861,7 @@ def pause(self, container):
852861
res = self._post(url)
853862
self._raise_for_status(res)
854863

855-
@utils.check_resource
864+
@utils.check_resource('container')
856865
def port(self, container, private_port):
857866
"""
858867
Lookup the public-facing port that is NAT-ed to ``private_port``.
@@ -901,7 +910,7 @@ def port(self, container, private_port):
901910

902911
return h_ports
903912

904-
@utils.check_resource
913+
@utils.check_resource('container')
905914
@utils.minimum_version('1.20')
906915
def put_archive(self, container, path, data):
907916
"""
@@ -949,7 +958,7 @@ def prune_containers(self, filters=None):
949958
url = self._url('/containers/prune')
950959
return self._result(self._post(url, params=params), True)
951960

952-
@utils.check_resource
961+
@utils.check_resource('container')
953962
def remove_container(self, container, v=False, link=False, force=False):
954963
"""
955964
Remove a container. Similar to the ``docker rm`` command.
@@ -973,7 +982,7 @@ def remove_container(self, container, v=False, link=False, force=False):
973982
self._raise_for_status(res)
974983

975984
@utils.minimum_version('1.17')
976-
@utils.check_resource
985+
@utils.check_resource('container')
977986
def rename(self, container, name):
978987
"""
979988
Rename a container. Similar to the ``docker rename`` command.
@@ -991,7 +1000,7 @@ def rename(self, container, name):
9911000
res = self._post(url, params=params)
9921001
self._raise_for_status(res)
9931002

994-
@utils.check_resource
1003+
@utils.check_resource('container')
9951004
def resize(self, container, height, width):
9961005
"""
9971006
Resize the tty session.
@@ -1010,7 +1019,7 @@ def resize(self, container, height, width):
10101019
res = self._post(url, params=params)
10111020
self._raise_for_status(res)
10121021

1013-
@utils.check_resource
1022+
@utils.check_resource('container')
10141023
def restart(self, container, timeout=10):
10151024
"""
10161025
Restart a container. Similar to the ``docker restart`` command.
@@ -1031,7 +1040,7 @@ def restart(self, container, timeout=10):
10311040
res = self._post(url, params=params)
10321041
self._raise_for_status(res)
10331042

1034-
@utils.check_resource
1043+
@utils.check_resource('container')
10351044
def start(self, container, *args, **kwargs):
10361045
"""
10371046
Start a container. Similar to the ``docker start`` command, but
@@ -1070,7 +1079,7 @@ def start(self, container, *args, **kwargs):
10701079
self._raise_for_status(res)
10711080

10721081
@utils.minimum_version('1.17')
1073-
@utils.check_resource
1082+
@utils.check_resource('container')
10741083
def stats(self, container, decode=None, stream=True):
10751084
"""
10761085
Stream statistics for a specific container. Similar to the
@@ -1096,7 +1105,7 @@ def stats(self, container, decode=None, stream=True):
10961105
return self._result(self._get(url, params={'stream': False}),
10971106
json=True)
10981107

1099-
@utils.check_resource
1108+
@utils.check_resource('container')
11001109
def stop(self, container, timeout=10):
11011110
"""
11021111
Stops a container. Similar to the ``docker stop`` command.
@@ -1117,7 +1126,7 @@ def stop(self, container, timeout=10):
11171126
timeout=(timeout + (self.timeout or 0)))
11181127
self._raise_for_status(res)
11191128

1120-
@utils.check_resource
1129+
@utils.check_resource('container')
11211130
def top(self, container, ps_args=None):
11221131
"""
11231132
Display the running processes of a container.
@@ -1139,7 +1148,7 @@ def top(self, container, ps_args=None):
11391148
params['ps_args'] = ps_args
11401149
return self._result(self._get(u, params=params), True)
11411150

1142-
@utils.check_resource
1151+
@utils.check_resource('container')
11431152
def unpause(self, container):
11441153
"""
11451154
Unpause all processes within a container.
@@ -1152,7 +1161,7 @@ def unpause(self, container):
11521161
self._raise_for_status(res)
11531162

11541163
@utils.minimum_version('1.22')
1155-
@utils.check_resource
1164+
@utils.check_resource('container')
11561165
def update_container(
11571166
self, container, blkio_weight=None, cpu_period=None, cpu_quota=None,
11581167
cpu_shares=None, cpuset_cpus=None, cpuset_mems=None, mem_limit=None,
@@ -1217,7 +1226,7 @@ def update_container(
12171226
res = self._post_json(url, data=data)
12181227
return self._result(res, True)
12191228

1220-
@utils.check_resource
1229+
@utils.check_resource('container')
12211230
def wait(self, container, timeout=None):
12221231
"""
12231232
Block until a container stops, then return its exit code. Similar to

docker/api/exec_api.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
class ExecApiMixin(object):
88
@utils.minimum_version('1.15')
9-
@utils.check_resource
9+
@utils.check_resource('container')
1010
def exec_create(self, container, cmd, stdout=True, stderr=True,
1111
stdin=False, tty=False, privileged=False, user='',
1212
environment=None):
@@ -110,7 +110,7 @@ def exec_resize(self, exec_id, height=None, width=None):
110110
self._raise_for_status(res)
111111

112112
@utils.minimum_version('1.15')
113-
@utils.check_resource
113+
@utils.check_resource('exec_id')
114114
def exec_start(self, exec_id, detach=False, tty=False, stream=False,
115115
socket=False):
116116
"""

0 commit comments

Comments
 (0)