Misbah commited on
Commit
f3153ad
·
1 Parent(s): 4506ba8

update Dockerfile for HF Spaces (non-root user, proper permissions)

Browse files
Files changed (1) hide show
  1. Dockerfile +20 -15
Dockerfile CHANGED
@@ -1,31 +1,36 @@
1
  FROM python:3.10-slim
2
 
 
 
 
 
3
  WORKDIR /app
4
 
5
- # install system deps
6
  RUN apt-get update && apt-get install -y --no-install-recommends \
7
  build-essential \
8
  && rm -rf /var/lib/apt/lists/*
9
 
10
- # copy requirements first for layer caching
11
- COPY requirements.txt .
12
- RUN pip install --no-cache-dir -r requirements.txt
 
 
 
 
 
 
 
 
13
 
14
- # copy source code
15
- COPY src/ src/
16
- COPY frontend/ frontend/
17
- COPY setup.py .
18
- COPY .env.example .env
19
 
20
- # HF Spaces sets PORT=7860 by default
21
  ENV PORT=7860
22
  ENV PYTHONUNBUFFERED=1
23
 
24
- # the data pipeline runs on first startup via the lifespan hook
25
- # but we can also pre-run it in the build step for faster cold starts
26
- # NOTE: this requires the OPENAI_API_KEY to be set as a build secret
27
- # If not available, setup will run at first request instead
28
-
29
  EXPOSE 7860
30
 
31
  CMD ["uvicorn", "src.api:app", "--host", "0.0.0.0", "--port", "7860"]
 
1
  FROM python:3.10-slim
2
 
3
+ # HF Spaces requires a non-root user
4
+ RUN useradd -m -u 1000 user
5
+ ENV PATH="/home/user/.local/bin:$PATH"
6
+
7
  WORKDIR /app
8
 
9
+ # system deps
10
  RUN apt-get update && apt-get install -y --no-install-recommends \
11
  build-essential \
12
  && rm -rf /var/lib/apt/lists/*
13
 
14
+ # install python deps first (layer caching)
15
+ COPY --chown=user requirements.txt .
16
+ RUN pip install --no-cache-dir --upgrade -r requirements.txt
17
+
18
+ # copy project files
19
+ COPY --chown=user src/ src/
20
+ COPY --chown=user frontend/ frontend/
21
+ COPY --chown=user evaluation/ evaluation/
22
+ COPY --chown=user setup.py .
23
+ COPY --chown=user README.md .
24
+ COPY --chown=user .env.example .env
25
 
26
+ # writable dirs for data pipeline + logs
27
+ RUN mkdir -p /app/data/processed && chown -R user:user /app
28
+
29
+ USER user
 
30
 
 
31
  ENV PORT=7860
32
  ENV PYTHONUNBUFFERED=1
33
 
 
 
 
 
 
34
  EXPOSE 7860
35
 
36
  CMD ["uvicorn", "src.api:app", "--host", "0.0.0.0", "--port", "7860"]