mirror of https://github.com/docker/docker-py.git
Compare commits
No commits in common. "main" and "7.1.0" have entirely different histories.
|
@ -6,7 +6,7 @@ FROM python:${PYTHON_VERSION}
|
|||
WORKDIR /src
|
||||
COPY . .
|
||||
|
||||
ARG VERSION=0.0.0.dev0
|
||||
ARG VERSION
|
||||
RUN --mount=type=cache,target=/cache/pip \
|
||||
PIP_CACHE_DIR=/cache/pip \
|
||||
SETUPTOOLS_SCM_PRETEND_VERSION=${VERSION} \
|
||||
|
|
|
@ -13,7 +13,7 @@ RUN addgroup --gid $gid sphinx \
|
|||
WORKDIR /src
|
||||
COPY . .
|
||||
|
||||
ARG VERSION=0.0.0.dev0
|
||||
ARG VERSION
|
||||
RUN --mount=type=cache,target=/cache/pip \
|
||||
PIP_CACHE_DIR=/cache/pip \
|
||||
SETUPTOOLS_SCM_PRETEND_VERSION=${VERSION} \
|
||||
|
|
13
Makefile
13
Makefile
|
@ -1,5 +1,5 @@
|
|||
TEST_API_VERSION ?= 1.45
|
||||
TEST_ENGINE_VERSION ?= 26.1
|
||||
TEST_API_VERSION ?= 1.44
|
||||
TEST_ENGINE_VERSION ?= 25.0
|
||||
|
||||
ifeq ($(OS),Windows_NT)
|
||||
PLATFORM := Windows
|
||||
|
@ -13,7 +13,7 @@ endif
|
|||
|
||||
SETUPTOOLS_SCM_PRETEND_VERSION_DOCKER ?= $(shell git describe --match '[0-9]*' --dirty='.m' --always --tags 2>/dev/null | sed -r 's/-([0-9]+)/.dev\1/' | sed 's/-/+/')
|
||||
ifeq ($(SETUPTOOLS_SCM_PRETEND_VERSION_DOCKER),)
|
||||
SETUPTOOLS_SCM_PRETEND_VERSION_DOCKER = "0.0.0.dev0"
|
||||
SETUPTOOLS_SCM_PRETEND_VERSION_DOCKER = "dev"
|
||||
endif
|
||||
|
||||
.PHONY: all
|
||||
|
@ -33,7 +33,7 @@ build-dind-ssh:
|
|||
--build-arg VERSION=${SETUPTOOLS_SCM_PRETEND_VERSION_DOCKER} \
|
||||
--build-arg ENGINE_VERSION=${TEST_ENGINE_VERSION} \
|
||||
--build-arg API_VERSION=${TEST_API_VERSION} \
|
||||
.
|
||||
--build-arg APT_MIRROR .
|
||||
|
||||
.PHONY: build
|
||||
build:
|
||||
|
@ -42,7 +42,7 @@ build:
|
|||
-t docker-sdk-python3 \
|
||||
-f tests/Dockerfile \
|
||||
--build-arg VERSION=${SETUPTOOLS_SCM_PRETEND_VERSION_DOCKER} \
|
||||
.
|
||||
--build-arg APT_MIRROR .
|
||||
|
||||
.PHONY: build-docs
|
||||
build-docs:
|
||||
|
@ -76,6 +76,9 @@ integration-test: build
|
|||
setup-network:
|
||||
docker network inspect dpy-tests || docker network create dpy-tests
|
||||
|
||||
.PHONY: integration-dind
|
||||
integration-dind: integration-dind
|
||||
|
||||
.PHONY: integration-dind
|
||||
integration-dind: build setup-network
|
||||
docker rm -vf dpy-dind || :
|
||||
|
|
|
@ -2,7 +2,7 @@ import sys
|
|||
|
||||
from .version import __version__
|
||||
|
||||
DEFAULT_DOCKER_API_VERSION = '1.45'
|
||||
DEFAULT_DOCKER_API_VERSION = '1.44'
|
||||
MINIMUM_DOCKER_API_VERSION = '1.24'
|
||||
DEFAULT_TIMEOUT_SECONDS = 60
|
||||
STREAM_HEADER_SIZE_BYTES = 8
|
||||
|
|
|
@ -181,8 +181,7 @@ 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. Ignored if ``detach`` is true.
|
||||
Default: False
|
||||
stream (bool): Stream response data. 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
|
||||
|
|
|
@ -407,8 +407,8 @@ class ImageCollection(Collection):
|
|||
if match:
|
||||
image_id = match.group(2)
|
||||
images.append(image_id)
|
||||
if 'errorDetail' in chunk:
|
||||
raise ImageLoadError(chunk['errorDetail']['message'])
|
||||
if 'error' in chunk:
|
||||
raise ImageLoadError(chunk['error'])
|
||||
|
||||
return [self.get(i) for i in images]
|
||||
|
||||
|
|
|
@ -242,7 +242,6 @@ 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.
|
||||
"""
|
||||
|
@ -250,7 +249,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, subpath=None):
|
||||
tmpfs_mode=None):
|
||||
self['Target'] = target
|
||||
self['Source'] = source
|
||||
if type not in ('bind', 'volume', 'tmpfs', 'npipe'):
|
||||
|
@ -268,7 +267,7 @@ class Mount(dict):
|
|||
self['BindOptions'] = {
|
||||
'Propagation': propagation
|
||||
}
|
||||
if any([labels, driver_config, no_copy, tmpfs_size, tmpfs_mode, subpath]):
|
||||
if any([labels, driver_config, no_copy, tmpfs_size, tmpfs_mode]):
|
||||
raise errors.InvalidArgument(
|
||||
'Incompatible options have been provided for the bind '
|
||||
'type mount.'
|
||||
|
@ -281,8 +280,6 @@ 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]):
|
||||
|
|
|
@ -28,7 +28,7 @@ RUN curl -sSL -o /opt/docker-credential-pass.tar.gz \
|
|||
WORKDIR /src
|
||||
COPY . .
|
||||
|
||||
ARG VERSION=0.0.0.dev0
|
||||
ARG VERSION
|
||||
RUN --mount=type=cache,target=/cache/pip \
|
||||
PIP_CACHE_DIR=/cache/pip \
|
||||
SETUPTOOLS_SCM_PRETEND_VERSION=${VERSION} \
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
# syntax=docker/dockerfile:1
|
||||
|
||||
ARG API_VERSION=1.45
|
||||
ARG ENGINE_VERSION=26.1
|
||||
ARG API_VERSION=1.44
|
||||
ARG ENGINE_VERSION=25.0
|
||||
|
||||
FROM docker:${ENGINE_VERSION}-dind
|
||||
|
||||
|
|
|
@ -275,7 +275,7 @@ class BuildTest(BaseAPIIntegrationTest):
|
|||
pass
|
||||
|
||||
info = self.client.inspect_image('build1')
|
||||
assert 'OnBuild' not in info['Config'] or not info['Config']['OnBuild']
|
||||
assert not info['Config']['OnBuild']
|
||||
|
||||
@requires_api_version('1.25')
|
||||
def test_build_with_network_mode(self):
|
||||
|
|
|
@ -620,56 +620,6 @@ class VolumeBindTest(BaseAPIIntegrationTest):
|
|||
assert mount['Source'] == mount_data['Name']
|
||||
assert mount_data['RW'] is True
|
||||
|
||||
@requires_api_version('1.45')
|
||||
def test_create_with_subpath_volume_mount(self):
|
||||
source_volume = helpers.random_name()
|
||||
self.client.create_volume(name=source_volume)
|
||||
|
||||
setup_container = None
|
||||
test_container = None
|
||||
|
||||
|
||||
# Create a file structure in the volume to test with
|
||||
setup_container = self.client.create_container(
|
||||
TEST_IMG,
|
||||
[
|
||||
"sh",
|
||||
"-c",
|
||||
'mkdir -p /vol/subdir && echo "test content" > /vol/subdir/testfile.txt',
|
||||
],
|
||||
host_config=self.client.create_host_config(
|
||||
binds=[f"{source_volume}:/vol"]
|
||||
),
|
||||
)
|
||||
self.client.start(setup_container)
|
||||
self.client.wait(setup_container)
|
||||
|
||||
# Now test with subpath
|
||||
mount = docker.types.Mount(
|
||||
type="volume",
|
||||
source=source_volume,
|
||||
target=self.mount_dest,
|
||||
read_only=True,
|
||||
subpath="subdir",
|
||||
)
|
||||
|
||||
|
||||
host_config = self.client.create_host_config(mounts=[mount])
|
||||
test_container = self.client.create_container(
|
||||
TEST_IMG,
|
||||
["cat", os.path.join(self.mount_dest, "testfile.txt")],
|
||||
host_config=host_config,
|
||||
)
|
||||
|
||||
self.client.start(test_container)
|
||||
self.client.wait(test_container) # Wait for container to finish
|
||||
output = self.client.logs(test_container).decode("utf-8").strip()
|
||||
|
||||
# If the subpath feature is working, we should be able to see the content
|
||||
# of the file in the subdir
|
||||
assert output == "test content"
|
||||
|
||||
|
||||
def check_container_data(self, inspect_data, rw, propagation='rprivate'):
|
||||
assert 'Mounts' in inspect_data
|
||||
filtered = list(filter(
|
||||
|
|
|
@ -5,7 +5,7 @@ import pytest
|
|||
|
||||
import docker
|
||||
|
||||
from ..helpers import force_leave_swarm, requires_api_version
|
||||
from ..helpers import force_leave_swarm, requires_api_version, requires_experimental
|
||||
from .base import TEST_IMG, BaseAPIIntegrationTest
|
||||
|
||||
|
||||
|
@ -140,7 +140,8 @@ class ServiceTest(BaseAPIIntegrationTest):
|
|||
assert len(services) == 1
|
||||
assert services[0]['ID'] == svc_id['ID']
|
||||
|
||||
@requires_api_version('1.29')
|
||||
@requires_api_version('1.25')
|
||||
@requires_experimental(until='1.29')
|
||||
def test_service_logs(self):
|
||||
name, svc_id = self.create_simple_service()
|
||||
assert self.get_service_container(name, include_stopped=True)
|
||||
|
|
|
@ -17,16 +17,10 @@ class TestVolumes(BaseAPIIntegrationTest):
|
|||
assert result['Driver'] == 'local'
|
||||
|
||||
def test_create_volume_invalid_driver(self):
|
||||
# special name to avoid exponential timeout loop
|
||||
# https://github.com/moby/moby/blob/9e00a63d65434cdedc444e79a2b33a7c202b10d8/pkg/plugins/client.go#L253-L254
|
||||
driver_name = 'this-plugin-does-not-exist'
|
||||
driver_name = 'invalid.driver'
|
||||
|
||||
with pytest.raises(docker.errors.APIError) as cm:
|
||||
with pytest.raises(docker.errors.NotFound):
|
||||
self.client.create_volume('perfectcherryblossom', driver_name)
|
||||
assert (
|
||||
cm.value.response.status_code == 404 or
|
||||
cm.value.response.status_code == 400
|
||||
)
|
||||
|
||||
def test_list_volumes(self):
|
||||
name = 'imperishablenight'
|
||||
|
|
|
@ -131,9 +131,10 @@ class ContainerCollectionTest(BaseIntegrationTest):
|
|||
assert 'NetworkSettings' in attrs
|
||||
assert 'Networks' in attrs['NetworkSettings']
|
||||
assert list(attrs['NetworkSettings']['Networks'].keys()) == [net_name]
|
||||
# Aliases no longer include the container's short-id in API v1.45.
|
||||
# Expect Aliases to list 'test_alias' and the container's short-id.
|
||||
# In API version 1.45, the short-id will be removed.
|
||||
assert attrs['NetworkSettings']['Networks'][net_name]['Aliases'] \
|
||||
== [test_alias]
|
||||
== [test_alias, attrs['Id'][:12]]
|
||||
assert attrs['NetworkSettings']['Networks'][net_name]['DriverOpts'] \
|
||||
== test_driver_opt
|
||||
|
||||
|
@ -190,9 +191,9 @@ class ContainerCollectionTest(BaseIntegrationTest):
|
|||
assert 'NetworkSettings' in attrs
|
||||
assert 'Networks' in attrs['NetworkSettings']
|
||||
assert list(attrs['NetworkSettings']['Networks'].keys()) == [net_name]
|
||||
# Aliases no longer include the container's short-id in API v1.45.
|
||||
assert (attrs['NetworkSettings']['Networks'][net_name]['Aliases']
|
||||
is None)
|
||||
# Aliases should include the container's short-id (but it will be removed
|
||||
# in API v1.45).
|
||||
assert attrs['NetworkSettings']['Networks'][net_name]['Aliases'] == [attrs["Id"][:12]]
|
||||
assert (attrs['NetworkSettings']['Networks'][net_name]['DriverOpts']
|
||||
is None)
|
||||
|
||||
|
@ -352,26 +353,14 @@ class ContainerTest(BaseIntegrationTest):
|
|||
assert exec_output[0] == 0
|
||||
assert exec_output[1] == b"hello\n"
|
||||
|
||||
def test_exec_run_error_code_from_exec(self):
|
||||
client = docker.from_env(version=TEST_API_VERSION)
|
||||
container = client.containers.run(
|
||||
"alpine", "sh -c 'sleep 20'", detach=True
|
||||
)
|
||||
self.tmp_containers.append(container.id)
|
||||
exec_output = container.exec_run("sh -c 'exit 42'")
|
||||
assert exec_output[0] == 42
|
||||
|
||||
def test_exec_run_failed(self):
|
||||
client = docker.from_env(version=TEST_API_VERSION)
|
||||
container = client.containers.run(
|
||||
"alpine", "sh -c 'sleep 60'", detach=True
|
||||
)
|
||||
self.tmp_containers.append(container.id)
|
||||
exec_output = container.exec_run("non-existent")
|
||||
# older versions of docker return `126` in the case that an exec cannot
|
||||
# be started due to a missing executable. We're fixing this for the
|
||||
# future, so accept both for now.
|
||||
assert exec_output[0] == 127 or exec_output[0] == 126
|
||||
exec_output = container.exec_run("docker ps")
|
||||
assert exec_output[0] == 126
|
||||
|
||||
def test_kill(self):
|
||||
client = docker.from_env(version=TEST_API_VERSION)
|
||||
|
|
|
@ -266,7 +266,7 @@ class BuildTest(BaseAPIIntegrationTest):
|
|||
pass
|
||||
|
||||
info = self.client.inspect_image('build1')
|
||||
assert 'OnBuild' not in info['Config'] or not info['Config']['OnBuild']
|
||||
assert not info['Config']['OnBuild']
|
||||
|
||||
@requires_api_version('1.25')
|
||||
def test_build_with_network_mode(self):
|
||||
|
|
Loading…
Reference in New Issue