eager-dress-66405
01/11/2022, 4:25 AMpex_binary
in a docker_image
. My python application includes a python package (pybedtools
) which has some native components. My dev system is ubuntu21.04. The docker image base is python:3.8.12-slim. When I package the pex it builds components of pybedtools
against the GLIBC 2.33 on my dev system, which then fails inside the docker image where 2.31 is installed:
root@e107dc414f9c:/color# python3 $PEX_BINARY
...
File "/root/.pex/installed_wheels/bf89cafd4094cc8d47719f572e0edb81d1c39ef9/pybedtools-0.8.2-cp38-cp38-linux_x86_64.whl/pybedtools/__init__.py", line 9, in <module>
from .cbedtools import (
ImportError: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.33' not found (required by /root/.pex/installed_wheels/bf89cafd4094cc8d47719f572e0edb81d1c39ef9/pybedtools-0.8.2-cp38-cp38-linux_x86_64.whl/pybedtools/cbedtools.cpython-38-x86_64-linux-gnu.so)
root@e107dc414f9c:/color# ls -lah /lib/x86_64-linux-gnu/libc.so.6
lrwxrwxrwx 1 root root 12 Oct 2 12:47 /lib/x86_64-linux-gnu/libc.so.6 -> libc-2.31.so
Possible solutions (none perfect):
1. Match my docker image base to my dev machine? (brittle)
2. Run the ./pants package path/to/Dockerfile
in a docker image? (gets convoluted fast)
3. Rebuild wheels somehow at docker image build time or runtime? (unclear how)enough-analyst-54434
01/11/2022, 4:34 AMpip wheel ...
say) and serve them up in a directory you let Pants see via:
[python-repos]
repos = [
"file:///network/mount/wheel/house",
"<https://central.server/wheel/house>"
]
And then add platforms
to your pex_binary
target: https://www.pantsbuild.org/docs/reference-pex_binary#codeplatformscodeenough-analyst-54434
01/11/2022, 4:35 AMeager-dress-66405
01/11/2022, 4:38 AMeager-dress-66405
01/11/2022, 4:39 AMenough-analyst-54434
01/11/2022, 4:41 AM$ pex --platform help
Traceback (most recent call last):
File "/home/jsirois/.venv/pex/lib/python3.10/site-packages/pex/platforms.py", line 48, in create
platform, impl, version, abi = platform.rsplit(cls.SEP, 3)
ValueError: not enough values to unpack (expected 4, got 1)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/jsirois/.venv/pex/lib/python3.10/site-packages/pex/resolve/target_options.py", line 212, in configure
convert_platforms(options.platforms)
File "/home/jsirois/.venv/pex/lib/python3.10/site-packages/pex/resolve/target_configuration.py", line 31, in convert_platforms
return tuple(_parsed_platform(platform) for platform in platforms or ()) if platforms else ()
File "/home/jsirois/.venv/pex/lib/python3.10/site-packages/pex/resolve/target_configuration.py", line 31, in <genexpr>
return tuple(_parsed_platform(platform) for platform in platforms or ()) if platforms else ()
File "/home/jsirois/.venv/pex/lib/python3.10/site-packages/pex/resolve/target_configuration.py", line 26, in _parsed_platform
return Platform.create(platform) if platform and platform != "current" else None
File "/home/jsirois/.venv/pex/lib/python3.10/site-packages/pex/platforms.py", line 51, in create
raise cls.InvalidPlatformError(
pex.platforms.InvalidPlatformError: Not a valid platform specifier: help
Platform strings must be in one of two forms:
1. Canonical: <platform>-<python impl abbr>-<python version>-<abi>
2. Abbreviated: <platform>-<python impl abbr>-<python version>-<abbr abi>
Given a canonical platform string for CPython 3.7.5 running on 64 bit linux of:
linux-x86_64-cp-37-cp37m
Where the fields above are:
+ <platform>: linux-x86_64
+ <python impl abbr>: cp
+ <python version>: 37
+ <abi>: cp37m
The abbreviated platform string is:
linux-x86_64-cp-37-m
Some other canonical platform string examples:
+ OSX CPython: macosx-10.13-x86_64-cp-36-cp36m
+ Linux PyPy: linux-x86_64-pp-273-pypy_73.
These fields stem from wheel name conventions as outlined in
<https://www.python.org/dev/peps/pep-0427#file-name-convention> and influenced by
<https://www.python.org/dev/peps/pep-0425>.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/jsirois/.venv/pex/bin/pex", line 8, in <module>
sys.exit(main())
File "/home/jsirois/.venv/pex/lib/python3.10/site-packages/pex/bin/pex.py", line 680, in main
target_configuration = target_options.configure(options)
File "/home/jsirois/.venv/pex/lib/python3.10/site-packages/pex/resolve/target_options.py", line 215, in configure
raise ArgumentTypeError(str(e))
argparse.ArgumentTypeError: Not a valid platform specifier: help
Platform strings must be in one of two forms:
1. Canonical: <platform>-<python impl abbr>-<python version>-<abi>
2. Abbreviated: <platform>-<python impl abbr>-<python version>-<abbr abi>
Given a canonical platform string for CPython 3.7.5 running on 64 bit linux of:
linux-x86_64-cp-37-cp37m
Where the fields above are:
+ <platform>: linux-x86_64
+ <python impl abbr>: cp
+ <python version>: 37
+ <abi>: cp37m
The abbreviated platform string is:
linux-x86_64-cp-37-m
Some other canonical platform string examples:
+ OSX CPython: macosx-10.13-x86_64-cp-36-cp36m
+ Linux PyPy: linux-x86_64-pp-273-pypy_73.
These fields stem from wheel name conventions as outlined in
<https://www.python.org/dev/peps/pep-0427#file-name-convention> and influenced by
<https://www.python.org/dev/peps/pep-0425>.
enough-analyst-54434
01/11/2022, 4:41 AMeager-dress-66405
01/11/2022, 4:46 AMpex --platform help
is doing for meenough-analyst-54434
01/11/2022, 4:48 AMpex --help
and read the --platform
help string. It will tell you what your current platform is.enough-analyst-54434
01/11/2022, 4:50 AMeager-dress-66405
01/11/2022, 4:52 AMeager-dress-66405
01/11/2022, 4:53 AMroot@a28014a7154c:/color# PEX_TOOLS=1 pex interpreter --verbose
{"path": "/usr/local/bin/python3.8", "requirement": "CPython==3.8.12", "platform": "manylinux_2_31_x86_64-cp-38-cp38"}
eager-dress-66405
01/11/2022, 4:58 AMenough-analyst-54434
01/11/2022, 4:59 AMeager-dress-66405
01/11/2022, 4:59 AMenough-analyst-54434
01/11/2022, 5:00 AMpex-tools interpreter --verbose
(I wrote this stuff and I forgot about it!).enough-analyst-54434
01/11/2022, 5:00 AMenough-analyst-54434
01/11/2022, 5:03 AMAssuming that support is several months away at least do you have any suggestions for building these wheels in the short term? I assume also in dockerYeah, just
pip wheel --wheel-dir /here
where /here/
is a volume you can get at from outside the container. Basically, docker aside, you want to use a production image machine for each production arch you have in the fleet (hopefully not too many!) to build all sdists you need into wheels. You then want to serve up all those wheels in either a flat network mounted directory or via an http(s) server with an index page.enough-analyst-54434
01/11/2022, 5:05 AMeager-dress-66405
01/11/2022, 5:07 AMpip wheel
(package names and pegged versions from constaints) from the pex or from pants?enough-analyst-54434
01/11/2022, 5:09 AMpex [requirements] --include-tools -orepo.pex
PEX_TOOLS=1 ./repo.pex repository extract --repo /here/
eager-dress-66405
01/11/2022, 5:11 AMenough-analyst-54434
01/11/2022, 5:11 AMis there a way to get the rest of the args forThe original requirements are in(package names and pegged versions from constaints) from the pex or from pants?pip wheel
PEX_TOOLS=1 ./my.pex info | jq .requirements
. The pins are a bit harder to get, but you can look at jq .distributions
keys which are the actual wheel names.eager-dress-66405
01/11/2022, 5:14 AMeager-dress-66405
01/11/2022, 5:16 AMeager-dress-66405
01/11/2022, 5:20 AMenough-analyst-54434
01/11/2022, 5:22 AMenough-analyst-54434
01/11/2022, 5:23 AMwitty-crayon-22786
01/11/2022, 6:01 PMeager-dress-66405
01/12/2022, 6:07 AMeager-dress-66405
01/20/2022, 2:24 AM[docker]
build_args = [
"BASE_PYTHON_IMAGE=python:3.8.12-slim"
]
`build/pants/docker_packager/Dockerfile`:
ARG BASE_PYTHON_IMAGE
FROM ${BASE_PYTHON_IMAGE}
RUN sed -iE 'p; s/^deb /deb-src /' /etc/apt/sources.list && \
apt-get update && \
apt-get install -y curl git-core <http://docker.io|docker.io> unzip build-essential python3-distutils && \
apt-get -y build-dep bedtools
WORKDIR /src
ENV COLOR_ROOT /src
ENV PANTS_PYTHON_BOOTSTRAP_SEARCH_PATH="['<PATH>']"
ENTRYPOINT ["./pants", "package"]
build/pants/docker_packager/packager.sh
#!/bin/bash -eux
# Runs the pants package goal on a target from inside a docker container based on BASE_PYTHON_IMAGE.
# Usage example:
# $ build/pants/docker_packager/packager.sh <target>
#
# This is done so that wheels will be built on a platform that matches the final environment. Eventually pants will support this natively.
# <https://github.com/pantsbuild/pants/issues/13682>
# <https://pantsbuild.slack.com/archives/C046T6T9U/p1641875149141400>
cd "$SRC_ROOT"
./pants \
run \
--docker-run-args="-v $SRC_ROOT:/src -v pants_builder_cache:/root/.cache -v /var/run/docker.sock:/var/run/docker.sock -e COMMIT_SHA" \
build/pants/docker_packager/Dockerfile \
-- \
"$@"