Skip to content

Commit af16944

Browse files
committed
initial commit
0 parents  commit af16944

File tree

9 files changed

+458
-0
lines changed

9 files changed

+458
-0
lines changed

.github/workflows/publish.yml

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
name: Publish Docker image
2+
3+
on:
4+
push:
5+
tags: ["v*.*.*"]
6+
workflow_dispatch:
7+
8+
env:
9+
REGISTRY: ghcr.io
10+
11+
jobs:
12+
build-and-push:
13+
runs-on: ubuntu-latest
14+
permissions:
15+
contents: read
16+
packages: write
17+
18+
strategy:
19+
matrix:
20+
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
37+
38+
steps:
39+
- name: Checkout repository
40+
uses: actions/checkout@v4
41+
42+
- name: Log in to the Container registry
43+
uses: docker/login-action@v3
44+
with:
45+
registry: ${{ env.REGISTRY }}
46+
username: ${{ github.actor }}
47+
password: ${{ secrets.GITHUB_TOKEN }}
48+
49+
- name: Extract metadata (tags, labels) for Docker
50+
id: meta
51+
uses: docker/metadata-action@v5
52+
with:
53+
images: ${{ env.REGISTRY }}/${{ github.repository }}
54+
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
64+
65+
- name: Build and push Docker image
66+
uses: docker/build-push-action@v5
67+
with:
68+
context: .
69+
push: true
70+
tags: ${{ steps.meta.outputs.tags }}
71+
labels: ${{ steps.meta.outputs.labels }}
72+
build-args: |
73+
PG_MAJOR=${{ matrix.pg_version }}
74+
POSTGIS_MAJOR_VERSION=3
75+
PGVECTOR_VERSION=${{ matrix.pgvector_version }}
76+
cache-from: type=gha
77+
cache-to: type=gha,mode=max

.github/workflows/test.yml

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
name: Test Docker Build and Extensions
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
workflow_dispatch:
9+
10+
jobs:
11+
test:
12+
runs-on: ubuntu-latest
13+
strategy:
14+
matrix:
15+
pg_version: [16, 15]
16+
pgvector_version: [v0.8.0, v0.7.2]
17+
18+
steps:
19+
- uses: actions/checkout@v4
20+
21+
- name: Set up Docker Buildx
22+
uses: docker/setup-buildx-action@v3
23+
24+
- name: Build Docker image
25+
uses: docker/build-push-action@v5
26+
with:
27+
context: .
28+
load: true
29+
tags: postgres-postgis-pgvector:test
30+
build-args: |
31+
PG_MAJOR=${{ matrix.pg_version }}
32+
POSTGIS_MAJOR_VERSION=3
33+
PGVECTOR_VERSION=${{ matrix.pgvector_version }}
34+
35+
- name: Start PostgreSQL container
36+
run: |
37+
docker run -d \
38+
--name postgres-test \
39+
-e POSTGRES_PASSWORD=test \
40+
-e POSTGRES_USER=test \
41+
-e POSTGRES_DB=test \
42+
-e ADDITIONAL_DATABASES=test2 \
43+
-p 5432:5432 \
44+
postgres-postgis-pgvector:test
45+
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'
49+
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+
"
56+
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+
"
68+
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+
"
75+
76+
- name: Check logs for any errors
77+
if: always()
78+
run: docker logs postgres-test
79+
80+
- name: Clean up
81+
if: always()
82+
run: docker rm -f postgres-test

.gitignore

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Environment variables
2+
.env
3+
4+
# Docker volumes
5+
postgres_data/
6+
7+
# IDE files
8+
.idea/
9+
.vscode/
10+
*.swp
11+
*.swo
12+
13+
# OS files
14+
.DS_Store
15+
Thumbs.db

