summaryrefslogtreecommitdiffstats
path: root/contrib/python
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/python')
-rw-r--r--contrib/python/docker/.dist-info/METADATA4
-rw-r--r--contrib/python/docker/docker/__init__.py2
-rw-r--r--contrib/python/docker/docker/_version.py30
-rw-r--r--contrib/python/docker/docker/client.py64
-rw-r--r--contrib/python/docker/docker/constants.py2
-rw-r--r--contrib/python/docker/docker/context/api.py27
-rw-r--r--contrib/python/docker/docker/models/containers.py3
-rw-r--r--contrib/python/docker/docker/models/images.py4
-rw-r--r--contrib/python/docker/docker/types/services.py7
-rw-r--r--contrib/python/docker/ya.make2
10 files changed, 123 insertions, 22 deletions
diff --git a/contrib/python/docker/.dist-info/METADATA b/contrib/python/docker/.dist-info/METADATA
index 90e41721a6f..d4e1c5135c2 100644
--- a/contrib/python/docker/.dist-info/METADATA
+++ b/contrib/python/docker/.dist-info/METADATA
@@ -1,6 +1,6 @@
-Metadata-Version: 2.3
+Metadata-Version: 2.4
Name: docker
-Version: 7.1.0
+Version: 7.2.0
Summary: A Python library for the Docker Engine API.
Project-URL: Changelog, https://docker-py.readthedocs.io/en/stable/change-log.html
Project-URL: Documentation, https://docker-py.readthedocs.io
diff --git a/contrib/python/docker/docker/__init__.py b/contrib/python/docker/docker/__init__.py
index fb7a5e921ad..4e06ac2ac69 100644
--- a/contrib/python/docker/docker/__init__.py
+++ b/contrib/python/docker/docker/__init__.py
@@ -1,5 +1,5 @@
from .api import APIClient
-from .client import DockerClient, from_env
+from .client import DockerClient, from_context, from_env
from .context import Context, ContextAPI
from .tls import TLSConfig
from .version import __version__
diff --git a/contrib/python/docker/docker/_version.py b/contrib/python/docker/docker/_version.py
index 32913e53d55..a8e096249dd 100644
--- a/contrib/python/docker/docker/_version.py
+++ b/contrib/python/docker/docker/_version.py
@@ -1,16 +1,24 @@
-# file generated by setuptools_scm
+# file generated by vcs-versioning
# don't change, don't track in version control
-TYPE_CHECKING = False
-if TYPE_CHECKING:
- from typing import Tuple, Union
- VERSION_TUPLE = Tuple[Union[int, str], ...]
-else:
- VERSION_TUPLE = object
+from __future__ import annotations
+
+__all__ = [
+ "__version__",
+ "__version_tuple__",
+ "version",
+ "version_tuple",
+ "__commit_id__",
+ "commit_id",
+]
version: str
__version__: str
-__version_tuple__: VERSION_TUPLE
-version_tuple: VERSION_TUPLE
+__version_tuple__: tuple[int | str, ...]
+version_tuple: tuple[int | str, ...]
+commit_id: str | None
+__commit_id__: str | None
+
+__version__ = version = '7.2.0'
+__version_tuple__ = version_tuple = (7, 2, 0)
-__version__ = version = '7.1.0'
-__version_tuple__ = version_tuple = (7, 1, 0)
+__commit_id__ = commit_id = None
diff --git a/contrib/python/docker/docker/client.py b/contrib/python/docker/docker/client.py
index 9012d24c9c1..821706387c1 100644
--- a/contrib/python/docker/docker/client.py
+++ b/contrib/python/docker/docker/client.py
@@ -1,5 +1,8 @@
+import os
+
from .api.client import APIClient
from .constants import DEFAULT_MAX_POOL_SIZE, DEFAULT_TIMEOUT_SECONDS
+from .context import ContextAPI
from .models.configs import ConfigCollection
from .models.containers import ContainerCollection
from .models.images import ImageCollection
@@ -78,6 +81,10 @@ class DockerClient:
use_ssh_client (bool): If set to `True`, an ssh connection is
made via shelling out to the ssh client. Ensure the ssh
client is installed and configured on the host.
+ use_context (bool): If ``True`` (the default), fall back to the
+ current Docker CLI context (``~/.docker/config.json`` /
+ ``DOCKER_CONTEXT``) when ``DOCKER_HOST`` is not set. This
+ allows the client to talk to Docker Desktop out of the box.
Example:
@@ -91,12 +98,66 @@ class DockerClient:
max_pool_size = kwargs.pop('max_pool_size', DEFAULT_MAX_POOL_SIZE)
version = kwargs.pop('version', None)
use_ssh_client = kwargs.pop('use_ssh_client', False)
+ use_context = kwargs.pop('use_context', True)
+ environment = kwargs.get('environment') or os.environ
+
+ params = kwargs_from_env(**kwargs)
+ if use_context and 'base_url' not in params:
+ for k, v in ContextAPI.kwargs_from_context(
+ environment=environment).items():
+ params.setdefault(k, v)
+
+ return cls(
+ timeout=timeout,
+ max_pool_size=max_pool_size,
+ version=version,
+ use_ssh_client=use_ssh_client,
+ **params,
+ )
+
+ @classmethod
+ def from_context(cls, name=None, **kwargs):
+ """
+ Return a client configured from a Docker CLI context.
+
+ With no ``name``, resolves the current context the same way the
+ Docker CLI does: ``DOCKER_CONTEXT`` env var, then the
+ ``currentContext`` field in ``~/.docker/config.json``, falling back
+ to the built-in ``default`` context. On a machine with Docker
+ Desktop installed this typically resolves to ``desktop-linux``.
+
+ Args:
+ name (str): Name of the context to load. ``None`` (the default)
+ means "use the current context".
+ version (str): The version of the API to use. Set to ``auto`` to
+ automatically detect the server's version.
+ timeout (int): Default timeout for API calls, in seconds.
+ max_pool_size (int): The maximum number of connections to save in
+ the pool.
+ use_ssh_client (bool): If ``True``, shell out to the ssh client
+ for ssh:// contexts.
+
+ Example:
+
+ >>> import docker
+ >>> client = docker.DockerClient.from_context()
+ >>> # or, pick a specific context:
+ >>> client = docker.DockerClient.from_context('desktop-linux')
+ """
+ timeout = kwargs.pop('timeout', DEFAULT_TIMEOUT_SECONDS)
+ max_pool_size = kwargs.pop('max_pool_size', DEFAULT_MAX_POOL_SIZE)
+ version = kwargs.pop('version', None)
+ use_ssh_client = kwargs.pop('use_ssh_client', False)
+
+ params = ContextAPI.kwargs_from_context(name=name)
+ params.update(kwargs)
+
return cls(
timeout=timeout,
max_pool_size=max_pool_size,
version=version,
use_ssh_client=use_ssh_client,
- **kwargs_from_env(**kwargs)
+ **params,
)
# Resources
@@ -220,3 +281,4 @@ class DockerClient:
from_env = DockerClient.from_env
+from_context = DockerClient.from_context
diff --git a/contrib/python/docker/docker/constants.py b/contrib/python/docker/docker/constants.py
index 3c527b47e3a..0e39dc2917c 100644
--- a/contrib/python/docker/docker/constants.py
+++ b/contrib/python/docker/docker/constants.py
@@ -2,7 +2,7 @@ import sys
from .version import __version__
-DEFAULT_DOCKER_API_VERSION = '1.44'
+DEFAULT_DOCKER_API_VERSION = '1.45'
MINIMUM_DOCKER_API_VERSION = '1.24'
DEFAULT_TIMEOUT_SECONDS = 60
STREAM_HEADER_SIZE_BYTES = 8
diff --git a/contrib/python/docker/docker/context/api.py b/contrib/python/docker/docker/context/api.py
index 9ac4ff470af..c86f1c74d17 100644
--- a/contrib/python/docker/docker/context/api.py
+++ b/contrib/python/docker/docker/context/api.py
@@ -133,6 +133,33 @@ class ContextAPI:
return cls.get_context()
@classmethod
+ def kwargs_from_context(cls, name=None, environment=None):
+ """Build ``base_url`` / ``tls`` kwargs from a Docker CLI context.
+
+ Mirrors the Docker CLI: if ``name`` is not given, honours the
+ ``DOCKER_CONTEXT`` env var, then the ``currentContext`` field in
+ ``~/.docker/config.json``, defaulting to the built-in ``default``
+ context (local socket / named pipe). On a host with Docker Desktop
+ this resolves to the ``desktop-linux`` (or equivalent) context, so
+ client construction targets Docker Desktop out of the box.
+ """
+ if environment is None:
+ environment = os.environ
+ if name is None:
+ name = environment.get("DOCKER_CONTEXT")
+ ctx = cls.get_context(name)
+ if ctx is None:
+ return {}
+ host = ctx.Host
+ if not host:
+ return {}
+ params = {"base_url": host}
+ tls_cfg = ctx.TLSConfig
+ if tls_cfg is not None:
+ params["tls"] = tls_cfg
+ return params
+
+ @classmethod
def set_current_context(cls, name="default"):
ctx = cls.get_context(name)
if not ctx:
diff --git a/contrib/python/docker/docker/models/containers.py b/contrib/python/docker/docker/models/containers.py
index 4795523a158..9c9e92c90fd 100644
--- a/contrib/python/docker/docker/models/containers.py
+++ b/contrib/python/docker/docker/models/containers.py
@@ -181,7 +181,8 @@ class Container(Model):
user (str): User to execute command as. Default: root
detach (bool): If true, detach from the exec command.
Default: False
- stream (bool): Stream response data. Default: False
+ stream (bool): Stream response data. Ignored if ``detach`` is true.
+ Default: False
socket (bool): Return the connection socket to allow custom
read/write operations. Default: False
environment (dict or list): A dictionary or a list of strings in
diff --git a/contrib/python/docker/docker/models/images.py b/contrib/python/docker/docker/models/images.py
index 4f058d24d93..0e8cce3f822 100644
--- a/contrib/python/docker/docker/models/images.py
+++ b/contrib/python/docker/docker/models/images.py
@@ -407,8 +407,8 @@ class ImageCollection(Collection):
if match:
image_id = match.group(2)
images.append(image_id)
- if 'error' in chunk:
- raise ImageLoadError(chunk['error'])
+ if 'errorDetail' in chunk:
+ raise ImageLoadError(chunk['errorDetail']['message'])
return [self.get(i) for i in images]
diff --git a/contrib/python/docker/docker/types/services.py b/contrib/python/docker/docker/types/services.py
index 821115411c6..69c0c498ea4 100644
--- a/contrib/python/docker/docker/types/services.py
+++ b/contrib/python/docker/docker/types/services.py
@@ -242,6 +242,7 @@ class Mount(dict):
for the ``volume`` type.
driver_config (DriverConfig): Volume driver configuration. Only valid
for the ``volume`` type.
+ subpath (str): Path inside a volume to mount instead of the volume root.
tmpfs_size (int or string): The size for the tmpfs mount in bytes.
tmpfs_mode (int): The permission mode for the tmpfs mount.
"""
@@ -249,7 +250,7 @@ class Mount(dict):
def __init__(self, target, source, type='volume', read_only=False,
consistency=None, propagation=None, no_copy=False,
labels=None, driver_config=None, tmpfs_size=None,
- tmpfs_mode=None):
+ tmpfs_mode=None, subpath=None):
self['Target'] = target
self['Source'] = source
if type not in ('bind', 'volume', 'tmpfs', 'npipe'):
@@ -267,7 +268,7 @@ class Mount(dict):
self['BindOptions'] = {
'Propagation': propagation
}
- if any([labels, driver_config, no_copy, tmpfs_size, tmpfs_mode]):
+ if any([labels, driver_config, no_copy, tmpfs_size, tmpfs_mode, subpath]):
raise errors.InvalidArgument(
'Incompatible options have been provided for the bind '
'type mount.'
@@ -280,6 +281,8 @@ class Mount(dict):
volume_opts['Labels'] = labels
if driver_config:
volume_opts['DriverConfig'] = driver_config
+ if subpath:
+ volume_opts['Subpath'] = subpath
if volume_opts:
self['VolumeOptions'] = volume_opts
if any([propagation, tmpfs_size, tmpfs_mode]):
diff --git a/contrib/python/docker/ya.make b/contrib/python/docker/ya.make
index 5dbd794e305..bf30b2c36b0 100644
--- a/contrib/python/docker/ya.make
+++ b/contrib/python/docker/ya.make
@@ -2,7 +2,7 @@
PY3_LIBRARY()
-VERSION(7.1.0)
+VERSION(7.2.0)
LICENSE(Apache-2.0)