Skip to content
This repository was archived by the owner on Nov 21, 2024. It is now read-only.

Run pg_embedding locally with docker compose #27

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Run pg_embedding locally with docker compose
  • Loading branch information
SirlyDreamer committed Aug 3, 2023
commit a792ef8af561eb16c93959af9617144cc6f0e1df
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,28 @@ The `pg_embedding` extension enables the using the Hierarchical Navigable Small
This extension is based on [ivf-hnsw](https://github.com/dbaranchuk/ivf-hnsw) implementation of HNSW
the code for the current state-of-the-art billion-scale nearest neighbor search system<sup>[[1]](#references)</sup>.

## Run pg_embedding locally with Docker Compose

Firstly, [install docker with docker-compose-plugin](https://docs.docker.com/engine/install/), then clone this repo.

```bash
git clone https://github.com/neondatabase/pg_embedding.git
```

Build the docker image.

```bash
docker compose build
```

Run docker container with docker compose.

```bash
docker compose up -d
```

You can modify docker-compose.yaml as your taste.

## Using the pg_embedding extension

This section describes how to use the `pg_embedding` extension in Neon with a simple example demonstrating the required statements, syntax, and options.
Expand Down
17 changes: 17 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
version: '3.1'

services:
pg-embedding:
container_name: Postgres-Embedding
build: docker
restart: on-failure
ports:
- 5432:5432
volumes:
- ./data:/var/lib/postgresql/data
environment:
POSTGRES_DB: postgres
POSTGRES_USER: pgembedding
POSTGRES_PASSWORD: 1_Strong_Password
PGDATA: /var/lib/postgresql/data/pgdata

24 changes: 24 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
ARG PG_VERSION=15

FROM debian:stable-slim AS build

ARG PG_VERSION

RUN apt-get update \
&& apt-get upgrade -y \
&& apt-get install git build-essential postgresql-server-dev-$PG_VERSION -y

WORKDIR /workspace

RUN git clone https://github.com/neondatabase/pg_embedding.git \

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A better solution is probably to ADD tar file, not a hole repo. It's possible to change refs if needed. But I am not 100% sure.

ADD https://github.com/neondatabase/pg_embedding/archive/refs/heads/main.tar.gz main.tar.gz
RUN tar --strip-components=1 -xvf main.tar.gz

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved.

&& cd pg_embedding \
&& make \
&& make install

FROM postgres:$PG_VERSION

COPY --from=build /usr/lib/postgresql/ /usr/lib/postgresql/
COPY --from=build /usr/share/postgresql/ /usr/share/postgresql/
COPY ./init-extension.sh /docker-entrypoint-initdb.d/init-extension.sh

RUN chmod +x /docker-entrypoint-initdb.d/init-extension.sh
3 changes: 3 additions & 0 deletions docker/init-extension.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL
CREATE EXTENSION embedding;
EOSQL