File size: 910 Bytes
fbcf103
746fab9
 
fbcf103
746fab9
 
fbcf103
746fab9
 
fbcf103
 
 
 
746fab9
 
fbcf103
 
 
 
 
 
 
 
 
 
746fab9
fbcf103
746fab9
 
fbcf103
 
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
# 1. Use the official Python image (starts as root)
FROM python:3.12-slim

# 2. Install uv for fast dependency installation
COPY --from=ghcr.io/astral-sh/uv:0.4.20 /uv /bin/uv

# 3. Set the working directory
WORKDIR /app

# 4. Copy requirements and install AS ROOT 
# (Root has permission to write to /usr/local/lib/python3.12)
COPY requirements.txt .
ENV UV_SYSTEM_PYTHON=1
RUN uv pip install -r requirements.txt

# 5. Create the non-root user (UID 1000 is required by Hugging Face)
RUN useradd -m -u 1000 user

# 6. Copy the rest of your app and change ownership to the 'user'
COPY . .
RUN chown -R user:user /app

# 7. Switch to the non-root user for security at runtime
USER user
ENV PATH="/home/user/.local/bin:$PATH"

# 8. Tell HF which port to use
EXPOSE 7860

# 9. Start the app (using Gunicorn is recommended for production)
CMD ["gunicorn", "--bind", "0.0.0.0:7860", "--timeout", "120", "app:server"]