-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathDockerfile
More file actions
143 lines (114 loc) · 5.58 KB
/
Copy pathDockerfile
File metadata and controls
143 lines (114 loc) · 5.58 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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# This file is inspired by github.com/neondatabase/neon's docker file.
ARG PG_MAJOR=18
ARG EXTENSION_DIR=/usr/share/postgresql/${PG_MAJOR}/extension
ARG INCLUDE_DIR=/usr/include/postgresql/${PG_MAJOR}
ARG LIB_DIR=/usr/lib/postgresql/${PG_MAJOR}
ARG BIN_DIR=${LIB_DIR}/bin
ARG PGCONFIG=${BIN_DIR}/pg_config
#########################################################################################
#
# Layer "pg-build"
# Used to copy postgres header files from, without needing postgres installed
#
#########################################################################################
FROM postgres:${PG_MAJOR}-trixie AS pg-build
RUN apt update && \
apt install -y postgresql-server-dev-$PG_MAJOR
#########################################################################################
#
# Layer "build-deps"
# Used to copy postgres header files from, without needing postgres installed
#
#########################################################################################
FROM debian:trixie-slim AS build-deps
ARG EXTENSION_DIR
ARG LIB_DIR
COPY --from=pg-build ${EXTENSION_DIR}/ ${EXTENSION_DIR}/
COPY --from=pg-build ${LIB_DIR}/ ${LIB_DIR}/
ENV CC=gcc
ENV CXX=g++
RUN apt update && \
apt install -y git autoconf automake libtool build-essential bison flex libreadline-dev \
zlib1g-dev libxml2-dev libcurl4-openssl-dev libossp-uuid-dev wget pkg-config libssl-dev \
libicu-dev libxslt1-dev liblz4-dev libzstd-dev zstd clang-19
#########################################################################################
#
# Layer "vector-ext"
# compile pgvector extension
#
#########################################################################################
FROM build-deps AS vector-ext
ARG EXTENSION_DIR
ARG LIB_DIR
ARG INCLUDE_DIR
ARG PGCONFIG
ENV PGVECTOR_VERSION=0.8.2
ENV PGVECTOR_SHA=69f4019389af05dc1c9548deb8628e62878e6e207c03907f2b8af2016472cdaa
COPY --from=pg-build ${EXTENSION_DIR}/ ${EXTENSION_DIR}/
COPY --from=pg-build ${LIB_DIR}/ ${LIB_DIR}/
COPY --from=pg-build ${INCLUDE_DIR}/ ${INCLUDE_DIR}/
RUN wget https://github.com/pgvector/pgvector/archive/refs/tags/v${PGVECTOR_VERSION}.tar.gz -O pgvector.tar.gz && \
echo "${PGVECTOR_SHA} pgvector.tar.gz" | sha256sum --check && \
mkdir pgvector-src && cd pgvector-src && tar xvzf ../pgvector.tar.gz --strip-components=1 -C . && \
make -j $(getconf _NPROCESSORS_ONLN) OPTFLAGS="" PG_CONFIG=${PGCONFIG} && \
make -j $(getconf _NPROCESSORS_ONLN) install OPTFLAGS="" PG_CONFIG=${PGCONFIG}
RUN mkdir /out /out/lib /out/share /out/share/extension && \
cp ${LIB_DIR}/lib/vector* /out/lib/ && \
cp ${EXTENSION_DIR}/vector* /out/share/extension/ && \
echo 'trusted = true' >> /out/share/extension/vector.control
#########################################################################################
#
# Final image
#
#########################################################################################
FROM postgres:${PG_MAJOR}-trixie
LABEL maintainer="Encore - https://encore.dev"
ARG EXTENSION_DIR
ARG LIB_DIR
ENV POSTGIS_MAJOR=3
RUN apt update \
&& apt install -y --no-install-recommends \
postgresql-$PG_MAJOR-postgis-$POSTGIS_MAJOR \
postgresql-$PG_MAJOR-postgis-$POSTGIS_MAJOR-scripts
COPY --from=vector-ext /out/lib/ ${LIB_DIR}/lib/
COPY --from=vector-ext /out/share/extension/ ${EXTENSION_DIR}/
# Ensure extensions are trusted. Note: not all extensions
RUN for ext in address_standardizer address_standardizer-3 address_standardizer_data_us \
address_standardizer_data_us-3 autoinc amcheck bloom btree_gin btree_gist citext \
cube dblink dict_int dict_xsyn earthdistance fuzzystrmatch hstore insert_username \
intagg intarray isn lo ltree moddatetime pageinspect pg_buffercache pgcrypto \
pg_freespacemap pg_prewarm pgrowlocks pg_stat_statements pgstattuple pg_trgm \
pg_visibility plpgsql postgis postgis-3 postgis_raster postgis_raster-3 postgis_sfcgal \
postgis_sfcgal-3 postgis_tiger_geocoder postgis_tiger_geocoder-3 postgis_topology \
postgis_topology-3 postgres_fdw refint seg sslinfo tablefunc tsm_system_rows \
tsm_system_time unaccent uuid-ossp vector; do \
if grep -q "trusted" "$EXTENSION_DIR/$ext.control"; then \
echo "INFO: $ext is already trusted"; \
else \
echo "INFO: $ext is not trusted, adding trusted = true to $ext.control"; \
echo "trusted = true" >> "$EXTENSION_DIR/$ext.control"; \
fi \
done
# Raise max_connections on first init. initdb's -c writes the setting into
# the generated postgresql.conf; editing postgresql.conf.sample alone is
# not enough because initdb recomputes max_connections from kernel limits.
ENV POSTGRES_INITDB_ARGS="-c max_connections=1000"
# Install legacy PostgreSQL server binaries plus matching extension
# libraries (postgis, pgvector) so the OLD cluster can load extensions
# during pg_upgrade's schema dump (opt-in via AUTO_PG_UPGRADE=1). Override
# at build time with --build-arg LEGACY_PG_VERSIONS="15 16 17" to support more.
ARG LEGACY_PG_VERSIONS="15"
RUN mkdir -p /etc/postgresql-common && \
echo 'create_main_cluster = false' > /etc/postgresql-common/createcluster.conf && \
apt update && \
for v in $LEGACY_PG_VERSIONS; do \
apt install -y --no-install-recommends \
postgresql-$v \
postgresql-$v-postgis-$POSTGIS_MAJOR \
postgresql-$v-pgvector; \
done && \
rm -rf /var/lib/apt/lists/*
COPY scripts/auto-upgrade-entrypoint.sh scripts/pg-auto-upgrade.sh /usr/local/bin/
RUN chmod +x /usr/local/bin/auto-upgrade-entrypoint.sh /usr/local/bin/pg-auto-upgrade.sh
ENTRYPOINT ["auto-upgrade-entrypoint.sh"]
CMD ["postgres"]