AlaBoussoffara commited on
Commit
7f38fd8
·
1 Parent(s): 4c58b1a

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +23 -13
Dockerfile CHANGED
@@ -1,33 +1,43 @@
1
  # Dockerfile — minimal image to run the Mini Transformer Chainlit UI
2
- # Uses a slim Python base. For GPU/CUDA you should use a CUDA-enabled base image
3
- # and install a matching torch wheel.
4
 
5
  FROM python:3.11-slim
6
 
7
- ENV PYTHONUNBUFFERED=1
8
- WORKDIR /app
 
 
 
 
9
 
10
- # Install build deps (kept minimal) and git for potential installs from repo
11
  RUN apt-get update \
12
  && apt-get install -y --no-install-recommends build-essential git curl \
13
  && rm -rf /var/lib/apt/lists/*
14
 
15
- # Copy project into the image
16
- COPY . /app
17
 
18
- # Upgrade pip
19
- RUN pip install --upgrade pip setuptools wheel
20
 
21
- # Install Python deps: prefer requirements.txt if present, otherwise install package with [server] extras
22
- RUN if [ -f requirements.txt ]; then \
 
23
  pip install -r requirements.txt; \
24
  else \
25
  pip install .[server]; \
26
  fi
27
 
28
- # Expose default Chainlit port
 
 
 
 
 
 
29
  EXPOSE 7860
30
  ENV PORT=7860
31
 
32
- # Default command: launch Chainlit to run the packaged chainlit_app
33
  CMD ["bash", "-c", "chainlit run src/mini_transformer/apps/chainlit_app.py --host 0.0.0.0 --port ${PORT}"]
 
1
  # Dockerfile — minimal image to run the Mini Transformer Chainlit UI
2
+ # Uses a slim Python base. For GPU/CUDA use a CUDA-enabled base image.
 
3
 
4
  FROM python:3.11-slim
5
 
6
+ # --- Create non-root user (HF Spaces runs as UID 1000) ---
7
+ RUN useradd -m -u 1000 user
8
+ ENV HOME=/home/user \
9
+ PATH=/home/user/.local/bin:$PATH \
10
+ PYTHONUNBUFFERED=1 \
11
+ PIP_NO_CACHE_DIR=1
12
 
13
+ # --- System deps ---
14
  RUN apt-get update \
15
  && apt-get install -y --no-install-recommends build-essential git curl \
16
  && rm -rf /var/lib/apt/lists/*
17
 
18
+ # --- Use a writable app dir owned by UID 1000 ---
19
+ WORKDIR /home/user/app
20
 
21
+ # --- Copy project (own it as UID 1000 to avoid permission issues) ---
22
+ COPY --chown=1000:1000 . .
23
 
24
+ # --- Python deps ---
25
+ RUN pip install --upgrade pip setuptools wheel && \
26
+ if [ -f requirements.txt ]; then \
27
  pip install -r requirements.txt; \
28
  else \
29
  pip install .[server]; \
30
  fi
31
 
32
+ # --- Optional: make Chainlit's .files persistent/writable (HF Spaces) ---
33
+ # RUN mkdir -p /data/chainlit_files && chown -R 1000:1000 /data/chainlit_files && ln -s /data/chainlit_files ./.files
34
+
35
+ # --- Run as non-root ---
36
+ USER 1000:1000
37
+
38
+ # --- Networking ---
39
  EXPOSE 7860
40
  ENV PORT=7860
41
 
42
+ # --- Launch Chainlit ---
43
  CMD ["bash", "-c", "chainlit run src/mini_transformer/apps/chainlit_app.py --host 0.0.0.0 --port ${PORT}"]