Spaces:
Sleeping
Sleeping
Update Dockerfile
Browse files- Dockerfile +28 -8
Dockerfile
CHANGED
|
@@ -1,16 +1,36 @@
|
|
| 1 |
-
|
|
|
|
| 2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
WORKDIR /code
|
| 4 |
|
| 5 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
RUN python3 -m pip install --no-cache-dir --upgrade pip
|
| 7 |
RUN python3 -m pip install --no-cache-dir --upgrade -r /code/requirements.txt
|
| 8 |
|
| 9 |
-
|
|
|
|
| 10 |
|
| 11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
RUN mkdir .chroma
|
| 16 |
-
RUN chmod 777 .chroma
|
|
|
|
| 1 |
+
# Use a smaller, more efficient base image
|
| 2 |
+
FROM python:3.11-slim
|
| 3 |
|
| 4 |
+
# Set environment variables to prevent caching and writing .pyc files
|
| 5 |
+
ENV PYTHONDONTWRITEBYTECODE 1
|
| 6 |
+
ENV PYTHONUNBUFFERED 1
|
| 7 |
+
|
| 8 |
+
# Set the working directory
|
| 9 |
WORKDIR /code
|
| 10 |
|
| 11 |
+
# Create a non-root user and group to run the application
|
| 12 |
+
RUN addgroup --system appgroup && adduser --system --group appuser
|
| 13 |
+
|
| 14 |
+
# Create necessary directories and set permissions *before* copying files
|
| 15 |
+
# This improves layer caching.
|
| 16 |
+
RUN mkdir -p /.cache ./.chroma \
|
| 17 |
+
&& chown -R appuser:appgroup /.cache ./.chroma
|
| 18 |
+
|
| 19 |
+
# Copy dependency file and set permissions
|
| 20 |
+
COPY --chown=appuser:appgroup ./requirements.txt /code/requirements.txt
|
| 21 |
+
|
| 22 |
+
# Install dependencies
|
| 23 |
RUN python3 -m pip install --no-cache-dir --upgrade pip
|
| 24 |
RUN python3 -m pip install --no-cache-dir --upgrade -r /code/requirements.txt
|
| 25 |
|
| 26 |
+
# Copy the rest of the application code and set permissions
|
| 27 |
+
COPY --chown=appuser:appgroup . .
|
| 28 |
|
| 29 |
+
# Switch to the non-root user
|
| 30 |
+
USER appuser
|
| 31 |
+
|
| 32 |
+
# Expose the port the app runs on
|
| 33 |
+
EXPOSE 7860
|
| 34 |
|
| 35 |
+
# Define the command to run the application
|
| 36 |
+
CMD ["panel", "serve", "/code/app.py", "--address", "0.0.0.0", "--port", "7860", "--allow-websocket-origin", "*"]
|
|
|
|
|
|