Repository navigation
Expand file tree
/
Copy pathDockerfile
More file actions
52 lines (44 loc) · 2.31 KB
/
Copy pathDockerfile
File metadata and controls
52 lines (44 loc) · 2.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# ─── Stage 1: frontend build ────────────────────────────────────────────────
# The Vite output is architecture-independent. Build it once on the native
# runner architecture instead of executing Node through QEMU for arm64 (which
# can crash with SIGILL during npm ci), then copy the static files into both
# runtime architectures.
FROM --platform=$BUILDPLATFORM node:22-alpine AS frontend
WORKDIR /build
COPY frontend/package.json frontend/package-lock.json ./
RUN npm ci --no-fund --no-audit
COPY frontend/ ./
RUN npm run build
# ─── Stage 2: backend dependencies ──────────────────────────────────────────
FROM python:3.13-slim AS backend-deps
COPY --from=ghcr.io/astral-sh/uv:0.5 /uv /usr/local/bin/uv
WORKDIR /app
ENV UV_LINK_MODE=copy UV_PYTHON_DOWNLOADS=never
COPY backend/pyproject.toml backend/uv.lock ./
RUN uv sync --frozen --no-dev
# ─── Stage 3: runtime ───────────────────────────────────────────────────────
FROM python:3.13-slim
RUN groupadd -r -g 1000 tvguide \
&& useradd -r -u 1000 -g tvguide -d /app -s /usr/sbin/nologin tvguide \
&& mkdir -p /data \
&& chown tvguide:tvguide /data
WORKDIR /app
ENV PATH="/app/.venv/bin:$PATH" \
PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1 \
MALLOC_ARENA_MAX=2 \
DATA_DIR=/data \
APP_PORT=8080
COPY --from=backend-deps --chown=tvguide:tvguide /app/.venv /app/.venv
COPY --chown=tvguide:tvguide backend/app /app/app
COPY --chown=tvguide:tvguide backend/alembic /app/alembic
COPY --chown=tvguide:tvguide backend/alembic.ini /app/alembic.ini
COPY --from=frontend --chown=tvguide:tvguide /build/dist /app/app/static
COPY --chown=tvguide:tvguide docker/entrypoint.sh /app/entrypoint.sh
RUN chmod +x /app/entrypoint.sh
USER tvguide
EXPOSE 8080
VOLUME ["/data"]
HEALTHCHECK --interval=30s --timeout=5s --retries=3 --start-period=20s \
CMD ["python", "-c", "import os,urllib.request,sys; sys.exit(0 if urllib.request.urlopen(f\"http://127.0.0.1:{os.environ.get('APP_PORT','8080')}/api/health\", timeout=4).status == 200 else 1)"]
ENTRYPOINT ["/app/entrypoint.sh"]