Skip to content

Commit 3fd2b6c

Browse files
authored
fix: make build work
1 parent af16944 commit 3fd2b6c

File tree

6 files changed

+226
-170
lines changed

6 files changed

+226
-170
lines changed

.github/workflows/publish.yml

Lines changed: 31 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,65 +2,63 @@ name: Publish Docker image
22

33
on:
44
push:
5-
tags: ["v*.*.*"]
6-
workflow_dispatch:
5+
tags: ["v*.*.*"] # Trigger on version tags like v1.0.0
6+
workflow_dispatch: # Allows manual triggering
77

88
env:
99
REGISTRY: ghcr.io
10+
# IMAGE_NAME is constructed as owner/repository_name by default in metadata-action
11+
# Example: ghcr.io/yourusername/yourrepositoryname
1012

1113
jobs:
1214
build-and-push:
1315
runs-on: ubuntu-latest
1416
permissions:
1517
contents: read
16-
packages: write
18+
packages: write # Required to publish to GHCR
1719

1820
strategy:
1921
matrix:
2022
include:
21-
# Latest PostgreSQL with latest pgvector
22-
- pg_version: 16
23-
pgvector_version: v0.8.0
24-
latest: true
25-
# Previous PostgreSQL with latest pgvector
26-
- pg_version: 15
27-
pgvector_version: v0.8.0
28-
latest: false
29-
# Latest PostgreSQL with previous pgvector
30-
- pg_version: 16
31-
pgvector_version: v0.7.2
32-
latest: false
33-
# Previous PostgreSQL with previous pgvector
34-
- pg_version: 15
35-
pgvector_version: v0.7.2
36-
latest: false
23+
- pg_major_version: 16
24+
postgis_major_version: 3
25+
pgvector_tag: v0.8.0
26+
latest_tag_suffix: true # This combination will also be tagged 'latest'
27+
- pg_major_version: 15
28+
postgis_major_version: 3
29+
pgvector_tag: v0.8.0
30+
latest_tag_suffix: false
31+
- pg_major_version: 16
32+
postgis_major_version: 3
33+
pgvector_tag: v0.7.2
34+
latest_tag_suffix: false
35+
- pg_major_version: 15
36+
postgis_major_version: 3
37+
pgvector_tag: v0.7.2
38+
latest_tag_suffix: false
3739

3840
steps:
3941
- name: Checkout repository
4042
uses: actions/checkout@v4
4143

42-
- name: Log in to the Container registry
44+
- name: Log in to GitHub Container Registry
4345
uses: docker/login-action@v3
4446
with:
4547
registry: ${{ env.REGISTRY }}
4648
username: ${{ github.actor }}
4749
password: ${{ secrets.GITHUB_TOKEN }}
4850

