From 4dfb70ecfbefcf58666255a65ffe277c9755f091 Mon Sep 17 00:00:00 2001 From: luojiyin Date: Wed, 5 Nov 2025 11:26:05 +0800 Subject: [PATCH] Improve Dockerfile build configuration and layer caching - Add SHELL pipefail to catch pipeline errors during build - Consolidate environment variables (PATH, PLAYWRIGHT_BROWSERS_PATH) - Fix DEBIAN_FRONTEND to inline usage (avoid runtime pollution) - Separate Playwright installation for better layer caching - Create dedicated /ms-playwright directory for browser binaries - Improve comments for better maintainability These changes enhance build robustness and optimize Docker layer caching without affecting runtime behavior. --- Dockerfile | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/Dockerfile b/Dockerfile index 53edd76..7cdb41e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,9 +1,13 @@ FROM python:3.11-slim -# Prevent Python from writing .pyc files and buffer stdout/stderr +SHELL ["/bin/bash", "-o", "pipefail", "-c"] + +# Prevent Python from writing .pyc files, buffer stdout/stderr, and pin common tooling paths ENV PYTHONDONTWRITEBYTECODE=1 \ PYTHONUNBUFFERED=1 \ - PIP_NO_CACHE_DIR=1 + PIP_NO_CACHE_DIR=1 \ + PATH="/root/.local/bin:${PATH}" \ + PLAYWRIGHT_BROWSERS_PATH=/ms-playwright # Install system dependencies required by scientific Python stack, Playwright, and Streamlit RUN apt-get update && apt-get install -y --no-install-recommends \ @@ -34,24 +38,24 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ ffmpeg \ && apt-get clean && rm -rf /var/lib/apt/lists/* -# Install uv and expose it on PATH -ENV PATH="/root/.local/bin:${PATH}" -RUN curl -LsSf https://astral.sh/uv/install.sh | sh +# Install the latest uv release and expose it on PATH +RUN curl -LsSf --retry 3 --retry-delay 2 https://astral.sh/uv/install.sh | sh WORKDIR /app # Install Python dependencies first to leverage Docker layer caching -COPY requirements.txt ./ -RUN uv pip install --system -r requirements.txt && \ - python -m playwright install chromium +COPY requirements.txt ./ +RUN uv pip install --system -r requirements.txt + +# Install Playwright browser binaries (system deps already handled above) +RUN python -m playwright install chromium # Copy application source COPY . . # Ensure runtime directories exist even if ignored in build context -RUN mkdir -p logs final_reports insight_engine_streamlit_reports media_engine_streamlit_reports query_engine_streamlit_reports +RUN mkdir -p /ms-playwright logs final_reports insight_engine_streamlit_reports media_engine_streamlit_reports query_engine_streamlit_reports -# Expose Flask and Streamlit ports EXPOSE 5000 8501 8502 8503 # Default command launches the Flask orchestrator which starts Streamlit agents