Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Default versions - can be overridden at build time using --build-arg
ARG PG_VERSION=17.9
ARG POSTGIS_VERSION=3.6.2
ARG PGVECTOR_VERSION=0.8.2
ARG PG_VERSION=18.6
ARG POSTGIS_VERSION=3.6.4
ARG PGVECTOR_VERSION=0.8.6

FROM postgres:${PG_VERSION}

Expand Down
46 changes: 27 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@ This Docker image extends the official PostgreSQL image with PostGIS and pgvecto

Pre-built images are available on GitHub Container Registry (GHCR). Replace `yourusername/yourrepositoryname` with your actual GHCR path (e.g., `ghcr.io/naorpeled/typeorm-postgres-docker`).

Example tags (refer to the `publish.yml` workflow matrix for all combinations):
Example tags (refer to `versions.json` and the `publish.yml` workflow matrix for all combinations):

- `ghcr.io/yourusername/yourrepositoryname:pg16-postgis3-pgvectorv0.8.0`
- `ghcr.io/yourusername/yourrepositoryname:postgres-18.6-postgis-3.6.4-pgvector-0.8.6`
- `ghcr.io/yourusername/yourrepositoryname:latest` (points to the default latest combination)

## Build Arguments

The following build arguments can be used with `docker build --build-arg VAR=value` or via the `args` section in `docker-compose.yml` (which can use environment variables from your `.env` file):

- `PG_MAJOR_VERSION`: PostgreSQL major version (default: 16). In `docker-compose.yml`, fed by `PG_MAJOR` env var.
- `POSTGIS_MAJOR_VERSION`: PostGIS major version (default: 3). In `docker-compose.yml`, fed by `POSTGIS_MAJOR_VERSION` env var.
- `PGVECTOR_TAG`: pgvector version tag (e.g., `v0.8.0`, default: v0.8.0). In `docker-compose.yml`, fed by `PGVECTOR_VERSION` env var.
- `PG_VERSION`: PostgreSQL image tag (default: 18.6). In `docker-compose.yml`, fed by the `PG_VERSION` env var.
- `POSTGIS_VERSION`: PostGIS package version (default: 3.6.4). In `docker-compose.yml`, fed by the `POSTGIS_VERSION` env var.
- `PGVECTOR_VERSION`: pgvector release version (e.g., `0.8.6`, default: `0.8.6`). In `docker-compose.yml`, fed by the `PGVECTOR_VERSION` env var.

## Building the Image

Expand All @@ -33,9 +33,9 @@ docker build -t your-image-name .

# Build with custom versions (using Docker build args)
docker build \\
--build-arg PG_MAJOR_VERSION=15 \\
--build-arg POSTGIS_MAJOR_VERSION=3 \\
--build-arg PGVECTOR_TAG=v0.7.2 \\
--build-arg PG_VERSION=17.9 \\
--build-arg POSTGIS_VERSION=3.6.2 \\
--build-arg PGVECTOR_VERSION=0.8.2 \\
-t your-image-name:custom .
```

Expand All @@ -51,11 +51,14 @@ docker run -d \\
-e POSTGRES_PASSWORD=yourpassword \\
-e POSTGRES_USER=youruser \\
-e POSTGRES_DB=yourdb \\
-e PGDATA=/var/lib/postgresql/pgdata \\
-p 5432:5432 \\
-v postgres_data_volume:/var/lib/postgresql/data \\
-v postgres_data_volume:/var/lib/postgresql \\
your-image-name postgres -c shared_preload_libraries=vector
```

Mount the parent directory at `/var/lib/postgresql` and set `PGDATA` to a subdirectory inside that mount (for example `/var/lib/postgresql/pgdata`). This keeps persistence working for both PostgreSQL 18+ and PostgreSQL 17 and earlier, whose upstream images use different default data directories and volume layouts.

### Using `docker-compose.yml`

The provided `docker-compose.yml` is configured to build and run the image, including preloading pgvector via the `command` directive.
Expand All @@ -67,24 +70,27 @@ services:
build:
context: .
args:
PG_MAJOR_VERSION: ${PG_MAJOR:-16}
POSTGIS_MAJOR_VERSION: ${POSTGIS_MAJOR_VERSION:-3}
PGVECTOR_TAG: ${PGVECTOR_VERSION:-v0.8.0}
command: postgres -c shared_preload_libraries=vector # Ensures pgvector preloading
PG_VERSION: ${PG_VERSION:-18.6}
POSTGIS_VERSION: ${POSTGIS_VERSION:-3.6.4}
PGVECTOR_VERSION: ${PGVECTOR_VERSION:-0.8.6}
environment:
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-test} # TypeORM test default
POSTGRES_USER: ${POSTGRES_USER:-test} # TypeORM test default
POSTGRES_DB: ${POSTGRES_DB:-test} # TypeORM test default
PGDATA: /var/lib/postgresql/pgdata
volumes:
- postgres_data:/var/lib/postgresql
command: postgres -c shared_preload_libraries=vector # Ensures pgvector preloading
# ... other environment variables ...
```

Create a `.env` file in the same directory as `docker-compose.yml` to set build arguments and PostgreSQL credentials (optional, defaults are provided):

```env
# .env (example)
PG_MAJOR=16
POSTGIS_MAJOR_VERSION=3
PGVECTOR_VERSION=v0.8.0
PG_VERSION=18.6
POSTGIS_VERSION=3.6.4
PGVECTOR_VERSION=0.8.6

