Phase 33 (story: .agent/user_stories/cache-busting.md). - app/core/caching.py: asset_version() — git short SHA (a commit is a deploy), stable content-hash fallback for non-git checkouts, "dev" for a missing static dir; computed once per process. CachingMiddleware — the five HTML pages revalidate (no-cache) with ?v=<token> asset refs rewritten in flight; /assets/* is public, max-age=31536000, immutable; everything else (all /api/*, the SSE chat stream in particular) passes through byte-identical. - tests/e2e/test_cache_busting.py: fresh-Chromium wire assertions — document no-cache, versioned CSS/JS request URLs sharing one token, immutable asset headers, /api/health baseline headers, SSE chat to done (mock LLM). - README 'Caching / deploys' section + story file. Also fixed two prod-image defects surfaced by this phase's podman smoke (the full app would not boot): - Containerfile: ship the scripts/ package — app/api/sync.py (phase 32) imports scripts.git_sync / scripts.import_docs at module level, so the container crashed on boot (ModuleNotFoundError: No module named 'scripts'). - compose.yaml: pass BOR_ADMIN_PASSWORD / BOR_SESSION_SECRET through to the app service (:- defaults keep 'podman compose up -d db' working; the app's own fail-loud gate still names missing admin auth). Smoke: podman compose --profile prod up -d on a fresh image + a fresh Chromium profile — /, /sources.html and /login.html all served Cache-Control: no-cache; all 8 asset requests versioned with one shared token (content-hash fallback inside the image — no .git there); /assets/* immutable for a year.
61 lines
2.9 KiB
Docker
61 lines
2.9 KiB
Docker
# syntax=docker/dockerfile:1
|
|
# Brain of Reese — production image (Podman/Docker compatible).
|
|
#
|
|
# Stage 1 (frontend): minify/bundle the local frontend with esbuild.
|
|
# NO CDN — every asset is built into this image.
|
|
# Stage 2 (python): install dependencies with uv (locked).
|
|
# Stage 3 (runtime): slim, non-root, migrations + uvicorn.
|
|
|
|
# ---------- Stage 1: frontend ----------
|
|
FROM docker.io/node:22-alpine AS frontend
|
|
WORKDIR /build
|
|
# Global install: puts the pinned esbuild binary on the PATH for the build step below
|
|
# (a local `npm install` leaves it in node_modules/.bin, invisible to RUN).
|
|
RUN npm install --no-audit --no-fund -g esbuild@0.25.5
|
|
COPY frontend ./
|
|
RUN mkdir -p /out/assets \
|
|
&& esbuild ./assets/app.js --bundle --minify --format=esm --target=es2022 --outfile=/out/assets/app.js \
|
|
&& esbuild ./assets/sources.js --bundle --minify --format=esm --target=es2022 --outfile=/out/assets/sources.js \
|
|
&& esbuild ./assets/document.js --bundle --minify --format=esm --target=es2022 --outfile=/out/assets/document.js \
|
|
&& esbuild ./assets/login.js --bundle --minify --format=esm --target=es2022 --outfile=/out/assets/login.js \
|
|
&& esbuild ./assets/tuning.js --bundle --minify --format=esm --target=es2022 --outfile=/out/assets/tuning.js \
|
|
&& esbuild ./assets/markdown.js --minify --outfile=/out/assets/markdown.js \
|
|
&& esbuild ./assets/styles.css --minify --outfile=/out/assets/styles.css \
|
|
&& cp ./index.html ./sources.html ./document.html ./login.html ./tuning.html /out/
|
|
|
|
# ---------- Stage 2: python dependencies ----------
|
|
FROM docker.io/python:3.12-slim AS python
|
|
WORKDIR /app
|
|
COPY --from=ghcr.io/astral-sh/uv:latest /uv /usr/local/bin/uv
|
|
COPY pyproject.toml uv.lock ./
|
|
RUN uv sync --frozen --no-dev --no-cache --no-install-project
|
|
COPY app ./app
|
|
RUN uv sync --frozen --no-dev --no-cache
|
|
|
|
# ---------- Stage 3: runtime ----------
|
|
FROM docker.io/python:3.12-slim AS runtime
|
|
ENV PATH="/app/.venv/bin:$PATH" \
|
|
PYTHONUNBUFFERED=1 \
|
|
PYTHONDONTWRITEBYTECODE=1 \
|
|
BOR_STATIC_DIR=/app/static \
|
|
BOR_ENVIRONMENT=production
|
|
RUN useradd --create-home --uid 10001 reese
|
|
WORKDIR /app
|
|
COPY --from=python /app/.venv /app/.venv
|
|
COPY --from=python /app/app /app/app
|
|
# app/api/sync.py (phase 32) imports scripts.git_sync / scripts.import_docs
|
|
# at module level — the scripts package must ship in the image or the
|
|
# container crashes on boot (phase 33: ModuleNotFoundError: No module
|
|
# named 'scripts').
|
|
COPY scripts ./scripts
|
|
COPY --from=frontend /out /app/static
|
|
COPY alembic ./alembic
|
|
COPY alembic.ini ./alembic.ini
|
|
COPY scripts/entrypoint.sh /usr/local/bin/entrypoint.sh
|
|
RUN chmod +x /usr/local/bin/entrypoint.sh && chown -R reese:reese /app
|
|
USER reese
|
|
EXPOSE 8000
|
|
HEALTHCHECK --interval=30s --timeout=5s --start-period=30s --retries=5 \
|
|
CMD ["python", "-c", "import sys, httpx; sys.exit(0 if httpx.get('http://127.0.0.1:8000/api/health', timeout=4).status_code == 200 else 1)"]
|
|
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
|