Dockerfile

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Default versions - can be overridden at build time using --build-arg
2+
ARG PG_MAJOR=16
3+
ARG POSTGIS_MAJOR_VERSION=3
4+
ARG PGVECTOR_VERSION=v0.7.2
5+
6+
FROM postgres:${PG_MAJOR}
7+
8+
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"
11+
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}
16+
17+
# Install build dependencies and PostgreSQL development packages
18+
RUN apt-get update \
19+
&& apt-get install -y --no-install-recommends \
20+
# Tools for adding repositories
21+
lsb-release \
22+
gnupg \
23+
ca-certificates \
24+
wget \
25+
# Build tools for pgvector
26+
build-essential \
27+
git \
28+
make \
29+
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
36+
&& apt-get install -y --no-install-recommends \
37+
postgis \
38+
postgresql-${PG_MAJOR}-postgis-${POSTGIS_MAJOR_VERSION} \
39+
postgresql-${PG_MAJOR}-postgis-${POSTGIS_MAJOR_VERSION}-scripts \
40+
# Build and install pgvector
41+
&& mkdir -p /usr/src/pgvector \
42+
&& git clone --branch ${PGVECTOR_VERSION} https://github.com/pgvector/pgvector.git /usr/src/pgvector \
43+
&& cd /usr/src/pgvector \
44+
&& make \
45+
&& make install \
46+
# Cleanup
47+
&& apt-get purge -y --auto-remove \
48+
wget \
49+
gnupg \
50+
build-essential \
51+
git \
52+
make \
53+
gcc \
54+
postgresql-server-dev-${PG_MAJOR} \
55+
&& rm -rf /var/lib/apt/lists/* \
56+
&& rm -rf /usr/src/pgvector
57+
58+
# Copy initialization scripts
59+
COPY docker-entrypoint-initdb.d/ /docker-entrypoint-initdb.d/
60+
61+
# Default PostgreSQL port
62+
EXPOSE 5432

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2025 Naor Peled
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# PostgreSQL with PostGIS and pgvector for TypeORM
2+
3+
This Docker image extends the official PostgreSQL image with PostGIS and pgvector extensions, specifically designed for TypeORM's testing. It provides a configurable PostgreSQL instance with spatial and vector search capabilities.
4+
5+
Pre-built images are available on GitHub Container Registry (GHCR). The following tags are available:
6+
7+
- `ghcr.io/naorpeled/postgis_pgvector:pg16-pgvectorv0.8.0` (also tagged as `latest`)
8+
- `ghcr.io/naorpeled/postgis_pgvector:pg15-pgvectorv0.8.0`
9+
- `ghcr.io/naorpeled/postgis_pgvector:pg16-pgvectorv0.7.2`
10+
- `ghcr.io/naorpeled/postgis_pgvector:pg15-pgvectorv0.7.2`
11+
12+
## Build Arguments
13+
14+
- `PG_MAJOR`: PostgreSQL major version (default: 16)
15+
- `POSTGIS_MAJOR_VERSION`: PostGIS major version (default: 3)
16+
- `PGVECTOR_VERSION`: pgvector version tag (default: v0.8.0)
17+
18+
## Building the Image
19+
20+
```bash
21+
# Build with default versions
22+
docker build -t postgres-postgis-pgvector .
23+
24+
# Build with custom versions
25+
docker build \
26+
--build-arg PG_MAJOR=15 \
27+
--build-arg POSTGIS_MAJOR_VERSION=3 \
28+
--build-arg PGVECTOR_VERSION=v0.7.2 \
29+
-t postgres-postgis-pgvector:pg15-pgvector0.7.2 .
30+
```
31+
32+
## Running the Container
33+
34+
```bash
35+
# Using docker run
36+
docker run -d \
37+
--name postgres-gis-vector \
38+
-e POSTGRES_PASSWORD=test \
39+
-e POSTGRES_USER=test \
40+
-e POSTGRES_DB=test \
41+
-p 5432:5432 \
42+
postgres-postgis-pgvector
43+
44+
# Using docker-compose
45+
docker-compose up -d
46+
```
47+
48+
## Environment Variables
49+
50+
Inherits all environment variables from the official PostgreSQL image. See the [official PostgreSQL image documentation](https://hub.docker.com/_/postgres/) for details.
51+
52+
Additional environment variables:
53+
54+
- `ADDITIONAL_DATABASES`: Comma-separated list of additional databases to create and initialize with extensions
55+
56+
### Testing
57+
58+
The repository includes GitHub Actions workflows that:
59+
60+
1. Test the image build with different PostgreSQL and pgvector versions
61+
2. Verify that PostGIS and pgvector extensions work correctly
62+
3. Test creation and initialization of additional databases
63+
64+
To run tests locally:
65+
66+
```bash
67+
# Build and test with default versions
68+
docker build -t postgres-postgis-pgvector:test .
69+
docker-compose -f docker-compose.test.yml up --exit-code-from test
70+
71+
# Test with specific versions
72+
PG_MAJOR=15 PGVECTOR_VERSION=v0.7.2 docker-compose -f docker-compose.test.yml up --exit-code-from test
73+
```
74+
75+
## License
76+
77+
MIT

docker-compose.test.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
version: "3.8"
2+
3+
services:
4+
postgres:
5+
build:
6+
context: .
7+
args:
8+
PG_MAJOR: ${PG_MAJOR:-16}
9+
POSTGIS_MAJOR_VERSION: ${POSTGIS_MAJOR_VERSION:-3}
10+
PGVECTOR_VERSION: ${PGVECTOR_VERSION:-v0.7.2}
11+
environment:
12+
POSTGRES_PASSWORD: test
13+
POSTGRES_USER: test
14+
POSTGRES_DB: test
15+
ADDITIONAL_DATABASES: test2
16+
healthcheck:
17+
test: ["CMD-SHELL", "pg_isready -U test"]
18+
interval: 5s
19+
timeout: 5s
20+
retries: 5
21+
22+
test:
23+
image: postgres:${PG_MAJOR:-16}
24+
depends_on:
25+
postgres:
26+
condition: service_healthy
27+
volumes:
28+
- ./tests:/tests
29+
environment:
30+
PGHOST: postgres
31+
PGUSER: test
32+
PGPASSWORD: test
33+
PGDATABASE: test
34+
command: >
35+
bash -c '
36+
psql -c "SELECT postgis_version();" &&
37+
psql -c "SELECT postgis_full_version();" &&
38+
psql -c "CREATE EXTENSION IF NOT EXISTS vector;" &&
39+
psql -c "CREATE TABLE items (id bigserial PRIMARY KEY, embedding vector(3));" &&
40+
psql -c "INSERT INTO items (embedding) VALUES ('\''[1,2,3]'\'');" &&
41+
psql -c "SELECT * FROM items WHERE embedding <-> '\''[3,2,1]'\'' < 5;" &&
42+
psql -d test2 -c "SELECT postgis_version();" &&
43+
psql -d test2 -c "SELECT * FROM pg_extension WHERE extname = '\''vector'\'';"
44+
'

0 commit comments

Comments
 (0)