File size: 1,661 Bytes
51e559a |
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 |
# =======================
# 1️⃣ Frontend build stage
# =======================
FROM node:22-slim AS frontend-builder
# Install pnpm globally
RUN corepack enable && corepack prepare pnpm@latest --activate
# Set working directory
WORKDIR /app/frontend
# Copy package files first for caching
COPY frontend/pnpm-lock.yaml frontend/package.json ./
# Install dependencies (prod only for frontend)
RUN pnpm install --frozen-lockfile
# Copy the rest of the frontend source
COPY frontend/ ./
# Build frontend
ENV VITE_APP_ENV=production
RUN pnpm build
# =======================
# 2️⃣ Backend build stage
# =======================
FROM python:3.12-slim AS backend-builder
# Install uv (fast Python package installer)
RUN pip install --no-cache-dir uv
# Set working directory
WORKDIR /app
# Copy backend requirements and install (no dev deps)
COPY backend/pyproject.toml backend/uv.lock ./backend/
RUN cd backend && uv pip install --no-cache-dir --system .
# Copy backend source
COPY backend/ ./backend/
# Copy built frontend from stage 1
COPY --from=frontend-builder /app/frontend/dist ./frontend/dist
# =======================
# 3️⃣ Production runtime
# =======================
FROM python:3.12-slim
# Create non-root user
RUN useradd -m appuser
WORKDIR /app
# Copy installed packages and app
COPY --from=backend-builder /usr/local /usr/local
COPY --from=backend-builder /app /app
# Set frontend path for FastAPI
ENV FRONTEND_PATH=/app/frontend/dist
# Switch to non-root user
USER appuser
# Expose port (adjust if needed)
EXPOSE 8000
# Run FastAPI via uvicorn
CMD ["uvicorn", "backend.src.app:app", "--host", "0.0.0.0", "--port", "8000"]
|