From 4dfb70ecfbefcf58666255a65ffe277c9755f091 Mon Sep 17 00:00:00 2001 From: luojiyin Date: Wed, 5 Nov 2025 11:26:05 +0800 Subject: [PATCH 1/3] 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 From 5d90e7ff45b112204a4779111151546e17d13af2 Mon Sep 17 00:00:00 2001 From: luojiyin Date: Wed, 5 Nov 2025 11:35:35 +0800 Subject: [PATCH 2/3] Add security flags to curl command in Dockerfile MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add --proto '=https' and --tlsv1.2 flags to prevent insecure HTTP redirects when downloading uv installer. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 7cdb41e..7721004 100644 --- a/Dockerfile +++ b/Dockerfile @@ -39,7 +39,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ && apt-get clean && rm -rf /var/lib/apt/lists/* # 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 +RUN curl -LsSf --retry 3 --retry-delay 2 --proto '=https' --tlsv1.2 https://astral.sh/uv/install.sh | sh WORKDIR /app From ae738e8acb8180e36fc99805f04d10bb00e235fb Mon Sep 17 00:00:00 2001 From: luojiyin Date: Wed, 5 Nov 2025 11:41:04 +0800 Subject: [PATCH 3/3] Add --proto-redir flag to enforce HTTPS on redirects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix Sonar warning by adding --proto-redir '=https' to ensure all redirects in the curl chain remain on HTTPS, not just the initial request. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 7721004..59efc20 100644 --- a/Dockerfile +++ b/Dockerfile @@ -39,7 +39,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ && apt-get clean && rm -rf /var/lib/apt/lists/* # Install the latest uv release and expose it on PATH -RUN curl -LsSf --retry 3 --retry-delay 2 --proto '=https' --tlsv1.2 https://astral.sh/uv/install.sh | sh +RUN curl -LsSf --retry 3 --retry-delay 2 --proto '=https' --proto-redir '=https' --tlsv1.2 https://astral.sh/uv/install.sh | sh WORKDIR /app