Skip to content

Commit

Permalink
Merge branch 'main' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
BobDu committed Apr 8, 2024
2 parents 0054f75 + 9ad4bdd commit 82c3e74
Show file tree
Hide file tree
Showing 111 changed files with 543 additions and 422 deletions.
15 changes: 14 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,19 @@ jobs:
- name: Run ruff
run: ruff docker tests

build:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
with:
python-version: '3.x'
- run: pip3 install build && python -m build .
- uses: actions/upload-artifact@v4
with:
name: dist
path: dist

unit-tests:
runs-on: ubuntu-latest
strategy:
Expand All @@ -34,7 +47,7 @@ jobs:
- name: Install dependencies
run: |
python3 -m pip install --upgrade pip
pip3 install -r test-requirements.txt -r requirements.txt
pip3 install '.[ssh,dev]'
- name: Run unit tests
run: |
docker logout
Expand Down
8 changes: 5 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@ jobs:
with:
python-version: '3.x'

- name: Generate Pacakge
- name: Generate Package
run: |
pip3 install setuptools wheel
python setup.py sdist bdist_wheel
pip3 install build
python -m build .
env:
# This is also supported by Hatch; see
# https://github.com/ofek/hatch-vcs#version-source-environment-variables
SETUPTOOLS_SCM_PRETEND_VERSION_FOR_DOCKER: ${{ inputs.tag }}

- name: Publish to PyPI
Expand Down
6 changes: 3 additions & 3 deletions .readthedocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ sphinx:
configuration: docs/conf.py

build:
os: ubuntu-20.04
os: ubuntu-22.04
tools:
python: '3.10'
python: '3.12'

python:
install:
- requirements: docs-requirements.txt
- method: pip
path: .
extra_requirements:
- ssh
- docs
16 changes: 6 additions & 10 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
# syntax=docker/dockerfile:1

ARG PYTHON_VERSION=3.12

FROM python:${PYTHON_VERSION}

WORKDIR /src

COPY requirements.txt /src/requirements.txt
RUN pip install --no-cache-dir -r requirements.txt

COPY test-requirements.txt /src/test-requirements.txt
RUN pip install --no-cache-dir -r test-requirements.txt

COPY . .
ARG SETUPTOOLS_SCM_PRETEND_VERSION_DOCKER
RUN pip install --no-cache-dir .

ARG VERSION
RUN --mount=type=cache,target=/cache/pip \
PIP_CACHE_DIR=/cache/pip \
SETUPTOOLS_SCM_PRETEND_VERSION=${VERSION} \
pip install .[ssh]
9 changes: 7 additions & 2 deletions Dockerfile-docs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ RUN addgroup --gid $gid sphinx \
&& useradd --uid $uid --gid $gid -M sphinx

WORKDIR /src
COPY requirements.txt docs-requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt -r docs-requirements.txt
COPY . .

ARG VERSION
RUN --mount=type=cache,target=/cache/pip \
PIP_CACHE_DIR=/cache/pip \
SETUPTOOLS_SCM_PRETEND_VERSION=${VERSION} \
pip install .[ssh,docs]

USER sphinx
9 changes: 0 additions & 9 deletions MANIFEST.in

This file was deleted.

64 changes: 40 additions & 24 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
TEST_API_VERSION ?= 1.43
TEST_ENGINE_VERSION ?= 24.0
TEST_API_VERSION ?= 1.44
TEST_ENGINE_VERSION ?= 25.0

ifeq ($(OS),Windows_NT)
PLATFORM := Windows
Expand All @@ -11,12 +11,17 @@ ifeq ($(PLATFORM),Linux)
uid_args := "--build-arg uid=$(shell id -u) --build-arg gid=$(shell id -g)"
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 = "dev"
endif

.PHONY: all
all: test

.PHONY: clean
clean:
-docker rm -f dpy-dind-py3 dpy-dind-certs dpy-dind-ssl
-docker rm -f dpy-dind dpy-dind-certs dpy-dind-ssl
find -name "__pycache__" | xargs rm -rf