POSTGRES_PASSWORD=supersecret
POSTGRES_USER=myuser
Expand All @@ -99,11 +105,13 @@ Then run:
docker compose up --build -d
```

If you already have a PostgreSQL 17 data volume mounted directly at `/var/lib/postgresql/data`, treat the move to the compose defaults above as a migration rather than a drop-in path change. Back up and restore the database or follow the official major-upgrade process before reusing existing data with `PGDATA=/var/lib/postgresql/pgdata`.

## GitHub Actions

This repository includes GitHub Actions workflows:

- `.github/workflows/test.yml`: Builds the Docker image with a matrix of PostgreSQL versions and pgvector tags, and runs basic extension checks. `POSTGIS_MAJOR_VERSION` is typically fixed (e.g., to 3) in these tests.
- `.github/workflows/test.yml`: Builds the Docker image with a matrix of PostgreSQL, PostGIS, and pgvector versions from `versions.json`, and runs basic extension checks.
- `.github/workflows/publish.yml`: Builds and publishes the Docker image to GHCR on tagged releases (e.g., `v1.0.0`). The image name on GHCR will be based on your GitHub username/organization and repository name (e.g., `ghcr.io/yourusername/yourrepositoryname`).

## TypeORM Compatibility
Expand All @@ -120,7 +128,7 @@ This setup ensures that TypeORM can connect and utilize PostGIS and pgvector fun

Inherits all environment variables from the official PostgreSQL image. See the [official PostgreSQL image documentation](https://hub.docker.com/_/postgres/) for details.

The build arguments `PG_MAJOR_VERSION`, `POSTGIS_MAJOR_VERSION`, and `PGVECTOR_TAG` are also exposed as environment variables with the same names within the running container for runtime inspection.
The image build is parameterized by the `PG_VERSION`, `POSTGIS_VERSION`, and `PGVECTOR_VERSION` build arguments. These values are used only at build time unless you also set them explicitly as runtime environment variables.

Additional runtime environment variables for the entrypoint script:

Expand All @@ -137,7 +145,7 @@ To run tests locally using this file:
docker compose -f docker-compose.test.yml up --build --exit-code-from test

# Test with specific versions by setting environment variables for the compose command:
PG_MAJOR=15 POSTGIS_MAJOR_VERSION=3 PGVECTOR_VERSION=v0.7.2 docker compose -f docker-compose.test.yml up --build --exit-code-from test
PG_VERSION=17.9 PG_MAJOR=17 POSTGIS_VERSION=3.6.2 PGVECTOR_VERSION=0.8.2 docker compose -f docker-compose.test.yml up --build --exit-code-from test
```

## License
Expand Down
8 changes: 4 additions & 4 deletions docker-compose.test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ services:
build:
context: .
args:
PG_MAJOR: ${PG_MAJOR:-16}
POSTGIS_MAJOR_VERSION: ${POSTGIS_MAJOR_VERSION:-3}
PGVECTOR_VERSION: ${PGVECTOR_VERSION:-v0.7.2}
PG_VERSION: ${PG_VERSION:-18.6}
POSTGIS_VERSION: ${POSTGIS_VERSION:-3.6.4}
PGVECTOR_VERSION: ${PGVECTOR_VERSION:-0.8.6}
environment:
POSTGRES_PASSWORD: test
POSTGRES_USER: test
Expand All @@ -20,7 +20,7 @@ services:
retries: 5

test:
image: postgres:${PG_MAJOR:-16}
image: postgres:${PG_MAJOR:-18}
depends_on:
postgres:
condition: service_healthy
Expand Down
11 changes: 5 additions & 6 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,20 @@ services:
build:
context: .
args:
PG_MAJOR_VERSION: ${PG_MAJOR:-16} # Environment variable PG_MAJOR, defaults to 16
POSTGIS_MAJOR_VERSION: ${POSTGIS_MAJOR_VERSION:-3} # Environment variable POSTGIS_MAJOR_VERSION, defaults to 3
PGVECTOR_TAG: ${PGVECTOR_VERSION:-v0.8.0} # Environment variable PGVECTOR_VERSION, defaults to v0.8.0
PG_VERSION: ${PG_VERSION:-18.6} # Environment variable PG_VERSION, defaults to 18.6
POSTGIS_VERSION: ${POSTGIS_VERSION:-3.6.4} # Environment variable POSTGIS_VERSION, defaults to 3.6.4
PGVECTOR_VERSION: ${PGVECTOR_VERSION:-0.8.6} # Environment variable PGVECTOR_VERSION, defaults to 0.8.6
environment:
# TypeORM test defaults, or override with your own .env file
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-test}
POSTGRES_USER: ${POSTGRES_USER:-test}
POSTGRES_DB: ${POSTGRES_DB:-test}
PGDATA: /var/lib/postgresql/pgdata
ADDITIONAL_DATABASES: ${ADDITIONAL_DATABASES:-}
# The following are set inside the Dockerfile from build ARGs for runtime access if needed:
# PG_MAJOR_VERSION, POSTGIS_MAJOR_VERSION, PGVECTOR_TAG
ports:
- "${POSTGRES_PORT:-5432}:5432"
volumes:
- postgres_data:/var/lib/postgresql/data
- postgres_data:/var/lib/postgresql
Comment thread
qodo-free-for-open-source-projects[bot] marked this conversation as resolved.
healthcheck:
test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER:-test}"]
interval: 10s
Expand Down
8 changes: 7 additions & 1 deletion versions.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
[
{
"pg_version": "18.6",
"postgis_version": "3.6.4",
"pgvector_version": "0.8.6",
"latest": true
},
{
"pg_version": "17.9",
"postgis_version": "3.6.2",
"pgvector_version": "0.8.2",
"latest": true
"latest": false
},
{
"pg_version": "16.13",
Expand Down
Loading