Same routes, same Docker topology, same env vars. Frontend untouched.
Backend swap:
- Hono on Node -> FastAPI on Python 3.12, served by uvicorn behind Caddy.
- Drizzle on Node -> SQLAlchemy 2.0 async (asyncpg driver) with declarative
models that mirror the previous schema 1:1. Migrations are still plain
SQL files (apps/api/app/migrations/) run idempotently at startup by
app/db/migrate.py via asyncpg, tracking each file's sha256 in a
schema_migrations table.
- aws4fetch -> boto3 wrapped in asyncio.to_thread so the async routes
do not block on MinIO/S3 calls. The presign_put / init_multipart /
complete_multipart / head / delete contract is unchanged so the React
client sees the same /api/uploads/* payloads.
- Cookie+JWT admin auth -> pyjwt + FastAPI Cookie() dependency.
constant-time password compare. Same 7-day HttpOnly cookie shape.
- QR code: qrcode lib + reportlab. /api/qrcode keeps format=png|svg|pdf;
the PDF is still A6 with the couple's names + 'Aponte a câmera' CTA.
- Pydantic-settings replaces the zod env loader and still fails fast
on missing required vars.
Routes ported with identical paths and JSON shapes:
- public: /api/event, /api/gallery, /api/qrcode, /api/stats
- uploads: /api/uploads/init, /{id}/confirm, /{id}/abort
- admin: /login, /logout, /me, /event (GET+PATCH), /uploads (GET with
?status, ?kind=photo|video, ?q= for search), /uploads/{id} (PATCH
for author/message edit), /uploads/{id}/{approve,reject,cover},
/uploads/{id} (DELETE), /event/cover (DELETE), /uploads/bulk, /stats.
Build pipeline:
- Dockerfile: stage 1 builds the React/Vite SPA with pnpm; stage 2 is
python:3.12-slim that installs deps via uv (fast, reproducible),
copies the app/, and copies the SPA dist from stage 1 into /app/public
so the FastAPI process serves both /api/* and the SPA assets.
- docker-compose.yml unchanged: postgres + minio + minio-init + app +
caddy. Same env vars (DATABASE_URL, S3_*, ADMIN_PASSWORD, SESSION_SECRET,
ALLOWED_ADMIN_EMAILS, AUTO_MIGRATE).
- Removed apps/api from the pnpm workspace; root package.json now only
scripts the web. Makefile centralizes dev/build/docker commands so
the Python side has the same DX as the Node side did.
45 lines
1.2 KiB
Docker
45 lines
1.2 KiB
Docker
# ---- Stage 1: build the React/Vite SPA with pnpm ----
|
|
FROM node:22-alpine AS web-build
|
|
RUN apk add --no-cache libc6-compat
|
|
RUN corepack enable && corepack prepare pnpm@9.12.0 --activate
|
|
|
|
WORKDIR /app
|
|
COPY pnpm-workspace.yaml package.json pnpm-lock.yaml ./
|
|
COPY packages/shared/package.json packages/shared/
|
|
COPY apps/web/package.json apps/web/
|
|
RUN pnpm install --frozen-lockfile
|
|
|
|
COPY tsconfig.base.json ./
|
|
COPY packages/shared packages/shared
|
|
COPY apps/web apps/web
|
|
RUN pnpm -F @leetete/web build
|
|
|
|
|
|
# ---- Stage 2: Python runtime ----
|
|
FROM python:3.12-slim AS runtime
|
|
ENV PYTHONUNBUFFERED=1 \
|
|
PYTHONDONTWRITEBYTECODE=1 \
|
|
PIP_DISABLE_PIP_VERSION_CHECK=1 \
|
|
PIP_NO_CACHE_DIR=1 \
|
|
PORT=3000 \
|
|
STATIC_DIR=/app/public
|
|
|
|
# Install uv (faster than pip for resolution + install)
|
|
RUN pip install --no-cache-dir uv==0.5.4
|
|
|
|
WORKDIR /app/apps/api
|
|
|
|
# Install Python dependencies into the system interpreter
|
|
COPY apps/api/pyproject.toml ./
|
|
RUN uv pip install --system --no-cache .
|
|
|
|
# Copy app source
|
|
COPY apps/api/app ./app
|
|
|
|
# Copy built web static assets from stage 1
|
|
COPY --from=web-build /app/apps/web/dist /app/public
|
|
|
|
EXPOSE 3000
|
|
|
|
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "3000", "--proxy-headers", "--forwarded-allow-ips=*"]
|