Sgridda commited on
Commit
ead1873
·
1 Parent(s): 2f0ed7b

Fix cache ownership permissions

Browse files
Files changed (1) hide show
  1. Dockerfile +13 -11
Dockerfile CHANGED
@@ -1,24 +1,26 @@
 
1
  # Use the official Python 3.9 slim image
2
  FROM python:3.9-slim
3
 
4
  # Set the working directory inside the container
5
  WORKDIR /code
6
 
7
- # Create a directory for the model cache and set the HF_HOME environment variable.
8
- # This tells the transformers library to download models here instead of the root .cache folder.
9
- RUN mkdir /code/cache
 
 
10
  ENV HF_HOME /code/cache
11
 
12
- # Copy the requirements file into the container
13
  COPY ./requirements.txt /code/requirements.txt
14
-
15
- # Install the Python dependencies
16
  RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
17
 
18
- # Copy the main application file into the container
19
  COPY ./main.py /code/main.py
20
 
21
- # Command to run the FastAPI server with Uvicorn
22
- # We use --host 0.0.0.0 to make it accessible from outside the container
23
- # and --port 7860 as this is the standard port Hugging Face Spaces expects
24
- CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
 
 
1
+
2
  # Use the official Python 3.9 slim image
3
  FROM python:3.9-slim
4
 
5
  # Set the working directory inside the container
6
  WORKDIR /code
7
 
8
+ # Create a directory for the model cache, and change its ownership to the non-root user.
9
+ # The user is 'user' in the standard Hugging Face environment.
10
+ RUN mkdir /code/cache && chown -R user:user /code/cache
11
+
12
+ # Set the HF_HOME environment variable to point to our new cache directory.
13
  ENV HF_HOME /code/cache
14
 
15
+ # Copy the requirements file and install dependencies
16
  COPY ./requirements.txt /code/requirements.txt
 
 
17
  RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
18
 
19
+ # Copy the application code
20
  COPY ./main.py /code/main.py
21
 
22
+ # Switch to the non-root user before running the app
23
+ USER user
24
+
25
+ # Command to run the FastAPI server
26
+ CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]