51+
- name: Set up Docker Buildx
52+
uses: docker/setup-buildx-action@v3
53+
4954
- name: Extract metadata (tags, labels) for Docker
5055
id: meta
5156
uses: docker/metadata-action@v5
5257
with:
53-
images: ${{ env.REGISTRY }}/${{ github.repository }}
58+
images: ${{ env.REGISTRY }}/${{ github.repository_owner }}/${{ github.event.repository.name }}
5459
tags: |
55-
type=raw,value=pg${{ matrix.pg_version }}-pgvector${{ matrix.pgvector_version }}
56-
type=raw,value=latest,enable=${{ matrix.latest }}
57-
labels: |
58-
org.opencontainers.image.title=PostgreSQL with PostGIS and pgvector
59-
org.opencontainers.image.description=PostgreSQL ${{ matrix.pg_version }} with PostGIS 3 and pgvector ${{ matrix.pgvector_version }}
60-
org.opencontainers.image.source=${{ github.server_url }}/${{ github.repository }}
61-
62-
- name: Set up Docker Buildx
63-
uses: docker/setup-buildx-action@v3
60+
type=raw,value=pg${{ matrix.pg_major_version }}-postgis${{ matrix.postgis_major_version }}-pgvector${{ matrix.pgvector_tag }}\n{{#if matrix.latest_tag_suffix}}latest{{/if}}
61+
type=ref,event=tag # Add tag from git tag if event is a tag push (e.g., v1.0.0)
6462
6563
- name: Build and push Docker image
6664
uses: docker/build-push-action@v5
@@ -70,8 +68,8 @@ jobs:
7068
tags: ${{ steps.meta.outputs.tags }}
7169
labels: ${{ steps.meta.outputs.labels }}
7270
build-args: |
73-
PG_MAJOR=${{ matrix.pg_version }}
74-
POSTGIS_MAJOR_VERSION=3
75-
PGVECTOR_VERSION=${{ matrix.pgvector_version }}
71+
PG_MAJOR_VERSION=${{ matrix.pg_major_version }}
72+
POSTGIS_MAJOR_VERSION=${{ matrix.postgis_major_version }}
73+
PGVECTOR_TAG=${{ matrix.pgvector_tag }}
7674
cache-from: type=gha
7775
cache-to: type=gha,mode=max

.github/workflows/test.yml

Lines changed: 31 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@ jobs:
1212
runs-on: ubuntu-latest
1313
strategy:
1414
matrix:
15-
pg_version: [16, 15]
16-
pgvector_version: [v0.8.0, v0.7.2]
15+
# Renaming for clarity in matrix, maps to Dockerfile ARGs
16+
pg_version_matrix: [16, 15] # Corresponds to PG_MAJOR_VERSION
17+
pgvector_tag_matrix: [v0.8.0, v0.7.2] # Corresponds to PGVECTOR_TAG
18+
# POSTGIS_MAJOR_VERSION is set to 3 directly in build-args below
1719

1820
steps:
1921
- uses: actions/checkout@v4
@@ -22,61 +24,46 @@ jobs:
2224
uses: docker/setup-buildx-action@v3
2325

2426
- name: Build Docker image
27+
id: build
2528
uses: docker/build-push-action@v5
2629
with:
2730
context: .
28-
load: true
29-
tags: postgres-postgis-pgvector:test
31+
load: true # Load image into local Docker daemon for testing
32+
tags: postgres-postgis-pgvector:test-${{ matrix.pg_version_matrix }}-pgvector${{ matrix.pgvector_tag_matrix }}
3033
build-args: |
31-
PG_MAJOR=${{ matrix.pg_version }}
34+
PG_MAJOR_VERSION=${{ matrix.pg_version_matrix }}
3235
POSTGIS_MAJOR_VERSION=3
33-
PGVECTOR_VERSION=${{ matrix.pgvector_version }}
36+
PGVECTOR_TAG=${{ matrix.pgvector_tag_matrix }}
3437
35-
- name: Start PostgreSQL container
38+
- name: Start PostgreSQL container and test extensions
3639
run: |
37-
docker run -d \
38-
--name postgres-test \
40+
IMAGE_TAG="postgres-postgis-pgvector:test-${{ matrix.pg_version_matrix }}-pgvector${{ matrix.pgvector_tag_matrix }}"
41+
echo "Testing image: $IMAGE_TAG"
42+
43+
docker run -d --name test-db \
3944
-e POSTGRES_PASSWORD=test \
4045
-e POSTGRES_USER=test \
4146
-e POSTGRES_DB=test \
42-
-e ADDITIONAL_DATABASES=test2 \
43-
-p 5432:5432 \
44-
postgres-postgis-pgvector:test
47+
$IMAGE_TAG \
48+
postgres -c shared_preload_libraries=vector # Ensure pgvector is preloaded
4549
46-
- name: Wait for PostgreSQL to be ready
47-
run: |
48-
timeout 30 bash -c 'until docker exec postgres-test pg_isready -U test; do sleep 1; done'
50+
echo "Waiting for PostgreSQL to start..."
51+
sleep 15 # Allow time for PostgreSQL to initialize
4952
50-
- name: Test PostGIS extension
51-
run: |
52-
docker exec postgres-test psql -U test -d test -c "
53-
SELECT postgis_version();
54-
SELECT postgis_full_version();
55-
"
53+
echo "PostgreSQL logs:"
54+
docker logs test-db
5655
57-
- name: Test pgvector extension
58-
run: |
59-
docker exec postgres-test psql -U test -d test -c "
60-
CREATE EXTENSION IF NOT EXISTS vector;
61-
-- Create a test table with a vector column
62-
CREATE TABLE items (id bigserial PRIMARY KEY, embedding vector(3));
63-
-- Insert a test vector
64-
INSERT INTO items (embedding) VALUES ('[1,2,3]');
65-
-- Test vector operations
66-
SELECT * FROM items WHERE embedding <-> '[3,2,1]' < 5;
67-
"
56+
echo "Checking PostGIS version..."
57+
docker exec test-db psql -U test -d test -c "SELECT postgis_full_version();"
6858
69-
- name: Test additional database
70-
run: |
71-
docker exec postgres-test psql -U test -d test2 -c "
72-
SELECT postgis_version();
73-
SELECT * FROM pg_extension WHERE extname = 'vector';
74-
"
59+
echo "Checking pgvector extension version..."
60+
docker exec test-db psql -U test -d test -c "CREATE EXTENSION IF NOT EXISTS vector; SELECT extversion FROM pg_extension WHERE extname = 'vector';"
7561
76-
- name: Check logs for any errors
77-
if: always()
78-
run: docker logs postgres-test
62+
echo "Attempting to create a table with a vector column and insert data..."
63+
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;"
7964
80-
- name: Clean up
81-
if: always()
82-
run: docker rm -f postgres-test
65+
- name: Stop and remove container
66+
if: always() # Ensure cleanup even if previous steps fail
67+
run: |
68+
docker stop test-db || true
69+
docker rm test-db || true

Dockerfile

Lines changed: 46 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,75 @@
11
# Default versions - can be overridden at build time using --build-arg
2-
ARG PG_MAJOR=16
2+
ARG PG_MAJOR_VERSION=16
33
ARG POSTGIS_MAJOR_VERSION=3
4-
ARG PGVECTOR_VERSION=v0.7.2
4+
ARG PGVECTOR_TAG=v0.8.0
55

6-
FROM postgres:${PG_MAJOR}
6+
FROM postgres:${PG_MAJOR_VERSION}
7+
8+
# Re-declare ARGs after FROM to make them available in this build stage
9+
ARG PG_MAJOR_VERSION
10+
ARG POSTGIS_MAJOR_VERSION
11+
ARG PGVECTOR_TAG
712

813
LABEL maintainer="Naor Peled me@naor.dev"
9-
LABEL description="PostgreSQL with PostGIS and pgvector extensions"
10-
LABEL org.opencontainers.image.source="https://github.com/naorpeled/postgis_pgvector"
14+
LABEL description="PostgreSQL with PostGIS and pgvector extensions for TypeORM"
15+
LABEL org.opencontainers.image.source="https://github.com/naorpeled/typeorm-postgres-docker"
1116

12-
# Set ENV vars from ARGs for use in subsequent RUN commands and runtime inspection
13-
ENV POSTGIS_MAJOR_VERSION=${POSTGIS_MAJOR_VERSION} \
14-
PGVECTOR_VERSION=${PGVECTOR_VERSION} \
15-
PG_MAJOR=${PG_MAJOR}
17+
# Set ENV vars from ARGs for runtime inspection and use within the container
18+
ENV PG_MAJOR_VERSION=${PG_MAJOR_VERSION} \
19+
POSTGIS_MAJOR_VERSION=${POSTGIS_MAJOR_VERSION} \
20+
PGVECTOR_TAG=${PGVECTOR_TAG}
1621

17-
# Install build dependencies and PostgreSQL development packages
22+
# Install base dependencies, setup PGDG repository, and install build tools
1823
RUN apt-get update \
1924
&& apt-get install -y --no-install-recommends \
20-
# Tools for adding repositories
2125
lsb-release \
2226
gnupg \
2327
ca-certificates \
2428
wget \
25-
# Build tools for pgvector
29+
# Add PostgreSQL official repository
30+
&& sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list' \
31+
&& wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - \
32+
# Update package lists again after adding the new repository
33+
&& apt-get update \
34+
# Install build tools and PostgreSQL development packages from PGDG
35+
&& apt-get install -y --no-install-recommends \
2636
build-essential \
2737
git \
2838
make \
2939
gcc \
30-
postgresql-server-dev-${PG_MAJOR} \
31-
# Add PostgreSQL repository for latest PostGIS
32-
&& wget --quiet -O /usr/share/keyrings/postgresql-archive-keyring.asc https://www.postgresql.org/media/keys/ACCC4CF8.asc \
33-
&& echo "deb [signed-by=/usr/share/keyrings/postgresql-archive-keyring.asc] http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main ${PG_MAJOR}" > /etc/apt/sources.list.d/pgdg.list \
34-
&& apt-get update \
35-
# Install PostGIS
40+
"postgresql-server-dev-${PG_MAJOR_VERSION}"
41+
42+
# Install PostGIS
43+
RUN apt-get update \
3644
&& apt-get install -y --no-install-recommends \
3745
postgis \
38-
postgresql-${PG_MAJOR}-postgis-${POSTGIS_MAJOR_VERSION} \
39-
postgresql-${PG_MAJOR}-postgis-${POSTGIS_MAJOR_VERSION}-scripts \
40-
# Build and install pgvector
46+
"postgresql-${PG_MAJOR_VERSION}-postgis-${POSTGIS_MAJOR_VERSION}" \
47+
"postgresql-${PG_MAJOR_VERSION}-postgis-${POSTGIS_MAJOR_VERSION}-scripts"
48+
49+
# Build and install pgvector
50+
RUN apt-get update \
51+
# Ensure build tools are available for this layer if they were aggressively purged before,
52+
# or if previous RUN commands didn't include them and they are needed.
53+
# For pgvector, we need git, make, gcc, and postgresql-server-dev.
54+
&& apt-get install -y --no-install-recommends git make gcc "postgresql-server-dev-${PG_MAJOR_VERSION}" \
4155
&& mkdir -p /usr/src/pgvector \
42-
&& git clone --branch ${PGVECTOR_VERSION} https://github.com/pgvector/pgvector.git /usr/src/pgvector \
56+
&& git clone --branch "${PGVECTOR_TAG}" https://github.com/pgvector/pgvector.git /usr/src/pgvector \
4357
&& cd /usr/src/pgvector \
4458
&& make \
45-
&& make install \
46-
# Cleanup
47-
&& apt-get purge -y --auto-remove \
48-
wget \
49-
gnupg \
59+
&& make install
60+
61+
# Cleanup build dependencies
62+
RUN apt-get purge -y --auto-remove \
5063
build-essential \
64+
# git make gcc "postgresql-server-dev-${PG_MAJOR_VERSION}" were re-installed for pgvector, purge them too
5165
git \
5266
make \
5367
gcc \
54-
postgresql-server-dev-${PG_MAJOR} \
68+
"postgresql-server-dev-${PG_MAJOR_VERSION}" \
69+
wget \
70+
# gnupg might be needed if other repositories are added later, but for now, we can remove it
71+
# if it was only for the postgresql repo key. lsb-release and ca-certificates are generally kept.
72+
&& apt-get clean \
5573
&& rm -rf /var/lib/apt/lists/* \
5674
&& rm -rf /usr/src/pgvector
5775

0 commit comments

Comments
 (0)