diff --git a/Dockerfile b/Dockerfile index 645127a9..f803e331 100644 --- a/Dockerfile +++ b/Dockerfile @@ -69,19 +69,30 @@ WORKDIR /app/ # Ref: https://docs.astral.sh/uv/guides/integration/docker/#using-the-environment ENV PATH="/app/.venv/bin:$PATH" -# Pass version from Makefile to setuptools-scm since .git is not in context -ARG SETUPTOOLS_SCM_PRETEND_VERSION_FOR_BREWMAN -ENV SETUPTOOLS_SCM_PRETEND_VERSION_FOR_BREWMAN=$SETUPTOOLS_SCM_PRETEND_VERSION_FOR_BREWMAN +# Pass the version from the Makefile. The build context has no usable .git +# (a git-URL build is a tag-less shallow clone and git is not installed), so +# hatch-vcs cannot discover the version itself. hatch-vcs calls +# setuptools_scm without a dist name, so only the generic +# SETUPTOOLS_SCM_PRETEND_VERSION is honored - the +# SETUPTOOLS_SCM_PRETEND_VERSION_FOR_ variant is silently ignored. +ARG SETUPTOOLS_SCM_PRETEND_VERSION +ENV SETUPTOOLS_SCM_PRETEND_VERSION=$SETUPTOOLS_SCM_PRETEND_VERSION # Install dependencies # Ref: https://docs.astral.sh/uv/guides/integration/docker/#intermediate-layers RUN --mount=type=cache,target=/root/.cache/uv \ --mount=type=bind,source=brewman/uv.lock,target=uv.lock \ --mount=type=bind,source=brewman/pyproject.toml,target=pyproject.toml \ - --mount=source=.git,target=.git,type=bind \ uv sync --locked --no-install-project COPY /brewman ./ + +# hatch-vcs generates _version.py only inside uv's isolated wheel build, so +# the source tree copied here lacks it. Write it ourselves (from the same +# build arg) so importing brewman from /app works identically to the +# installed wheel package in .venv. +RUN printf '__version__ = version = "%s"\n' "$SETUPTOOLS_SCM_PRETEND_VERSION" > brewman/_version.py + COPY --from=builder /frontend/browser /app/frontend # Sync the project @@ -89,7 +100,6 @@ COPY --from=builder /frontend/browser /app/frontend RUN --mount=type=cache,target=/root/.cache/uv \ --mount=type=bind,source=brewman/uv.lock,target=uv.lock \ --mount=type=bind,source=brewman/pyproject.toml,target=pyproject.toml \ - --mount=source=.git,target=.git,type=bind \ uv sync --locked --no-editable EXPOSE 80 diff --git a/Makefile b/Makefile index d22f323a..73f8e782 100644 --- a/Makefile +++ b/Makefile @@ -1,12 +1,13 @@ .PHONY: build-production build-production: ## Build the production container image. Usage: make build-production TAG=15.4.0 + @test -n "$(TAG)" || { echo "Usage: make build-production TAG=15.4.0" >&2; exit 1; } @echo "Building image..." @podman manifest rm registry.tanshu.com/brewman:latest 2>/dev/null || true @podman build \ --platform linux/amd64,linux/arm64 \ --manifest registry.tanshu.com/brewman:latest \ --pull \ - --build-arg SETUPTOOLS_SCM_PRETEND_VERSION_FOR_BREWMAN=$(TAG) \ + --build-arg SETUPTOOLS_SCM_PRETEND_VERSION=$(TAG) \ https://git.tanshu.com/tanshu/brewman.git#v$(TAG) @echo "Pushing manifests..." @@ -15,22 +16,25 @@ build-production: ## Build the production container image. Usage: make build-pro .PHONY: build-check build-check: ## Multi-arch build without push (compile check). Usage: make build-check TAG=15.4.0 + @test -n "$(TAG)" || { echo "Usage: make build-check TAG=15.4.0" >&2; exit 1; } @echo "Building image..." @podman manifest rm brewman:test 2>/dev/null || true @podman build \ --platform linux/amd64,linux/arm64 \ --manifest brewman:test \ --pull \ - --build-arg SETUPTOOLS_SCM_PRETEND_VERSION_FOR_BREWMAN=$(TAG) \ + --build-arg SETUPTOOLS_SCM_PRETEND_VERSION=$(TAG) \ https://git.tanshu.com/tanshu/brewman.git#v$(TAG) .PHONY: build-check-local -build-check-local: ## Multi-arch build without push (compile check). Usage: make build-check TAG=15.4.0 +# Defaults the version when built without a tag; an explicit TAG still wins. +build-check-local: TAG = 0.0.0 +build-check-local: ## Single-arch build without push (compile check). Usage: make build-check-local [TAG=15.4.0] @echo "Building image..." @podman manifest rm brewman:test 2>/dev/null || true @podman build \ --platform linux/amd64 \ --manifest brewman:test \ --no-cache \ - --build-arg SETUPTOOLS_SCM_PRETEND_VERSION_FOR_BREWMAN=$(TAG) \ + --build-arg SETUPTOOLS_SCM_PRETEND_VERSION=$(TAG) \ .