Repository navigation
Expand file tree
/
Copy pathDockerfile
More file actions
96 lines (83 loc) · 4.28 KB
/
Copy pathDockerfile
File metadata and controls
96 lines (83 loc) · 4.28 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# syntax=docker/dockerfile:1
# ---------------------------------------------------------------------------
# Stage 1: build the SPA
# ---------------------------------------------------------------------------
FROM docker.io/library/node:22-alpine AS web
WORKDIR /web
RUN corepack enable
ENV npm_config_store_dir=/pnpm-store
# pnpm-workspace.yaml carries the allowBuilds policy: esbuild's install script is
# approved deliberately (pnpm 11+ blocks dependency scripts by default) because
# Vite needs the platform binary it places.
COPY apps/web/package.json apps/web/pnpm-workspace.yaml apps/web/pnpm-lock.yaml* ./
# The lockfile is committed, so a cached, reproducible install is the only
# acceptable outcome here. Falling back to a resolving install would silently
# build a different dependency tree than the one that was tested.
RUN --mount=type=cache,target=/pnpm-store pnpm install --frozen-lockfile
COPY apps/web/ ./
RUN pnpm run build
# ---------------------------------------------------------------------------
# Stage 2: resolve Python dependencies
# ---------------------------------------------------------------------------
FROM docker.io/library/python:3.12-slim AS pybuild
COPY --from=ghcr.io/astral-sh/uv:0.12.23 /uv /uvx /usr/local/bin/
ENV UV_COMPILE_BYTECODE=1 \
UV_LINK_MODE=copy \
UV_PYTHON_DOWNLOADS=never
WORKDIR /app
COPY pyproject.toml README.md ./
# Dependency layer first so source edits do not invalidate it.
RUN --mount=type=cache,target=/root/.cache/uv \
uv sync --no-install-project --no-dev --no-editable
COPY src/ ./src/
COPY migrations/ ./migrations/
COPY alembic.ini ./
RUN --mount=type=cache,target=/root/.cache/uv \
uv sync --no-dev --no-editable
# ---------------------------------------------------------------------------
# Stage 3: runtime
# ---------------------------------------------------------------------------
FROM docker.io/library/python:3.12-slim AS runtime
ENV PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1 \
PATH="/app/.venv/bin:$PATH" \
WEB_DIST_DIR=/app/web
RUN groupadd --system --gid 10001 appuser \
&& useradd --system --uid 10001 --gid appuser --home-dir /app --shell /usr/sbin/nologin appuser
WORKDIR /app
COPY --from=pybuild --chown=10001:10001 /app/.venv /app/.venv
COPY --from=pybuild --chown=10001:10001 /app/src /app/src
COPY --from=pybuild --chown=10001:10001 /app/migrations /app/migrations
COPY --from=pybuild --chown=10001:10001 /app/alembic.ini /app/alembic.ini
COPY --from=web --chown=10001:10001 /web/dist /app/web
USER 10001:10001
EXPOSE 8080
# Liveness only: must not depend on Postgres or Jellyfin.
HEALTHCHECK --interval=30s --timeout=5s --start-period=15s --retries=3 \
CMD python -c "import urllib.request,sys; sys.exit(0 if urllib.request.urlopen('http://127.0.0.1:8080/api/health', timeout=4).status == 200 else 1)"
CMD ["uvicorn", "metaedit.main:app", "--host", "0.0.0.0", "--port", "8080", "--no-access-log"]
# ---------------------------------------------------------------------------
# Stage 4: test fixtures
#
# A separate target so the `runtime` stage above stays deployable and ships no test
# code. It exists because the e2e seed needs the app's own package to write through the
# real archive, and mounting the script from the host made it unreadable to the
# unprivileged user the image runs as.
#
# This must stay the LAST stage in the file. Docker's default target is the final
# stage, and the multi-arch publish job builds without naming one -- so a built image
# runs whatever this stage runs. When `seed` was last, `ghcr.io/.../metaedit:main`
# started the seed script instead of the server and failed its own health check.
# ---------------------------------------------------------------------------
FROM runtime AS seed
COPY --chown=10001:10001 tests/e2e/seed_archive.py /app/seed_archive.py
CMD ["python", "/app/seed_archive.py"]
# ---------------------------------------------------------------------------
# Stage 5: unbreakable default target
#
# The publish pipeline builds with no `--target`. Rather than rely on reading
# order to decide what gets shipped, the default target is declared: packaging
# bookkeeping only, no filesystem changes. Anything added below this line
# silently changes what the registry serves.
# ---------------------------------------------------------------------------
FROM runtime AS release