.PHONY: build-dind-ssh
Expand All @@ -25,51 +30,62 @@ build-dind-ssh:
--pull \
-t docker-dind-ssh \
-f tests/Dockerfile-ssh-dind \
--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-py3
build-py3:
.PHONY: build
build:
docker build \
--pull \
-t docker-sdk-python3 \
-f tests/Dockerfile \
--build-arg VERSION=${SETUPTOOLS_SCM_PRETEND_VERSION_DOCKER} \
--build-arg APT_MIRROR .

.PHONY: build-docs
build-docs:
docker build -t docker-sdk-python-docs -f Dockerfile-docs $(uid_args) .
docker build \
-t docker-sdk-python-docs \
-f Dockerfile-docs \
--build-arg VERSION=${SETUPTOOLS_SCM_PRETEND_VERSION_DOCKER} \
$(uid_args) \
.

.PHONY: build-dind-certs
build-dind-certs:
docker build -t dpy-dind-certs -f tests/Dockerfile-dind-certs .
docker build \
-t dpy-dind-certs \
-f tests/Dockerfile-dind-certs \
--build-arg VERSION=${SETUPTOOLS_SCM_PRETEND_VERSION_DOCKER} \
.

.PHONY: test
test: ruff unit-test-py3 integration-dind integration-dind-ssl
test: ruff unit-test integration-dind integration-dind-ssl

.PHONY: unit-test-py3
unit-test-py3: build-py3
.PHONY: unit-test
unit-test: build
docker run -t --rm docker-sdk-python3 py.test tests/unit

.PHONY: integration-test-py3
integration-test-py3: build-py3
.PHONY: integration-test
integration-test: build
docker run -t --rm -v /var/run/docker.sock:/var/run/docker.sock docker-sdk-python3 py.test -v tests/integration/${file}

.PHONY: setup-network
setup-network:
docker network inspect dpy-tests || docker network create dpy-tests

.PHONY: integration-dind
integration-dind: integration-dind-py3
integration-dind: integration-dind

.PHONY: integration-dind-py3
integration-dind-py3: build-py3 setup-network
docker rm -vf dpy-dind-py3 || :
.PHONY: integration-dind
integration-dind: build setup-network
docker rm -vf dpy-dind || :

docker run \
--detach \
--name dpy-dind-py3 \
--name dpy-dind \
--network dpy-tests \
--pull=always \
--privileged \
Expand All @@ -82,22 +98,22 @@ integration-dind-py3: build-py3 setup-network
--rm \
--tty \
busybox \
sh -c 'while ! nc -z dpy-dind-py3 2375; do sleep 1; done'
sh -c 'while ! nc -z dpy-dind 2375; do sleep 1; done'

docker run \
--env="DOCKER_HOST=tcp://dpy-dind-py3:2375" \
--env="DOCKER_HOST=tcp://dpy-dind:2375" \
--env="DOCKER_TEST_API_VERSION=${TEST_API_VERSION}" \
--network dpy-tests \
--rm \
--tty \
docker-sdk-python3 \
py.test tests/integration/${file}

docker rm -vf dpy-dind-py3
docker rm -vf dpy-dind


.PHONY: integration-dind-ssh
integration-dind-ssh: build-dind-ssh build-py3 setup-network
integration-dind-ssh: build-dind-ssh build setup-network
docker rm -vf dpy-dind-ssh || :
docker run -d --network dpy-tests --name dpy-dind-ssh --privileged \
docker-dind-ssh dockerd --experimental
Expand All @@ -116,7 +132,7 @@ integration-dind-ssh: build-dind-ssh build-py3 setup-network


.PHONY: integration-dind-ssl
integration-dind-ssl: build-dind-certs build-py3 setup-network
integration-dind-ssl: build-dind-certs build setup-network
docker rm -vf dpy-dind-certs dpy-dind-ssl || :
docker run -d --name dpy-dind-certs dpy-dind-certs

Expand Down Expand Up @@ -164,13 +180,13 @@ integration-dind-ssl: build-dind-certs build-py3 setup-network
docker rm -vf dpy-dind-ssl dpy-dind-certs

.PHONY: ruff
ruff: build-py3
ruff: build
docker run -t --rm docker-sdk-python3 ruff docker tests

.PHONY: docs
docs: build-docs
docker run --rm -t -v `pwd`:/src docker-sdk-python-docs sphinx-build docs docs/_build

