suh4s commited on
Commit
3cdcb59
·
1 Parent(s): 30d3c6d

Refine Dockerfile for uv build and permission handling

Browse files
Files changed (1) hide show
  1. Dockerfile +23 -20
Dockerfile CHANGED
@@ -4,9 +4,10 @@ FROM python:3.11-slim
4
  ENV PYTHONDONTWRITEBYTECODE=1 \
5
  PYTHONUNBUFFERED=1 \
6
  PYTHONFAULTHANDLER=1 \
7
- HOME=/home/user \
8
- PATH="/home/user/.local/bin:$PATH" \
9
- PYTHONPATH="$HOME/app:$PYTHONPATH"
 
10
 
11
  # Add non-root user
12
  RUN useradd -m -u 1000 user
@@ -17,33 +18,35 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
17
  curl \
18
  && rm -rf /var/lib/apt/lists/*
19
 
20
- # Set working directory
21
- WORKDIR $HOME/app
22
 
23
- # Copy project files first (copy everything at once to avoid missing files)
24
- COPY --chown=user . .
25
 
26
- # Install UV as root (required for system installation)
27
- RUN curl -LsSf https://astral.sh/uv/install.sh | sh && \
28
- echo 'export PATH=/root/.local/bin:$PATH' >> /root/.bashrc
 
29
 
30
- # Install dependencies using uv as root
31
- RUN /root/.local/bin/uv pip install -r requirements.txt
 
32
 
33
- # Set permissions for the app directory
34
- RUN chown -R user:user $HOME/app
35
 
36
- # Switch to non-root user for running the app
37
  USER user
38
 
39
- # Create any necessary runtime directories
40
- RUN mkdir -p exports
41
 
42
- # Run data download script to initialize data sources
43
- RUN python download_data.py
44
 
45
  # Expose the port the app runs on
46
- EXPOSE 7860
47
 
48
  # Run the app
49
  CMD ["chainlit", "run", "app.py", "--host", "0.0.0.0", "--port", "7860"]
 
4
  ENV PYTHONDONTWRITEBYTECODE=1 \
5
  PYTHONUNBUFFERED=1 \
6
  PYTHONFAULTHANDLER=1 \
7
+ HOME_DIR=/home/user \
8
+ APP_DIR=/home/user/app \
9
+ PATH="/root/.local/bin:$PATH" \
10
+ PYTHONPATH="/home/user/app:$PYTHONPATH"
11
 
12
  # Add non-root user
13
  RUN useradd -m -u 1000 user
 
18
  curl \
19
  && rm -rf /var/lib/apt/lists/*
20
 
21
+ # Install uv (as root, it will go to /root/.local/bin)
22
+ RUN curl -LsSf https://astral.sh/uv/install.sh | sh
23
 
24
+ # Set working directory
25
+ WORKDIR ${APP_DIR}
26
 
27
+ # Copy all project files. Crucially, these are now owned by root by default
28
+ # as we haven't switched user yet. This ensures setuptools (run by root's uv)
29
+ # can read them and write build artifacts in this directory.
30
+ COPY . ${APP_DIR}
31
 
32
+ # Install dependencies using uv (run as root, installing system-wide)
33
+ # This will also build and install the local insightflow-ai package
34
+ RUN uv pip install --system --no-cache .
35
 
36
+ # Now that installation is done, change ownership of the app directory to the non-root user
37
+ RUN chown -R user:user ${APP_DIR}
38
 
39
+ # Switch to non-root user for subsequent operations and runtime
40
  USER user
41
 
42
+ # Create necessary runtime directories (as non-root user)
43
+ RUN mkdir -p ${APP_DIR}/exports ${APP_DIR}/data_sources
44
 
45
+ # Run data download script to initialize data sources (as non-root user)
46
+ RUN python ${APP_DIR}/download_data.py
47
 
48
  # Expose the port the app runs on
49
+ EXPOSE 7860
50
 
51
  # Run the app
52
  CMD ["chainlit", "run", "app.py", "--host", "0.0.0.0", "--port", "7860"]