-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
108 lines (92 loc) · 3.69 KB
/
Copy pathDockerfile
File metadata and controls
108 lines (92 loc) · 3.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# Lean PostgreSQL image with pgvector, PostGIS, pg_textsearch, and pg_partman
# Multi-stage build - all toolchains discarded, only artifacts kept
ARG PG_VERSION=18
ARG PGVECTOR_VERSION=0.8.2
ARG POSTGIS_VERSION=3.6.4
ARG PG_TEXTSEARCH_VERSION=1.3.1
ARG PG_PARTMAN_VERSION=5.4.3
#############################################
# Stage 1: Build extensions
#############################################
FROM postgres:${PG_VERSION}-alpine AS builder
ARG PGVECTOR_VERSION
ARG POSTGIS_VERSION
ARG PG_TEXTSEARCH_VERSION
ARG PG_PARTMAN_VERSION
RUN apk add --no-cache \
git \
build-base \
postgresql-dev \
curl \
# PostGIS dependencies
geos-dev \
proj-dev \
gdal-dev \
json-c-dev \
protobuf-c-dev \
libxml2-dev \
pcre2-dev \
# PostGIS build tools
perl \
flex \
bison
WORKDIR /build
# Install the clang/llvm major version postgres was compiled with (for JIT bitcode)
RUN ver="$(sed -n 's/^CLANG *= *clang-//p' /usr/local/lib/postgresql/pgxs/src/Makefile.global)" && \
apk add --no-cache "clang${ver}" "llvm${ver}" && \
ln -sf "/usr/bin/llvm${ver}-lto" "/usr/bin/llvm-lto-${ver}"
# pgvector
RUN git clone --branch v${PGVECTOR_VERSION} --depth 1 https://github.com/pgvector/pgvector.git && \
cd pgvector && \
make OPTFLAGS="" -j$(nproc) && \
make install
# PostGIS with Tiger geocoder and address standardizer.
# patches/ carries upstream security fixes released after the 3.6.4 tarball
# (CVE-2026-73515 FlatGeobuf, CVE-2026-73514 address_standardizer) — `patch`
# exits non-zero on a reject, so a patch that stops applying fails the build.
COPY patches/ /build/patches/
RUN curl -L https://download.osgeo.org/postgis/source/postgis-${POSTGIS_VERSION}.tar.gz | tar xz && \
cd postgis-${POSTGIS_VERSION} && \
for p in /build/patches/*.patch; do \
echo "Applying $(basename "$p")" && patch -p1 --batch --forward < "$p"; \
done && \
./configure --without-raster --without-topology && \
make && \
make install && \
mkdir -p /usr/local/share/postgresql/security && \
{ echo "postgis_source_version=${POSTGIS_VERSION}"; \
for p in /build/patches/*.patch; do echo "patch=$(basename "$p")"; done; \
echo "cve_fixed=CVE-2026-73514"; \
echo "cve_fixed=CVE-2026-73515"; \
} > /usr/local/share/postgresql/security/postgis-patches.txt
# pg_textsearch (BM25)
RUN git clone --branch v${PG_TEXTSEARCH_VERSION} --depth 1 https://github.com/timescale/pg_textsearch.git && \
cd pg_textsearch && \
make -j$(nproc) && \
make install
# pg_partman (partition management)
RUN git clone --branch v${PG_PARTMAN_VERSION} --depth 1 https://github.com/pgpartman/pg_partman.git && \
cd pg_partman && \
make -j$(nproc) && \
make install
#############################################
# Stage 2: Final lean runtime image
#############################################
FROM postgres:${PG_VERSION}-alpine
# Runtime deps only
RUN apk add --no-cache \
geos \
proj \
gdal \
json-c \
protobuf-c \
libxml2 \
pcre2
# Copy compiled extensions from builder
COPY --from=builder /usr/local/lib/postgresql/ /usr/local/lib/postgresql/
COPY --from=builder /usr/local/share/postgresql/ /usr/local/share/postgresql/
# Preload extensions that require shared_preload_libraries
RUN echo "shared_preload_libraries = 'pg_stat_statements,pg_textsearch,pg_partman_bgw'" >> /usr/local/share/postgresql/postgresql.conf.sample && \
echo "track_io_timing = on" >> /usr/local/share/postgresql/postgresql.conf.sample
LABEL org.opencontainers.image.source="https://github.com/constructive-io/docker"
LABEL org.opencontainers.image.description="PostgreSQL 18 with pgvector, PostGIS, pg_textsearch, pg_partman, and pg_stat_statements"