Skip to content

Commit 311d76e

Browse files
committed
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.
1 parent 5a3dcfc commit 311d76e

2 files changed

Lines changed: 72 additions & 2 deletions

File tree

Dockerfile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,11 @@ ENV CERTS="{}" \
1919
WAN_USERS='["all"]' \
2020
HBA_EXTRA_RULES=""
2121
RUN apk add --no-cache python3 py3-netifaces \
22-
&& if [ "${PG_MAJOR:-0}" -ge 12 ]; then \
23-
apk add --no-cache --virtual .pgvector-build build-base clang19 llvm19 linux-headers ca-certificates; \
22+
&& if [ "${PG_MAJOR:-0}" -ge 13 ]; then \
23+
PG_CLANG="$(pg_config --configure | tr "'" "\n" | sed -n 's/^CLANG=clang-//p')"; \
24+
PG_LLVM="$(pg_config --configure | tr "'" "\n" | sed -n 's#^LLVM_CONFIG=/usr/lib/llvm\([0-9][0-9]*\)/bin/llvm-config#\1#p')"; \
25+
test -n "${PG_CLANG}" && test -n "${PG_LLVM}" && test "${PG_CLANG}" = "${PG_LLVM}"; \
26+
apk add --no-cache --virtual .pgvector-build build-base linux-headers ca-certificates "clang${PG_CLANG}" "llvm${PG_LLVM}"; \
2427
wget -qO- "https://github.com/pgvector/pgvector/archive/refs/tags/v${PGVECTOR_VERSION}.tar.gz" \
2528
| tar -xz -C /tmp; \
2629
cd "/tmp/pgvector-${PGVECTOR_VERSION}" \

tests/test.py

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,73 @@ def test_hba_extra_rules_added(self):
356356
for rule in hba_extra_rules:
357357
self.assertIn(rule, hba_conf)
358358

359+
def test_pgvector_extension(self):
360+
"""Test that pgvector is installed and works."""
361+
if float(local.env["DOCKER_TAG"].split("-")[0]) < 13:
362+
self.skipTest("pgvector not built for PostgreSQL < 13")
363+
self.postgres_container = docker(
364+
"container",
365+
"run",
366+
"-d",
367+
"--network",
368+
"lan",
369+
"-e",
370+
"POSTGRES_DB=test_db",
371+
"-e",
372+
"POSTGRES_PASSWORD=test_password",
373+
"-e",
374+
"POSTGRES_USER=test_user",
375+
CONF_EXTRA,
376+
self.image,
377+
).strip()
378+
self._check_local_connection()
379+
self.assertEqual(
380+
"vector\n",
381+
docker(
382+
"container",
383+
"exec",
384+
self.postgres_container,
385+
"psql",
386+
"--command",
387+
"SELECT name FROM pg_available_extensions WHERE name = 'vector';",
388+
"--dbname",
389+
"test_db",
390+
"--no-align",
391+
"--tuples-only",
392+
"--username",
393+
"test_user",
394+
),
395+
)
396+
docker(
397+
"container",
398+
"exec",
399+
self.postgres_container,
400+
"psql",
401+
"--command",
402+
"CREATE EXTENSION vector;",
403+
"--dbname",
404+
"test_db",
405+
"--username",
406+
"test_user",
407+
)
408+
self.assertEqual(
409+
"1\n",
410+
docker(
411+
"container",
412+
"exec",
413+
self.postgres_container,
414+
"psql",
415+
"--command",
416+
"SELECT ('[1,2,3]'::vector <-> '[1,2,4]'::vector)::int;",
417+
"--dbname",
418+
"test_db",
419+
"--no-align",
420+
"--tuples-only",
421+
"--username",
422+
"test_user",
423+
),
424+
)
425+
359426

360427
if __name__ == "__main__":
361428
unittest.main()

0 commit comments

Comments
 (0)