Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion sdks/python/container/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,13 @@ RUN \
pip install upgrade_ensurepip; \
python3 -m upgrade_ensurepip; \
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; \
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; \
else \
python3 /tmp/upgrade_bundled_pip.py; \
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;
# Verify ensurepip can bootstrap pip. Required by boot.go worker venv creation.
python3 -m ensurepip;

ENTRYPOINT ["/opt/apache/beam/boot"]

Expand Down
15 changes: 13 additions & 2 deletions sdks/python/container/license_scripts/upgrade_bundled_pip.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
The script is executed within Docker after the image pip has been upgraded.
upgrade_ensurepip expects setuptools to be bundled as well, but Python 3.12+
only ships pip in ensurepip/_bundled.

After downloading, removes other pip-* files from _bundled so only the wheel
matching the installed pip version remains. Worker harness startup (boot.go)
creates a venv via ensurepip, so that wheel must be present.
"""

import subprocess
Expand All @@ -34,8 +38,8 @@ def main():
ep_path = Path(ensurepip.__file__)
wheel_dir = ep_path.parent / '_bundled'
pip_version = subprocess.check_output(
[sys.executable, '-m', 'pip', '--version'],
text=True).split()[1]
[sys.executable, '-m', 'pip', '--version'], text=True).split()[1]
expected_wheel_name = 'pip-{}-py3-none-any.whl'.format(pip_version)
subprocess.check_call([
sys.executable,
'-m',
Expand All @@ -46,6 +50,13 @@ def main():
str(wheel_dir),
'--no-deps',
])
for path in wheel_dir.glob('pip-*'):
if path.name != expected_wheel_name:
path.unlink()
if not (wheel_dir / expected_wheel_name).is_file():
sys.exit(
'ensurepip bundled pip wheel missing after install: {}'.format(
wheel_dir / expected_wheel_name))
lines = ep_path.read_text().splitlines()
pip_line = None
for idx, line in enumerate(lines):
Expand Down
Loading