From e859d71d1966e046bb6648b6e02c72e4b703cd51 Mon Sep 17 00:00:00 2001 From: Dragomir Penev Date: Tue, 16 Jan 2024 23:17:18 +0200 Subject: [PATCH 01/11] Shebang magic and dump plugin --- charmcraft.yaml | 10 ++++-- poetry.lock | 94 ++++++++++++++----------------------------------- pyproject.toml | 8 +++-- src/charm.py | 2 +- tox.ini | 2 +- 5 files changed, 41 insertions(+), 75 deletions(-) diff --git a/charmcraft.yaml b/charmcraft.yaml index 261045638..f8e36fb60 100644 --- a/charmcraft.yaml +++ b/charmcraft.yaml @@ -26,6 +26,10 @@ parts: - rustc - cargo - pkg-config - charm-binary-python-packages: - - psycopg2-binary - - psycopg-binary + - libpq-dev + libpq: + plugin: dump + source: http://archive.ubuntu.com/ubuntu/pool/main/p/postgresql-14/libpq5_14.10-0ubuntu0.22.04.1_amd64.deb + source-type: deb + organize: + 'usr/lib/*-linux-gnu/libpq.so*': binlibs/ diff --git a/poetry.lock b/poetry.lock index 1f2af6884..c30979134 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1261,7 +1261,7 @@ files = [ [package.dependencies] "backports.zoneinfo" = {version = ">=0.2.0", markers = "python_version < \"3.9\""} -psycopg-binary = {version = "3.1.17", optional = true, markers = "implementation_name != \"pypy\" and extra == \"binary\""} +psycopg-c = {version = "3.1.17", optional = true, markers = "implementation_name != \"pypy\" and extra == \"c\""} typing-extensions = ">=4.1" tzdata = {version = "*", markers = "sys_platform == \"win32\""} @@ -1274,77 +1274,35 @@ pool = ["psycopg-pool"] test = ["anyio (>=3.6.2,<4.0)", "mypy (>=1.4.1)", "pproxy (>=2.7)", "pytest (>=6.2.5)", "pytest-cov (>=3.0)", "pytest-randomly (>=3.5)"] [[package]] -name = "psycopg-binary" +name = "psycopg-c" version = "3.1.17" description = "PostgreSQL database adapter for Python -- C optimisation distribution" optional = false python-versions = ">=3.7" files = [ - {file = "psycopg_binary-3.1.17-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:f9ba559eabb0ba1afd4e0504fa0b10e00a212cac0c4028b8a1c3b087b5c1e5de"}, - {file = "psycopg_binary-3.1.17-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:2b2a689eaede08cf91a36b10b0da6568dd6e4669200f201e082639816737992b"}, - {file = "psycopg_binary-3.1.17-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:a16abab0c1abc58feb6ab11d78d0f8178a67c3586bd70628ec7c0218ec04c4ef"}, - {file = "psycopg_binary-3.1.17-cp310-cp310-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:73e7097b81cad9ae358334e3cec625246bb3b8013ae6bb287758dd6435e12f65"}, - {file = "psycopg_binary-3.1.17-cp310-cp310-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:67a5b93101bc85a95a189c0a23d02a29cf06c1080a695a0dedfdd50dd734662a"}, - {file = "psycopg_binary-3.1.17-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:751b31c2faae0348f87f22b45ef58f704bdcfc2abdd680fa0c743c124071157e"}, - {file = "psycopg_binary-3.1.17-cp310-cp310-musllinux_1_1_aarch64.whl", hash = "sha256:b447ea765e71bc33a82cf070bba814b1efa77967442d116b95ccef8ce5da7631"}, - {file = "psycopg_binary-3.1.17-cp310-cp310-musllinux_1_1_i686.whl", hash = "sha256:d2e9ed88d9a6a475c67bf70fc8285e88ccece0391727c7701e5a512e0eafbb05"}, - {file = "psycopg_binary-3.1.17-cp310-cp310-musllinux_1_1_ppc64le.whl", hash = "sha256:a89f36bf7b612ff6ed3e789bd987cbd0787cf0d66c49386fa3bad816dd7bee87"}, - {file = "psycopg_binary-3.1.17-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:5ccbe8b2ec444763a51ecb1213befcbb75defc1ef36e7dd5dff501a23d7ce8cf"}, - {file = "psycopg_binary-3.1.17-cp310-cp310-win_amd64.whl", hash = "sha256:adb670031b27949c9dc5cf585c4a5a6b4469d3879fd2fb9d39b6d53e5f66b9bc"}, - {file = "psycopg_binary-3.1.17-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:0227885686c2cc0104ceb22d6eebc732766e9ad48710408cb0123237432e5435"}, - {file = "psycopg_binary-3.1.17-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:9124b6db07e8d8b11f4512b8b56cbe136bf1b7d0417d1280e62291a9dcad4408"}, - {file = "psycopg_binary-3.1.17-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:c8a46f77ba0ca7c5a5449b777170a518fa7820e1710edb40e777c9798f00d033"}, - {file = "psycopg_binary-3.1.17-cp311-cp311-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:5f5f5bcbb772d8c243d605fc7151beec760dd27532d42145a58fb74ef9c5fbf2"}, - {file = "psycopg_binary-3.1.17-cp311-cp311-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:267a82548c21476120e43dc72b961f1af52c380c0b4c951bdb34cf14cb26bd35"}, - {file = "psycopg_binary-3.1.17-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:4b20013051f1fd7d02b8d0766cfe8d009e8078babc00a6d39bc7e2d50a7b96af"}, - {file = "psycopg_binary-3.1.17-cp311-cp311-musllinux_1_1_aarch64.whl", hash = "sha256:8c5c38129cc79d7e3ba553035b9962a442171e9f97bb1b8795c0885213f206f3"}, - {file = "psycopg_binary-3.1.17-cp311-cp311-musllinux_1_1_i686.whl", hash = "sha256:d01c4faae66de60fcd3afd3720dcc8ffa03bc2087f898106da127774db12aac5"}, - {file = "psycopg_binary-3.1.17-cp311-cp311-musllinux_1_1_ppc64le.whl", hash = "sha256:e6ae27b0617ad3809449964b5e901b21acff8e306abacb8ba71d5ee7c8c47eeb"}, - {file = "psycopg_binary-3.1.17-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:40af298b209dd77ca2f3e7eb3fbcfb87a25999fc015fcd14140bde030a164c7e"}, - {file = "psycopg_binary-3.1.17-cp311-cp311-win_amd64.whl", hash = "sha256:7b4e4c2b05f3b431e9026e82590b217e87696e7a7548f512ae8059d59fa8af3b"}, - {file = "psycopg_binary-3.1.17-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:ea425a8dcd808a7232a5417d2633bfa543da583a2701b5228e9e29989a50deda"}, - {file = "psycopg_binary-3.1.17-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:a3f1196d76860e72d338fab0d2b6722e8d47e2285d693e366ae36011c4a5898a"}, - {file = "psycopg_binary-3.1.17-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:e1e867c2a729348df218a14ba1b862e627177fd57c7b4f3db0b4c708f6d03696"}, - {file = "psycopg_binary-3.1.17-cp312-cp312-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:b0711e46361ea3047cd049868419d030c8236a9dea7e9ed1f053cbd61a853ec9"}, - {file = "psycopg_binary-3.1.17-cp312-cp312-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:d1c0115bdf80cf6c8c9109cb10cf6f650fd1a8d841f884925e8cb12f34eb5371"}, - {file = "psycopg_binary-3.1.17-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:3d0d154c780cc7b28a3a0886e8a4b18689202a1dbb522b3c771eb3a1289cf7c3"}, - {file = "psycopg_binary-3.1.17-cp312-cp312-musllinux_1_1_aarch64.whl", hash = "sha256:f4028443bf25c1e04ecffdc552c0a98d826903dec76a1568dfddf5ebbbb03db7"}, - {file = "psycopg_binary-3.1.17-cp312-cp312-musllinux_1_1_i686.whl", hash = "sha256:bf424d92dd7e94705b31625b02d396297a7c8fab4b6f7de8dba6388323a7b71c"}, - {file = "psycopg_binary-3.1.17-cp312-cp312-musllinux_1_1_ppc64le.whl", hash = "sha256:00377f6963ee7e4bf71cab17c2c235ef0624df9483f3b615d86aa24cde889d42"}, - {file = "psycopg_binary-3.1.17-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:9690a535d9ccd361bbc3590bfce7fe679e847f44fa7cc97f3b885f4744ca8a2c"}, - {file = "psycopg_binary-3.1.17-cp312-cp312-win_amd64.whl", hash = "sha256:6b2ae342d69684555bfe77aed5546d125b4a99012e0b83a8b3da68c8829f0935"}, - {file = "psycopg_binary-3.1.17-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:86bb3656c8d744cc1e42003414cd6c765117d70aa23da6c0f4ff2b826e0fd0fd"}, - {file = "psycopg_binary-3.1.17-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:c10b7713e3ed31df7319c2a72d5fea5a2536476d7695a3e1d18a1f289060997c"}, - {file = "psycopg_binary-3.1.17-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:12eab8bc91b4ba01b2ecee3b5b80501934b198f6e1f8d4b13596f3f38ba6e762"}, - {file = "psycopg_binary-3.1.17-cp37-cp37m-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:6a728beefd89b430ebe2729d04ba10e05036b5e9d01648da60436000d2fcd242"}, - {file = "psycopg_binary-3.1.17-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:61104b8e7a43babf2bbaa36c08e31a12023e2f967166e99d6b052b11a4c7db06"}, - {file = "psycopg_binary-3.1.17-cp37-cp37m-musllinux_1_1_aarch64.whl", hash = "sha256:02cd2eb62ffc56f8c847d68765cbf461b3d11b438fe48951e44b6c563ec27d18"}, - {file = "psycopg_binary-3.1.17-cp37-cp37m-musllinux_1_1_i686.whl", hash = "sha256:ca1757a6e080086f7234dc45684e81a47a66a6dd492a37d6ce38c58a1a93e9ff"}, - {file = "psycopg_binary-3.1.17-cp37-cp37m-musllinux_1_1_ppc64le.whl", hash = "sha256:6e3543edc18553e31a3884af3cd7eea43d6c44532d8b9b16f3e743cdf6cfe6c5"}, - {file = "psycopg_binary-3.1.17-cp37-cp37m-musllinux_1_1_x86_64.whl", hash = "sha256:914254849486e14aa931b0b3382cd16887f1507068ffba775cbdc5a55fe9ef19"}, - {file = "psycopg_binary-3.1.17-cp37-cp37m-win_amd64.whl", hash = "sha256:92fad8f1aa80a5ab316c0493dc6d1b54c1dba21937e43eea7296ff4a0ccc071e"}, - {file = "psycopg_binary-3.1.17-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:6d4f2e15d33ed4f9776fdf23683512d76f4e7825c4b80677e9e3ce6c1b193ff2"}, - {file = "psycopg_binary-3.1.17-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:4fa26836ce074a1104249378727e1f239a01530f36bae16e77cf6c50968599b4"}, - {file = "psycopg_binary-3.1.17-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:d54bcf2dfc0880bf13f38512d44b194c092794e4ee9e01d804bc6cd3eed9bfb7"}, - {file = "psycopg_binary-3.1.17-cp38-cp38-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:7e28024204dc0c61094268c682041d2becfedfea2e3b46bed5f6138239304d98"}, - {file = "psycopg_binary-3.1.17-cp38-cp38-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:0b1ec6895cab887b92c303565617f994c9b9db53befda81fa2a31b76fe8a3ab1"}, - {file = "psycopg_binary-3.1.17-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:420c1eb1626539c261cf3fbe099998da73eb990f9ce1a34da7feda414012ea5f"}, - {file = "psycopg_binary-3.1.17-cp38-cp38-musllinux_1_1_aarch64.whl", hash = "sha256:83404a353240fdff5cfe9080665fdfdcaa2d4d0c5112e15b0a2fe2e59200ed57"}, - {file = "psycopg_binary-3.1.17-cp38-cp38-musllinux_1_1_i686.whl", hash = "sha256:a0c4ba73f9e7721dd6cc3e6953016652dbac206f654229b7a1a8ac182b16e689"}, - {file = "psycopg_binary-3.1.17-cp38-cp38-musllinux_1_1_ppc64le.whl", hash = "sha256:f6898bf1ca5aa01115807643138e3e20ec603b17a811026bc4a49d43055720a7"}, - {file = "psycopg_binary-3.1.17-cp38-cp38-musllinux_1_1_x86_64.whl", hash = "sha256:6b40fa54a02825d3d6a8009d9a82a2b4fad80387acf2b8fd6d398fd2813cb2d9"}, - {file = "psycopg_binary-3.1.17-cp38-cp38-win_amd64.whl", hash = "sha256:78ebb43dca7d5b41eee543cd005ee5a0256cecc74d84acf0fab4f025997b837e"}, - {file = "psycopg_binary-3.1.17-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:02ac573f5a6e79bb6df512b3a6279f01f033bbd45c47186e8872fee45f6681d0"}, - {file = "psycopg_binary-3.1.17-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:704f6393d758b12a4369887fe956b2a8c99e4aced839d9084de8e3f056015d40"}, - {file = "psycopg_binary-3.1.17-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:0340ef87a888fd940796c909e038426f4901046f61856598582a817162c64984"}, - {file = "psycopg_binary-3.1.17-cp39-cp39-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:a880e4113af3ab84d6a0991e3f85a2424924c8a182733ab8d964421df8b5190a"}, - {file = "psycopg_binary-3.1.17-cp39-cp39-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:93921178b9a40c60c26e47eb44970f88c49fe484aaa3bb7ec02bb8b514eab3d9"}, - {file = "psycopg_binary-3.1.17-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:2a05400e9314fc30bc1364865ba9f6eaa2def42b5e7e67f71f9a4430f870023e"}, - {file = "psycopg_binary-3.1.17-cp39-cp39-musllinux_1_1_aarch64.whl", hash = "sha256:3e2cc2bbf37ff1cf11e8b871c294e3532636a3cf7f0c82518b7537158923d77b"}, - {file = "psycopg_binary-3.1.17-cp39-cp39-musllinux_1_1_i686.whl", hash = "sha256:a343261701a8f63f0d8268f7fd32be40ffe28d24b65d905404ca03e7281f7bb5"}, - {file = "psycopg_binary-3.1.17-cp39-cp39-musllinux_1_1_ppc64le.whl", hash = "sha256:dceb3930ec426623c0cacc78e447a90882981e8c49d6fea8d1e48850e24a0170"}, - {file = "psycopg_binary-3.1.17-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:d613a23f8928f30acb2b6b2398cb7775ba9852e8968e15df13807ba0d3ebd565"}, - {file = "psycopg_binary-3.1.17-cp39-cp39-win_amd64.whl", hash = "sha256:d90c0531e9d591bde8cea04e75107fcddcc56811b638a34853436b23c9a3cb7d"}, + {file = "psycopg-c-3.1.17.tar.gz", hash = "sha256:5cc4d544d552b8ab92a9e3a9dbe3b4f46ce0a86338654d26387fc076e0c97977"}, +] + +[[package]] +name = "psycopg2" +version = "2.9.9" +description = "psycopg2 - Python-PostgreSQL Database Adapter" +optional = false +python-versions = ">=3.7" +files = [ + {file = "psycopg2-2.9.9-cp310-cp310-win32.whl", hash = "sha256:38a8dcc6856f569068b47de286b472b7c473ac7977243593a288ebce0dc89516"}, + {file = "psycopg2-2.9.9-cp310-cp310-win_amd64.whl", hash = "sha256:426f9f29bde126913a20a96ff8ce7d73fd8a216cfb323b1f04da402d452853c3"}, + {file = "psycopg2-2.9.9-cp311-cp311-win32.whl", hash = "sha256:ade01303ccf7ae12c356a5e10911c9e1c51136003a9a1d92f7aa9d010fb98372"}, + {file = "psycopg2-2.9.9-cp311-cp311-win_amd64.whl", hash = "sha256:121081ea2e76729acfb0673ff33755e8703d45e926e416cb59bae3a86c6a4981"}, + {file = "psycopg2-2.9.9-cp312-cp312-win32.whl", hash = "sha256:d735786acc7dd25815e89cc4ad529a43af779db2e25aa7c626de864127e5a024"}, + {file = "psycopg2-2.9.9-cp312-cp312-win_amd64.whl", hash = "sha256:a7653d00b732afb6fc597e29c50ad28087dcb4fbfb28e86092277a559ae4e693"}, + {file = "psycopg2-2.9.9-cp37-cp37m-win32.whl", hash = "sha256:5e0d98cade4f0e0304d7d6f25bbfbc5bd186e07b38eac65379309c4ca3193efa"}, + {file = "psycopg2-2.9.9-cp37-cp37m-win_amd64.whl", hash = "sha256:7e2dacf8b009a1c1e843b5213a87f7c544b2b042476ed7755be813eaf4e8347a"}, + {file = "psycopg2-2.9.9-cp38-cp38-win32.whl", hash = "sha256:ff432630e510709564c01dafdbe996cb552e0b9f3f065eb89bdce5bd31fabf4c"}, + {file = "psycopg2-2.9.9-cp38-cp38-win_amd64.whl", hash = "sha256:bac58c024c9922c23550af2a581998624d6e02350f4ae9c5f0bc642c633a2d5e"}, + {file = "psycopg2-2.9.9-cp39-cp39-win32.whl", hash = "sha256:c92811b2d4c9b6ea0285942b2e7cac98a59e166d59c588fe5cfe1eda58e72d59"}, + {file = "psycopg2-2.9.9-cp39-cp39-win_amd64.whl", hash = "sha256:de80739447af31525feddeb8effd640782cf5998e1a4e9192ebdf829717e3913"}, + {file = "psycopg2-2.9.9.tar.gz", hash = "sha256:d1454bde93fb1e224166811694d600e746430c006fbb031ea06ecc2ea41bf156"}, ] [[package]] @@ -2354,4 +2312,4 @@ testing = ["big-O", "jaraco.functools", "jaraco.itertools", "more-itertools", "p [metadata] lock-version = "2.0" python-versions = "^3.8.10" -content-hash = "701289957a294dad000a757fb2a30e4d9f57fb826d9ce0804a56fd53f5798d03" +content-hash = "c243e1dbcc650f8d9de60f54f6f175329ad0c92f2f53e4f7e6d3f0d59353f830" diff --git a/pyproject.toml b/pyproject.toml index 75b1bc699..f5ab8a4c0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -22,8 +22,8 @@ poetry-core = "^1.8.1" lightkube = "^0.15.0" lightkube-models = "^1.29.0.6" pydantic = "^1.10.13" -psycopg2-binary = "^2.9.9" -psycopg = {extras = ["binary"], version = "^3.1.17"} +psycopg2 = "^2.9.9" +psycopg = {extras = ["c"], version = "^3.1.17"} [tool.poetry.group.charm-libs.dependencies] # data_platform_libs/v0/data_interfaces.py @@ -58,6 +58,10 @@ pytest = "^7.4.4" pytest-asyncio = "*" jinja2 = "^3.1.2" psycopg2-binary = "^2.9.9" +lightkube = "*" +cryptography = "*" +jsonschema = "*" +tenacity = "*" [tool.poetry.group.integration] optional = true diff --git a/src/charm.py b/src/charm.py index 8d5f4a60b..e6b4af26b 100755 --- a/src/charm.py +++ b/src/charm.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python3 +#!/usr/bin/env -S LD_LIBRARY_PATH=binlibs python3 # Copyright 2023 Canonical Ltd. # See LICENSE file for licensing details. diff --git a/tox.ini b/tox.ini index c6b8965da..7fa5dcf25 100644 --- a/tox.ini +++ b/tox.ini @@ -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 commands = poetry run coverage run --source={[vars]src_path},{[vars]lib_path} \ -m pytest -v --tb native -s {posargs} {[vars]tests_path}/unit From 2290ec58b96df5c264c6d339b5206de18f3d328d Mon Sep 17 00:00:00 2001 From: Dragomir Penev Date: Wed, 17 Jan 2024 14:57:01 +0200 Subject: [PATCH 02/11] Remove usr/share --- charmcraft.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/charmcraft.yaml b/charmcraft.yaml index f8e36fb60..50d5701e7 100644 --- a/charmcraft.yaml +++ b/charmcraft.yaml @@ -31,5 +31,7 @@ parts: plugin: dump source: http://archive.ubuntu.com/ubuntu/pool/main/p/postgresql-14/libpq5_14.10-0ubuntu0.22.04.1_amd64.deb source-type: deb + prime: + - "-usr/share/*" organize: 'usr/lib/*-linux-gnu/libpq.so*': binlibs/ From 9fe0f849391551da17e628b39408cfd40785e806 Mon Sep 17 00:00:00 2001 From: Dragomir Penev Date: Wed, 17 Jan 2024 16:13:06 +0200 Subject: [PATCH 03/11] Don't download the deb directly --- charmcraft.yaml | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/charmcraft.yaml b/charmcraft.yaml index 50d5701e7..2c417b6ad 100644 --- a/charmcraft.yaml +++ b/charmcraft.yaml @@ -28,10 +28,12 @@ parts: - pkg-config - libpq-dev libpq: + build-packages: + - libpq-dev plugin: dump - source: http://archive.ubuntu.com/ubuntu/pool/main/p/postgresql-14/libpq5_14.10-0ubuntu0.22.04.1_amd64.deb - source-type: deb + source: /usr/lib/ + source-type: local prime: - - "-usr/share/*" + - binlibs/ organize: - 'usr/lib/*-linux-gnu/libpq.so*': binlibs/ + "*-linux-gnu/libpq.so*": binlibs/ From 8fe03af2a7ec79aa1ad3fce193cbdea704d1f797 Mon Sep 17 00:00:00 2001 From: Dragomir Penev Date: Fri, 26 Jan 2024 15:25:34 +0200 Subject: [PATCH 04/11] Move binlibs into the lib dir --- charmcraft.yaml | 4 ++-- src/charm.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/charmcraft.yaml b/charmcraft.yaml index 2c417b6ad..023dcf775 100644 --- a/charmcraft.yaml +++ b/charmcraft.yaml @@ -34,6 +34,6 @@ parts: source: /usr/lib/ source-type: local prime: - - binlibs/ + - lib/ organize: - "*-linux-gnu/libpq.so*": binlibs/ + "*-linux-gnu/libpq.so*": lib/ diff --git a/src/charm.py b/src/charm.py index e6b4af26b..744103dee 100755 --- a/src/charm.py +++ b/src/charm.py @@ -1,4 +1,4 @@ -#!/usr/bin/env -S LD_LIBRARY_PATH=binlibs python3 +#!/usr/bin/env -S LD_LIBRARY_PATH=lib python3 # Copyright 2023 Canonical Ltd. # See LICENSE file for licensing details. From 4e8c21f58ec1804cf0dbf61521001eacc57ca7b5 Mon Sep 17 00:00:00 2001 From: Dragomir Penev Date: Fri, 26 Jan 2024 15:34:47 +0200 Subject: [PATCH 05/11] Try to revert tox --- poetry.lock | 2 +- pyproject.toml | 4 ---- tox.ini | 2 +- 3 files changed, 2 insertions(+), 6 deletions(-) diff --git a/poetry.lock b/poetry.lock index e507ad51f..9b43606f3 100644 --- a/poetry.lock +++ b/poetry.lock @@ -2321,4 +2321,4 @@ testing = ["big-O", "jaraco.functools", "jaraco.itertools", "more-itertools", "p [metadata] lock-version = "2.0" python-versions = "^3.8.10" -content-hash = "329d6bc1f91b6b3beb4ab62492733fb24761ae87878b1efd3f4ad2d18a1b4519" +content-hash = "48bbc51f005fc9e9347994c5e25e5de27a49154068c15922db1c815edbe2e313" diff --git a/pyproject.toml b/pyproject.toml index 255d89fdd..26324d7b9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -58,10 +58,6 @@ pytest = "^7.4.4" pytest-asyncio = "*" jinja2 = "^3.1.3" psycopg2-binary = "^2.9.9" -lightkube = "*" -cryptography = "*" -jsonschema = "*" -tenacity = "*" [tool.poetry.group.integration] optional = true diff --git a/tox.ini b/tox.ini index 7fa5dcf25..c6b8965da 100644 --- a/tox.ini +++ b/tox.ini @@ -69,7 +69,7 @@ commands = [testenv:unit] description = Run unit tests commands_pre = - poetry install --only charm-libs,unit --no-root + poetry install --only main,charm-libs,unit --no-root commands = poetry run coverage run --source={[vars]src_path},{[vars]lib_path} \ -m pytest -v --tb native -s {posargs} {[vars]tests_path}/unit From 5cc185f6d6a0679cb3a94d816c6fa685f2c9ffcf Mon Sep 17 00:00:00 2001 From: Dragomir Penev Date: Fri, 26 Jan 2024 17:07:47 +0200 Subject: [PATCH 06/11] Try to break unit tests --- .github/workflows/ci.yaml | 4 ++++ poetry.lock | 2 +- pyproject.toml | 1 - 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 8fe413336..fe5208565 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -31,6 +31,10 @@ jobs: steps: - name: Checkout uses: actions/checkout@v4 + - name: remove libpq + run: | + sudo apt remove libpq-dev + sudo apt remove libpq5 - name: Install tox & poetry run: | pipx install tox diff --git a/poetry.lock b/poetry.lock index 9b43606f3..e83c23b0e 100644 --- a/poetry.lock +++ b/poetry.lock @@ -2321,4 +2321,4 @@ testing = ["big-O", "jaraco.functools", "jaraco.itertools", "more-itertools", "p [metadata] lock-version = "2.0" python-versions = "^3.8.10" -content-hash = "48bbc51f005fc9e9347994c5e25e5de27a49154068c15922db1c815edbe2e313" +content-hash = "17e3f886999eedae646740d967072a43d5d1263bdf0f829a6b145f155f6505dc" diff --git a/pyproject.toml b/pyproject.toml index 26324d7b9..eb5008ffe 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -57,7 +57,6 @@ coverage = {extras = ["toml"], version = "^7.4.0"} pytest = "^7.4.4" pytest-asyncio = "*" jinja2 = "^3.1.3" -psycopg2-binary = "^2.9.9" [tool.poetry.group.integration] optional = true From 0085c81457fc1f7ebbe12f1560dc7d9c5964a984 Mon Sep 17 00:00:00 2001 From: Dragomir Penev Date: Fri, 26 Jan 2024 17:26:05 +0200 Subject: [PATCH 07/11] Split away cdeps --- poetry.lock | 2 +- pyproject.toml | 7 +++++++ tox.ini | 2 +- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/poetry.lock b/poetry.lock index e83c23b0e..90c6ec11a 100644 --- a/poetry.lock +++ b/poetry.lock @@ -2321,4 +2321,4 @@ testing = ["big-O", "jaraco.functools", "jaraco.itertools", "more-itertools", "p [metadata] lock-version = "2.0" python-versions = "^3.8.10" -content-hash = "17e3f886999eedae646740d967072a43d5d1263bdf0f829a6b145f155f6505dc" +content-hash = "8f0d2c08936ef8e8f4fab66ea1d09497bf9686fc0a3b10c8513cd5056d051179" diff --git a/pyproject.toml b/pyproject.toml index eb5008ffe..aa1e3f59a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -22,6 +22,12 @@ poetry-core = "^1.8.1" lightkube = "^0.15.0" lightkube-models = "^1.29.0.6" pydantic = "^1.10.14" + + +[tool.poetry.group.cdeps] +optional = true + +[tool.poetry.group.cdeps.dependencies] psycopg2 = "^2.9.9" psycopg = {extras = ["c"], version = "^3.1.17"} @@ -57,6 +63,7 @@ coverage = {extras = ["toml"], version = "^7.4.0"} pytest = "^7.4.4" pytest-asyncio = "*" jinja2 = "^3.1.3" +psycopg2-binary = "^2.9.9" [tool.poetry.group.integration] optional = true diff --git a/tox.ini b/tox.ini index c6b8965da..a88c51d3e 100644 --- a/tox.ini +++ b/tox.ini @@ -35,7 +35,7 @@ allowlist_externals = charmcraftcache mv commands_pre = - poetry export --only main,charm-libs --output requirements.txt + poetry export --only main,charm-libs,cdeps --output requirements.txt commands = build-production: charmcraft pack {posargs} build-dev: charmcraftcache pack {posargs} From 973c45eb4f6f592a30a636b12ead1f05e8ff768f Mon Sep 17 00:00:00 2001 From: Dragomir Penev Date: Fri, 26 Jan 2024 17:38:36 +0200 Subject: [PATCH 08/11] Revert ci --- .github/workflows/ci.yaml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index fe5208565..8fe413336 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -31,10 +31,6 @@ jobs: steps: - name: Checkout uses: actions/checkout@v4 - - name: remove libpq - run: | - sudo apt remove libpq-dev - sudo apt remove libpq5 - name: Install tox & poetry run: | pipx install tox From f31d321ee22f6cee40acc0a175eb8a4bd67e356e Mon Sep 17 00:00:00 2001 From: Dragomir Penev Date: Tue, 30 Jan 2024 18:03:53 +0200 Subject: [PATCH 09/11] Psycopg2 from source --- poetry.lock | 2 +- pyproject.toml | 7 ------- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/poetry.lock b/poetry.lock index f74aeb4ba..3a3836a72 100644 --- a/poetry.lock +++ b/poetry.lock @@ -2309,4 +2309,4 @@ testing = ["big-O", "jaraco.functools", "jaraco.itertools", "more-itertools", "p [metadata] lock-version = "2.0" python-versions = "^3.8.10" -content-hash = "e1682914e78a56d0228749128a5384edbddfb189fd1b9f010ac040df9b265c58" +content-hash = "b9a6d6d704f3b076cb06c5280d34a2cee663d55cbfc633dc2e821f0035ea435e" diff --git a/pyproject.toml b/pyproject.toml index 2c736e775..d06122836 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -22,12 +22,6 @@ poetry-core = "^1.8.1" lightkube = "^0.15.0" lightkube-models = "^1.29.0.6" pydantic = "^1.10.14" - - -[tool.poetry.group.cdeps] -optional = true - -[tool.poetry.group.cdeps.dependencies] psycopg2 = "^2.9.9" psycopg = {extras = ["c"], version = "^3.1.17"} @@ -63,7 +57,6 @@ coverage = {extras = ["toml"], version = "^7.4.1"} pytest = "^8.0.0" pytest-asyncio = "*" jinja2 = "^3.1.3" -psycopg2-binary = "^2.9.9" [tool.poetry.group.integration] optional = true From 0915ebdb74642e20b58c12f70afedc14acc441ce Mon Sep 17 00:00:00 2001 From: Dragomir Penev Date: Tue, 30 Jan 2024 18:31:34 +0200 Subject: [PATCH 10/11] Remove extra dep group --- tox.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tox.ini b/tox.ini index a88c51d3e..c6b8965da 100644 --- a/tox.ini +++ b/tox.ini @@ -35,7 +35,7 @@ allowlist_externals = charmcraftcache mv commands_pre = - poetry export --only main,charm-libs,cdeps --output requirements.txt + poetry export --only main,charm-libs --output requirements.txt commands = build-production: charmcraft pack {posargs} build-dev: charmcraftcache pack {posargs} From 185b5af5095097b55427a0cd6053ed80bb4a3d24 Mon Sep 17 00:00:00 2001 From: Dragomir Penev Date: Wed, 31 Jan 2024 19:30:32 +0200 Subject: [PATCH 11/11] Bump libs --- lib/charms/postgresql_k8s/v0/postgresql.py | 22 +++++++++++++++++-- .../v2/tls_certificates.py | 10 +++++---- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/lib/charms/postgresql_k8s/v0/postgresql.py b/lib/charms/postgresql_k8s/v0/postgresql.py index 7512ef81f..9b6c0c8f8 100644 --- a/lib/charms/postgresql_k8s/v0/postgresql.py +++ b/lib/charms/postgresql_k8s/v0/postgresql.py @@ -19,6 +19,7 @@ Any charm using this library should import the `psycopg2` or `psycopg2-binary` dependency. """ import logging +from collections import OrderedDict from typing import Dict, List, Optional, Set, Tuple import psycopg2 @@ -34,10 +35,21 @@ # Increment this PATCH version before using `charmcraft publish-lib` or reset # to 0 if you are raising the major API version -LIBPATCH = 21 +LIBPATCH = 22 INVALID_EXTRA_USER_ROLE_BLOCKING_MESSAGE = "invalid role(s) for extra user roles" +REQUIRED_PLUGINS = { + "address_standardizer": ["postgis"], + "address_standardizer_data_us": ["postgis"], + "jsonb_plperl": ["plperl"], + "postgis_raster": ["postgis"], + "postgis_tiger_geocoder": ["postgis", "fuzzystrmatch"], + "postgis_topology": ["postgis"], +} +DEPENDENCY_PLUGINS = set() +for dependencies in REQUIRED_PLUGINS.values(): + DEPENDENCY_PLUGINS |= set(dependencies) logger = logging.getLogger(__name__) @@ -289,12 +301,18 @@ def enable_disable_extensions(self, extensions: Dict[str, bool], database: str = cursor.execute("SELECT datname FROM pg_database WHERE NOT datistemplate;") databases = {database[0] for database in cursor.fetchall()} + ordered_extensions = OrderedDict() + for plugin in DEPENDENCY_PLUGINS: + ordered_extensions[plugin] = extensions.get(plugin, False) + for extension, enable in extensions.items(): + ordered_extensions[extension] = enable + # Enable/disabled the extension in each database. for database in databases: with self._connect_to_database( database=database ) as connection, connection.cursor() as cursor: - for extension, enable in extensions.items(): + for extension, enable in ordered_extensions.items(): cursor.execute( f"CREATE EXTENSION IF NOT EXISTS {extension};" if enable diff --git a/lib/charms/tls_certificates_interface/v2/tls_certificates.py b/lib/charms/tls_certificates_interface/v2/tls_certificates.py index ff234ff46..5992faf43 100644 --- a/lib/charms/tls_certificates_interface/v2/tls_certificates.py +++ b/lib/charms/tls_certificates_interface/v2/tls_certificates.py @@ -307,7 +307,7 @@ def _on_all_certificates_invalidated(self, event: AllCertificatesInvalidatedEven # Increment this PATCH version before using `charmcraft publish-lib` or reset # to 0 if you are raising the major API version -LIBPATCH = 23 +LIBPATCH = 24 PYDEPS = ["cryptography", "jsonschema"] @@ -938,9 +938,11 @@ def generate_private_key( key_bytes = private_key.private_bytes( encoding=serialization.Encoding.PEM, format=serialization.PrivateFormat.TraditionalOpenSSL, - encryption_algorithm=serialization.BestAvailableEncryption(password) - if password - else serialization.NoEncryption(), + encryption_algorithm=( + serialization.BestAvailableEncryption(password) + if password + else serialization.NoEncryption() + ), ) return key_bytes