-
-
Save ImreSamu/a2cce208e588914c762763d519a9bec6 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 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 \ | |
xsltproc \ | |
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 \ | |
# 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 | |
# 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 \ | |
&& 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 > /PostGIS_cgal_last_commit.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 > /PostGIS_sfcgal_last_commit.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 \ | |
&& cmake --build . -j$(nproc) \ | |
&& cmake --build . --target install \ | |
&& 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 \ | |
&& 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 > /PostGIS_proj_last_commit.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 \ | |
&& 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 \ | |
&& 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 > /PostGIS_geos_last_commit.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 \ | |
&& find /usr/local/src/ -mindepth 1 -delete | |
# build GDAL (slim & vector-centric) | |
FROM build-deps AS gdal-builder | |
WORKDIR /usr/local/src/ | |
ARG GDAL_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 | |
RUN set -ex \ | |
&& 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 > /PostGIS_gdal_last_commit.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 \ | |
&& find /usr/local/src/ -mindepth 1 -delete | |
# build postgis # --without-raster | |
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 | |
COPY --from=cgal-sfcgal-builder /*.txt / | |
COPY --from=proj-builder /*.txt / | |
COPY --from=geos-builder /*.txt / | |
COPY --from=gdal-builder /*.txt / | |
RUN set -ex \ | |
&& 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 > /PostGIS_last_commit.txt \ | |
&& ./autogen.sh \ | |
&& CFLAGS='-O2' CXXFLAGS='-O2' ./configure --enable-lto --without-interrupt-tests \ | |
&& make -j$(nproc) \ | |
&& make install \ | |
&& make install -C utils \ | |
&& make install -C loader \ | |
&& find /usr/local/src/ -mindepth 1 -delete | |
# testing stage | |
FROM postgis-builder as postgis-tests | |
WORKDIR / | |
# minimal check for PostGIS | |
RUN set -ex \ | |
&& mkdir /tempdb \ | |
&& chown -R postgres:postgres /tempdb \ | |
&& ldconfig \ | |
&& 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' > /PostGIS_full_version.txt \ | |
&& su postgres -c 'psql -c "SELECT PostGIS_Full_Version();" -t' >> /PostGIS_full_version.txt \ | |
&& su postgres -c 'psql -c "\dx" -t' >> /PostGIS_full_version.txt \ | |
&& su postgres -c 'pg_ctl -D /tempdb --mode=immediate stop' | |
# minimal check for CLI tools | |
RUN set -ex \ | |
&& ldconfig \ | |
&& cs2cs \ | |
&& ldd "$(which gdalinfo)" \ | |
&& gdalinfo --version \ | |
&& gdal-config --formats \ | |
&& geos-config --version \ | |
&& ogr2ogr --version \ | |
&& proj \ | |
&& sfcgal-config --version \ | |
&& pcre-config --version \ | |
&& { postgis help 2>/dev/null || true; } # TODO: better PostGIS handling | |
# 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-tests,target=/opt \ | |
set -ex \ | |
&& cd /opt/ \ | |
&& cp --archive --target / *.txt \ | |
&& cp --archive --target / --parent --recursive usr/local/ \ | |
&& find . -path '*address_standardizer*' -o -path '*postgis*' -type f ! -path '*/src/*' -exec cp --archive --parent --target / {} \+ \ | |
&& apt install -y \ | |
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment