matrix-terminal-posthog-cv/Dockerfile
2026-08-11 14:20:56 +01:00

46 lines
1.5 KiB
Docker

# syntax=docker/dockerfile:1
FROM python:3.13-slim AS builder
COPY --from=ghcr.io/astral-sh/uv:0.10.9 /uv /uvx /bin/
WORKDIR /app
ENV UV_COMPILE_BYTECODE=1 \
UV_LINK_MODE=copy \
UV_PYTHON_INSTALL_DIR=/python \
UV_PYTHON_PREFERENCE=only-managed
RUN uv python install 3.13
COPY pyproject.toml uv.lock ./
RUN --mount=type=cache,target=/root/.cache/uv \
uv sync --frozen --no-dev --no-install-project
COPY app ./app
COPY web ./web
# Minify CSS/JS in place and cache-bust with a build-timestamp query string
RUN --mount=type=cache,target=/root/.cache/uv \
uv sync --frozen --group dev --no-install-project && \
uv run --no-sync python -m rcssmin < web/static/css/style.css > /tmp/style.css && \
mv /tmp/style.css web/static/css/style.css && \
for f in web/static/js/*.js; do \
uv run --no-sync python -m rjsmin < "$f" > /tmp/js.tmp && mv /tmp/js.tmp "$f"; \
done && \
BUILD_ID=$(date +%s) && \
sed -i "s#\(\./[a-z-]*\.js\)#\1?v=${BUILD_ID}#g" web/static/js/app.js && \
sed -i "s#/static/css/style.css#/static/css/style.css?v=${BUILD_ID}#; s#/static/js/app.js#/static/js/app.js?v=${BUILD_ID}#" web/index.html web/login.html
RUN uv sync --frozen --no-dev
# ---- runtime image: no uv, no build cache, no extra chown layer ----
FROM gcr.io/distroless/python3-debian12:nonroot
WORKDIR /app
ENV PATH="/app/.venv/bin:$PATH"
COPY --from=builder /python /python
COPY --from=builder --chown=nonroot:nonroot /app /app
EXPOSE 8000
ENTRYPOINT ["python", "-m", "uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"]