-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
29 lines (27 loc) · 1.25 KB
/
Copy pathDockerfile
File metadata and controls
29 lines (27 loc) · 1.25 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
# Stage 1: Build frontend
FROM node:20-alpine AS frontend-build
WORKDIR /app/frontend
COPY frontend/package*.json ./
RUN npm ci
COPY frontend/ ./
ARG CACHEBUST=1
RUN npm run build
# Stage 2: Python backend + serve built frontend
FROM python:3.12-slim
WORKDIR /app
COPY backend/requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt
COPY backend/ ./
COPY --from=frontend-build /app/frontend/dist ./static
ENV PORT=8000
ENV PYTHONUNBUFFERED=1
EXPOSE ${PORT}
# Run Alembic migrations, then start the server.
# Seed categories/laws as well so a fresh DB has reference data.
# Startup:
# 1. Create base tables (no-op if they exist) — handles fresh Postgres DBs
# 2. Stamp alembic head so migrations know baseline was just created
# 3. Run any migrations after head (no-op on first boot; applies new migrations on subsequent deploys)
# 4. Seed reference data (categories, laws)
# 5. Start server
CMD ["sh", "-c", "python -c 'from app.database import Base, engine; Base.metadata.create_all(bind=engine); print(\"base tables ensured\")' && alembic stamp head 2>/dev/null; alembic upgrade head && python -c 'from app.database import seed_categories_and_laws; seed_categories_and_laws()' && uvicorn app.main:app --host 0.0.0.0 --port $PORT --workers 1 --log-level info"]