CodeCommunity commited on
Commit
9c78f2e
·
verified ·
1 Parent(s): 7d5ec63

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +37 -30
Dockerfile CHANGED
@@ -1,31 +1,38 @@
1
- # Use a lightweight Python image
2
- FROM python:3.10-slim
3
-
4
- # Set working directory
5
- WORKDIR /code
6
-
7
- # Install system dependencies
8
- RUN apt-get update && apt-get install -y \
9
- build-essential \
10
- && rm -rf /var/lib/apt/lists/*
11
-
12
- # Copy requirements and install
13
- COPY ./requirements.txt /code/requirements.txt
14
- RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
15
-
16
- # Create a non-root user (Hugging Face requirement)
17
- RUN useradd -m -u 1000 user
18
- USER user
19
- ENV HOME=/home/user \
20
- PATH=/home/user/.local/bin:$PATH
21
-
22
- # Copy the rest of the app
23
- WORKDIR $HOME/app
24
- COPY --chown=user . $HOME/app
25
-
26
- # Ensure the transformers cache is in a writable directory
27
- ENV HF_HOME=/home/user/app/.cache
28
- RUN mkdir -p /home/user/app/.cache && chmod 777 /home/user/app/.cache
29
-
30
- # Expose port 7860 (Hugging Face default)
 
 
 
 
 
 
 
31
  CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "7860"]
 
1
+ # 1. Use a lightweight Python image
2
+ FROM python:3.10-slim
3
+
4
+ # 2. Set environment variables
5
+ ENV PYTHONUNBUFFERED=1 \
6
+ PYTHONDONTWRITEBYTECODE=1 \
7
+ PYTHONPATH=/code \
8
+ HOME=/home/user \
9
+ PATH=/home/user/.local/bin:$PATH \
10
+ HF_HOME=/code/.cache
11
+
12
+ # 3. Set working directory
13
+ WORKDIR /code
14
+
15
+ # 4. Install system dependencies
16
+ RUN apt-get update && apt-get install -y \
17
+ build-essential \
18
+ && rm -rf /var/lib/apt/lists/*
19
+
20
+ # 5. Create a non-root user (Hugging Face Requirement)
21
+ RUN useradd -m -u 1000 user
22
+ RUN mkdir -p /code/.cache && chown -R user:user /code
23
+
24
+ # 6. Switch to the non-root user
25
+ USER user
26
+
27
+ # 7. Copy requirements and install
28
+ COPY --chown=user requirements.txt /code/requirements.txt
29
+ RUN pip install --no-cache-dir --user --upgrade -r /code/requirements.txt
30
+
31
+ # 8. Copy the entire project
32
+ COPY --chown=user . /code
33
+
34
+ # 9. Expose port 7860
35
+ EXPOSE 7860
36
+
37
+ # 10. Start the application
38
  CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "7860"]