# Build stage - Angular frontend
FROM docker.m.daocloud.io/node:24-alpine AS frontend-builder

WORKDIR /app/frontend
COPY frontend/ ./
RUN npm install
RUN npm run build -- --configuration production

# Production stage - FastAPI backend
FROM docker.m.daocloud.io/python:3.12-slim

WORKDIR /app

# Install dependencies
COPY backend/requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

# Copy backend code
COPY backend/app/ ./app/
COPY backend/db/ ./db/

# Copy Angular build output to web directory
COPY --from=frontend-builder /app/frontend/dist/frontend/browser ./web/

# Set environment variables
ENV PORT=8000
ENV WEB_DIR=/app/web

EXPOSE 8000

CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"]
