Files
PyRIGS/Dockerfile
Joe Banks a29384a314 Bootstrap 5 & remove jQuery (#661)
* build: move frontend assets to Bootstrap 5.3 and Tom Select

* feat: migrate templates and scripts to Bootstrap 5, dropping jQuery

Templates
- Rename Bootstrap 4 classes and data attributes (data-bs-*, ms-/me-/ps-/pe-,
  text-start/end, form-group -> mb-3, input-group wrappers removed, badges,
  custom controls -> form-check/form-select, media -> d-flex, btn-close, ...)
- Dark mode now uses Bootstrap 5.3 colour modes (data-bs-theme on <html>),
  set from <head> to avoid a flash of the light theme
- Remove the Bootstrap 4 /bootstrap/ demo page
- Contextual table classes (table-success etc.) still work as plain
  backgrounds for the rigboard key

JavaScript
- Remove jQuery: src.js/interaction.js and every inline template script are
  rewritten in plain JS on top of small helpers (helpers.js, bundled with
  Bootstrap into jpop.js so inline scripts can use them)
- Replace bootstrap-select/ajax-bootstrap-select with Tom Select. The remote
  search now sends the `q` parameter and reads `text`, which is what the
  API actually uses (the old picker sent `term` and read `label`)
- HTML fragments are fetched with an X-Requested-With header so views keep
  rendering their modal variants, and fetched scripts are re-executed
- Remove the Bootstrap 4 plugin script includes

* fix: stop rigboard header buttons stretching to full width under Bootstrap 5

* fix: restore dark-mode brand colours and contextual table colours under Bootstrap 5

* fix: brighten dark-mode links and make coloured card outlines visible

* fix: calendar layout and grid borders, navbar search button width, guard missing modal links

* fix: readable text in dark-mode Tom Select inputs and placeholders, restore form-control column widths

* build: split the Dockerfile into cached stages with prod and dev targets

* deploy: make compose.yml development-only with live reload, and document it

* fix: keep badge text colour for links inside badges

* fix: restore table-bordered grid lines in dark mode

* fix: include Bootstrap's progress styles and keep progress labels readable
2026-10-02 16:28:11 +01:00

103 lines
3.7 KiB
Docker

# syntax=docker/dockerfile:1
#
# Targets:
# prod (default, last stage) gunicorn image with assets and static files baked in
# dev dependencies only; the source is bind-mounted by compose.override.yml
#
# Stages are ordered so that editing application code only invalidates the cheap final layers:
# apt packages, Python dependencies and node modules are all cached separately.
# ---- Frontend assets (multi-arch: official node image) ----
FROM node:24-slim AS assets
WORKDIR /app
COPY package.json package-lock.json ./
RUN --mount=type=cache,target=/root/.npm \
npm ci
COPY gulpfile.js ./
COPY pipeline/source_assets ./pipeline/source_assets
RUN npm run build
# ---- Shared Python base: runtime system libraries only ----
FROM python:3.14-slim-trixie AS python-base
# Keep downloaded packages between builds (the default Docker config for Debian images deletes them)
RUN rm -f /etc/apt/apt.conf.d/docker-clean \
&& echo 'Binary::apt::APT::Keep-Downloaded-Packages "true";' > /etc/apt/apt.conf.d/keep-cache
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
--mount=type=cache,target=/var/lib/apt,sharing=locked \
apt-get update \
&& apt-get install -y --no-install-recommends libcairo2
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
UV_PROJECT_ENVIRONMENT=/opt/venv \
UV_LINK_MODE=copy \
PATH="/opt/venv/bin:$PATH"
# ---- Python dependencies (only rebuilt when pyproject.toml / uv.lock change) ----
FROM python-base AS deps-base
COPY --from=ghcr.io/astral-sh/uv:0.12.21 /uv /uvx /bin/
# pycairo (via z3c.rml) has no wheels and is compiled against cairo
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
--mount=type=cache,target=/var/lib/apt,sharing=locked \
apt-get update \
&& apt-get install -y --no-install-recommends build-essential pkg-config libcairo2-dev
WORKDIR /app
FROM deps-base AS deps-prod
ENV UV_COMPILE_BYTECODE=1
RUN --mount=type=cache,target=/root/.cache/uv \
--mount=type=bind,source=uv.lock,target=uv.lock \
--mount=type=bind,source=pyproject.toml,target=pyproject.toml \
uv sync --frozen --no-install-project --no-dev
FROM deps-base AS deps-dev
RUN --mount=type=cache,target=/root/.cache/uv \
--mount=type=bind,source=uv.lock,target=uv.lock \
--mount=type=bind,source=pyproject.toml,target=pyproject.toml \
uv sync --frozen --no-install-project
# ---- Development: dependencies only, source and static assets are mounted at runtime ----
FROM python-base AS dev
COPY --from=deps-dev /opt/venv /opt/venv
WORKDIR /app
EXPOSE 8000
CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"]
# ---- Static files: depends on the source, so this is the first stage that reruns on a code change ----
FROM python-base AS static
COPY --from=deps-prod /opt/venv /opt/venv
WORKDIR /app
COPY . /app
COPY --from=assets /app/pipeline/built_assets /app/pipeline/built_assets
# Placeholder values only satisfy settings that are mandatory when DEBUG is off; they are not kept in the image
RUN DEBUG=false EMAIL_HOST=build EMAIL_HOST_USER=build EMAIL_HOST_PASSWORD=build EMAIL_FROM=build@example.com \
python manage.py collectstatic --noinput
# ---- Production image ----
FROM python-base AS prod
RUN addgroup --system app \
&& adduser --system --group --home /home/app app
COPY --from=deps-prod /opt/venv /opt/venv
WORKDIR /app
COPY --chown=app:app . /app
COPY --from=static --chown=app:app /app/static /app/static
COPY --from=assets --chown=app:app /app/pipeline/built_assets /app/pipeline/built_assets
# DEBUG must never be on in a built image; enable it explicitly via the environment if needed
ENV DEBUG=false
USER app
EXPOSE 8000
CMD ["gunicorn", "--bind", "0.0.0.0:8000", "--workers", "3", "PyRIGS.wsgi"]