# Stage 1: Build React Frontend FROM node:24-slim AS frontend-builder WORKDIR /app/algospaced-ui RUN npm install -g npm@12.0.2 --loglevel=error COPY algospaced-ui/package*.json ./ RUN npm ci --loglevel=error --no-audit --no-fund COPY algospaced-ui/ ./ RUN npm run build # Stage 2: Python Backend FROM python:3.14-slim COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/ WORKDIR /app # Set up non-root user for Hugging Face Spaces (UID 1000) RUN useradd -m -u 1000 user && \ chown -R user:user /app # Switch to non-root user early USER user ENV HOME=/home/user \ PATH=/home/user/.local/bin:$PATH \ PORT=7860 # Install python dependencies via uv sync COPY --chown=user:user pyproject.toml uv.lock ./ RUN uv sync --frozen --no-install-project # Add the virtual environment to PATH ENV PATH="/app/.venv/bin:$PATH" # Copy application source and assets COPY --chown=user:user *.py schema.sql README.md ./ COPY --chown=user:user core/ ./core/ COPY --chown=user:user routers/ ./routers/ COPY --chown=user:user src/ ./src/ RUN mkdir -p /app/data /app/scratch # Sync the project itself RUN uv sync --frozen # Ensure the fresh build from Stage 1 is used COPY --from=frontend-builder --chown=user:user /app/algospaced-ui/dist /app/algospaced-ui/dist EXPOSE 7860 CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]