Synapse's docker images (and CI?) do not pin the specific build requirements of poetry #13849
Description
Synapse's docker file installs a specific version of poetry in build stage 0:
Lines 58 to 61 in 08297f2
and uses it to export a requirements.txt file for the other stages to use (without having to install poetry).
Lines 78 to 85 in 08297f2
The former step is not fully reproducible1, because pip
will use the latest version of poetry's build-time dependencies to install poetry. (As of poetry 1.3.2 those dependencies are the unbounded range poetry-core >= 1.1.0
, see here). I advised the reporter to patch the Dockerfile in order to get Synapse 1.61 built again.
We saw this manifest in the report below: a version of poetry-core was released under which previous versions of poetry would fail to build, see #13849 (comment).
It seems like the Python packaging ecosystem doesn't have an obvious way to pin build-time dependencies. (See for instance https://discuss.python.org/t/pinning-build-dependencies/8363 or pypa/pip#9542.) The best approach that I can see is described in pypa/pip#9542 (comment), namely
- install the build-time dependencies into the environment you're interested in
pip install --no-build-isolation ...
Original issue:
Unable to build v1.61.0 docker image with clean caches
Just tried to build v1.61.0 on Linux and Windows and both fail.
I know this worked a few weeks ago and I basically think that OP was right with the version pining.
Motivation: I want to bisect and thus build v1.61.0 .. v1.62.0 for identifying a patch which destroyed the generate call for us (I'll open a new ticket for that one).
Here is the error:
git checkout tags/v1.61.0
DOCKER_BUILDKIT=1 docker build -f docker/Dockerfile -t fred .
[+] Building 76.9s (14/25)
=> [internal] load build definition from Dockerfile 0.1s
=> => transferring dockerfile: 5.28kB 0.0s
=> [internal] load .dockerignore 0.1s
=> => transferring context: 170B 0.0s
=> resolve image config for docker.io/docker/dockerfile:1 1.3s
=> [auth] docker/dockerfile:pull token for registry-1.docker.io 0.0s
=> docker-image://docker.io/docker/dockerfile:1@sha256:9ba7531bd80fb0a858632727cf7a112fbfd19b17e94c4e84ced81e24ef1a0dbc 1.0s
=> => resolve docker.io/docker/dockerfile:1@sha256:9ba7531bd80fb0a858632727cf7a112fbfd19b17e94c4e84ced81e24ef1a0dbc 0.0s
=> => sha256:9ba7531bd80fb0a858632727cf7a112fbfd19b17e94c4e84ced81e24ef1a0dbc 2.00kB / 2.00kB 0.0s
=> => sha256:ad87fb03593d1b71f9a1cfc1406c4aafcb253b1dabebf569768d6e6166836f34 528B / 528B 0.0s
=> => sha256:1e8a16826fd1c80a63fa6817a9c7284c94e40cded14a9b0d0d3722356efa47bd 2.37kB / 2.37kB 0.0s
=> => sha256:1328b32c40fca9bcf9d70d8eccb72eb873d1124d72dadce04db8badbe7b08546 9.94MB / 9.94MB 0.7s
=> => extracting sha256:1328b32c40fca9bcf9d70d8eccb72eb873d1124d72dadce04db8badbe7b08546 0.2s
=> [internal] load build definition from Dockerfile 0.0s
=> [internal] load .dockerignore 0.0s
=> [internal] load metadata for docker.io/library/python:3.9-slim 0.0s
=> [internal] load build context 0.3s
=> => transferring context: 7.41MB 0.2s
=> [stage-2 1/5] FROM docker.io/library/python:3.9-slim 0.2s
=> [builder 2/7] RUN --mount=type=cache,target=/var/cache/apt,sharing=locked --mount=type=cache,target=/var/lib/apt,sharing=locked apt-get update && apt-get install -y build-essential libffi-dev libjpeg-dev 51.4s
=> [stage-2 2/5] RUN --mount=type=cache,target=/var/cache/apt,sharing=locked --mount=type=cache,target=/var/lib/apt,sharing=locked apt-get update && apt-get install -y curl gosu libjpeg62-turbo libpq5 70.1s
=> [requirements 2/6] RUN --mount=type=cache,target=/var/cache/apt,sharing=locked --mount=type=cache,target=/var/lib/apt,sharing=locked apt-get update && apt-get install -y git && rm -rf /var/lib/apt/lists/* 60.6s
=> ERROR [requirements 3/6] RUN --mount=type=cache,target=/root/.cache/pip pip install --user "poetry-core==1.1.0a7" "git+https://github.com/python-poetry/poetry.git@fb13b3a676f476177f7937ffa480ee5cff9a90a5" 13.0s
------
> [requirements 3/6] RUN --mount=type=cache,target=/root/.cache/pip pip install --user "poetry-core==1.1.0a7" "git+https://github.com/python-poetry/poetry.git@fb13b3a676f476177f7937ffa480ee5cff9a90a5":
#13 3.856 Collecting git+https://github.com/python-poetry/poetry.git@fb13b3a676f476177f7937ffa480ee5cff9a90a5
#13 3.858 Cloning https://github.com/python-poetry/poetry.git (to revision fb13b3a676f476177f7937ffa480ee5cff9a90a5) to /tmp/pip-req-build-tufn8q4p
#13 3.866 Running command git clone --filter=blob:none --quiet https://github.com/python-poetry/poetry.git /tmp/pip-req-build-tufn8q4p
#13 7.242 Running command git rev-parse -q --verify 'sha^fb13b3a676f476177f7937ffa480ee5cff9a90a5'
#13 7.250 Running command git fetch -q https://github.com/python-poetry/poetry.git fb13b3a676f476177f7937ffa480ee5cff9a90a5
#13 7.839 Running command git checkout -q fb13b3a676f476177f7937ffa480ee5cff9a90a5
#13 9.253 Resolved https://github.com/python-poetry/poetry.git to commit fb13b3a676f476177f7937ffa480ee5cff9a90a5
#13 9.720 Installing build dependencies: started
#13 12.36 Installing build dependencies: finished with status 'done'
#13 12.37 Getting requirements to build wheel: started
#13 12.46 Getting requirements to build wheel: finished with status 'done'
#13 12.46 Preparing metadata (pyproject.toml): started
#13 12.77 Preparing metadata (pyproject.toml): finished with status 'error'
#13 12.77 error: subprocess-exited-with-error
#13 12.77
#13 12.77 × Preparing metadata (pyproject.toml) did not run successfully.
#13 12.77 │ exit code: 1
#13 12.77 ╰─> [26 lines of output]
#13 12.77 Traceback (most recent call last):
#13 12.77 File "/usr/local/lib/python3.9/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 363, in <module>
#13 12.77 main()
#13 12.77 File "/usr/local/lib/python3.9/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 345, in main
#13 12.77 json_out['return_val'] = hook(**hook_input['kwargs'])
#13 12.77 File "/usr/local/lib/python3.9/site-packages/pip/_vendor/pep517/in_process/_in_process.py", line 164, in prepare_metadata_for_build_wheel
#13 12.77 return hook(metadata_directory, config_settings)
#13 12.77 File "/tmp/pip-build-env-yp6fwb9j/overlay/lib/python3.9/site-packages/poetry/core/masonry/api.py", line 40, in prepare_metadata_for_build_wheel
#13 12.77 poetry = Factory().create_poetry(Path(".").resolve(), with_groups=False)
#13 12.77 File "/tmp/pip-build-env-yp6fwb9j/overlay/lib/python3.9/site-packages/poetry/core/factory.py", line 62, in create_poetry
#13 12.77 package = self.configure_package(
#13 12.77 File "/tmp/pip-build-env-yp6fwb9j/overlay/lib/python3.9/site-packages/poetry/core/factory.py", line 156, in configure_package
#13 12.77 cls._add_package_group_dependencies(
#13 12.77 File "/tmp/pip-build-env-yp6fwb9j/overlay/lib/python3.9/site-packages/poetry/core/factory.py", line 102, in _add_package_group_dependencies
#13 12.77 cls.create_dependency(
#13 12.77 File "/tmp/pip-build-env-yp6fwb9j/overlay/lib/python3.9/site-packages/poetry/core/factory.py", line 366, in create_dependency
#13 12.77 dependency = Dependency(name, constraint, groups=groups)
#13 12.77 File "/tmp/pip-build-env-yp6fwb9j/overlay/lib/python3.9/site-packages/poetry/core/packages/dependency.py", line 66, in __init__
#13 12.77 self.constraint = constraint # type: ignore[assignment]
#13 12.77 File "/tmp/pip-build-env-yp6fwb9j/overlay/lib/python3.9/site-packages/poetry/core/packages/dependency.py", line 110, in constraint
#13 12.77 self._constraint = parse_constraint(constraint)
#13 12.77 File "/tmp/pip-build-env-yp6fwb9j/overlay/lib/python3.9/site-packages/poetry/core/semver/helpers.py", line 31, in parse_constraint
#13 12.77 constraint_objects.append(parse_single_constraint(constraint))
#13 12.77 File "/tmp/pip-build-env-yp6fwb9j/overlay/lib/python3.9/site-packages/poetry/core/semver/helpers.py", line 147, in parse_single_constraint
#13 12.77 raise ParseConstraintError(f"Could not parse version constraint: {constraint}")
#13 12.77 poetry.core.semver.exceptions.ParseConstraintError: Could not parse version constraint: (>=20.4.3
#13 12.77 [end of output]
#13 12.77
#13 12.77 note: This error originates from a subprocess, and is likely not a problem with pip.
#13 12.78 error: metadata-generation-failed
#13 12.78
#13 12.78 × Encountered error while generating package metadata.
#13 12.78 ╰─> See above for output.
#13 12.78
#13 12.78 note: This is an issue with the package mentioned above, not pip.
#13 12.78 hint: See above for details.
#13 12.79 WARNING: You are using pip version 22.0.4; however, version 22.2.2 is available.
#13 12.79 You should consider upgrading via the '/usr/local/bin/python -m pip install --upgrade pip' command.
------
executor failed running [/bin/sh -c pip install --user "poetry-core==1.1.0a7" "git+https://github.com/python-poetry/poetry.git@fb13b3a676f476177f7937ffa480ee5cff9a90a5"]: exit code: 1
Originally posted by @qknight in #11537 (comment)
Footnotes
-
The steps which run
apt-get update
and run the abitrarysh.rustup.sh
script aren't reproducible either, if anyone's counting. ↩