From 311d76e2dfc017202a3d231f2f240b28d7c2d1e2 Mon Sep 17 00:00:00 2001 From: Liam Noonan Date: Mon, 6 Jul 2026 12:33:12 +0000 Subject: [PATCH] Fix clang/llvm Base for Postgres 14-18 was bumped from alpine v3.23 to v3.24 in docker-library/official-images@769849f Alpine v3.24 dropped support for clang19/llvm19, which caused pgvector-build to fail for versions 14 and up. As it turns out, using hardcoded clang19/llvm19 was already not the best idea as it did not match the version used by postgres itself. Only postgres 13 uses clang19 and llvm19, everything above uses clang21 and llvm21. Also, pgvector 0.8.1 does not support pg12 https://github.com/pgvector/pgvector/blob/fb1b8966ebb9254032b6d0e7a594fdcc86f8efcc/CHANGELOG.md?plain=1#L34 Ultimately, I beleive pgvector was only properly installed in a few versions. This commit makes sure it is installed from 13 upwards and also tests that it is installed and working. --- Dockerfile | 7 ++++-- tests/test.py | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index e5260c5..5b0fcd2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -19,8 +19,11 @@ ENV CERTS="{}" \ WAN_USERS='["all"]' \ HBA_EXTRA_RULES="" RUN apk add --no-cache python3 py3-netifaces \ - && if [ "${PG_MAJOR:-0}" -ge 12 ]; then \ - apk add --no-cache --virtual .pgvector-build build-base clang19 llvm19 linux-headers ca-certificates; \ + && if [ "${PG_MAJOR:-0}" -ge 13 ]; then \ + PG_CLANG="$(pg_config --configure | tr "'" "\n" | sed -n 's/^CLANG=clang-//p')"; \ + PG_LLVM="$(pg_config --configure | tr "'" "\n" | sed -n 's#^LLVM_CONFIG=/usr/lib/llvm\([0-9][0-9]*\)/bin/llvm-config#\1#p')"; \ + test -n "${PG_CLANG}" && test -n "${PG_LLVM}" && test "${PG_CLANG}" = "${PG_LLVM}"; \ + apk add --no-cache --virtual .pgvector-build build-base linux-headers ca-certificates "clang${PG_CLANG}" "llvm${PG_LLVM}"; \ wget -qO- "https://github.com/pgvector/pgvector/archive/refs/tags/v${PGVECTOR_VERSION}.tar.gz" \ | tar -xz -C /tmp; \ cd "/tmp/pgvector-${PGVECTOR_VERSION}" \ diff --git a/tests/test.py b/tests/test.py index c0e9966..8111807 100755 --- a/tests/test.py +++ b/tests/test.py @@ -356,6 +356,73 @@ def test_hba_extra_rules_added(self): for rule in hba_extra_rules: self.assertIn(rule, hba_conf) + def test_pgvector_extension(self): + """Test that pgvector is installed and works.""" + if float(local.env["DOCKER_TAG"].split("-")[0]) < 13: + self.skipTest("pgvector not built for PostgreSQL < 13") + self.postgres_container = docker( + "container", + "run", + "-d", + "--network", + "lan", + "-e", + "POSTGRES_DB=test_db", + "-e", + "POSTGRES_PASSWORD=test_password", + "-e", + "POSTGRES_USER=test_user", + CONF_EXTRA, + self.image, + ).strip() + self._check_local_connection() + self.assertEqual( + "vector\n", + docker( + "container", + "exec", + self.postgres_container, + "psql", + "--command", + "SELECT name FROM pg_available_extensions WHERE name = 'vector';", + "--dbname", + "test_db", + "--no-align", + "--tuples-only", + "--username", + "test_user", + ), + ) + docker( + "container", + "exec", + self.postgres_container, + "psql", + "--command", + "CREATE EXTENSION vector;", + "--dbname", + "test_db", + "--username", + "test_user", + ) + self.assertEqual( + "1\n", + docker( + "container", + "exec", + self.postgres_container, + "psql", + "--command", + "SELECT ('[1,2,3]'::vector <-> '[1,2,4]'::vector)::int;", + "--dbname", + "test_db", + "--no-align", + "--tuples-only", + "--username", + "test_user", + ), + ) + if __name__ == "__main__": unittest.main()