Mimi commited on
Commit
bdc9847
·
1 Parent(s): 1644bb2
Files changed (1) hide show
  1. Dockerfile +15 -17
Dockerfile CHANGED
@@ -1,32 +1,30 @@
1
  # Use Python 3.12 as the base image
2
  FROM python:3.12
3
 
4
- # Set working directory
5
- WORKDIR /code
6
 
7
- # Create a non-root user and set permissions
8
- RUN useradd -m -u 1000 user && \
9
- mkdir -p /home/user/.cache/huggingface && \
10
- chown -R user:user /home/user/.cache /code
11
 
12
- # Set environment variables
13
  ENV HOME=/home/user \
14
- HF_HOME=/home/user/.cache/huggingface \
15
- PATH=/home/user/.local/bin:$PATH
16
 
17
- # Switch to the new user
18
- USER user
19
 
20
- # Copy requirements and install dependencies
21
- COPY --chown=user:user ./requirements.txt /code/requirements.txt
22
- RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
 
23
 
24
- # Copy application files
25
- COPY --chown=user:user . /code/app
26
 
27
  # Hugging Face Spaces does NOT support --mount=type=secret.
28
  # Instead, access HF_TOKEN via environment variables at runtime.
29
- CMD huggingface-cli login --token "$HF_TOKEN" --add-to-git-credential && \
30
  streamlit run app.py \
31
  --server.headless true \
32
  --server.enableCORS false \
 
1
  # Use Python 3.12 as the base image
2
  FROM python:3.12
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=/home/user/.local/bin:$PATH
 
13
 
14
+ # Set the working directory to the user's home directory
15
+ WORKDIR $HOME/app
16
 
17
+ # Try and run pip command after setting the user with `USER user` to avoid permission issues with Python
18
+ RUN pip install --no-cache-dir --upgrade pip
19
+ # Copy the current directory contents into the container at $HOME/app setting the owner to the user
20
+ COPY --chown=user . $HOME/app
21
 
22
+ # Copy requirements and install dependencies
23
+ RUN pip install --no-cache-dir --upgrade -r requirements.txt
24
 
25
  # Hugging Face Spaces does NOT support --mount=type=secret.
26
  # Instead, access HF_TOKEN via environment variables at runtime.
27
+ CMD huggingface-cli login --token $HF_TOKEN --add-to-git-credential && \
28
  streamlit run app.py \
29
  --server.headless true \
30
  --server.enableCORS false \