Skip to content

Commit

Permalink
add pgvector
Browse files Browse the repository at this point in the history
  • Loading branch information
gjtorikian committed Jul 22, 2024
1 parent 751c5f2 commit 7f9360a
Showing 1 changed file with 33 additions and 6 deletions.
39 changes: 33 additions & 6 deletions Dockerfile.db
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,36 @@ ARG DEBIAN_VERSION="bookworm"
# First Stage: Builder
###############################################

FROM postgres:${PG_VERSION_MAJOR}-${DEBIAN_VERSION} as builder
FROM postgres:${PG_VERSION_MAJOR}-${DEBIAN_VERSION} AS builder

# repeated above, because Docker
ARG PG_VERSION_MAJOR=16
ARG DEBIAN_VERSION="bookworm"
ARG DEBIAN_FRONTEND=noninteractive

ARG RUST_VERSION=1.78.0
ARG PGRX_VERSION=0.11.2
ARG PGX_ULID_VERSION=0.1.5
ARG PGVECTOR_VERSION=0.7.2

# Declare buildtime environment variables
ENV PG_VERSION_MAJOR=${PG_VERSION_MAJOR} \
DEBIAN_VERSION=${DEBIAN_VERSION} \
RUST_VERSION=${RUST_VERSION} \
PGRX_VERSION=${PGRX_VERSION} \
PGX_ULID_VERSION=${PGX_ULID_VERSION}
PGX_ULID_VERSION=${PGX_ULID_VERSION} \
PGVECTOR_VERSION=${PGVECTOR_VERSION}

# Install build dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
pkg-config \
cmake \
ca-certificates \
git \
build-essential \
checkinstall \
libpq-dev \
postgresql-server-dev-${PG_VERSION_MAJOR} \
curl \
libreadline6-dev \
zlib1g-dev \
&& rm -rf /var/lib/apt/lists/*

# Install Rust
Expand All @@ -49,14 +50,30 @@ RUN $HOME/.cargo/bin/cargo pgrx init --pg${PG_VERSION_MAJOR} $(which pg_config)
# pgx_ulid
######################

FROM builder as builder-pgx_ulid
FROM builder AS builder-pgx_ulid

# Build the extension
WORKDIR /tmp
RUN git clone --branch v${PGX_ULID_VERSION} https://github.com/pksunkara/pgx_ulid.git
WORKDIR /tmp/pgx_ulid
RUN $HOME/.cargo/bin/cargo pgrx package --pg-config "/usr/lib/postgresql/${PG_VERSION_MAJOR}/bin/pg_config"

######################
# pgvector
######################

FROM builder AS builder-pgvector

WORKDIR /tmp

# Download and extract the pgvector release
RUN curl -L -o pgvector.tar.gz "https://github.com/pgvector/pgvector/archive/refs/tags/v${PGVECTOR_VERSION}.tar.gz" && \
mkdir -p /tmp/pgvector && \
tar -xvf pgvector.tar.gz --strip-components=1 -C /tmp/pgvector && \
cd /tmp/pgvector && \
make OPTFLAGS="" "-j$(nproc)" && \
checkinstall -D --nodoc --install=no --fstrans=no --backup=no --pakdir=/tmp

###############################################
# Second Stage: PostgreSQL
###############################################
Expand All @@ -68,6 +85,16 @@ ARG PG_VERSION_MAJOR
COPY --from=builder-pgx_ulid /tmp/pgx_ulid/target/release/ulid-pg${PG_VERSION_MAJOR}/usr/lib/postgresql/${PG_VERSION_MAJOR}/lib/* /usr/lib/postgresql/${PG_VERSION_MAJOR}/lib/
COPY --from=builder-pgx_ulid /tmp/pgx_ulid/target/release/ulid-pg${PG_VERSION_MAJOR}/usr/share/postgresql/${PG_VERSION_MAJOR}/extension/* /usr/share/postgresql/${PG_VERSION_MAJOR}/extension

# Copy the compiled pgvector extension from the builder stage
COPY --from=builder-pgvector /tmp/pgvector*.deb /tmp
RUN dpkg -i /tmp/pgvector*.deb && rm /tmp/pgvector*.deb

# Clean up build dependencies and temporary files
RUN apt-get autoremove -y && \
apt-get clean && \
rm -rf /var/lib/apt/lists/* && \
rm -rf /tmp

# Configure shared_preload_libraries
RUN echo 'ALTER SYSTEM SET shared_preload_libraries = 'ulid';\n\
CREATE EXTENSION IF NOT EXISTS ulid;\n' > /docker-entrypoint-initdb.d/01-init.sql
Expand Down

0 comments on commit 7f9360a

Please sign in to comment.