Spaces:
Running
Running
Update Dockerfile
Browse files- Dockerfile +35 -12
Dockerfile
CHANGED
|
@@ -1,19 +1,42 @@
|
|
| 1 |
-
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
-
WORKDIR /
|
| 4 |
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
|
| 9 |
-
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
-
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
-
|
|
|
|
|
|
|
| 14 |
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
RUN
|
|
|
|
|
|
|
|
|
|
| 19 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# syntax=docker/dockerfile:1
|
| 2 |
+
#
|
| 3 |
+
# Stage 1: build wheels using full base image (with compilers)
|
| 4 |
+
FROM python:3.12-slim AS builder
|
| 5 |
|
| 6 |
+
WORKDIR /app
|
| 7 |
|
| 8 |
+
# Prevent unwanted cache and bytecode files
|
| 9 |
+
ENV PYTHONDONTWRITEBYTECODE=1 \
|
| 10 |
+
PYTHONUNBUFFERED=1
|
| 11 |
|
| 12 |
+
# Install build dependencies
|
| 13 |
+
RUN apt-get update && \
|
| 14 |
+
apt-get install -y --no-install-recommends gcc build-essential && \
|
| 15 |
+
rm -rf /var/lib/apt/lists/*
|
| 16 |
|
| 17 |
+
# Install dependencies as wheels to avoid needing compilers in final stage
|
| 18 |
+
COPY requirements.txt .
|
| 19 |
+
RUN python3 -m pip install --no-cache-dir --upgrade pip && \
|
| 20 |
+
pip wheel --no-cache-dir --no-deps --wheel-dir /app/wheels -r requirements.txt
|
| 21 |
|
| 22 |
+
# Stage 2: final runtime image
|
| 23 |
+
FROM python:3.12-slim AS runtime
|
| 24 |
+
WORKDIR /app
|
| 25 |
|
| 26 |
+
# Copy wheels and install runtime dependencies
|
| 27 |
+
COPY --from=builder /app/wheels /wheels
|
| 28 |
+
COPY requirements.txt .
|
| 29 |
+
RUN python3 -m pip install --no-cache-dir /wheels/*
|
| 30 |
+
|
| 31 |
+
# Copy application code
|
| 32 |
+
COPY . .
|
| 33 |
|
| 34 |
+
# Create cache directories with proper permissions (if needed)
|
| 35 |
+
RUN mkdir /.cache /.chroma && chmod 777 /.cache /.chroma
|
| 36 |
+
|
| 37 |
+
# Use non‑root user for better security
|
| 38 |
+
RUN useradd --no-log-init -r appuser && chown -R appuser /app /.cache /.chroma
|
| 39 |
+
USER appuser
|
| 40 |
+
|
| 41 |
+
EXPOSE 7860
|
| 42 |
+
CMD ["panel", "serve", "/app/app.py", "--address", "0.0.0.0", "--port", "7860", "--allow-websocket-origin", "*"]
|