Spaces:
Running
Running
| # βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| # CodeSentry β Hugging Face Spaces Docker Image | |
| # Serves FastAPI backend + React frontend from a single container | |
| # βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| # ββ Stage 1: Build the React frontend ββββββββββββββββββββββ | |
| FROM node:20-slim AS frontend-builder | |
| WORKDIR /build | |
| COPY codesentry-frontend/package.json codesentry-frontend/package-lock.json ./ | |
| RUN npm install | |
| COPY codesentry-frontend/ ./ | |
| # In HF Spaces the frontend talks to the same origin (backend serves static) | |
| ENV VITE_MOCK_MODE=false | |
| ENV VITE_API_URL= | |
| RUN npm run build | |
| # ββ Stage 2: Production image βββββββββββββββββββββββββββββ | |
| FROM python:3.11-slim | |
| # Hugging Face Spaces expects port 7860 | |
| ENV PORT=7860 | |
| ENV HOST=0.0.0.0 | |
| ENV RELOAD=false | |
| # Install system dependencies | |
| RUN apt-get update && apt-get install -y --no-install-recommends \ | |
| curl \ | |
| git \ | |
| && rm -rf /var/lib/apt/lists/* | |
| # Create a non-root user (HF Spaces requirement) | |
| RUN useradd -m -u 1000 user | |
| USER user | |
| ENV HOME=/home/user | |
| ENV PATH="/home/user/.local/bin:$PATH" | |
| WORKDIR /home/user/app | |
| # Install Python dependencies | |
| COPY --chown=user codesentry-backend/requirements.txt ./requirements.txt | |
| RUN pip install --no-cache-dir --upgrade pip && \ | |
| pip install --no-cache-dir -r requirements.txt | |
| # Copy backend source | |
| COPY --chown=user codesentry-backend/ ./ | |
| # Copy the pre-built frontend into a static directory the backend will serve | |
| COPY --from=frontend-builder --chown=user /build/dist ./static | |
| # Expose the port | |
| EXPOSE 7860 | |
| # Launch the FastAPI server | |
| CMD ["python", "-m", "uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"] | |