From 1658578cdee95551c575d22f0d992eaaf25cfdd8 Mon Sep 17 00:00:00 2001 From: Xitee1 <59659167+Xitee1@users.noreply.github.com> Date: Tue, 12 May 2026 11:34:53 +0200 Subject: [PATCH] feat: dockerize + switch to hatch-vcs versioning - Switch version source to hatch-vcs (driven by git tags). __init__.py reads from the generated _version.py with importlib.metadata fallback for editable installs. - Add Dockerfile based on python:3.13-slim-bookworm with all runtime tools (dar, par2, genisoimage, growisofs, dvd+rw-tools, udisks2, lsof, eject, mount). Version is injected via SETUPTOOLS_SCM_PRETEND_VERSION build-arg, so .git/ does not need to be in the build context. - Add docker-publish workflow that builds linux/amd64 + linux/arm64 images on v*.*.* tag push and publishes them to ghcr.io with semver tag fan-out (5.0.0, 5.0, 5, latest). Co-Authored-By: Claude Opus 4.7 (1M context) --- .dockerignore | 9 +++++ .github/workflows/docker-publish.yml | 52 ++++++++++++++++++++++++++++ .gitignore | 3 ++ Dockerfile | 28 +++++++++++++++ pyproject.toml | 7 ++-- src/bd_archive/__init__.py | 10 +++++- 6 files changed, 106 insertions(+), 3 deletions(-) create mode 100644 .dockerignore create mode 100644 .github/workflows/docker-publish.yml create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..34c92fd --- /dev/null +++ b/.dockerignore @@ -0,0 +1,9 @@ +.git/ +.venv/ +__pycache__/ +*.egg-info/ +dist/ +build/ +.ruff_cache/ +.pytest_cache/ +docs/ diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml new file mode 100644 index 0000000..bdc294f --- /dev/null +++ b/.github/workflows/docker-publish.yml @@ -0,0 +1,52 @@ +name: Docker Publish + +on: + push: + tags: ['v*.*.*'] + +permissions: + contents: read + packages: write + +jobs: + build-and-push: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Derive version + lowercase image name + id: vars + run: | + echo "version=${GITHUB_REF#refs/tags/v}" >> "$GITHUB_OUTPUT" + echo "image=${GITHUB_REPOSITORY,,}" >> "$GITHUB_OUTPUT" + + - uses: docker/setup-qemu-action@v3 + + - uses: docker/setup-buildx-action@v3 + + - uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - uses: docker/metadata-action@v5 + id: meta + with: + images: ghcr.io/${{ steps.vars.outputs.image }} + tags: | + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + type=semver,pattern={{major}} + + - uses: docker/build-push-action@v6 + with: + context: . + platforms: linux/amd64,linux/arm64 + push: true + build-args: | + BD_ARCHIVE_VERSION=${{ steps.vars.outputs.version }} + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=gha + cache-to: type=gha,mode=max diff --git a/.gitignore b/.gitignore index 1b122a7..2231253 100644 --- a/.gitignore +++ b/.gitignore @@ -18,3 +18,6 @@ venv/ # Local plans (not committed) docs/plans/ + +# hatch-vcs generated +src/bd_archive/_version.py diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..6af2dd8 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,28 @@ +FROM python:3.13-slim-bookworm + +RUN apt-get update && apt-get install -y --no-install-recommends \ + dar \ + par2 \ + genisoimage \ + growisofs \ + dvd+rw-tools \ + udisks2 \ + mount \ + eject \ + util-linux \ + lsof \ + ca-certificates \ + && rm -rf /var/lib/apt/lists/* + +ARG BD_ARCHIVE_VERSION=0.0.0+docker-local +ENV SETUPTOOLS_SCM_PRETEND_VERSION=${BD_ARCHIVE_VERSION} + +WORKDIR /src +COPY pyproject.toml README.md ./ +COPY src/ ./src/ + +RUN pip install --no-cache-dir . + +WORKDIR /data +ENTRYPOINT ["bd-archive"] +CMD ["--help"] diff --git a/pyproject.toml b/pyproject.toml index dbb35ad..40f4088 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,5 @@ [build-system] -requires = ["hatchling"] +requires = ["hatchling", "hatch-vcs"] build-backend = "hatchling.build" [project] @@ -16,7 +16,10 @@ bd-archive = "bd_archive.cli:main" dev = ["ruff>=0.4", "pre-commit>=3.7"] [tool.hatch.version] -path = "src/bd_archive/__init__.py" +source = "vcs" + +[tool.hatch.build.hooks.vcs] +version-file = "src/bd_archive/_version.py" [tool.hatch.build.targets.wheel] packages = ["src/bd_archive"] diff --git a/src/bd_archive/__init__.py b/src/bd_archive/__init__.py index ba7be38..a5a136a 100644 --- a/src/bd_archive/__init__.py +++ b/src/bd_archive/__init__.py @@ -1 +1,9 @@ -__version__ = "5.0.0" +try: + from ._version import __version__ +except ImportError: + try: + from importlib.metadata import version + + __version__ = version("bd-archive") + except Exception: + __version__ = "0.0.0+unknown"