Spaces:
Sleeping
Sleeping
Update Dockerfile
Browse files- Dockerfile +20 -25
Dockerfile
CHANGED
|
@@ -1,34 +1,29 @@
|
|
| 1 |
FROM python:3.11-slim
|
| 2 |
|
| 3 |
-
# Set working directory
|
| 4 |
WORKDIR /app
|
| 5 |
|
| 6 |
-
#
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
&& rm -rf /var/lib/apt/lists/*
|
| 12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
-
# Copy
|
| 15 |
-
COPY
|
| 16 |
-
RUN pip install --no-cache-dir -r requirements.txt
|
| 17 |
|
| 18 |
-
#
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
|
|
|
| 22 |
|
| 23 |
-
|
| 24 |
|
| 25 |
-
#
|
| 26 |
-
|
| 27 |
-
ENV FLASK_ENV=production
|
| 28 |
-
ENV PORT=7860
|
| 29 |
-
|
| 30 |
-
# Expose port
|
| 31 |
-
EXPOSE 7860
|
| 32 |
-
|
| 33 |
-
# Run the application
|
| 34 |
-
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
|
|
|
|
| 1 |
FROM python:3.11-slim
|
| 2 |
|
|
|
|
| 3 |
WORKDIR /app
|
| 4 |
|
| 5 |
+
# Playwright saves browsers here during the image build. The same path is then
|
| 6 |
+
# available to the non-root FastAPI process at runtime.
|
| 7 |
+
ENV PYTHONUNBUFFERED=1 \
|
| 8 |
+
PORT=7860 \
|
| 9 |
+
PLAYWRIGHT_BROWSERS_PATH=/ms-playwright
|
|
|
|
| 10 |
|
| 11 |
+
# Install the application dependencies first so Docker can cache this layer.
|
| 12 |
+
COPY requirements.txt ./
|
| 13 |
+
RUN pip install --no-cache-dir -r requirements.txt \
|
| 14 |
+
&& python -m playwright install --with-deps chromium \
|
| 15 |
+
&& rm -rf /var/lib/apt/lists/* /root/.cache/pip
|
| 16 |
|
| 17 |
+
# Copy the FastAPI application after dependency installation.
|
| 18 |
+
COPY . ./
|
|
|
|
| 19 |
|
| 20 |
+
# Avoid running the web app as root. The installed browser path is readable by
|
| 21 |
+
# this user and /tmp remains writable for temporary MP4 output.
|
| 22 |
+
RUN useradd --create-home --uid 1000 appuser \
|
| 23 |
+
&& chown -R appuser:appuser /app /ms-playwright
|
| 24 |
+
USER appuser
|
| 25 |
|
| 26 |
+
EXPOSE 7860
|
| 27 |
|
| 28 |
+
# Uses $PORT when a host injects it, and otherwise listens on 7860.
|
| 29 |
+
CMD ["sh", "-c", "uvicorn app:app --host 0.0.0.0 --port ${PORT:-7860}"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|