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

[DPE-3062] Removing binary deps #179

Merged
merged 21 commits into from
Feb 5, 2024
Merged

[DPE-3062] Removing binary deps #179

merged 21 commits into from
Feb 5, 2024

Conversation

dragomirp
Copy link
Contributor

@dragomirp dragomirp commented Jan 16, 2024

Remove charmcraft binary python packages and instead bundle necessary SO libraries to build from source.

- libpq-dev
libpq:
build-packages:
- libpq-dev
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it will be installed by the other plugin but might as well.

charmcraft.yaml Outdated
Comment on lines 38 to 39
organize:
"*-linux-gnu/libpq.so*": binlibs/
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We only want libpq SOs

src/charm.py Outdated
@@ -1,4 +1,4 @@
#!/usr/bin/env python3
#!/usr/bin/env -S LD_LIBRARY_PATH=binlibs python3
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is magical, but seems to also work in focal. Alternatively, we can try to override the hooks to also add this, but I'm not sure there is a clean way to do that either.

Copy link
Member

Choose a reason for hiding this comment

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

IMHO, it's cleaner to keep it here.

Copy link
Contributor

Choose a reason for hiding this comment

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

It might be cleaner to override dispatch (which overrides all the hooks)

You can grab the default dispatch from charmcraft's repo, override it, and charmcraft will use that instead

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think we should rely on the structure of the charmcraft repo. We won't notice if anything changes there.

tox.ini Outdated
@@ -69,7 +69,7 @@ commands =
[testenv:unit]
description = Run unit tests
commands_pre =
poetry install --only main,charm-libs,unit --no-root
poetry install --only charm-libs,unit --no-root
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Had issues installing psycopg3 locally for the unit tests, may end up not being necessary.

Copy link
Member

@marceloneppel marceloneppel left a comment

Choose a reason for hiding this comment

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

The solution looks very clean. I liked it.

src/charm.py Outdated
@@ -1,4 +1,4 @@
#!/usr/bin/env python3
#!/usr/bin/env -S LD_LIBRARY_PATH=binlibs python3
Copy link
Member

Choose a reason for hiding this comment

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

IMHO, it's cleaner to keep it here.

@taurus-forever
Copy link
Contributor

In general LGTM, we can try LD_LIBRARY_PATH approach.
What is the building time difference?

@dragomirp
Copy link
Contributor Author

What is the building time difference?

The build without cached psycopg on this PR took ~4 mins. I don't think it will be drastically affected.

@dragomirp dragomirp changed the title [TEST] Removing binary deps [DPE-3062] Removing binary deps Jan 27, 2024
Comment on lines +38 to +39
organize:
"*-linux-gnu/libpq.so*": lib/
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@delgod requested moving the SO to lib.

pyproject.toml Outdated
Comment on lines 27 to 32
[tool.poetry.group.cdeps]
optional = true

[tool.poetry.group.cdeps.dependencies]
psycopg2 = "^2.9.9"
psycopg = {extras = ["c"], version = "^3.1.17"}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

If installing psycopg in the main group. It will be compiled at each unit test run and the unit tests won't be able to run on systems that do not have libpq installed.

@dragomirp dragomirp marked this pull request as ready for review January 27, 2024 18:59
Copy link
Member

@marceloneppel marceloneppel left a comment

Choose a reason for hiding this comment

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

LGTM!

Copy link
Contributor

@taurus-forever taurus-forever left a comment

Choose a reason for hiding this comment

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

Hey! This is superb!!! Well done!

pyproject.toml Outdated
Comment on lines 27 to 32
[tool.poetry.group.cdeps]
optional = true

[tool.poetry.group.cdeps.dependencies]
psycopg2 = "^2.9.9"
psycopg = {extras = ["c"], version = "^3.1.17"}
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't this this group is necessary or should be added

Installing pyscopg2 without --no-binary (aka with poetry, during unit tests) works fine on Ubuntu

Installing pyscopg2 with --no-binary (aka with charmcraft pack), with the changes Dragomir made, works fine

So, it's possible to only have pyscopg2 and pyscopg in the main dependency group, remove psycopg2-binary from the unit dependency group, and remove the c dependency group entirely

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Libpq was not present for sure on the self-hosted runner images nor is it a given that unit tests would be run on Ubuntu flavour that has libpq. Using compiled psycopg also means that CI unit tests would have to recompile on each run. @marceloneppel @taurus-forever what do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

unit tests would have to recompile on each run

wdym by recompile?

fwiw pip install pyscopg2 on ubuntu runs quite quickly (few seconds)—I believe it's building a wheel from source but it doesn't seem to be any slower than a normal pip install from a binary wheel download

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In this version unit tests task passes in ~10s: https://github.com/canonical/pgbouncer-k8s-operator/actions/runs/7714293497/job/21026204594?pr=179
If using just psycopg2 from the main group unit tests task takes ~30s: https://github.com/canonical/pgbouncer-k8s-operator/actions/runs/7714361605/job/21026430075?pr=203

Considering that the difference is up to declaring dependencies differently, I think this is the better approach.

Copy link
Contributor

Choose a reason for hiding this comment

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

it seems like something weird is going on

poetry add pyscopg2 takes 8 seconds (including venv creation) on a fresh gh runner: https://github.com/canonical/pgbouncer-k8s-operator/actions/runs/7723418033/job/21053662267

that doesn't account for a >= 20 second difference

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Removing pre-compiled binary here has a way bigger strategic effect comparing to 20 seconds saving.
BTW, 20 seconds is a noticeable time, we can safe, but as a separate PR IMHO.

Please, branch this to a new bugreport and unblock this huge merge please (as both options are safe and does the job). Tnx!

@dragomirp dragomirp merged commit c010b48 into main Feb 5, 2024
29 checks passed
@dragomirp dragomirp deleted the dpe-3062-binaries branch February 5, 2024 13:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants