Skip to content

Commit 9ad4bdd

Browse files
authored
chore(ci): fix-ups across Make / Docker / GitHub Actions (#3241)
1 parent 336e65f commit 9ad4bdd

13 files changed

+86
-81
lines changed

.github/workflows/ci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ jobs:
4747
- name: Install dependencies
4848
run: |
4949
python3 -m pip install --upgrade pip
50-
pip3 install -r test-requirements.txt -r requirements.txt
50+
pip3 install '.[ssh,dev]'
5151
- name: Run unit tests
5252
run: |
5353
docker logout

.readthedocs.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ sphinx:
44
configuration: docs/conf.py
55

66
build:
7-
os: ubuntu-20.04
7+
os: ubuntu-22.04
88
tools:
9-
python: '3.10'
9+
python: '3.12'
1010

1111
python:
1212
install:
13-
- requirements: docs-requirements.txt
1413
- method: pip
1514
path: .
1615
extra_requirements:
1716
- ssh
17+
- docs

Dockerfile

+6-10
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
11
# syntax=docker/dockerfile:1
22

33
ARG PYTHON_VERSION=3.12
4-
54
FROM python:${PYTHON_VERSION}
65

76
WORKDIR /src
8-
9-
COPY requirements.txt /src/requirements.txt
10-
RUN pip install --no-cache-dir -r requirements.txt
11-
12-
COPY test-requirements.txt /src/test-requirements.txt
13-
RUN pip install --no-cache-dir -r test-requirements.txt
14-
157
COPY . .
16-
ARG SETUPTOOLS_SCM_PRETEND_VERSION_DOCKER
17-
RUN pip install --no-cache-dir .
8+
9+
ARG VERSION
10+
RUN --mount=type=cache,target=/cache/pip \
11+
PIP_CACHE_DIR=/cache/pip \
12+
SETUPTOOLS_SCM_PRETEND_VERSION=${VERSION} \
13+
pip install .[ssh]

Dockerfile-docs

+7-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,12 @@ RUN addgroup --gid $gid sphinx \
1111
&& useradd --uid $uid --gid $gid -M sphinx
1212

1313
WORKDIR /src
14-
COPY requirements.txt docs-requirements.txt ./
15-
RUN pip install --no-cache-dir -r requirements.txt -r docs-requirements.txt
14+
COPY . .
15+
16+
ARG VERSION
17+
RUN --mount=type=cache,target=/cache/pip \
18+
PIP_CACHE_DIR=/cache/pip \
19+
SETUPTOOLS_SCM_PRETEND_VERSION=${VERSION} \
20+
pip install .[ssh,docs]
1621

1722
USER sphinx

MANIFEST.in

-9
This file was deleted.

Makefile

+38-22
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,17 @@ ifeq ($(PLATFORM),Linux)
1111
uid_args := "--build-arg uid=$(shell id -u) --build-arg gid=$(shell id -g)"
1212
endif
1313

14+
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/-/+/')
15+
ifeq ($(SETUPTOOLS_SCM_PRETEND_VERSION_DOCKER),)
16+
SETUPTOOLS_SCM_PRETEND_VERSION_DOCKER = "dev"
17+
endif
18+
1419
.PHONY: all
1520
all: test
1621

1722
.PHONY: clean
1823
clean:
19-
-docker rm -f dpy-dind-py3 dpy-dind-certs dpy-dind-ssl
24+
-docker rm -f dpy-dind dpy-dind-certs dpy-dind-ssl
2025
find -name "__pycache__" | xargs rm -rf
2126

2227
.PHONY: build-dind-ssh
@@ -25,51 +30,62 @@ build-dind-ssh:
2530
--pull \
2631
-t docker-dind-ssh \
2732
-f tests/Dockerfile-ssh-dind \
33+
--build-arg VERSION=${SETUPTOOLS_SCM_PRETEND_VERSION_DOCKER} \
2834
--build-arg ENGINE_VERSION=${TEST_ENGINE_VERSION} \
2935
--build-arg API_VERSION=${TEST_API_VERSION} \
3036
--build-arg APT_MIRROR .
3137

32-
.PHONY: build-py3
33-
build-py3:
38+
.PHONY: build
39+
build:
3440
docker build \
3541
--pull \
3642
-t docker-sdk-python3 \
3743
-f tests/Dockerfile \
44+
--build-arg VERSION=${SETUPTOOLS_SCM_PRETEND_VERSION_DOCKER} \
3845
--build-arg APT_MIRROR .
3946

4047
.PHONY: build-docs
4148
build-docs:
42-
docker build -t docker-sdk-python-docs -f Dockerfile-docs $(uid_args) .
49+
docker build \
50+
-t docker-sdk-python-docs \
51+
-f Dockerfile-docs \
52+
--build-arg VERSION=${SETUPTOOLS_SCM_PRETEND_VERSION_DOCKER} \
53+
$(uid_args) \
54+
.
4355

4456
.PHONY: build-dind-certs
4557
build-dind-certs:
46-
docker build -t dpy-dind-certs -f tests/Dockerfile-dind-certs .
58+
docker build \
59+
-t dpy-dind-certs \
60+
-f tests/Dockerfile-dind-certs \
61+
--build-arg VERSION=${SETUPTOOLS_SCM_PRETEND_VERSION_DOCKER} \
62+
.
4763

4864
.PHONY: test
49-
test: ruff unit-test-py3 integration-dind integration-dind-ssl
65+
test: ruff unit-test integration-dind integration-dind-ssl
5066

51-
.PHONY: unit-test-py3
52-
unit-test-py3: build-py3
67+
.PHONY: unit-test
68+
unit-test: build
5369
docker run -t --rm docker-sdk-python3 py.test tests/unit
5470

55-
.PHONY: integration-test-py3
56-
integration-test-py3: build-py3
71+
.PHONY: integration-test
72+
integration-test: build
5773
docker run -t --rm -v /var/run/docker.sock:/var/run/docker.sock docker-sdk-python3 py.test -v tests/integration/${file}
5874

5975
.PHONY: setup-network
6076
setup-network:
6177
docker network inspect dpy-tests || docker network create dpy-tests
6278

6379
.PHONY: integration-dind
64-
integration-dind: integration-dind-py3
80+
integration-dind: integration-dind
6581

66-
.PHONY: integration-dind-py3
67-
integration-dind-py3: build-py3 setup-network
68-
docker rm -vf dpy-dind-py3 || :
82+
.PHONY: integration-dind
83+
integration-dind: build setup-network
84+
docker rm -vf dpy-dind || :
6985

7086
docker run \
7187
--detach \
72-
--name dpy-dind-py3 \
88+
--name dpy-dind \
7389
--network dpy-tests \
7490
--pull=always \
7591
--privileged \
@@ -82,22 +98,22 @@ integration-dind-py3: build-py3 setup-network
8298
--rm \
8399
--tty \
84100
busybox \
85-
sh -c 'while ! nc -z dpy-dind-py3 2375; do sleep 1; done'
101+
sh -c 'while ! nc -z dpy-dind 2375; do sleep 1; done'
86102

87103
docker run \
88-
--env="DOCKER_HOST=tcp://dpy-dind-py3:2375" \
104+
--env="DOCKER_HOST=tcp://dpy-dind:2375" \
89105
--env="DOCKER_TEST_API_VERSION=${TEST_API_VERSION}" \
90106
--network dpy-tests \
91107
--rm \
92108
--tty \
93109
docker-sdk-python3 \
94110
py.test tests/integration/${file}
95111

96-
docker rm -vf dpy-dind-py3
112+
docker rm -vf dpy-dind
97113

98114

99115
.PHONY: integration-dind-ssh
100-
integration-dind-ssh: build-dind-ssh build-py3 setup-network
116+
integration-dind-ssh: build-dind-ssh build setup-network
101117
docker rm -vf dpy-dind-ssh || :
102118
docker run -d --network dpy-tests --name dpy-dind-ssh --privileged \
103119
docker-dind-ssh dockerd --experimental
@@ -116,7 +132,7 @@ integration-dind-ssh: build-dind-ssh build-py3 setup-network
116132

117133

118134
.PHONY: integration-dind-ssl
119-
integration-dind-ssl: build-dind-certs build-py3 setup-network
135+
integration-dind-ssl: build-dind-certs build setup-network
120136
docker rm -vf dpy-dind-certs dpy-dind-ssl || :
121137
docker run -d --name dpy-dind-certs dpy-dind-certs
122138

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

166182
.PHONY: ruff
167-
ruff: build-py3
183+
ruff: build
168184
docker run -t --rm docker-sdk-python3 ruff docker tests
169185

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

174190
.PHONY: shell
175-
shell: build-py3
191+
shell: build
176192
docker run -it -v /var/run/docker.sock:/var/run/docker.sock docker-sdk-python3 python

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ A Python library for the Docker Engine API. It lets you do anything the `docker`
66

77
## Installation
88

9-
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:
9+
The latest stable version [is available on PyPI](https://pypi.python.org/pypi/docker/). Install with pip:
1010

1111
pip install docker
1212

docs-requirements.txt

-2
This file was deleted.

pyproject.toml

+22-1
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,34 @@ dependencies = [
3636
]
3737

3838
[project.optional-dependencies]
39+
# ssh feature allows DOCKER_HOST=ssh://... style connections
3940
ssh = [
4041
"paramiko>=2.4.3",
4142
]
42-
tls = [] # kept for backwards compatibility
43+
# tls is always supported, the feature is a no-op for backwards compatibility
44+
tls = []
45+
# websockets can be used as an alternate container attach mechanism but
46+
# by default docker-py hijacks the TCP connection and does not use Websockets
47+
# unless attach_socket(container, ws=True) is called
4348
websockets = [
4449
"websocket-client >= 1.3.0",
4550
]
51+
# docs are dependencies required to build the ReadTheDocs site
52+
# this is only needed for CI / working on the docs!
53+
docs = [
54+
"myst-parser==0.18.0",
55+
"Sphinx==5.1.1",
56+
57+
]
58+
# dev are dependencies required to test & lint this project
59+
# this is only needed if you are making code changes to docker-py!
60+
dev = [
61+
"coverage==7.2.7",
62+
"pytest==7.4.2",
63+
"pytest-cov==4.1.0",
64+
"pytest-timeout==2.1.0",
65+
"ruff==0.1.8",
66+
]
4667

4768
[project.urls]
4869
Changelog = "https://docker-py.readthedocs.io/en/stable/change-log.html"

requirements.txt

-6
This file was deleted.

test-requirements.txt

-6
This file was deleted.

tests/Dockerfile

+6-13
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# syntax=docker/dockerfile:1
22

33
ARG PYTHON_VERSION=3.12
4-
54
FROM python:${PYTHON_VERSION}
65

76
RUN apt-get update && apt-get -y install --no-install-recommends \
@@ -27,16 +26,10 @@ RUN curl -sSL -o /opt/docker-credential-pass.tar.gz \
2726
chmod +x /usr/local/bin/docker-credential-pass
2827

2928
WORKDIR /src
29+
COPY . .
3030

31-
COPY requirements.txt /src/requirements.txt
32-
RUN --mount=type=cache,target=/root/.cache/pip \
33-
pip install -r requirements.txt
34-
35-
COPY test-requirements.txt /src/test-requirements.txt
36-
RUN --mount=type=cache,target=/root/.cache/pip \
37-
pip install -r test-requirements.txt
38-
39-
COPY . /src
40-
ARG SETUPTOOLS_SCM_PRETEND_VERSION=99.0.0+docker
41-
RUN --mount=type=cache,target=/root/.cache/pip \
42-
pip install -e .
31+
ARG VERSION
32+
RUN --mount=type=cache,target=/cache/pip \
33+
PIP_CACHE_DIR=/cache/pip \
34+
SETUPTOOLS_SCM_PRETEND_VERSION=${VERSION} \
35+
pip install .[dev,ssh,websockets]

tox.ini

+2-5
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,8 @@ skipsdist=True
66
usedevelop=True
77
commands =
88
py.test -v --cov=docker {posargs:tests/unit}
9-
deps =
10-
-r{toxinidir}/test-requirements.txt
11-
-r{toxinidir}/requirements.txt
9+
extras = dev
1210

1311
[testenv:ruff]
1412
commands = ruff docker tests setup.py
15-
deps =
16-
-r{toxinidir}/test-requirements.txt
13+
extras = dev

0 commit comments

Comments
 (0)