Spaces:
Sleeping
Sleeping
Refactor Dockerfile to improve user permissions and cache handling
Browse files- Dockerfile +11 -20
Dockerfile
CHANGED
@@ -15,26 +15,20 @@ FROM python:${PYTHON_VERSION}-slim as base
|
|
15 |
# the application crashes without emitting any logs due to buffering.
|
16 |
ENV PYTHONUNBUFFERED=1
|
17 |
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
--no-create-home \
|
29 |
-
--uid "${UID}" \
|
30 |
-
appuser
|
31 |
-
|
32 |
-
ENV PATH="/home/appuser/.local/bin:$PATH"
|
33 |
|
34 |
COPY --chown=appuser ./requirements.txt requirements.txt
|
35 |
RUN mkdir -p /app/.cache \
|
36 |
&& chown -R appuser:appuser /app/.cache
|
37 |
-
ENV TRANSFORMERS_CACHE=/app/.cache/huggingface/hub
|
38 |
|
39 |
# Download dependencies as a separate step to take advantage of Docker's caching.
|
40 |
# Leverage a cache mount to /root/.cache/pip to speed up subsequent builds.
|
@@ -43,11 +37,8 @@ ENV TRANSFORMERS_CACHE=/app/.cache/huggingface/hub
|
|
43 |
RUN python -m pip install --upgrade pip \
|
44 |
&& python -m pip install --no-cache-dir -r requirements.txt
|
45 |
|
46 |
-
# Switch to the non-privileged user to run the application.
|
47 |
-
USER appuser
|
48 |
-
|
49 |
# Copy the source code into the container.
|
50 |
-
COPY --chown=
|
51 |
|
52 |
# Expose the port that the application listens on.
|
53 |
EXPOSE 7860
|
|
|
15 |
# the application crashes without emitting any logs due to buffering.
|
16 |
ENV PYTHONUNBUFFERED=1
|
17 |
|
18 |
+
RUN adduser appuser
|
19 |
+
|
20 |
+
USER appuser
|
21 |
+
|
22 |
+
ENV HOME=/home/appuser \
|
23 |
+
PATH=/home/appuser/.local/bin:$PATH
|
24 |
+
|
25 |
+
ENV TRANSFORMERS_CACHE=$HOME/app/.cache/huggingface/hub
|
26 |
+
|
27 |
+
WORKDIR $HOME/app
|
|
|
|
|
|
|
|
|
|
|
28 |
|
29 |
COPY --chown=appuser ./requirements.txt requirements.txt
|
30 |
RUN mkdir -p /app/.cache \
|
31 |
&& chown -R appuser:appuser /app/.cache
|
|
|
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.
|
|
|
37 |
RUN python -m pip install --upgrade pip \
|
38 |
&& python -m pip install --no-cache-dir -r requirements.txt
|
39 |
|
|
|
|
|
|
|
40 |
# Copy the source code into the container.
|
41 |
+
COPY --chown=appuser . $HOME/app
|
42 |
|
43 |
# Expose the port that the application listens on.
|
44 |
EXPOSE 7860
|