shahabkahn commited on
Commit
e2f2177
·
verified ·
1 Parent(s): 51c9213

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +15 -28
Dockerfile CHANGED
@@ -1,11 +1,5 @@
1
  # syntax=docker/dockerfile:1
2
 
3
- # Comments are provided throughout this file to help you get started.
4
- # If you need more help, visit the Dockerfile reference guide at
5
- # https://docs.docker.com/go/dockerfile-reference/
6
-
7
- # Want to help us make this template better? Share your feedback here: https://forms.gle/ybq9Krt8jtBL3iCk7
8
-
9
  ARG PYTHON_VERSION=3.12.3
10
  FROM python:${PYTHON_VERSION}-slim as base
11
 
@@ -16,10 +10,10 @@ ENV PYTHONDONTWRITEBYTECODE=1
16
  # the application crashes without emitting any logs due to buffering.
17
  ENV PYTHONUNBUFFERED=1
18
 
 
19
  WORKDIR /app
20
 
21
  # Create a non-privileged user that the app will run under.
22
- # See https://docs.docker.com/go/dockerfile-user-best-practices/
23
  ARG UID=10001
24
  RUN adduser \
25
  --disabled-password \
@@ -30,38 +24,31 @@ RUN adduser \
30
  --uid "${UID}" \
31
  appuser
32
 
33
- # Download dependencies as a separate step to take advantage of Docker's caching.
34
- # Leverage a cache mount to /root/.cache/pip to speed up subsequent builds.
35
- # Leverage a bind mount to requirements.txt to avoid having to copy them into
36
- # into this layer.
37
- RUN --mount=type=cache,target=/root/.cache/pip \
38
- --mount=type=bind,source=requirements.txt,target=requirements.txt \
39
- python -m pip install -r requirements.txt
40
 
 
 
 
41
 
42
- # Create a directory named 'data' and assign its ownership to appuser
43
- RUN mkdir -p /data
44
- RUN chown appuser /data
 
45
 
 
 
 
46
 
47
  # Switch to the non-privileged user to run the application.
48
  USER appuser
49
 
50
- # Set the TRANSFORMERS_CACHE environment variable
51
- ENV TRANSFORMERS_CACHE=/tmp/.cache/huggingface
52
-
53
- # Create the cache folder with appropriate permissions
54
- RUN mkdir -p $TRANSFORMERS_CACHE && chmod -R 777 $TRANSFORMERS_CACHE
55
-
56
-
57
- # Copy the source code into the container.
58
  COPY . .
59
 
60
- # Expose the port that the application listens on.
61
  EXPOSE 7860
62
  EXPOSE 8501
63
 
64
- # Run the application.
65
  # Run the application.
66
  CMD ["bash", "-c", "uvicorn app:app --host 0.0.0.0 --port 7860 & streamlit run frontend.py --server.port 8501 --server.enableXsrfProtection false"]
67
-
 
1
  # syntax=docker/dockerfile:1
2
 
 
 
 
 
 
 
3
  ARG PYTHON_VERSION=3.12.3
4
  FROM python:${PYTHON_VERSION}-slim as base
5
 
 
10
  # the application crashes without emitting any logs due to buffering.
11
  ENV PYTHONUNBUFFERED=1
12
 
13
+ # Set the working directory
14
  WORKDIR /app
15
 
16
  # Create a non-privileged user that the app will run under.
 
17
  ARG UID=10001
18
  RUN adduser \
19
  --disabled-password \
 
24
  --uid "${UID}" \
25
  appuser
26
 
27
+ # Copy requirements.txt before other files to leverage Docker's caching mechanism
28
+ COPY requirements.txt .
 
 
 
 
 
29
 
30
+ # Install dependencies
31
+ RUN --mount=type=cache,target=/root/.cache/pip \
32
+ python -m pip install --no-cache-dir -r requirements.txt
33
 
34
+ # Create necessary directories with appropriate permissions
35
+ RUN mkdir -p /data /app/.cache/huggingface && \
36
+ chown -R appuser:appuser /data /app/.cache/huggingface && \
37
+ chmod -R 777 /data /app/.cache/huggingface
38
 
39
+ # Set the TRANSFORMERS_CACHE and HF_HOME environment variables
40
+ ENV TRANSFORMERS_CACHE=/app/.cache/huggingface
41
+ ENV HF_HOME=/app/.cache/huggingface
42
 
43
  # Switch to the non-privileged user to run the application.
44
  USER appuser
45
 
46
+ # Copy the rest of the source code into the container.
 
 
 
 
 
 
 
47
  COPY . .
48
 
49
+ # Expose the ports that the application listens on.
50
  EXPOSE 7860
51
  EXPOSE 8501
52
 
 
53
  # Run the application.
54
  CMD ["bash", "-c", "uvicorn app:app --host 0.0.0.0 --port 7860 & streamlit run frontend.py --server.port 8501 --server.enableXsrfProtection false"]