@ -1,12 +1,29 @@
# ===================================================================
# Stage 1: Build the Rust backend
# Stage 1: Build the frontend
# ===================================================================
FROM node:22-alpine AS frontend-builder
WORKDIR /app
# Copy package files first for dependency caching
COPY frontend/package.json frontend/package-lock.json ./
RUN npm ci
# Copy source and build
COPY frontend/ ./
RUN npm run build
# ===================================================================
# Stage 2: Build the Rust backend
# ===================================================================
FROM rust:1.85-bookworm AS builder
WORKDIR /app
# Copy manifests first for dependency caching
COPY Cargo.toml Cargo.lock ./
COPY backend/ Cargo.toml backend/ Cargo.lock ./
# Create a dummy main.rs to build dependencies
RUN mkdir src && echo "fn main() {}" > src/main.rs
@ -14,8 +31,8 @@ RUN cargo build --release
RUN rm -rf src
# Copy the actual source code and migrations
COPY src/ src/
COPY migrations/ migrations/
COPY backend/ src/ src/
COPY backend/ migrations/ migrations/
# Set sqlx offline mode (no live DB needed during build)
ENV SQLX_OFFLINE = true
@ -26,7 +43,7 @@ RUN touch src/main.rs
RUN cargo build --release
# ===================================================================
# Stage 2 : Minimal runtime image
# Stage 3 : Minimal runtime image
# ===================================================================
FROM debian:bookworm-slim AS runtime
@ -50,6 +67,9 @@ COPY --from=builder /app/target/release/ai-synth-backend ./ai-synth-backend
# Copy migrations (run at startup)
COPY --from= builder /app/migrations/ ./migrations/
# Copy built frontend
COPY --from= frontend-builder /app/dist/ ./static/
# Set ownership
RUN chown -R appuser:appuser /app