Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/Seven45/pdm-ci
PDM-based image for ci usage
https://github.com/Seven45/pdm-ci
docker-image dockerhub gitlab-ci multistage-build package-manager pdm python python3
Last synced: about 1 month ago
JSON representation
PDM-based image for ci usage
- Host: GitHub
- URL: https://github.com/Seven45/pdm-ci
- Owner: Seven45
- License: mit
- Created: 2022-12-29T13:42:30.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-10-29T12:02:45.000Z (about 2 months ago)
- Last Synced: 2024-10-29T14:33:51.474Z (about 2 months ago)
- Topics: docker-image, dockerhub, gitlab-ci, multistage-build, package-manager, pdm, python, python3
- Language: Dockerfile
- Homepage: https://hub.docker.com/r/seven45/pdm-ci
- Size: 170 KB
- Stars: 11
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-pdm - pdm-ci - A docker image for usage in multistage builds or gitlab-ci (Eco-system)
README
# pdm-ci
[PDM](https://github.com/pdm-project/pdm) in docker [image](https://hub.docker.com/r/seven45/pdm-ci) (versioned like official python image)
Your project's structure:
- my_project/ (workdir)
- `src/`
- your files and folders here
- `__init__.py`
- `__main__.py`
- `tests/`
- `Dockerfile`
- `pdm.lock`
- `pyproject.toml`
- `README.md`## Python multistage build
`Dockerfile`:
```dockerfile
ARG PYTHON_VERSION=3.10FROM 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-editableFROM 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"]
```## Continuous Integration
`pyproject.toml`:
```toml
...[tool.pdm.dev-dependencies]
testing = ["pytest-cov>=5.0.0"]
linting = [
"ruff>=0.3.4",
][tool.pdm.scripts]
lint = {composite = ["ruff format src tests", "ruff check src tests --fix"]}
lint_check = {composite = ["ruff format src tests --check", "ruff check src tests"]}
test = "pytest -vvv -s tests"
test_cov = "pytest --cov-branch --cov-report=xml --cov=src tests"...
````gitlab-ci.yaml`:
```yaml
stages:
- lint
- testruff:
stage: lint
image: seven45/pdm-ci:3.10-alpine
only: [ "merge_requests" ]
script:
- pdm install --no-default -G linting
- pdm run lint_check
cache:
paths: [ ".venv" ]
key:
prefix: venv_lint
files: [ "pdm.lock" ]
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:
reports:
coverage_report:
coverage_format: cobertura
path: coverage.xml
cache:
paths: [ ".venv" ]
key:
prefix: venv_test
files: [ "pdm.lock" ]
```## Pre-commit hooks
`pre-commit-config.yaml`:
```yaml
repos:
- repo: local
hooks:
- id: ruff
name: ruff format and lint
language: system
types: [python]
entry: pdm run lint_check
```## Extended usage
Dynamic versioning:
Put your version into file `src/__version__.py` with content:
```python
__version__ = "0.1.0"```
Put into your `pyproject.toml` file lines:
```toml
[project]
...
dynamic = ["version"][tool.pdm]
build = {includes = ["src"]}
version = { source = "file", path = "src/__version__.py" }
...
```