chore(ci): fix-ups across Make / Docker / GitHub Actions (#3241)

This commit is contained in:
Milas Bowman 2024-04-03 08:44:29 -04:00 committed by GitHub
parent 336e65fc3c
commit 9ad4bddc9e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
13 changed files with 86 additions and 81 deletions

View File

@ -47,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

View File

@ -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

View File

@ -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]

View File

@ -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

View File

@ -1,9 +0,0 @@
include test-requirements.txt
include requirements.txt
include README.md
include README.rst
include LICENSE
recursive-include tests *.py
recursive-include tests/unit/testdata *
recursive-include tests/integration/testdata *
recursive-include tests/gpg-keys *

View File

@ -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
@ -25,35 +30,46 @@ 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
@ -61,15 +77,15 @@ 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 \
@ -82,10 +98,10 @@ 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 \
@ -93,11 +109,11 @@ integration-dind-py3: build-py3 setup-network
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
@ -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
@ -164,7 +180,7 @@ 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
@ -172,5 +188,5 @@ 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

View File

@ -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

View File

@ -1,2 +0,0 @@
myst-parser==0.18.0
Sphinx==5.1.1

View File

@ -36,13 +36,34 @@ dependencies = [
]
[project.optional-dependencies]
# ssh feature allows DOCKER_HOST=ssh://... style connections
ssh = [
"paramiko>=2.4.3",
]
tls = [] # kept for backwards compatibility
# tls is always supported, the feature is a no-op for backwards compatibility
tls = []
# websockets can be used as an alternate container attach mechanism but
# by default docker-py hijacks the TCP connection and does not use Websockets
# unless attach_socket(container, ws=True) is called
websockets = [
"websocket-client >= 1.3.0",
]
# docs are dependencies required to build the ReadTheDocs site
# this is only needed for CI / working on the docs!
docs = [
"myst-parser==0.18.0",
"Sphinx==5.1.1",
]
# dev are dependencies required to test & lint this project
# this is only needed if you are making code changes to docker-py!
dev = [
"coverage==7.2.7",
"pytest==7.4.2",
"pytest-cov==4.1.0",
"pytest-timeout==2.1.0",
"ruff==0.1.8",
]
[project.urls]
Changelog = "https://docker-py.readthedocs.io/en/stable/change-log.html"

View File

@ -1,6 +0,0 @@
packaging==21.3
paramiko==2.11.0
pywin32==304; sys_platform == 'win32'
requests==2.31.0
urllib3==1.26.18
websocket-client==1.3.3

View File

@ -1,6 +0,0 @@
setuptools==65.5.1
coverage==7.2.7
ruff==0.1.8
pytest==7.4.2
pytest-cov==4.1.0
pytest-timeout==2.1.0

View File

@ -1,7 +1,6 @@
# syntax=docker/dockerfile:1
ARG PYTHON_VERSION=3.12
FROM python:${PYTHON_VERSION}
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 \
chmod +x /usr/local/bin/docker-credential-pass
WORKDIR /src
COPY . .
COPY requirements.txt /src/requirements.txt
RUN --mount=type=cache,target=/root/.cache/pip \
pip install -r requirements.txt
COPY test-requirements.txt /src/test-requirements.txt
RUN --mount=type=cache,target=/root/.cache/pip \
pip install -r test-requirements.txt
COPY . /src
ARG SETUPTOOLS_SCM_PRETEND_VERSION=99.0.0+docker
RUN --mount=type=cache,target=/root/.cache/pip \
pip install -e .
ARG VERSION
RUN --mount=type=cache,target=/cache/pip \
PIP_CACHE_DIR=/cache/pip \
SETUPTOOLS_SCM_PRETEND_VERSION=${VERSION} \
pip install .[dev,ssh,websockets]

View File

@ -6,11 +6,8 @@ skipsdist=True
usedevelop=True
commands =
py.test -v --cov=docker {posargs:tests/unit}
deps =
-r{toxinidir}/test-requirements.txt
-r{toxinidir}/requirements.txt
extras = dev
[testenv:ruff]
commands = ruff docker tests setup.py
deps =
-r{toxinidir}/test-requirements.txt
extras = dev