From 63c2f79129e1301ed7b5a7e65f5144c5f1fddb57 Mon Sep 17 00:00:00 2001 From: jrmccluskey Date: Tue, 28 Apr 2026 15:06:24 +0000 Subject: [PATCH 1/3] use uv over pip in Python Dockerfiles --- sdks/python/container/Dockerfile | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/sdks/python/container/Dockerfile b/sdks/python/container/Dockerfile index 3bdef2dc1ddc..c7172b312998 100644 --- a/sdks/python/container/Dockerfile +++ b/sdks/python/container/Dockerfile @@ -47,11 +47,11 @@ RUN \ && \ rm -rf /var/lib/apt/lists/* && \ - pip install --upgrade pip setuptools wheel && \ + pip install --upgrade pip setuptools wheel uv && \ # Install required packages for Beam Python SDK and common dependencies used by users. # use --no-deps to ensure the list includes all transitive dependencies. - pip install --no-deps -r /tmp/base_image_requirements.txt --extra-index-url https://download.pytorch.org/whl/cpu && \ + uv pip install --no-deps -r /tmp/base_image_requirements.txt --extra-index-url https://download.pytorch.org/whl/cpu && \ rm -rf /tmp/base_image_requirements.txt && \ python -c "import nltk; nltk.download('stopwords')" && \ rm /root/nltk_data/corpora/stopwords.zip && \ @@ -75,17 +75,17 @@ RUN \ # Install Apache Beam SDK. Use --no-deps and pip check to verify that all # necessary dependencies are specified in base_image_requirements.txt. - pip install --no-deps -v /opt/apache/beam/tars/apache-beam.tar.gz[gcp] && \ - pip check || (echo "Container does not include required Beam dependencies or has conflicting dependencies. If Beam dependencies have changed, you need to regenerate base_image_requirements.txt files. See: https://s.apache.org/beam-python-requirements-generate" && exit 1) && \ + uv pip install --no-deps -v /opt/apache/beam/tars/apache-beam.tar.gz[gcp] && \ + uv pip check || (echo "Container does not include required Beam dependencies or has conflicting dependencies. If Beam dependencies have changed, you need to regenerate base_image_requirements.txt files. See: https://s.apache.org/beam-python-requirements-generate" && exit 1) && \ # Log complete list of what exact packages and versions are installed. - pip freeze --all && \ + uv pip freeze --all && \ # Remove pip cache. rm -rf /root/.cache/pip && \ # Update ensurepip to use most recent versions of setuptools and pip. This avoids some vulnerabilities which won't be fixed on older versions of python. - pip install upgrade_ensurepip; \ + uv pip install upgrade_ensurepip; \ python3 -m upgrade_ensurepip; \ # setuptools is not bundled with ensurepip in Python 3.12+ if [ "${py_version}" = "3.10" ] || [ "${py_version}" = "3.11" ]; then \ From 38db5561685e8d8dd5588c73f7c2c38f10e981c6 Mon Sep 17 00:00:00 2001 From: jrmccluskey Date: Tue, 28 Apr 2026 15:39:28 +0000 Subject: [PATCH 2/3] fix breakages --- sdks/python/container/Dockerfile | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/sdks/python/container/Dockerfile b/sdks/python/container/Dockerfile index c7172b312998..ac7cbbe9ae24 100644 --- a/sdks/python/container/Dockerfile +++ b/sdks/python/container/Dockerfile @@ -51,7 +51,7 @@ RUN \ # Install required packages for Beam Python SDK and common dependencies used by users. # use --no-deps to ensure the list includes all transitive dependencies. - uv pip install --no-deps -r /tmp/base_image_requirements.txt --extra-index-url https://download.pytorch.org/whl/cpu && \ + uv pip install --no-deps -r /tmp/base_image_requirements.txt --extra-index-url https://download.pytorch.org/whl/cpu --system --index-strategy "unsafe-best-match" && \ rm -rf /tmp/base_image_requirements.txt && \ python -c "import nltk; nltk.download('stopwords')" && \ rm /root/nltk_data/corpora/stopwords.zip && \ @@ -75,24 +75,24 @@ RUN \ # Install Apache Beam SDK. Use --no-deps and pip check to verify that all # necessary dependencies are specified in base_image_requirements.txt. - uv pip install --no-deps -v /opt/apache/beam/tars/apache-beam.tar.gz[gcp] && \ + uv pip install --no-deps -v /opt/apache/beam/tars/apache-beam.tar.gz[gcp] --system && \ uv pip check || (echo "Container does not include required Beam dependencies or has conflicting dependencies. If Beam dependencies have changed, you need to regenerate base_image_requirements.txt files. See: https://s.apache.org/beam-python-requirements-generate" && exit 1) && \ # Log complete list of what exact packages and versions are installed. - uv pip freeze --all && \ + uv pip freeze && \ # Remove pip cache. rm -rf /root/.cache/pip && \ # Update ensurepip to use most recent versions of setuptools and pip. This avoids some vulnerabilities which won't be fixed on older versions of python. - uv pip install upgrade_ensurepip; \ + uv pip install upgrade_ensurepip --system; \ python3 -m upgrade_ensurepip; \ # setuptools is not bundled with ensurepip in Python 3.12+ if [ "${py_version}" = "3.10" ] || [ "${py_version}" = "3.11" ]; then \ find /usr/local/lib/python${py_version}/ensurepip/_bundled/setuptools-* -type f ! -name $(basename $(ls -v /usr/local/lib/python${py_version}/ensurepip/_bundled/setuptools-*-py3-none-any.whl | tail -n 1)) -delete; \ fi; \ find /usr/local/lib/python${py_version}/ensurepip/_bundled/pip-* -type f ! -name $(basename $(ls -v /usr/local/lib/python${py_version}/ensurepip/_bundled/pip-*-py3-none-any.whl | tail -n 1)) -delete; \ - pip uninstall upgrade_ensurepip -y; \ + uv pip uninstall upgrade_ensurepip -y --system; \ python3 -m ensurepip; ENTRYPOINT ["/opt/apache/beam/boot"] @@ -112,7 +112,7 @@ COPY target/go-licenses/* /opt/apache/beam/third_party_licenses/golang/ COPY target/license_scripts /tmp/license_scripts/ RUN if [ "$pull_licenses" = "true" ] ; then \ - pip install 'pip-licenses<6' pyyaml tenacity && \ + uv pip install 'pip-licenses<6' pyyaml tenacity --system && \ python /tmp/license_scripts/pull_licenses_py.py ; \ fi From 6b4a3599e40d6a98bbdff57e9ee22344a8f765ff Mon Sep 17 00:00:00 2001 From: jrmccluskey Date: Tue, 28 Apr 2026 15:49:23 +0000 Subject: [PATCH 3/3] gemini suggestions --- sdks/python/container/Dockerfile | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/sdks/python/container/Dockerfile b/sdks/python/container/Dockerfile index ac7cbbe9ae24..cd54ace5e472 100644 --- a/sdks/python/container/Dockerfile +++ b/sdks/python/container/Dockerfile @@ -51,7 +51,7 @@ RUN \ # Install required packages for Beam Python SDK and common dependencies used by users. # use --no-deps to ensure the list includes all transitive dependencies. - uv pip install --no-deps -r /tmp/base_image_requirements.txt --extra-index-url https://download.pytorch.org/whl/cpu --system --index-strategy "unsafe-best-match" && \ + uv pip install --no-cache --no-deps -r /tmp/base_image_requirements.txt --extra-index-url https://download.pytorch.org/whl/cpu --system --index-strategy "unsafe-best-match" && \ rm -rf /tmp/base_image_requirements.txt && \ python -c "import nltk; nltk.download('stopwords')" && \ rm /root/nltk_data/corpora/stopwords.zip && \ @@ -75,24 +75,24 @@ RUN \ # Install Apache Beam SDK. Use --no-deps and pip check to verify that all # necessary dependencies are specified in base_image_requirements.txt. - uv pip install --no-deps -v /opt/apache/beam/tars/apache-beam.tar.gz[gcp] --system && \ - uv pip check || (echo "Container does not include required Beam dependencies or has conflicting dependencies. If Beam dependencies have changed, you need to regenerate base_image_requirements.txt files. See: https://s.apache.org/beam-python-requirements-generate" && exit 1) && \ + uv pip install --no-cache --no-deps -v /opt/apache/beam/tars/apache-beam.tar.gz[gcp] --system && \ + uv pip check --system || (echo "Container does not include required Beam dependencies or has conflicting dependencies. If Beam dependencies have changed, you need to regenerate base_image_requirements.txt files. See: https://s.apache.org/beam-python-requirements-generate" && exit 1) && \ # Log complete list of what exact packages and versions are installed. - uv pip freeze && \ + uv pip freeze --system && \ # Remove pip cache. rm -rf /root/.cache/pip && \ # Update ensurepip to use most recent versions of setuptools and pip. This avoids some vulnerabilities which won't be fixed on older versions of python. - uv pip install upgrade_ensurepip --system; \ + uv pip install --no-cache upgrade_ensurepip --system; \ python3 -m upgrade_ensurepip; \ # setuptools is not bundled with ensurepip in Python 3.12+ if [ "${py_version}" = "3.10" ] || [ "${py_version}" = "3.11" ]; then \ find /usr/local/lib/python${py_version}/ensurepip/_bundled/setuptools-* -type f ! -name $(basename $(ls -v /usr/local/lib/python${py_version}/ensurepip/_bundled/setuptools-*-py3-none-any.whl | tail -n 1)) -delete; \ fi; \ find /usr/local/lib/python${py_version}/ensurepip/_bundled/pip-* -type f ! -name $(basename $(ls -v /usr/local/lib/python${py_version}/ensurepip/_bundled/pip-*-py3-none-any.whl | tail -n 1)) -delete; \ - uv pip uninstall upgrade_ensurepip -y --system; \ + uv pip uninstall upgrade_ensurepip --system; \ python3 -m ensurepip; ENTRYPOINT ["/opt/apache/beam/boot"] @@ -112,7 +112,7 @@ COPY target/go-licenses/* /opt/apache/beam/third_party_licenses/golang/ COPY target/license_scripts /tmp/license_scripts/ RUN if [ "$pull_licenses" = "true" ] ; then \ - uv pip install 'pip-licenses<6' pyyaml tenacity --system && \ + uv pip install --no-cache 'pip-licenses<6' pyyaml tenacity --system && \ python /tmp/license_scripts/pull_licenses_py.py ; \ fi