Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Respect poetry lockfile in Synapse container, if present #1220

Merged
merged 7 commits into from
Mar 25, 2022

Conversation

squahtx
Copy link
Contributor

@squahtx squahtx commented Mar 24, 2022

Install pinned dependencies using poetry if a poetry.lock file is
present in the Synapse source directory, otherwise fall back to pip.

The Synapse container installs Synapse dependencies twice, once at
Docker build time and once at test time. The former installation is
intended to speed up the latter. To make this poetry-compatible, we
have to convince poetry to use the same virtual env both times. By
using the virtualenvs.in-project config option, we can get poetry to
use a virtual env at ./.venv. The source directory is going to be a
mounted volume and writing into it is impolite, so we have to make a
copy of it. For simplicity, we ditch the tarball for non-poetry
installs and always make a copy.

To make offline mode work, we have to make a cached copy of a
poetry-core wheel available to pip. For simplicity, we do the same
thing for setuptools and wheel for pre-poetry Synapses.

Once Synapse develop has been converted to poetry, the TODO in
docker/synapse.Dockerfile can be resolved.


NB: This blocks progress on poetry-izing Synapse, since some of the CI
steps can't be updated until the Synapse container includes poetry.

Can be reviewed commit by commit. The first commit is from #1219.

To test the container changes locally:

sudo docker build -f docker/synapse.Dockerfile docker
sudo docker run -it --env SYTEST_BRANCH=squah/pyproject-poetry-contribs --volume /home/squah/repos/synapse:/src ${hex-string-from-docker-build}
sudo docker run -it --env SYTEST_BRANCH=squah/pyproject-poetry-contribs --env OFFLINE=1 --volume /home/squah/repos/synapse:/src ${hex-string-from-docker-build}
sudo docker run -it --env SYTEST_BRANCH=squah/pyproject-poetry-contribs --volume /home/squah/repos/synapse-poetry:/src ${hex-string-from-docker-build}
sudo docker run -it --env SYTEST_BRANCH=squah/pyproject-poetry-contribs --env OFFLINE=1 --volume /home/squah/repos/synapse-poetry:/src ${hex-string-from-docker-build}

Sean Quah added 6 commits March 23, 2022 17:32
`--no-use-pep517` is incompatible with a poetry-using `pyproject.toml`.

Signed-off-by: Sean Quah <[email protected]>
Code to be uncommented once Synapse develop is on poetry.

Signed-off-by: Sean Quah <[email protected]>
Poetry will want to create `.venv/` inside of the Synapse source
directory, which means we have to make a copy to avoid writing to the
`/src` mounted volume.

Signed-off-by: Sean Quah <[email protected]>
@squahtx squahtx requested a review from a team as a code owner March 24, 2022 13:32
@squahtx squahtx force-pushed the squah/pyproject-poetry-contribs branch from 4fc5b04 to 9b6d8b7 Compare March 24, 2022 13:34
@squahtx
Copy link
Contributor Author

squahtx commented Mar 24, 2022

CI is failing because it's running against old containers. If desired, I could split this into two PRs, one for the Dockerfile and one for the scripts, but neither makes much sense in isolation.

@squahtx squahtx changed the title Respect poetry lockfiles in Synapse container, if present Respect poetry lockfile in Synapse container, if present Mar 24, 2022
else
# We've already created the virtualenv, but lets double check we have all
# deps.
/venv/bin/pip install -q --upgrade --no-cache-dir "$SYNAPSE_SOURCE"[redis]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm surprised we only install redis here, rather than all!

Comment on lines 153 to 162
poetry install --extras redis
popd
else
# Install Synapse and dependencies using pip. As of pip 20.1, this will
# try to build Synapse in-tree, which means writing changes to the source
# directory.
# The virtual env will already be populated with dependencies from the
# Docker build.
echo "Installing Synapse using pip..."
/venv/bin/pip install -q --upgrade --no-cache-dir /synapse[redis]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be all rather than redis---a bug from before. (If any extra other than redis changed since the container was built, that won't be picked up in this script---I think?)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(to be addressed in a PR I will insert after #1219 but before this one)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in #1224

@squahtx squahtx requested a review from DMRobertson March 25, 2022 16:59
Comment on lines +156 to +162
# Install Synapse and dependencies using pip. As of pip 20.1, this will
# try to build Synapse in-tree, which means writing changes to the source
# directory.
# The virtual env will already be populated with dependencies from the
# Docker build.
echo "Installing Synapse using pip..."
/venv/bin/pip install -q --upgrade --no-cache-dir /synapse[all]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we will end up nuking this once poetry has landed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not entirely sure. I'm half thinking that we should keep compatibility for pre-poetry versions of synapse. Then again you can just specify a pre-poetry branch of sytest?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd be inclined to leave it for a few releases and then do the nuking. One for the future, I suppose.

Copy link
Contributor

@DMRobertson DMRobertson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. (Keen to see this in CI to make sure we haven't missed anything or broken the pre-poetry world!)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants