Spaces:
Running
Running
File size: 2,030 Bytes
7b4f5dd 04bc2e9 7b4f5dd 4ed28a0 7b4f5dd 8f2289d 7b4f5dd | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | # βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
# 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"]
|