.PHONY: shell
shell: build-py3
shell: build
docker run -it -v /var/run/docker.sock:/var/run/docker.sock docker-sdk-python3 python
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ A Python library for the Docker Engine API. It lets you do anything the `docker`

## Installation

The latest stable version [is available on PyPI](https://pypi.python.org/pypi/docker/). Either add `docker` to your `requirements.txt` file or install with pip:
The latest stable version [is available on PyPI](https://pypi.python.org/pypi/docker/). Install with pip:

pip install docker

Expand Down
3 changes: 1 addition & 2 deletions docker/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from .api import APIClient
from .client import DockerClient, from_env
from .context import Context
from .context import ContextAPI
from .context import Context, ContextAPI
from .tls import TLSConfig
from .version import __version__

Expand Down
6 changes: 1 addition & 5 deletions docker/api/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@
import os
import random

from .. import auth
from .. import constants
from .. import errors
from .. import utils

from .. import auth, constants, errors, utils

log = logging.getLogger(__name__)

Expand Down
22 changes: 16 additions & 6 deletions docker/api/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,22 @@
import requests.exceptions

from .. import auth
from ..constants import (DEFAULT_NUM_POOLS, DEFAULT_NUM_POOLS_SSH,
DEFAULT_MAX_POOL_SIZE, DEFAULT_TIMEOUT_SECONDS,
DEFAULT_USER_AGENT, IS_WINDOWS_PLATFORM,
MINIMUM_DOCKER_API_VERSION, STREAM_HEADER_SIZE_BYTES)
from ..errors import (DockerException, InvalidVersion, TLSParameterError,
create_api_error_from_http_exception)
from ..constants import (
DEFAULT_MAX_POOL_SIZE,
DEFAULT_NUM_POOLS,
DEFAULT_NUM_POOLS_SSH,
DEFAULT_TIMEOUT_SECONDS,
DEFAULT_USER_AGENT,
IS_WINDOWS_PLATFORM,
MINIMUM_DOCKER_API_VERSION,
STREAM_HEADER_SIZE_BYTES,
)
from ..errors import (
DockerException,
InvalidVersion,
TLSParameterError,
create_api_error_from_http_exception,
)
from ..tls import TLSConfig
from ..transport import UnixHTTPAdapter
from ..utils import check_resource, config, update_headers, utils
Expand Down
15 changes: 8 additions & 7 deletions docker/api/container.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
from datetime import datetime

from .. import errors
from .. import utils
from .. import errors, utils
from ..constants import DEFAULT_DATA_CHUNK_SIZE
from ..types import CancellableStream
from ..types import ContainerConfig
from ..types import EndpointConfig
from ..types import HostConfig
from ..types import NetworkingConfig
from ..types import (
CancellableStream,
ContainerConfig,
EndpointConfig,
HostConfig,
NetworkingConfig,
)


class ContainerApiMixin:
Expand Down
3 changes: 1 addition & 2 deletions docker/api/exec_api.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from .. import errors
from .. import utils
from .. import errors, utils
from ..types import CancellableStream


Expand Down
5 changes: 2 additions & 3 deletions docker/api/network.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from ..errors import InvalidVersion
from ..utils import check_resource, minimum_version
from ..utils import version_lt
from .. import utils
from ..errors import InvalidVersion
from ..utils import check_resource, minimum_version, version_lt


class NetworkApiMixin:
Expand Down
3 changes: 1 addition & 2 deletions docker/api/secret.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import base64

from .. import errors
from .. import utils
from .. import errors, utils


class SecretApiMixin:
Expand Down
7 changes: 3 additions & 4 deletions docker/api/swarm.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import logging
import http.client as http_client
import logging

from .. import errors, types, utils
from ..constants import DEFAULT_SWARM_ADDR_POOL, DEFAULT_SWARM_SUBNET_SIZE
from .. import errors
from .. import types
from .. import utils

log = logging.getLogger(__name__)

Expand Down
3 changes: 1 addition & 2 deletions docker/api/volume.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from .. import errors
from .. import utils
from .. import errors, utils


class VolumeApiMixin:
Expand Down

0 comments on commit 82c3e74

Please sign in to comment.