zach commited on
Commit
4817845
·
1 Parent(s): ea08a90

Update docker file for huggingface space

Browse files
Files changed (1) hide show
  1. Dockerfile +22 -25
Dockerfile CHANGED
@@ -1,49 +1,46 @@
1
  # Use the official lightweight Python 3.11 slim image as the base
2
  FROM python:3.11-slim
3
 
4
- # Set up a new user named "user" with user ID 1000
5
  RUN useradd -m -u 1000 user
6
 
7
- # Switch to the "user" user
8
- USER user
9
-
10
- # Set home to the user's home directory
11
- ENV HOME=/home/user \
12
- PATH=/root/.local/bin:/home/user/.local/bin:$PATH
13
-
14
- # Set the working directory to the user's home directory
15
- WORKDIR $HOME/app
16
 
17
  # Install uv and required system dependencies
18
- # - `apt-get update` fetches the latest package lists
19
- # - `apt-get install -y --no-install-recommends curl libpq-dev gcc build-essential` installs:
20
- # - curl: to fetch the uv installer script
21
- # - libpq-dev: provides pg_config required by psycopg2
22
- # - gcc & build-essential: required for compiling C extensions (e.g. psycopg2)
23
- # - `curl -LsSf` downloads and runs the uv installer script
24
- # - `apt-get remove -y curl` removes curl after installation to save space
25
- # - `apt-get clean && rm -rf /var/lib/apt/lists/*` removes cached package lists to reduce image size
26
  RUN apt-get update && \
27
  apt-get install -y --no-install-recommends curl libpq-dev gcc build-essential && \
 
28
  curl -LsSf https://astral.sh/uv/install.sh | sh && \
 
 
 
 
29
  apt-get remove -y curl && \
30
  apt-get clean && rm -rf /var/lib/apt/lists/*
31
 
32
- # Copy dependency files first (pyproject.toml & uv.lock) to leverage Docker’s build cache
33
- # - Ensures that if only the application code changes, dependencies do not need to be reinstalled
34
- COPY pyproject.toml uv.lock /app/
 
 
 
 
 
 
 
 
 
35
 
36
  # Install dependencies using uv
37
  # - Reads pyproject.toml (and uv.lock, if available) to install dependencies
38
  # - Creates a .venv in the project directory with all required packages
39
  RUN uv sync
40
 
41
- # Copy the remaining project files into the container
42
- COPY . .
43
 
44
  # Document the port used by Gradio
45
- # - This does not actually expose the port, it is just metadata for users
46
- # - To actually expose the port, use `docker run -p 7860:7860 <image>`
47
  EXPOSE 7860
48
 
49
  # Define the command to start the application
 
1
  # Use the official lightweight Python 3.11 slim image as the base
2
  FROM python:3.11-slim
3
 
4
+ # Set up a non-root user for improved security
5
  RUN useradd -m -u 1000 user
6
 
7
+ # Create app directory and set proper ownership
8
+ RUN mkdir -p /app && chown -R user:user /app
 
 
 
 
 
 
 
9
 
10
  # Install uv and required system dependencies
 
 
 
 
 
 
 
 
11
  RUN apt-get update && \
12
  apt-get install -y --no-install-recommends curl libpq-dev gcc build-essential && \
13
+ mkdir -p /home/user/.local/bin && \
14
  curl -LsSf https://astral.sh/uv/install.sh | sh && \
15
+ cp /root/.local/bin/uv /usr/local/bin/ && \
16
+ cp /root/.local/bin/uvx /usr/local/bin/ && \
17
+ chmod +x /usr/local/bin/uv /usr/local/bin/uvx && \
18
+ chown -R user:user /home/user/.local && \
19
  apt-get remove -y curl && \
20
  apt-get clean && rm -rf /var/lib/apt/lists/*
21
 
22
+ # Switch to the non-root user
23
+ USER user
24
+
25
+ # Set environment variables for the user
26
+ ENV HOME=/home/user \
27
+ PATH="/home/user/.local/bin:/usr/local/bin:$PATH"
28
+
29
+ # Set the working directory in the container
30
+ WORKDIR /app
31
+
32
+ # Copy dependency files first with proper ownership
33
+ COPY --chown=user pyproject.toml uv.lock /app/
34
 
35
  # Install dependencies using uv
36
  # - Reads pyproject.toml (and uv.lock, if available) to install dependencies
37
  # - Creates a .venv in the project directory with all required packages
38
  RUN uv sync
39
 
40
+ # Copy the remaining project files into the container with proper ownership
41
+ COPY --chown=user . .
42
 
43
  # Document the port used by Gradio
 
 
44
  EXPOSE 7860
45
 
46
  # Define the command to start the application