File size: 1,443 Bytes
bf6e4b4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
84379ba
 
bf6e4b4
 
 
 
84379ba
 
 
bf6e4b4
 
 
 
 
 
 
7cf51ae
 
 
 
 
84379ba
7cf51ae
 
bf6e4b4
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
# Use an official lightweight Python image
FROM python:3.11-slim

# Create a non-root user (UID 1000 is required by Hugging Face Spaces)
RUN useradd -m -u 1000 user

# Set the working directory
WORKDIR /app

# Install system dependencies (required for Pillow and image processing)
RUN apt-get update && apt-get install -y \
    build-essential \
    libpq-dev \
    && rm -rf /var/lib/apt/lists/*

# Copy the requirements file from the backend folder first
COPY keystone-backend/requirements.txt .

# Install Python dependencies
RUN pip install --no-cache-dir -r requirements.txt

# Copy the contents of the backend folder into the container
# and assign ownership to the non-root user
COPY --chown=user:user keystone-backend/ .

# Switch to the non-root user
USER user

# Hugging Face Spaces route web traffic to port 7860
EXPOSE 7860

# Health check: verify the bucket at /data is mounted before reporting healthy.
# If the bucket is missing, the Space will show as unhealthy immediately.
HEALTHCHECK --interval=30s --timeout=10s --start-period=15s --retries=3 \
    CMD python -c "import os, sys; sys.exit(0 if os.path.exists('/data') else 1)"

# Start the FastAPI server (it will run main.py from the copied backend files)
# NOTE: main.py will raise a RuntimeError at startup if /data is not mounted,
#       ensuring photos are NEVER saved to ephemeral container storage.
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]