Last active
November 4, 2023 06:56
-
-
Save tobwen/679755fe3f740558d9713447ae227b95 to your computer and use it in GitHub Desktop.
PostGIS Debian OCI
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# commits to be built | |
ARG CGAL55_GIT_COMMIT=tags/v5.6 # https://github.com/CGAL/cgal/tags | |
ARG SFCGAL_GIT_COMMIT=tags/v1.5.0 # https://github.com/Oslandia/SFCGAL_CI/tags | |
ARG PROJ_GIT_COMMIT=tags/9.3.0 # https://github.com/OSGeo/PROJ/tags | |
ARG GEOS_GIT_COMMIT=tags/3.12.0 # https://github.com/libgeos/geos/tags | |
ARG GDAL_GIT_COMMIT=tags/v3.7.3 # https://github.com/OSGeo/gdal/tags | |
ARG POSTGIS_GIT_COMMIT=tags/3.4.0 # https://github.com/postgis/postgis/tags | |
# base container with build-dependencies | |
FROM docker://postgres:16-bookworm AS build-deps | |
# get dependencies (install-recommends are welcome here) | |
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \ | |
--mount=type=cache,target=/var/lib/apt,sharing=locked \ | |
set -ex \ | |
&& rm -f /etc/apt/apt.conf.d/docker-clean \ | |
&& echo 'Binary::apt::APT::Keep-Downloaded-Packages "true";' > /etc/apt/apt.conf.d/keep-cache \ | |
&& apt update \ | |
&& apt upgrade -y \ | |
&& apt install -y \ | |
ca-certificates \ | |
curl \ | |
libcurl3-gnutls \ | |
sqlite3 \ | |
# build dependencies | |
automake \ | |
bison \ | |
build-essential \ | |
cmake \ | |
git \ | |
make \ | |
pkg-config \ | |
postgresql-server-dev-"$PG_MAJOR" \ | |
protobuf-c-compiler \ | |
stow \ | |
xsltproc \ | |
libboost-all-dev \ | |
libcurl4-gnutls-dev \ | |
libgmp-dev \ | |
libjson-c-dev \ | |
libmpfr-dev \ | |
libpcre2-dev \ | |
libpq-dev \ | |
libprotobuf-c-dev \ | |
libsqlite3-dev \ | |
libtiff-dev \ | |
libtool \ | |
libxml2-dev \ | |
# gdal+ | |
libblosc-dev \ | |
libcfitsio-dev \ | |
libfreexl-dev \ | |
libfyba-dev \ | |
libhdf5-dev \ | |
libkml-dev \ | |
liblz4-dev \ | |
libopenjp2-7-dev \ | |
libqhull-dev \ | |
libxerces-c-dev \ | |
libwebp-dev \ | |
libzstd-dev \ | |
&& mkdir -p /usr/local/share/doc/postgis-container | |
# build CGAL & header-only build for SFCGAL | |
FROM build-deps AS cgal-sfcgal-builder | |
WORKDIR /usr/local/src/ | |
ARG CGAL55_GIT_COMMIT | |
ARG SFCGAL_GIT_COMMIT | |
RUN set -ex \ | |
&& ldconfig \ | |
&& git init -q cgal \ | |
&& cd cgal/ \ | |
&& git fetch --depth=1 https://github.com/CGAL/cgal "$CGAL55_GIT_COMMIT" \ | |
&& git reset --hard FETCH_HEAD \ | |
&& git log -1 > /usr/local/share/doc/postgis-container/commit_cgal.txt \ | |
&& cd .. \ | |
&& git init -q SFCGAL \ | |
&& cd SFCGAL/ \ | |
&& git fetch --depth=1 https://github.com/Oslandia/SFCGAL_CI "$SFCGAL_GIT_COMMIT" \ | |
&& git reset --hard FETCH_HEAD \ | |
&& git log -1 > /usr/local/share/doc/postgis-container/commit_sfcgal.txt \ | |
&& mkdir build/ \ | |
&& cd build/ \ | |
&& cmake .. \ | |
-DCMAKE_BUILD_TYPE=Release \ | |
-DBUILD_SHARED_LIBS=ON \ | |
-DCGAL_DIR=/usr/local/src/cgal \ | |
-DSFCGAL_BUILD_BENCH=OFF \ | |
-DSFCGAL_BUILD_EXAMPLES=OFF \ | |
-DSFCGAL_BUILD_TESTS=OFF \ | |
-DSFCGAL_WITH_OSG=OFF \ | |
-DCMAKE_CXX_FLAGS="-w" \ | |
&& cmake --build . -j$(nproc) \ | |
&& cmake --build . --target install \ | |
&& ldconfig \ | |
&& find /usr/local/src/ -mindepth 1 -delete | |
# build PROJ | |
FROM build-deps AS proj-builder | |
WORKDIR /usr/local/src/ | |
ARG PROJ_GIT_COMMIT | |
RUN set -ex \ | |
&& ldconfig \ | |
&& git init -q PROJ \ | |
&& cd PROJ/ \ | |
&& git fetch --depth=1 https://github.com/OSGeo/PROJ "$PROJ_GIT_COMMIT" \ | |
&& git reset --hard FETCH_HEAD \ | |
&& git log -1 > /usr/local/share/doc/postgis-container/commit_proj.txt \ | |
&& mkdir build/ \ | |
&& cd build/ \ | |
&& cmake .. \ | |
-DCMAKE_BUILD_TYPE=Release \ | |
-DBUILD_SHARED_LIBS=ON \ | |
-DBUILD_TESTING=OFF \ | |
-DENABLE_IPO=ON \ | |
&& cmake --build . -j$(nproc) \ | |
&& cmake --build . --target install \ | |
&& ldconfig \ | |
&& find /usr/local/src/ -mindepth 1 -delete | |
# build GEOS | |
FROM build-deps AS geos-builder | |
WORKDIR /usr/local/src/ | |
ARG GEOS_GIT_COMMIT | |
RUN set -ex \ | |
&& ldconfig \ | |
&& git init -q geos \ | |
&& cd geos/ \ | |
&& git fetch --depth=1 https://github.com/libgeos/geos "$GEOS_GIT_COMMIT" \ | |
&& git reset --hard FETCH_HEAD \ | |
&& git log -1 > /usr/local/share/doc/postgis-container/commit_geos.txt \ | |
&& mkdir build/ \ | |
&& cd build/ \ | |
&& cmake .. \ | |
-DCMAKE_BUILD_TYPE=Release \ | |
-DBUILD_SHARED_LIBS=ON \ | |
-DBUILD_TESTING=OFF \ | |
-DGEOS_BUILD_DEVELOPER=OFF \ | |
&& cmake --build . -j$(nproc) \ | |
&& cmake --build . --target install \ | |
&& ldconfig \ | |
&& find /usr/local/src/ -mindepth 1 -delete | |
# intermediate | |
FROM build-deps AS gdal-intermediate | |
RUN --mount=from=geos-builder,source=/usr/,target=/opt/geos \ | |
--mount=from=proj-builder,source=/usr/,target=/opt/proj \ | |
set -ex \ | |
&& cp --archive -rsu /opt/geos/local/ /usr/ \ | |
&& cp --archive -rsu /opt/proj/local/ /usr/ | |
# && find /opt/geos/ -type f -exec cp -rsu "{}" -t /usr/local/ \; \ | |
# && find /opt/proj/ -type f -exec cp -rsu "{}" -t /usr/local/ \; | |
# build GDAL (slim & vector-centric) | |
FROM build-deps AS gdal-builder | |
WORKDIR /usr/local/src/ | |
ARG GDAL_GIT_COMMIT | |
# COPY --link --from=proj-builder /usr/local /usr/local | |
# COPY --link --from=geos-builder /usr/local /usr/local | |
RUN --mount=from=geos-builder,source=/usr/local/,target=/opt/geos \ | |
--mount=from=proj-builder,source=/usr/local/,target=/opt/proj \ | |
set -ex \ | |
&& ldconfig \ | |
&& git init -q gdal \ | |
&& cd gdal/ \ | |
&& git fetch --depth=1 https://github.com/OSGeo/gdal "$GDAL_GIT_COMMIT" \ | |
&& git reset --hard FETCH_HEAD \ | |
&& git log -1 > /usr/local/share/doc/postgis-container/commit_gdal.txt \ | |
&& mkdir build/ \ | |
&& cd build/ \ | |
&& cmake .. \ | |
-DCMAKE_BUILD_TYPE=Release \ | |
-DCMAKE_EXE_LINKER_FLAGS='-s' \ | |
-DBUILD_SHARED_LIBS=ON \ | |
-DBUILD_TESTING=OFF \ | |
-DBUILD_DOCS=OFF \ | |
&& cmake --build . -j$(nproc) \ | |
&& cmake --build . --target install \ | |
&& ldconfig \ | |
&& find /usr/local/src/ -mindepth 1 -delete | |
# build PostGIS | |
FROM build-deps AS postgis-builder | |
WORKDIR /usr/local/src/ | |
ARG POSTGIS_GIT_COMMIT | |
COPY --from=cgal-sfcgal-builder /usr/local /usr/local | |
COPY --from=proj-builder /usr/local /usr/local | |
COPY --from=geos-builder /usr/local /usr/local | |
COPY --from=gdal-builder /usr/local /usr/local | |
RUN set -ex \ | |
&& ldconfig \ | |
&& git init -q postgis \ | |
&& cd postgis/ \ | |
&& git fetch --depth=1 https://github.com/postgis/postgis "$POSTGIS_GIT_COMMIT" \ | |
&& git reset --hard FETCH_HEAD \ | |
&& git log -1 > /usr/local/share/doc/postgis-container/commit_postgis.txt \ | |
&& ./autogen.sh \ | |
&& CFLAGS='-O2 -flto=auto' CXXFLAGS='-O2 -flto=auto' LDFLAGS='-flto=auto' ./configure --without-interrupt-tests \ | |
&& make -j$(nproc) \ | |
&& make install \ | |
&& make install -C utils \ | |
&& make install -C loader \ | |
&& ldconfig \ | |
&& find /usr/local/src/ -mindepth 1 -delete | |
# final stage | |
FROM docker://postgres:16-bookworm AS pg16_postgis | |
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \ | |
--mount=type=cache,target=/var/lib/apt,sharing=locked \ | |
--mount=from=postgis-builder,target=/opt \ | |
set -ex \ | |
&& cd /opt/ \ | |
&& cp --archive --parent --recursive --target / usr/local/ \ | |
&& find . -type f -regex '.*\(address_standardizer\|postgis\).*' ! -path '*/src/*' -exec cp --archive --parent --target / "{}" \+ \ | |
&& apt upgrade -y \ | |
&& apt install -y --no-install-recommends \ | |
libblosc1 \ | |
libboost-serialization1.74.0 \ | |
libcfitsio10 \ | |
libfreexl1 \ | |
libfyba0 \ | |
libgmpxx4ldbl \ | |
libhdf5-103-1 \ | |
libjson-c5 \ | |
libkmlengine1 \ | |
libmpfr6 \ | |
libopenjp2-7 \ | |
libprotobuf-c1 \ | |
libqhull-r8.0 \ | |
libtiff6 \ | |
libxerces-c3.2 \ | |
&& ldconfig | |
# final checks | |
FROM pg16_postgis AS pg16_postgis-tests | |
RUN set -ex \ | |
&& mkdir /tempdb \ | |
&& chown -R postgres:postgres /tempdb \ | |
&& su postgres -c 'pg_ctl -D /tempdb init' \ | |
&& su postgres -c 'pg_ctl -D /tempdb start' \ | |
&& 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 "SELECT version();" -t' > /usr/local/share/doc/postgis-container/commit_postgis.txt \ | |
&& su postgres -c 'psql -c "SELECT PostGIS_Full_Version();" -t' >> /usr/local/share/doc/postgis-container/commit_postgis.txt \ | |
&& su postgres -c 'psql -c "\dx" -t' >> /usr/local/share/doc/postgis-container/commit_postgis.txt \ | |
&& su postgres -c 'pg_ctl -D /tempdb --mode=immediate stop' \ | |
&& rm -rf /tempdb \ | |
\ | |
&& sfcgal-config --version \ | |
&& geos-config --version \ | |
&& cs2cs \ | |
&& proj \ | |
&& gdalinfo --version \ | |
&& gdal-config --formats \ | |
&& ogr2ogr --version \ | |
&& ogr2ogr --formats \ | |
&& ldd "$(which gdalinfo)" \ | |
&& find /usr/lib/postgresql/16/lib/ -type f -regex '.*\(address_standardizer\|postgis\).*so$' -exec ldd "{}" \+ \ | |
&& { postgis help 2>/dev/null || true; } \ | |
&& find /usr/local/share/doc/postgis-container/ -type f -name '*.txt' -exec cat "{}" \+ | |
# podman build --jobs 4 --target pg16_postgis-tests . |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment