Skip to content

Commit 4b75469

Browse files
committed
refactor: address review feedback across all files
Dockerfile: - Remove redundant apt-get install of already-installed build tools - Add --depth 1 to pgvector git clone - Purge lsb-release and gnupg in cleanup step Workflows (shared): - Add versions.json as single source of truth for version matrix - Both workflows read from versions.json via load-versions job - Add fail-fast: false to all matrix strategies - Add timeout-minutes to all jobs - Add GHA build cache with per-version per-runner scoping test.yml: - Replace sleep 15 with pg_isready health check polling - Add PostGIS functional test (ST_Point) - Add version assertions (verify installed matches requested) - Simplify container cleanup to docker rm -f publish.yml: - Add explicit platform field mapped from runner - Add name= to push-by-digest output for unambiguous registry reference - Add imagetools inspect verification after manifest creation
1 parent ca612b3 commit 4b75469

File tree

4 files changed

+132
-39
lines changed

4 files changed

+132
-39
lines changed

.github/workflows/publish.yml

Lines changed: 37 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,42 @@ env:
1010
IMAGE_NAME: ${{ github.repository_owner }}/${{ github.event.repository.name }}
1111

1212
jobs:
13+
load-versions:
14+
runs-on: ubuntu-latest
15+
outputs:
16+
pg_versions: ${{ steps.set-matrix.outputs.pg_versions }}
17+
postgis_versions: ${{ steps.set-matrix.outputs.postgis_versions }}
18+
pgvector_versions: ${{ steps.set-matrix.outputs.pgvector_versions }}
19+
versions: ${{ steps.set-matrix.outputs.versions }}
20+
steps:
21+
- uses: actions/checkout@v6
22+
- id: set-matrix
23+
run: |
24+
echo "pg_versions=$(jq -c '[.[].pg_version] | unique' versions.json)" >> "$GITHUB_OUTPUT"
25+
echo "postgis_versions=$(jq -c '[.[].postgis_version] | unique' versions.json)" >> "$GITHUB_OUTPUT"
26+
echo "pgvector_versions=$(jq -c '[.[].pgvector_version] | unique' versions.json)" >> "$GITHUB_OUTPUT"
27+
echo "versions=$(jq -c '.' versions.json)" >> "$GITHUB_OUTPUT"
28+
1329
build:
30+
needs: load-versions
1431
runs-on: ${{ matrix.runner }}
32+
timeout-minutes: 30
1533
permissions:
1634
contents: read
1735
packages: write
1836

1937
strategy:
38+
fail-fast: false
2039
matrix:
2140
runner: [ubuntu-latest, ubuntu-24.04-arm]
22-
pg_version: ["17.9", "16.13", "15.17", "14.22"]
23-
postgis_version: ["3.6.2"]
24-
pgvector_version: ["0.8.2"]
41+
pg_version: ${{ fromJSON(needs.load-versions.outputs.pg_versions) }}
42+
postgis_version: ${{ fromJSON(needs.load-versions.outputs.postgis_versions) }}
43+
pgvector_version: ${{ fromJSON(needs.load-versions.outputs.pgvector_versions) }}
44+
include:
45+
- runner: ubuntu-latest
46+
platform: linux/amd64
47+
- runner: ubuntu-24.04-arm
48+
platform: linux/arm64
2549

2650
steps:
2751
- name: Checkout repository
@@ -49,14 +73,15 @@ jobs:
4973
with:
5074
context: .
5175
push: true
76+
platforms: ${{ matrix.platform }}
5277
labels: ${{ steps.meta.outputs.labels }}
5378
build-args: |
5479
PG_VERSION=${{ matrix.pg_version }}
5580
POSTGIS_VERSION=${{ matrix.postgis_version }}
5681
PGVECTOR_VERSION=${{ matrix.pgvector_version }}
5782
cache-from: type=gha,scope=${{ matrix.pg_version }}-${{ matrix.runner }}
5883
cache-to: type=gha,mode=max,scope=${{ matrix.pg_version }}-${{ matrix.runner }}
59-
outputs: type=image,push-by-digest=true,name-canonical=true,push=true
84+
outputs: type=image,name=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }},push-by-digest=true,name-canonical=true,push=true
6085

6186
- name: Export digest
6287
run: |
@@ -74,30 +99,16 @@ jobs:
7499

75100
merge:
76101
runs-on: ubuntu-latest
77-
needs: build
102+
timeout-minutes: 10
103+
needs: [load-versions, build]
78104
permissions:
79105
contents: read
80106
packages: write
81107

