Spaces:
Sleeping
Sleeping
Update Dockerfile
Browse files- Dockerfile +26 -9
Dockerfile
CHANGED
|
@@ -2,24 +2,41 @@
|
|
| 2 |
FROM python:3.11-bookworm AS builder
|
| 3 |
|
| 4 |
WORKDIR /app
|
|
|
|
|
|
|
| 5 |
COPY requirements.txt .
|
| 6 |
-
RUN pip install --no-cache-dir --prefix=/install -r requirements.txt
|
| 7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
COPY app app
|
| 9 |
|
| 10 |
# Stage 2: Production
|
| 11 |
-
FROM
|
| 12 |
|
| 13 |
WORKDIR /app
|
| 14 |
|
| 15 |
-
# Copy installed modules
|
| 16 |
-
COPY --from=builder /
|
| 17 |
-
|
| 18 |
-
COPY app app
|
| 19 |
|
| 20 |
-
|
| 21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
|
|
|
|
| 23 |
USER zaws
|
| 24 |
|
| 25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
FROM python:3.11-bookworm AS builder
|
| 3 |
|
| 4 |
WORKDIR /app
|
| 5 |
+
|
| 6 |
+
# Copy requirements.txt
|
| 7 |
COPY requirements.txt .
|
|
|
|
| 8 |
|
| 9 |
+
# Install dependencies
|
| 10 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
| 11 |
+
|
| 12 |
+
# Copy everything
|
| 13 |
COPY app app
|
| 14 |
|
| 15 |
# Stage 2: Production
|
| 16 |
+
FROM python:3.11-slim as production
|
| 17 |
|
| 18 |
WORKDIR /app
|
| 19 |
|
| 20 |
+
# Copy installed modules from the builder stage
|
| 21 |
+
COPY --from=builder /usr/local/lib/python3.11/site-packages /usr/local/lib/python3.11/site-packages
|
|
|
|
|
|
|
| 22 |
|
| 23 |
+
# Install playwright dependencies
|
| 24 |
+
RUN python -m playwright install-deps && \
|
| 25 |
+
# Clean up
|
| 26 |
+
rm -f /usr/lib/x86_64-linux-gnu/libmfxhw* /usr/lib/x86_64-linux-gnu/mfx/* && \
|
| 27 |
+
# Create non-root user
|
| 28 |
+
useradd --home-dir /app --shell /bin/sh zaws && \
|
| 29 |
+
chown -R zaws:zaws .
|
| 30 |
|
| 31 |
+
# Switch to non-root user
|
| 32 |
USER zaws
|
| 33 |
|
| 34 |
+
# Installfirefox inside non-root
|
| 35 |
+
# Do not install firefox in root to avoid permission error otherwise you need to give zaws permission to access installation path
|
| 36 |
+
RUN python -m playwright install firefox
|
| 37 |
+
|
| 38 |
+
# Copy application code from the builder stage
|
| 39 |
+
COPY --from=builder /app /app
|
| 40 |
+
|
| 41 |
+
# Run application
|
| 42 |
+
CMD ["python", "app/main.py"]
|