|
| 1 | +# ============================================================================= |
| 2 | +# Stage 1: Build – compile translations, build static assets, build wheel |
| 3 | +# ============================================================================= |
| 4 | +FROM python:3.12-slim AS builder |
| 5 | + |
| 6 | +WORKDIR /build |
| 7 | + |
| 8 | +# Install Node.js 18, build tools, and libpq headers for psycopg2 |
| 9 | +RUN apt-get update && apt-get install -y --no-install-recommends \ |
| 10 | + build-essential \ |
| 11 | + libpq-dev \ |
| 12 | + curl \ |
| 13 | + ca-certificates \ |
| 14 | + && curl -fsSL https://deb.nodesource.com/setup_18.x | bash - \ |
| 15 | + && apt-get install -y --no-install-recommends nodejs \ |
| 16 | + && rm -rf /var/lib/apt/lists/* |
| 17 | + |
| 18 | +# Install Python build tools |
| 19 | +RUN pip install --no-cache-dir --upgrade pip babel hatchling hatch-regex-commit build |
| 20 | + |
| 21 | +# Copy the full source tree |
| 22 | +COPY . . |
| 23 | + |
| 24 | +# Build JavaScript/CSS static assets |
| 25 | +RUN npm ci && npm run build |
| 26 | + |
| 27 | +# Compile gettext .po → .mo translation files |
| 28 | +RUN pybabel compile --domain=messages --directory=fief/locale |
| 29 | + |
| 30 | +# Build the Python wheel |
| 31 | +RUN python -m build --wheel --outdir /build/dist |
| 32 | + |
| 33 | +# ============================================================================= |
| 34 | +# Stage 2: Runtime image |
| 35 | +# ============================================================================= |
| 36 | +FROM python:3.12-slim |
| 37 | + |
| 38 | +WORKDIR /app |
| 39 | + |
| 40 | +ENV PYTHONUNBUFFERED=1 |
| 41 | + |
| 42 | +# Install runtime system dependencies: |
| 43 | +# - libpq-dev / libpq5 for psycopg2 |
| 44 | +# - redis-server (bundled, no separate Redis pod needed) |
| 45 | +# - supervisor to manage multiple processes |
| 46 | +RUN apt-get update && apt-get install -y --no-install-recommends \ |
| 47 | + build-essential \ |
| 48 | + libpq-dev \ |
| 49 | + redis-server \ |
| 50 | + supervisor \ |
| 51 | + && rm -rf /var/lib/apt/lists/* |
| 52 | + |
| 53 | +# Install the wheel built in stage 1 |
| 54 | +COPY --from=builder /build/dist/*.whl /tmp/ |
| 55 | +RUN pip install --no-cache-dir --upgrade pip \ |
| 56 | + && pip install --no-cache-dir /tmp/*.whl \ |
| 57 | + && rm /tmp/*.whl |
| 58 | + |
| 59 | +# Trim build-only system packages |
| 60 | +RUN apt-get purge -y --auto-remove build-essential && rm -rf /var/lib/apt/lists/* |
| 61 | + |
| 62 | +# Create persistent data directory (used when DATABASE_TYPE=SQLITE) |
| 63 | +RUN mkdir -p /data/db |
| 64 | + |
| 65 | +COPY docker/supervisord.conf /etc/supervisord.conf |
| 66 | + |
| 67 | +# Runtime environment defaults (override via k8s Secrets / ConfigMaps) |
| 68 | +ENV DATABASE_LOCATION=/data/db |
| 69 | +ENV SECRETS_DIR=/run/secrets |
| 70 | +ENV PORT=8000 |
| 71 | + |
| 72 | +EXPOSE 8000 |
| 73 | + |
| 74 | +CMD ["supervisord", "-c", "/etc/supervisord.conf"] |
0 commit comments