Zachary Greathouse commited on
Commit
ad3bef5
·
unverified ·
1 Parent(s): 9f33991

Zg/more huggingface config (#14)

Browse files

* Fix docker file

* Update docker file for huggingface space

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