|
1 | 1 | ARG PG_MAJOR=18 |
2 | 2 |
|
3 | | -# Stage 1: Build pgvector extension from Hanzo fork |
4 | | -FROM postgres:${PG_MAJOR}-alpine AS builder |
| 3 | +# Stage 1: Build all extensions on Debian (documentdb requires glibc toolchain) |
| 4 | +FROM postgres:${PG_MAJOR}-bookworm AS builder |
5 | 5 | ARG PG_MAJOR |
6 | 6 |
|
7 | | -RUN apk add --no-cache --virtual .build-deps \ |
8 | | - build-base \ |
9 | | - clang19 \ |
10 | | - llvm19 \ |
11 | | - postgresql${PG_MAJOR}-dev && \ |
12 | | - cd /tmp && \ |
13 | | - wget -qO- https://github.com/hanzoai/sql-vector/archive/refs/heads/master.tar.gz | tar xz && \ |
| 7 | +ENV DEBIAN_FRONTEND=noninteractive |
| 8 | + |
| 9 | +# Install build dependencies for pgvector, pg_cron, and pg_documentdb |
| 10 | +RUN apt-get update && apt-get install -y --no-install-recommends \ |
| 11 | + build-essential \ |
| 12 | + cmake \ |
| 13 | + git \ |
| 14 | + curl \ |
| 15 | + ca-certificates \ |
| 16 | + pkg-config \ |
| 17 | + postgresql-server-dev-${PG_MAJOR} \ |
| 18 | + libpq-dev \ |
| 19 | + libicu-dev \ |
| 20 | + libkrb5-dev \ |
| 21 | + # PostGIS (runtime dep for documentdb CREATE EXTENSION) |
| 22 | + postgresql-${PG_MAJOR}-postgis-3 \ |
| 23 | + && rm -rf /var/lib/apt/lists/* |
| 24 | + |
| 25 | +# --- pgvector --- |
| 26 | +RUN cd /tmp && \ |
| 27 | + curl -sL https://github.com/hanzoai/sql-vector/archive/refs/heads/master.tar.gz | tar xz && \ |
14 | 28 | cd sql-vector-master && \ |
15 | 29 | make clean && \ |
16 | | - make OPTFLAGS="" PG_CONFIG=/usr/local/bin/pg_config && \ |
17 | | - make install PG_CONFIG=/usr/local/bin/pg_config && \ |
18 | | - cd / && rm -rf /tmp/sql-vector-master && \ |
19 | | - apk del .build-deps |
| 30 | + make OPTFLAGS="" PG_CONFIG=/usr/bin/pg_config && \ |
| 31 | + make install PG_CONFIG=/usr/bin/pg_config && \ |
| 32 | + cd / && rm -rf /tmp/sql-vector-master |
| 33 | + |
| 34 | +# --- pg_cron --- |
| 35 | +ARG PG_CRON_VERSION=v1.6.7 |
| 36 | +RUN cd /tmp && \ |
| 37 | + curl -sL https://github.com/citusdata/pg_cron/archive/refs/tags/${PG_CRON_VERSION}.tar.gz | tar xz && \ |
| 38 | + cd pg_cron-* && \ |
| 39 | + make PG_CONFIG=/usr/bin/pg_config && \ |
| 40 | + make install PG_CONFIG=/usr/bin/pg_config && \ |
| 41 | + cd / && rm -rf /tmp/pg_cron-* |
| 42 | + |
| 43 | +# --- pg_documentdb dependencies: libbson, Intel Decimal Math Lib, pcre2 --- |
| 44 | + |
| 45 | +ARG LIBBSON_VERSION=1.28.0 |
| 46 | +RUN cd /tmp && \ |
| 47 | + curl -sL https://github.com/mongodb/mongo-c-driver/releases/download/${LIBBSON_VERSION}/mongo-c-driver-${LIBBSON_VERSION}.tar.gz | tar xz && \ |
| 48 | + cd mongo-c-driver-${LIBBSON_VERSION}/build && \ |
| 49 | + cmake -DENABLE_MONGOC=ON -DMONGOC_ENABLE_ICU=OFF -DENABLE_ICU=OFF \ |
| 50 | + -DCMAKE_C_FLAGS="-fPIC -g" -DCMAKE_BUILD_TYPE=Release \ |
| 51 | + -DCMAKE_INSTALL_PREFIX=/usr .. && \ |
| 52 | + make -j$(nproc) install && \ |
| 53 | + cd / && rm -rf /tmp/mongo-c-driver-* |
| 54 | + |
| 55 | +ARG INTEL_MATH_LIB_VERSION=applied/2.0u3-1 |
| 56 | +RUN cd /tmp && \ |
| 57 | + mkdir -p intelmathlib/lib/intelmathlib && \ |
| 58 | + cd intelmathlib/lib/intelmathlib && \ |
| 59 | + git init && \ |
| 60 | + git remote add origin https://git.launchpad.net/ubuntu/+source/intelrdfpmath && \ |
| 61 | + git fetch --depth 1 origin "${INTEL_MATH_LIB_VERSION}" && \ |
| 62 | + git checkout FETCH_HEAD && \ |
| 63 | + cd LIBRARY && \ |
| 64 | + make -j$(nproc) _CFLAGS_OPT=-fPIC CC=gcc CALL_BY_REF=0 GLOBAL_RND=0 GLOBAL_FLAGS=0 UNCHANGED_BINARY_FLAGS=0 && \ |
| 65 | + cd /tmp/intelmathlib && \ |
| 66 | + # Create pkg-config file |
| 67 | + printf 'prefix=/usr/lib/intelmathlib\nlibdir=${prefix}/LIBRARY\nincludedir=${prefix}/LIBRARY/src\n\nName: intelmathlib\nDescription: Intel Decimal Floating point math library\nVersion: 2.0 Update 2\nCflags: -I${includedir}\nLibs: -L${libdir} -lbid\n' > intelmathlib.pc && \ |
| 68 | + cp -R lib/intelmathlib /usr/lib/ && \ |
| 69 | + cp intelmathlib.pc /usr/lib/pkgconfig/ && \ |
| 70 | + cd / && rm -rf /tmp/intelmathlib |
| 71 | + |
| 72 | +ARG PCRE2_VERSION=10.40 |
| 73 | +RUN cd /tmp && \ |
| 74 | + curl -sL https://github.com/PCRE2Project/pcre2/releases/download/pcre2-${PCRE2_VERSION}/pcre2-${PCRE2_VERSION}.tar.gz | tar xz && \ |
| 75 | + cd pcre2-${PCRE2_VERSION} && \ |
| 76 | + ./configure --prefix=/usr --disable-shared --enable-static --enable-jit && \ |
| 77 | + make -j$(nproc) AM_CFLAGS=-fPIC install && \ |
| 78 | + cd / && rm -rf /tmp/pcre2-* |
20 | 79 |
|
21 | | -# Stage 2: Runtime image |
22 | | -FROM postgres:${PG_MAJOR}-alpine |
| 80 | +# --- pg_documentdb (core + api) --- |
| 81 | +ARG DOCUMENTDB_VERSION=main |
| 82 | +RUN cd /tmp && \ |
| 83 | + curl -sL https://github.com/microsoft/documentdb/archive/refs/heads/${DOCUMENTDB_VERSION}.tar.gz | tar xz && \ |
| 84 | + cd documentdb-* && \ |
| 85 | + make -C pg_documentdb_core PG_CONFIG=/usr/bin/pg_config install && \ |
| 86 | + make -C pg_documentdb PG_CONFIG=/usr/bin/pg_config install && \ |
| 87 | + cd / && rm -rf /tmp/documentdb-* |
| 88 | + |
| 89 | +# Stage 2: Runtime image (Debian for glibc compat with documentdb) |
| 90 | +FROM postgres:${PG_MAJOR}-bookworm |
23 | 91 |
|
24 | 92 | LABEL maintainer="dev@hanzo.ai" |
25 | 93 | LABEL org.opencontainers.image.source="https://github.com/hanzoai/sql" |
26 | | -LABEL org.opencontainers.image.description="Hanzo SQL - PostgreSQL with pgvector for AI workloads" |
| 94 | +LABEL org.opencontainers.image.description="Hanzo SQL - PostgreSQL with pgvector, pg_cron, and pg_documentdb" |
| 95 | + |
| 96 | +# Runtime deps: libpq (pg_cron), PostGIS (documentdb geospatial), ICU |
| 97 | +ARG PG_MAJOR=18 |
| 98 | +RUN apt-get update && apt-get install -y --no-install-recommends \ |
| 99 | + libpq5 \ |
| 100 | + postgresql-${PG_MAJOR}-postgis-3 \ |
| 101 | + && rm -rf /var/lib/apt/lists/* |
| 102 | + |
| 103 | +# Copy Intel Decimal Math Library (runtime dep for documentdb) |
| 104 | +COPY --from=builder /usr/lib/intelmathlib /usr/lib/intelmathlib |
| 105 | + |
| 106 | +# Copy pgvector extension |
| 107 | +COPY --from=builder /usr/lib/postgresql/${PG_MAJOR}/lib/vector.so /usr/lib/postgresql/${PG_MAJOR}/lib/ |
| 108 | +COPY --from=builder /usr/share/postgresql/${PG_MAJOR}/extension/vector* /usr/share/postgresql/${PG_MAJOR}/extension/ |
| 109 | + |
| 110 | +# Copy pg_cron extension |
| 111 | +COPY --from=builder /usr/lib/postgresql/${PG_MAJOR}/lib/pg_cron.so /usr/lib/postgresql/${PG_MAJOR}/lib/ |
| 112 | +COPY --from=builder /usr/share/postgresql/${PG_MAJOR}/extension/pg_cron* /usr/share/postgresql/${PG_MAJOR}/extension/ |
| 113 | + |
| 114 | +# Copy pg_documentdb_core extension |
| 115 | +COPY --from=builder /usr/lib/postgresql/${PG_MAJOR}/lib/pg_documentdb_core.so /usr/lib/postgresql/${PG_MAJOR}/lib/ |
| 116 | +COPY --from=builder /usr/share/postgresql/${PG_MAJOR}/extension/documentdb_core* /usr/share/postgresql/${PG_MAJOR}/extension/ |
27 | 117 |
|
28 | | -# Copy pgvector extension from builder (shared object + SQL files) |
29 | | -COPY --from=builder /usr/local/lib/postgresql/vector.so /usr/local/lib/postgresql/ |
30 | | -COPY --from=builder /usr/local/share/postgresql/extension/vector* /usr/local/share/postgresql/extension/ |
| 118 | +# Copy pg_documentdb extension |
| 119 | +COPY --from=builder /usr/lib/postgresql/${PG_MAJOR}/lib/pg_documentdb.so /usr/lib/postgresql/${PG_MAJOR}/lib/ |
| 120 | +COPY --from=builder /usr/share/postgresql/${PG_MAJOR}/extension/documentdb* /usr/share/postgresql/${PG_MAJOR}/extension/ |
31 | 121 |
|
32 | 122 | # Custom postgresql.conf tuned for AI workloads |
33 | 123 | COPY conf/postgresql.conf /etc/postgresql/postgresql.conf |
34 | 124 |
|
35 | | -# Init scripts: enable pgvector on startup |
| 125 | +# Init scripts: enable extensions on startup |
36 | 126 | COPY docker-entrypoint-initdb.d/ /docker-entrypoint-initdb.d/ |
37 | 127 |
|
38 | 128 | # Health check |
|
0 commit comments