diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..13b20f7 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,19 @@ +# Claude worktrees and other local tooling state. +.claude/ + +# A host venv, at any depth, must not shadow the one built inside the image. +**/.venv/ + +# Secrets: supply .env at runtime, never bake it into the image. `*.env` matches any env file +# but not the `*.env.example` templates, which stay. +.env +**/*.env + +# Caches / build noise. +**/__pycache__/ +*.pyc +.mypy_cache/ +.pytest_cache/ +.ruff_cache/ +.cache/ +.DS_Store diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..529a909 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,29 @@ +# syntax=docker/dockerfile:1.19 +FROM debian:trixie-slim@sha256:a72b4433de1cf7d6bae0c4cee74d0547f58601a643b3375f070c51600d63b6b2 + +COPY --from=ghcr.io/astral-sh/uv:0.13.9@sha256:d3b601f0c7b118bc1753febf7c41cc80981df678445e0254284eecf84db79a7d /uv /uvx /bin/ + +ENV UV_PYTHON_INSTALL_DIR=/opt/python + +WORKDIR /app + +RUN : \ + && apt-get update \ + && apt-get install --no-install-recommends --yes \ + ca-certificates \ + git \ + libexpat1 \ + && rm -rf /var/lib/apt/lists/* \ + && git config --system --add safe.directory /app \ + && : + +COPY pyproject.toml uv.lock .python-version ./ +RUN uv sync --frozen --no-install-project --no-dev + +COPY --exclude=.git . . +RUN uv sync --frozen --no-dev + +COPY .git .git +RUN git rev-parse --verify HEAD + +ENV PATH="/app/.venv/bin:${PATH}" diff --git a/jdluc/utils.py b/jdluc/utils.py index 61e7ca0..20ff959 100644 --- a/jdluc/utils.py +++ b/jdluc/utils.py @@ -75,6 +75,9 @@ def save_remote_url_to_local_path( @functools.cache def get_git_version(default_branch_name: str = "main") -> str: repo = git.Repo(__file__, search_parent_directories=True) + # NB: a detached HEAD, as CI checks out a pull request, has no branch to name + if repo.head.is_detached: + return repo.head.commit.hexsha[:8] if (branch_name := repo.active_branch.name) == default_branch_name: return f"{branch_name:s}-{repo.head.commit.hexsha[:8]:s}" else: