-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
73 lines (54 loc) · 2.75 KB
/
Copy pathDockerfile
File metadata and controls
73 lines (54 loc) · 2.75 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
# Stage 1: install Python dependencies into a venv. Kept separate from the
# runtime stage so that if a future dependency ever needs a C toolchain to
# build (none currently do - every dependency has a prebuilt wheel for this
# platform), only this stage grows, not the shipped image.
FROM python:3.12-slim AS backend-builder
COPY --from=ghcr.io/astral-sh/uv:latest /uv /usr/local/bin/uv
WORKDIR /app
COPY README.md ./
COPY backend/pyproject.toml backend/uv.lock ./backend/
WORKDIR /app/backend
RUN uv sync --frozen --no-dev --no-cache
# Stage 2: dump this app's own OpenAPI schema - frontend/src/client/ (the
# generated API client) is gitignored, never committed, and gets generated
# fresh from this in every build (see Makefile's `generate-client` for the
# same thing locally) rather than checked in, so it can never silently
# drift from the actual backend routes/models it's generated from. No live
# server/open port needed - see backend/scripts/dump_openapi.py.
FROM backend-builder AS openapi-schema
COPY backend/lnurl_server/ ./lnurl_server/
COPY backend/alembic.ini ./
COPY backend/migrations/ ./migrations/
COPY backend/scripts/ ./scripts/
# db.py's Users repo only queries the `users` table lazily, on first real
# access (not just from importing lnurl_server.server, which is all
# generating the schema needs) - migrating this stage's own throwaway
# sqlite db first is just cheap insurance against that changing later, not
# a hard requirement of the schema dump itself
RUN .venv/bin/alembic upgrade head && .venv/bin/python scripts/dump_openapi.py openapi.json
# Stage 3: build the SolidJS frontend
FROM node:24-alpine AS frontend-builder
WORKDIR /build
COPY frontend/package.json frontend/package-lock.json ./
RUN npm ci
COPY frontend/tsconfig.json frontend/vite.config.ts frontend/index.html frontend/favicon.ico frontend/openapi-ts.config.ts ./
COPY frontend/src ./src
COPY --from=openapi-schema /app/backend/openapi.json ./openapi.json
RUN npm run openapi-ts
RUN npm run build
# Stage 4: Python runtime with embedded frontend - no uv, no compilers, just
# the venv built above plus the app's own source
FROM python:3.12-slim AS runtime
WORKDIR /app/backend
COPY --from=backend-builder /app/backend/.venv ./.venv
COPY backend/lnurl_server/ ./lnurl_server/
COPY backend/alembic.ini ./
COPY backend/migrations/ ./migrations/
COPY --from=frontend-builder /build/dist ./dist
ENV FORWARDED_ALLOW_IPS=*
ENV PATH="/app/backend/.venv/bin:${PATH}"
# runtime settings (see lnurl_server/config.py) are read from real
# environment variables - pass them with `docker run --env-file backend/.env`
# (see backend/.env.template for what's available), no file needs copying in
EXPOSE 8000
CMD ["sh", "-c", "alembic upgrade head && fastapi run lnurl_server/server.py --host 0.0.0.0 --port 8000"]