AlaBoussoffara commited on
Commit
8ce5a19
·
1 Parent(s): 7f38fd8

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +32 -30
Dockerfile CHANGED
@@ -1,43 +1,45 @@
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}"]
 
1
+ # Dockerfile for Spaces creates writable .files and runs Chainlit
2
+ # Uses python:3.11-slim as base. For GPU/CUDA, replace base image accordingly.
3
 
4
  FROM python:3.11-slim
5
 
6
+ ENV PYTHONUNBUFFERED=1
7
+ WORKDIR /home/user/app
 
 
 
 
8
 
9
+ # Create a non-root user (UID 1000) and home dir, then create .files with correct permissions.
10
+ # Using a dedicated non-root user is a good practice for containerized Spaces.
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
+ && groupadd -g 1000 appuser || true \
15
+ && useradd -m -u 1000 -g appuser -s /bin/bash appuser || true
16
+
17
+ # Create app dir and .files, set ownership to appuser
18
+ RUN mkdir -p /home/user/app/.files \
19
+ && mkdir -p /home/user/app/.cache /home/user/app/.local /home/user/app/logs \
20
+ && chown -R appuser:appuser /home/user/app \
21
+ && chmod -R 700 /home/user/app/.files
22
+
23
+ # Copy project files as root, then install deps as root
24
+ COPY . /home/user/app
25
+
26
+ # Use a requirements.txt if present; otherwise install package with [server] extras
27
+ RUN python -m pip install --upgrade pip setuptools wheel
28
+ RUN if [ -f /home/user/app/requirements.txt ]; then \
29
+ pip install -r /home/user/app/requirements.txt; \
30
  else \
31
  pip install .[server]; \
32
  fi
33
 
34
+ # Switch to non-root user
35
+ USER appuser
36
+ ENV HOME=/home/user/app
37
+ ENV XDG_CACHE_HOME=/home/user/app/.cache
38
+ ENV XDG_CONFIG_HOME=/home/user/app/.config
39
+ ENV XDG_DATA_HOME=/home/user/app/.local/share
40
+ ENV CHAINLIT_FILES_DIR=/home/user/app/.files
41
 
 
42
  EXPOSE 7860
 
43
 
44
+ # Default command: run Chainlit against the packaged chainlit_app.py
45
+ CMD ["bash", "-lc", "chainlit run src/mini_transformer/apps/chainlit_app.py --host 0.0.0.0 --port ${PORT:-7860}"]