82108
strategy:
109+
fail-fast: false
83110
matrix:
84-
include:
85-
- pg_version: "17.9"
86-
postgis_version: "3.6.2"
87-
pgvector_version: "0.8.2"
88-
latest: true
89-
- pg_version: "16.13"
90-
postgis_version: "3.6.2"
91-
pgvector_version: "0.8.2"
92-
latest: false
93-
- pg_version: "15.17"
94-
postgis_version: "3.6.2"
95-
pgvector_version: "0.8.2"
96-
latest: false
97-
- pg_version: "14.22"
98-
postgis_version: "3.6.2"
99-
pgvector_version: "0.8.2"
100-
latest: false
111+
include: ${{ fromJSON(needs.load-versions.outputs.versions) }}
101112

102113
steps:
103114
- name: Download digests
@@ -130,3 +141,7 @@ jobs:
130141
docker buildx imagetools create \
131142
$(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
132143
$(printf '${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}@sha256:%s ' *)
144+
145+
- name: Verify multi-arch manifest
146+
run: |
147+
docker buildx imagetools inspect $(jq -cr '.tags[0]' <<< "$DOCKER_METADATA_OUTPUT_JSON")

.github/workflows/test.yml

Lines changed: 66 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,31 @@ on:
88
workflow_dispatch:
99

1010
jobs:
11+
load-versions:
12+
runs-on: ubuntu-latest
13+
outputs:
14+
pg_versions: ${{ steps.set-matrix.outputs.pg_versions }}
15+
postgis_versions: ${{ steps.set-matrix.outputs.postgis_versions }}
16+
pgvector_versions: ${{ steps.set-matrix.outputs.pgvector_versions }}
17+
steps:
18+
- uses: actions/checkout@v6
19+
- id: set-matrix
20+
run: |
21+
echo "pg_versions=$(jq -c '[.[].pg_version] | unique' versions.json)" >> "$GITHUB_OUTPUT"
22+
echo "postgis_versions=$(jq -c '[.[].postgis_version] | unique' versions.json)" >> "$GITHUB_OUTPUT"
23+
echo "pgvector_versions=$(jq -c '[.[].pgvector_version] | unique' versions.json)" >> "$GITHUB_OUTPUT"
24+
1125
test:
26+
needs: load-versions
1227
runs-on: ${{ matrix.runner }}
28+
timeout-minutes: 15
1329
strategy:
30+
fail-fast: false
1431
matrix:
1532
runner: [ubuntu-latest, ubuntu-24.04-arm]
16-
pg_version: ["17.9", "16.13", "15.17", "14.22"]
17-
postgis_version: ["3.6.2"]
18-
pgvector_version: ["0.8.2"]
33+
pg_version: ${{ fromJSON(needs.load-versions.outputs.pg_versions) }}
34+
postgis_version: ${{ fromJSON(needs.load-versions.outputs.postgis_versions) }}
35+
pgvector_version: ${{ fromJSON(needs.load-versions.outputs.pgvector_versions) }}
1936

2037
steps:
2138
- uses: actions/checkout@v6
@@ -33,8 +50,10 @@ jobs:
3350
PG_VERSION=${{ matrix.pg_version }}
3451
POSTGIS_VERSION=${{ matrix.postgis_version }}
3552
PGVECTOR_VERSION=${{ matrix.pgvector_version }}
53+
cache-from: type=gha,scope=${{ matrix.pg_version }}-${{ matrix.runner }}
54+
cache-to: type=gha,mode=max,scope=${{ matrix.pg_version }}-${{ matrix.runner }}
3655

37-
- name: Start PostgreSQL container and test extensions
56+
- name: Start PostgreSQL container
3857
run: |
3958
IMAGE_TAG="postgres-test:pg${{ matrix.pg_version }}"
4059
echo "Testing image: $IMAGE_TAG (runner: ${{ matrix.runner }})"
@@ -43,26 +62,60 @@ jobs:
4362
-e POSTGRES_PASSWORD=test \
4463
-e POSTGRES_USER=test \
4564
-e POSTGRES_DB=test \
65+
--health-cmd="pg_isready -U test -d test" \
66+
--health-interval=2s \
67+
--health-timeout=5s \
68+
--health-retries=30 \
4669
$IMAGE_TAG \
4770
postgres -c shared_preload_libraries=vector
4871
49-
echo "Waiting for PostgreSQL to start..."
50-
sleep 15
51-
52-
echo "PostgreSQL logs:"
53-
docker logs test-db
72+
echo "Waiting for PostgreSQL to become healthy..."
73+
until [ "$(docker inspect -f '{{.State.Health.Status}}' test-db)" = "healthy" ]; do
74+
if [ "$(docker inspect -f '{{.State.Status}}' test-db)" != "running" ]; then
75+
echo "Container exited unexpectedly!"
76+
docker logs test-db
77+
exit 1
78+
fi
79+
sleep 1
80+
done
81+
echo "PostgreSQL is ready."
5482
83+
- name: Test PostGIS extension
84+
run: |
5585
echo "Checking PostGIS version..."
5686
docker exec test-db psql -U test -d test -c "SELECT postgis_full_version();"
5787
88+
echo "Testing PostGIS spatial functionality..."
89+
docker exec test-db psql -U test -d test -c "SELECT ST_AsText(ST_Point(1, 2));"
90+
91+
- name: Test pgvector extension
92+
run: |
5893
echo "Checking pgvector extension version..."
5994
docker exec test-db psql -U test -d test -c "CREATE EXTENSION IF NOT EXISTS vector; SELECT extversion FROM pg_extension WHERE extname = 'vector';"
6095
61-
echo "Attempting to create a table with a vector column and insert data..."
96+
echo "Testing vector operations..."
6297
docker exec test-db psql -U test -d test -c "CREATE TABLE items (id bigserial PRIMARY KEY, embedding vector(3)); INSERT INTO items (embedding) VALUES ('[1,2,3]'), ('[4,5,6]'); SELECT COUNT(*) FROM items;"
6398
99+
- name: Verify installed versions match requested
100+
run: |
101+
EXPECTED_PGVECTOR="${{ matrix.pgvector_version }}"
102+
ACTUAL_PGVECTOR=$(docker exec test-db psql -U test -d test -tAc \
103+
"SELECT extversion FROM pg_extension WHERE extname = 'vector';")
104+
if [ "$ACTUAL_PGVECTOR" != "$EXPECTED_PGVECTOR" ]; then
105+
echo "FAIL: expected pgvector $EXPECTED_PGVECTOR, got $ACTUAL_PGVECTOR"
106+
exit 1
107+
fi
108+
echo "pgvector version OK: $ACTUAL_PGVECTOR"
109+
110+
EXPECTED_POSTGIS="${{ matrix.postgis_version }}"
111+
ACTUAL_POSTGIS=$(docker exec test-db psql -U test -d test -tAc \
112+
"SELECT extversion FROM pg_extension WHERE extname = 'postgis';")
113+
if [ "$ACTUAL_POSTGIS" != "$EXPECTED_POSTGIS" ]; then
114+
echo "FAIL: expected PostGIS $EXPECTED_POSTGIS, got $ACTUAL_POSTGIS"
115+
exit 1
116+
fi
117+
echo "PostGIS version OK: $ACTUAL_POSTGIS"
118+
64119
- name: Stop and remove container
65120
if: always()
66-
run: |
67-
docker stop test-db || true
68-
docker rm test-db || true
121+
run: docker rm -f test-db || true

Dockerfile

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,7 @@ RUN POSTGIS_MAJOR=$(echo "${POSTGIS_VERSION}" | cut -d. -f1) \
4040
"postgresql-${PG_MAJOR}-postgis-${POSTGIS_MAJOR}-scripts=${POSTGIS_VERSION}+dfsg*"
4141

4242
# Build and install pinned pgvector version from source
43-
RUN apt-get update \
44-
&& apt-get install -y --no-install-recommends git make gcc "postgresql-server-dev-${PG_MAJOR}" \
45-
&& mkdir -p /usr/src/pgvector \
46-
&& git clone --branch "v${PGVECTOR_VERSION}" https://github.com/pgvector/pgvector.git /usr/src/pgvector \
43+
RUN git clone --branch "v${PGVECTOR_VERSION}" --depth 1 https://github.com/pgvector/pgvector.git /usr/src/pgvector \
4744
&& cd /usr/src/pgvector \
4845
&& make \
4946
&& make install
@@ -56,6 +53,8 @@ RUN apt-get purge -y --auto-remove \
5653
gcc \
5754
"postgresql-server-dev-${PG_MAJOR}" \
5855
wget \
56+
lsb-release \
57+
gnupg \
5958
&& apt-get clean \
6059
&& rm -rf /var/lib/apt/lists/* \
6160
&& rm -rf /usr/src/pgvector

versions.json

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
[
2+
{
3+
"pg_version": "17.9",
4+
"postgis_version": "3.6.2",
5+
"pgvector_version": "0.8.2",
6+
"latest": true
7+
},
8+
{
9+
"pg_version": "16.13",
10+
"postgis_version": "3.6.2",
11+
"pgvector_version": "0.8.2",
12+
"latest": false
13+
},
14+
{
15+
"pg_version": "15.17",
16+
"postgis_version": "3.6.2",
17+
"pgvector_version": "0.8.2",
18+
"latest": false
19+
},
20+
{
21+
"pg_version": "14.22",
22+
"postgis_version": "3.6.2",
23+
"pgvector_version": "0.8.2",
24+
"latest": false
25+
}
26+
]

0 commit comments

Comments
 (0)