Spaces:
Sleeping
Sleeping
Joffrey Thomas
commited on
Commit
·
e3a4f02
1
Parent(s):
759c7e1
docker
Browse files- Dockerfile +9 -16
Dockerfile
CHANGED
|
@@ -5,28 +5,21 @@ WORKDIR /app
|
|
| 5 |
# Create a non-root user and group
|
| 6 |
RUN groupadd -r appgroup && useradd -r -g appgroup -d /app -s /sbin/nologin -c "Docker image user" appuser
|
| 7 |
|
| 8 |
-
# Install uv for faster package management
|
| 9 |
-
RUN pip install uv
|
| 10 |
-
|
| 11 |
-
# Set UV_CACHE_DIR to a writable location
|
| 12 |
-
ENV UV_CACHE_DIR /app/.uv_cache
|
| 13 |
-
|
| 14 |
# Copy requirements file first to leverage Docker cache
|
| 15 |
COPY --chown=appuser:appgroup requirements.txt .
|
| 16 |
|
| 17 |
-
#
|
| 18 |
-
# This ensures the directory exists and is writable by appuser
|
| 19 |
-
RUN mkdir -p ${UV_CACHE_DIR} && chown -R appuser:appgroup ${UV_CACHE_DIR}
|
| 20 |
-
|
| 21 |
-
# Grant appuser ownership of /app to allow creating .venv
|
| 22 |
RUN chown appuser:appgroup /app
|
| 23 |
|
| 24 |
# Switch to the non-root user
|
| 25 |
USER appuser
|
| 26 |
|
| 27 |
-
#
|
| 28 |
-
RUN
|
| 29 |
-
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
# Copy application code
|
| 32 |
# Ensure the appuser owns the application code as well
|
|
@@ -35,5 +28,5 @@ COPY --chown=appuser:appgroup server.py .
|
|
| 35 |
# Expose the port the server runs on
|
| 36 |
EXPOSE 7860
|
| 37 |
|
| 38 |
-
# Command to run the server
|
| 39 |
-
CMD ["
|
|
|
|
| 5 |
# Create a non-root user and group
|
| 6 |
RUN groupadd -r appgroup && useradd -r -g appgroup -d /app -s /sbin/nologin -c "Docker image user" appuser
|
| 7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
# Copy requirements file first to leverage Docker cache
|
| 9 |
COPY --chown=appuser:appgroup requirements.txt .
|
| 10 |
|
| 11 |
+
# Grant appuser ownership of /app
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
RUN chown appuser:appgroup /app
|
| 13 |
|
| 14 |
# Switch to the non-root user
|
| 15 |
USER appuser
|
| 16 |
|
| 17 |
+
# Create and activate virtual environment
|
| 18 |
+
RUN python -m venv .venv
|
| 19 |
+
ENV PATH="/app/.venv/bin:$PATH"
|
| 20 |
+
|
| 21 |
+
# Install dependencies using standard pip
|
| 22 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
| 23 |
|
| 24 |
# Copy application code
|
| 25 |
# Ensure the appuser owns the application code as well
|
|
|
|
| 28 |
# Expose the port the server runs on
|
| 29 |
EXPOSE 7860
|
| 30 |
|
| 31 |
+
# Command to run the server with python directly
|
| 32 |
+
CMD ["python", "server.py"]
|