PDM in docker image (versioned like official python image)
Your project's structure:
src/
__init__.py__main__.pytests/Dockerfilepdm.lockpyproject.tomlREADME.mdDockerfile:
ARG PYTHON_VERSION=3.10
FROM seven45/pdm-ci:$PYTHON_VERSION as pdm
WORKDIR /project
COPY pyproject.toml pdm.lock /project/
RUN python -m venv --copies .venv
RUN pdm install --prod --no-self --no-lock --no-editable
FROM python:$PYTHON_VERSION
WORKDIR /project
COPY --from=pdm /project/.venv /project/.venv
ENV PATH="/project/.venv/bin:$PATH"
COPY src /project/src
CMD ["python", "src/__main__.py"]
pyproject.toml:
...
[tool.pdm.dev-dependencies]
testing = ["pytest-cov>=4.0.0"]
linting = [
"setuptools>=65.6.3",
"black>=22.12.0",
"isort>=5.11.4",
"flake8-pyproject>=1.2.2"
]
[tool.pdm.scripts]
lint = {composite = ["black src tests", "isort src tests", "flake8p src tests"]}
lint_check = {composite = ["black src tests --check", "isort src tests --check-only", "flake8p src tests"]}
test = "pytest -vvv -s tests"
test_cov = "pytest --cov-branch --cov-report=xml --cov=src tests"
test_file = "pytest -s -vv ./{args}"
test_all = {composite = ["test", "lint_check"]}
...
gitlab-ci.yaml:
stages:
- lint
- test
linters:
stage: lint
image: seven45/pdm-ci:3.10-alpine
only: [ "merge_requests" ]
script:
- pdm install --no-default -G linting
- pdm run lint
pytest:
stage: test
image: seven45/pdm-ci:3.10-slim
only: [ "merge_requests" ]
script:
- pdm install -dG testing
- pdm run test_cov
coverage: '/(?i)total.*? (100(?:\.0+)?\%|[1-9]?\d(?:\.\d+)?\%)$/'
artifacts:
paths:
- coverage.xml
Dynamic versioning:
Put your version into file src/__version__.py with content:
__version__ = "0.1.0"
Put into your pyproject.toml file lines:
[project]
...
dynamic = ["version"]
[tool.pdm]
build = {includes = ["src"]}
version = { source = "file", path = "src/__version__.py" }
...
Content type
Image
Digest
sha256:17f4c4af0…
Size
422.2 MB
Last updated
about 22 hours ago
docker pull seven45/pdm-ci:3.13-trixie