-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile.back
520 lines (520 loc) · 17.5 KB
/
Dockerfile.back
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
ARG PG_MAJOR_VERSION=16
ARG DOCKER_CMAKE_BUILD_TYPE=Release
ARG CGAL_GIT_BRANCH=5.6.x-branch
FROM postgres:${PG_MAJOR_VERSION} AS builder
ARG PG_MAJOR_VERSION
ARG DOCKER_CMAKE_BUILD_TYPE
LABEL maintainer="TKamitaSoft Service - https://tkamitasoft.com" \
org.opencontainers.image.description="TKamitaSoft PostgrSQL database" \
org.opencontainers.image.source="https://gitlab.com/tkamitasoft/apps/host"
WORKDIR /
# apt-get install
RUN set -ex \
&& apt-get update -y \
#&& apt-mark hold locales \
&& apt-get install -y --no-install-recommends \
curl \
libboost-atomic1.74.0 \
libboost-chrono1.74.0 \
libboost-date-time1.74.0 \
libboost-filesystem1.74.0 \
libboost-program-options1.74.0 \
libboost-serialization1.74.0 \
libboost-system1.74.0 \
libboost-test1.74.0 \
libboost-thread1.74.0 \
libboost-timer1.74.0 \
libcurl3-gnutls \
libexpat1 \
libgmp10 \
libgmpxx4ldbl \
libjson-c5 \
libmpfr6 \
libprotobuf-c1 \
libtiff6 \
libxml2 \
sqlite3 \
# build dependency
autoconf \
automake \
autotools-dev \
bison \
build-essential \
ca-certificates \
cmake \
g++ \
git \
libboost-all-dev \
libcurl4-gnutls-dev \
libgmp-dev \
libjson-c-dev \
libmpfr-dev \
libpcre3-dev \
libpq-dev \
libprotobuf-c-dev \
libsqlite3-dev \
libtiff-dev \
libtool \
libxml2-dev \
make \
pkg-config \
protobuf-c-compiler \
xsltproc \
# gdal+
libblosc-dev \
libcfitsio-dev \
libfreexl-dev \
libfyba-dev \
libhdf5-dev \
libkml-dev \
liblz4-dev \
liblzma-dev \
libopenjp2-7-dev \
libqhull-dev \
libwebp-dev \
libzstd-dev
ENV DOCKER_CMAKE_BUILD_TYPE=${DOCKER_CMAKE_BUILD_TYPE}
# cgal & sfcgal
# By utilizing the latest commit of the CGAL 5.x.x-branch and implementing a header-only build for SFCGAL,
# one can benefit from the latest CGAL patches while avoiding compatibility issues.
ARG CGAL_GIT_BRANCH
ENV CGAL_GIT_BRANCH=${CGAL_GIT_BRANCH}
ENV CGAL5X_GIT_HASH=188e51bad36ffc30e49dbabda29620b71a84664c
ENV SFCGAL_GIT_HASH=61f3b08ade49493b56c6bafa98c7c1f84addbc10
RUN set -ex \
&& mkdir -p /usr/src \
&& cd /usr/src \
&& git clone --branch ${CGAL_GIT_BRANCH} https://github.com/CGAL/cgal.git \
&& cd cgal \
&& git checkout ${CGAL5X_GIT_HASH} \
&& git log -1 > /_pgis_cgal_last_commit.txt \
&& cd /usr/src \
&& git clone https://gitlab.com/SFCGAL/SFCGAL.git \
&& cd SFCGAL \
&& git checkout ${SFCGAL_GIT_HASH} \
&& git log -1 > /_pgis_sfcgal_last_commit.txt \
&& mkdir cmake-build \
&& cd cmake-build \
&& cmake .. \
-DCGAL_DIR=/usr/src/cgal \
-DCMAKE_BUILD_TYPE=${DOCKER_CMAKE_BUILD_TYPE} \
-DSFCGAL_BUILD_BENCH=OFF \
-DSFCGAL_BUILD_EXAMPLES=OFF \
-DSFCGAL_BUILD_TESTS=OFF \
-DSFCGAL_WITH_OSG=OFF \
&& make -j$(nproc) \
&& make install \
#
## testing with -DSFCGAL_BUILD_TESTS=ON
# && CTEST_OUTPUT_ON_FAILURE=TRUE ctest \
#
# clean
&& rm -fr /usr/src/SFCGAL \
&& rm -fr /usr/src/cgal
# proj
ENV PROJ_GIT_HASH=356496f7b60ee0235189dd51d99aac700fbd2bdc
RUN set -ex \
&& cd /usr/src \
&& git clone https://github.com/OSGeo/PROJ.git \
&& cd PROJ \
&& git checkout ${PROJ_GIT_HASH} \
&& git log -1 > /_pgis_proj_last_commit.txt \
# check the autotools exist? https://github.com/OSGeo/PROJ/pull/3027
&& if [ -f "autogen.sh" ] ; then \
set -eux \
&& echo "autotools version: 'autogen.sh' exists! Older version!" \
&& ./autogen.sh \
&& ./configure --disable-static \
&& make -j$(nproc) \
&& make install \
; \
else \
set -eux \
&& echo "cmake version: 'autogen.sh' does not exists! Newer version!" \
&& mkdir build \
&& cd build \
&& cmake .. -DCMAKE_BUILD_TYPE=${DOCKER_CMAKE_BUILD_TYPE} -DBUILD_TESTING=OFF \
&& make -j$(nproc) \
&& make install \
; \
fi \
\
&& rm -fr /usr/src/PROJ
# geos
ENV GEOS_GIT_HASH=a8d2ed0aba46f88f9b8987526e68eea6565d16ae
RUN set -ex \
&& cd /usr/src \
&& git clone https://github.com/libgeos/geos.git \
&& cd geos \
&& git checkout ${GEOS_GIT_HASH} \
&& git log -1 > /_pgis_geos_last_commit.txt \
&& mkdir cmake-build \
&& cd cmake-build \
&& cmake .. -DCMAKE_BUILD_TYPE=${DOCKER_CMAKE_BUILD_TYPE} -DBUILD_TESTING=OFF \
&& make -j$(nproc) \
&& make install \
&& cd / \
&& rm -fr /usr/src/geos
# gdal
ENV GDAL_GIT_HASH=d7aed6e0b03f949ba40684f868c63a08d89177b1
RUN set -ex \
&& cd /usr/src \
&& git clone https://github.com/OSGeo/gdal.git \
&& cd gdal \
&& git checkout ${GDAL_GIT_HASH} \
&& git log -1 > /_pgis_gdal_last_commit.txt \
\
# gdal project directory structure - has been changed !
&& if [ -d "gdal" ] ; then \
echo "Directory 'gdal' dir exists -> older version!" ; \
cd gdal ; \
else \
echo "Directory 'gdal' does not exists! Newer version! " ; \
fi \
\
&& if [ -f "./autogen.sh" ]; then \
# Building with autoconf ( old/deprecated )
set -eux \
&& ./autogen.sh \
&& ./configure --disable-static \
; \
else \
# Building with cmake
set -eux \
&& mkdir build \
&& cd build \
# config based on: https://salsa.debian.org/debian-gis-team/gdal/-/blob/master/debian/rules
&& cmake .. -DCMAKE_BUILD_TYPE=${DOCKER_CMAKE_BUILD_TYPE} -DBUILD_TESTING=OFF \
-DBUILD_DOCS=OFF \
\
-DGDAL_HIDE_INTERNAL_SYMBOLS=ON \
-DRENAME_INTERNAL_TIFF_SYMBOLS=ON \
-DGDAL_USE_BLOSC=ON \
-DGDAL_USE_CFITSIO=ON \
-DGDAL_USE_CURL=ON \
-DGDAL_USE_DEFLATE=ON \
-DGDAL_USE_EXPAT=ON \
-DGDAL_USE_FREEXL=ON \
-DGDAL_USE_FYBA=ON \
-DGDAL_USE_GEOS=ON \
-DGDAL_USE_HDF5=ON \
-DGDAL_USE_JSONC=ON \
-DGDAL_USE_LERC_INTERNAL=ON \
-DGDAL_USE_LIBKML=ON \
-DGDAL_USE_LIBLZMA=ON \
-DGDAL_USE_LZ4=ON \
-DGDAL_USE_OPENJPEG=ON \
-DGDAL_USE_POSTGRESQL=ON \
-DGDAL_USE_QHULL=ON \
-DGDAL_USE_SQLITE3=ON \
-DGDAL_USE_TIFF=ON \
-DGDAL_USE_WEBP=ON \
-DGDAL_USE_ZSTD=ON \
\
# OFF and Not working https://github.com/OSGeo/gdal/issues/7100
# -DRENAME_INTERNAL_GEOTIFF_SYMBOLS=ON \
-DGDAL_USE_ECW=OFF \
-DGDAL_USE_GEOTIFF=OFF \
-DGDAL_USE_HEIF=OFF \
-DGDAL_USE_SPATIALITE=OFF \
; \
fi \
\
&& make -j$(nproc) \
&& make install \
&& cd / \
&& rm -fr /usr/src/gdal
# Minimal command line test.
RUN set -ex \
&& ldconfig \
&& cs2cs \
&& ldd $(which gdalinfo) \
&& gdalinfo --version \
&& geos-config --version \
&& ogr2ogr --version \
&& proj \
&& sfcgal-config --version \
&& pcre-config --version
# -------------------------------------------
# STAGE final
# -------------------------------------------
FROM postgres:${PG_MAJOR_VERSION}
ARG DOCKER_CMAKE_BUILD_TYPE
ENV DOCKER_CMAKE_BUILD_TYPE=${DOCKER_CMAKE_BUILD_TYPE}
RUN set -ex \&& apt-get update -y \
&& apt-get install -y --no-install-recommends \
curl \
libboost-atomic1.74.0 \
libboost-chrono1.74.0 \
libboost-date-time1.74.0 \
libboost-filesystem1.74.0 \
libboost-program-options1.74.0 \
libboost-serialization1.74.0 \
libboost-system1.74.0 \
libboost-test1.74.0 \
libboost-thread1.74.0 \
libboost-timer1.74.0 \
libcurl3-gnutls \
libexpat1 \
libgmp10 \
libgmpxx4ldbl \
libjson-c5 \
libmpfr6 \
libpcre3 \
libprotobuf-c1 \
libtiff6 \
libxml2 \
sqlite3 \
# gdal+
libblosc1 \
libcfitsio10 \
libfreexl1 \
libfyba0 \
libhdf5-103-1 \
libkmlbase1 \
libkmldom1 \
libkmlengine1 \
libopenjp2-7 \
libqhull-r8.0 \
&& apt-get clean -y \
&& rm -rf /var/lib/apt/lists/*
COPY --from=builder /_pgis*.* /
COPY --from=builder /usr/local /usr/local
ARG CGAL_GIT_BRANCH
ENV CGAL_GIT_BRANCH=${CGAL_GIT_BRANCH}
ENV CGAL5X_GIT_HASH=188e51bad36ffc30e49dbabda29620b71a84664c
ENV SFCGAL_GIT_HASH=61f3b08ade49493b56c6bafa98c7c1f84addbc10
ENV PROJ_GIT_HASH=356496f7b60ee0235189dd51d99aac700fbd2bdc
ENV GEOS_GIT_HASH=a8d2ed0aba46f88f9b8987526e68eea6565d16ae
ENV GDAL_GIT_HASH=d7aed6e0b03f949ba40684f868c63a08d89177b1
# Minimal command line test ( fail fast )
RUN set -ex \
&& ldconfig \
&& cs2cs \
&& ldd $(which gdalinfo) \
&& gdalinfo --version \
&& gdal-config --formats \
&& geos-config --version \
&& ogr2ogr --version \
&& proj \
&& sfcgal-config --version \
\
# Testing ogr2ogr PostgreSQL driver.
&& ogr2ogr --formats | grep -q "PostgreSQL/PostGIS" && exit 0 \
|| echo "ogr2ogr missing PostgreSQL driver" && exit 1
# install postgis, pgvector, pgmq, pg_partman, potgresml, pgcat, patroni, pgcopydb
ENV POSTGIS_GIT_HASH=8ed84517a9b86c86724504d1b6a0f0c1ccd86cf6
ENV PGVECTOR_GIT_HASH=v0.7.2
ENV PGMQ_GIT_HASH=v1.3.3
ENV PGPARTMAN_GIT_HASH=v5.1.0
ENV TZ=UTC
ENV DEBIAN_FRONTEND=noninteractive
RUN set -ex \
&& export DEBIAN_FRONTEND=noninteractive \
&& apt-get update -y \
&& apt-get install -y --no-install-recommends \
autoconf \
automake \
autotools-dev \
bison \
build-essential \
ca-certificates \
cmake \
docbook-xml \
docbook5-xml \
g++ \
git \
libboost-all-dev \
libcunit1-dev \
libcurl4-gnutls-dev \
libgmp-dev \
libjson-c-dev \
libmpfr-dev \
libpcre3-dev \
libprotobuf-c-dev \
libsqlite3-dev \
libtiff-dev \
libtool \
libxml2-dev \
libxml2-utils \
make \
pkg-config \
postgresql-server-dev-16 \
protobuf-c-compiler \
xsltproc \
clang \
gcc \
libssl-dev \
# pgcopydb
pgcopydb \
&& cd \
# postgis
&& cd /usr/src/ \
&& git clone https://github.com/postgis/postgis.git \
&& cd postgis \
&& git checkout ${POSTGIS_GIT_HASH} \
&& git log -1 > /_pgis_last_commit.txt \
&& ./autogen.sh \
# configure options taken from:
# https://anonscm.debian.org/cgit/pkg-grass/postgis.git/tree/debian/rules?h=jessie
&& ./configure \
--enable-lto \
&& make -j$(nproc) \
&& make install \
# refresh proj data - workarounds: https://trac.osgeo.org/postgis/ticket/5316
&& projsync --system-directory --file ch_swisstopo_CHENyx06_ETRS \
&& projsync --system-directory --file us_noaa_eshpgn \
&& projsync --system-directory --file us_noaa_prvi \
&& projsync --system-directory --file us_noaa_wmhpgn \
# pgvector
&& apt-mark hold locales \
&& cd /usr/src/ \
&& git clone https://github.com/pgvector/pgvector.git \
&& cd pgvector \
&& git checkout ${PGVECTOR_GIT_HASH} \
&& git log -1 > /_pgvector_last_commit.txt \
&& make clean \
&& make OPTFLAGS="" \
&& make install \
&& mkdir /usr/share/doc/pgvector \
&& cp LICENSE README.md /usr/share/doc/pgvector \
&& apt-mark unhold locales \
# pgmq
&& cd /usr/src/ \
&& git clone https://github.com/tembo-io/pgmq.git \
&& cd pgmq \
&& git checkout ${PGMQ_GIT_HASH} \
&& git log -1 > /_pgmq_last_commit.txt \
&& make clean \
&& make install \
# pg_partman
&& cd /usr/src/ \
&& git clone https://github.com/pgpartman/pg_partman.git \
&& cd pg_partman \
&& git checkout ${PGPARTMAN_GIT_HASH} \
&& git log -1 > /_pgpartman_last_commit.txt \
&& make clean \
&& make install \
# postgresml, pgcat $(lsb_release -cs)
# && echo "deb [trusted=yes] https://apt.postgresml.org bookworm main" > /etc/apt/sources.list.d/postgresml.list \
# && echo "deb [trusted=yes] https://apt.postgresml.org bookworm main" | tee -a /etc/apt/sources.list \
# && apt-get update -y \
&& apt-get install -y --no-install-recommends \
postgresql-16-pgml \
pgcat \
# patroni
&& echo 'APT::Install-Recommends "0";\nAPT::Install-Suggests "0";' > /etc/apt/apt.conf.d/01norecommend \
&& apt-cache depends patroni | sed -n -e 's/.* Depends: \(python3-.\+\)$/\1/p' \
| grep -Ev '^python3-(sphinx|etcd|consul|kazoo|kubernetes)' \
| xargs apt-get install -y vim-tiny curl jq locales git python3-pip python3-wheel \
## Make sure we have a en_US.UTF-8 locale available
&& localedef -i en_US -c -f UTF-8 -A /usr/share/locale/locale.alias en_US.UTF-8 \
&& pip3 install --break-system-packages setuptools \
&& pip3 install --break-system-packages 'git+https://github.com/patroni/patroni.git#egg=patroni[kubernetes]' \
&& PGHOME=/home/postgres \
&& mkdir -p $PGHOME \
&& chown postgres $PGHOME \
&& sed -i "s|/var/lib/postgresql.*|$PGHOME:/bin/bash|" /etc/passwd \
# Set permissions for OpenShift
&& chmod 775 $PGHOME \
&& chmod 664 /etc/passwd \
# regress check
&& mkdir /tempdb \
&& chown -R postgres:postgres /tempdb \
&& su postgres -c 'pg_ctl -D /tempdb init' \
&& su postgres -c 'pg_ctl -D /tempdb -c -l /tmp/logfile -o '-F' start ' \
&& ldconfig \
&& cd regress \
&& make -j$(nproc) check RUNTESTFLAGS=--extension PGUSER=postgres \
\
&& su postgres -c 'psql -c "CREATE EXTENSION IF NOT EXISTS postgis;"' \
&& su postgres -c 'psql -c "CREATE EXTENSION IF NOT EXISTS postgis_raster;"' \
&& su postgres -c 'psql -c "CREATE EXTENSION IF NOT EXISTS postgis_sfcgal;"' \
&& su postgres -c 'psql -c "CREATE EXTENSION IF NOT EXISTS fuzzystrmatch; --needed for postgis_tiger_geocoder "' \
&& su postgres -c 'psql -c "CREATE EXTENSION IF NOT EXISTS address_standardizer;"' \
&& su postgres -c 'psql -c "CREATE EXTENSION IF NOT EXISTS address_standardizer_data_us;"' \
&& su postgres -c 'psql -c "CREATE EXTENSION IF NOT EXISTS postgis_tiger_geocoder;"' \
&& su postgres -c 'psql -c "CREATE EXTENSION IF NOT EXISTS postgis_topology;"' \
&& su postgres -c 'psql -c "CREATE EXTENSION IF NOT EXISTS pgvector;"' \
&& su postgres -c 'psql -c "CREATE EXTENSION IF NOT EXISTS pgmq;"' \
&& su postgres -c 'psql -c "CREATE EXTENSION IF NOT EXISTS pg_partman;"' \
&& su postgres -c 'psql -c "CREATE EXTENSION IF NOT EXISTS pgml;"' \
&& su postgres -c 'psql -c "CREATE EXTENSION IF NOT EXISTS hstore;"' \
&& su postgres -c 'psql -t -c "SELECT version();"' >> /_pgis_full_version.txt \
&& su postgres -c 'psql -t -c "SELECT PostGIS_Full_Version();"' >> /_pgis_full_version.txt \
&& su postgres -c 'psql -t -c "\dx"' >> /_pgis_full_version.txt \
\
&& su postgres -c 'pg_ctl -D /tempdb --mode=immediate stop' \
&& rm -rf /tempdb \
&& rm -rf /tmp/logfile \
&& rm -rf /tmp/pgis_reg \
# clean
&& cd / \
&& rm -rf /usr/src/postgis \
&& rm -rf /usr/src/pgvector \
&& rm -rf /usr/src/pgmq \
&& rm -rf /usr/src/pg_partman \
&& apt-get purge -y --autoremove \
autoconf \
automake \
autotools-dev \
bison \
build-essential \
clang \
cmake \
docbook-xml \
docbook5-xml \
g++ \
gcc \
git \
libboost-all-dev \
libcurl4-gnutls-dev \
libgmp-dev \
libjson-c-dev \
libmpfr-dev \
libpcre3-dev \
libprotobuf-c-dev \
libsqlite3-dev \
libssl-dev \
libtiff-dev \
libtool \
libxml2-dev \
libxml2-utils \
make \
pkg-config \
postgresql-server-dev-16 \
protobuf-c-compiler \
python3-pip \
python3-wheel \
xsltproc \
&& apt-get clean -y \
&& rm -rf /var/lib/apt/lists/* /root/.cache
RUN mkdir -p /docker-entrypoint-initdb.d
COPY ./postgis/initdb-postgis.sh /docker-entrypoint-initdb.d/10_postgis.sh
COPY ./postgis/update-postgis.sh /usr/local/bin
COPY ./patroni/entrypoint.sh /
EXPOSE 5432 8008
ENV LC_ALL=en_US.UTF-8 LANG=en_US.UTF-8 EDITOR=/usr/bin/editor
USER postgres
WORKDIR /home/postgres
CMD ["/bin/bash", "/entrypoint.sh"]
# last final test
RUN set -ex \
&& ldconfig \
&& cs2cs \
&& ldd $(which gdalinfo) \
&& gdalinfo --version \
&& gdal-config --formats \
&& geos-config --version \
&& ogr2ogr --version \
&& proj \
&& sfcgal-config --version \
\
# Is the "ca-certificates" package installed? (for accessing remote raster files)
# https://github.com/postgis/docker-postgis/issues/307
&& dpkg-query -W -f='${Status}' ca-certificates 2>/dev/null | grep -c "ok installed" \
\
# list last commits.
&& find /_pgis_*_last_commit.txt -type f -print -exec cat {} \; \
# list postgresql, postgis version
&& cat _pgis_full_version.txt