# Stage 1: Build the React frontend FROM node:20-alpine AS frontend-builder WORKDIR /app/frontend # Copy package files and install dependencies COPY algospaced-ui/package*.json ./ RUN npm install # Copy the rest of the frontend source code COPY algospaced-ui/ ./ # Run the build RUN npm run build # Stage 2: Run the FastAPI backend FROM python:3.11-slim WORKDIR /app # Install system dependencies RUN apt-get update && apt-get install -y --no-install-recommends \ build-essential \ && rm -rf /var/lib/apt/lists/* # Install python dependencies COPY requirements.txt ./ RUN pip install --no-cache-dir -r requirements.txt # Copy all source files COPY . . # Copy compiled frontend from Stage 1 into the backend's static directory COPY --from=frontend-builder /app/frontend/dist ./algospaced-ui/dist # Expose port (Render/Railway will set PORT env var, default to 8000) ENV PORT=8000 CMD uvicorn main:app --host 0.0.0.0 --port $PORT