From f8652746fa7084e9348d70035d19cb77c209f56c Mon Sep 17 00:00:00 2001 From: Piyush Raj Date: Tue, 6 Feb 2024 16:38:30 +0530 Subject: [PATCH] add postgis extension with smoke test --- .github/workflows/smoke-test.yml | 10 ++++ Dockerfile | 95 +++++++++++++++++++++++++++++++- Makefile | 4 +- bitnami/Dockerfile | 52 +++++++++++++++++ bitnami/Makefile | 5 +- 5 files changed, 163 insertions(+), 3 deletions(-) diff --git a/.github/workflows/smoke-test.yml b/.github/workflows/smoke-test.yml index 4b4b1a9a..bb2e6b19 100644 --- a/.github/workflows/smoke-test.yml +++ b/.github/workflows/smoke-test.yml @@ -55,6 +55,16 @@ jobs: echo "Test pg_cron Extension" psql -c "CREATE EXTENSION pg_cron"; psql -c "SELECT cron.schedule('30 3 * * 6',\$\$DELETE FROM events WHERE event_time < now() - interval '1 week'\$\$)"; + + echo "Test PostGIS Extension" + psql -c "CREATE EXTENSION postgis;" || true + psql -c "SELECT PostGIS_Version();" + + echo "Test PostGIS Geometry Function" + psql -c "CREATE TABLE test_geometry_table (id serial primary key, geom geometry(Point, 4326));" + psql -c "INSERT INTO test_geometry_table (geom) VALUES (ST_GeomFromText('POINT(0 0)', 4326));" + psql -c "SELECT * FROM test_geometry_table;" + break fi sleep 1 diff --git a/Dockerfile b/Dockerfile index 79c8f8fb..0fb49beb 100644 --- a/Dockerfile +++ b/Dockerfile @@ -131,4 +131,97 @@ RUN set -ex \ && cd / \ && rm /tmp/pg_cron.tar.gz \ && rm -rf /tmp/pg_cron \ - && apk del .pg_cron-deps .pg_cron-build-deps \ No newline at end of file + && apk del .pg_cron-deps .pg_cron-build-deps + +# Add PostGIS Extension +ARG POSTGIS_VERSION + +RUN set -eux \ + \ + && if [ $(printf %.1s "$POSTGIS_VERSION") == 3 ]; then \ + set -eux ; \ + export GEOS_ALPINE_VER=3.11 ; \ + export GDAL_ALPINE_VER=3.5 ; \ + export PROJ_ALPINE_VER=9.1 ; \ + elif [ $(printf %.1s "$POSTGIS_VERSION") == 2 ]; then \ + set -eux ; \ + export GEOS_ALPINE_VER=3.8 ; \ + export GDAL_ALPINE_VER=3.2 ; \ + export PROJ_ALPINE_VER=7.2 ; \ + \ + echo 'https://dl-cdn.alpinelinux.org/alpine/v3.14/main' >> /etc/apk/repositories ; \ + echo 'https://dl-cdn.alpinelinux.org/alpine/v3.14/community' >> /etc/apk/repositories ; \ + echo 'https://dl-cdn.alpinelinux.org/alpine/v3.13/main' >> /etc/apk/repositories ; \ + echo 'https://dl-cdn.alpinelinux.org/alpine/v3.13/community' >> /etc/apk/repositories ; \ + \ + else \ + set -eux ; \ + echo ".... unknown \$POSTGIS_VERSION ...." ; \ + exit 1 ; \ + fi \ + \ + && apk add --no-cache --virtual .fetch-deps \ + ca-certificates \ + openssl \ + tar \ + \ + && wget -O postgis.tar.gz "https://github.com/postgis/postgis/archive/${POSTGIS_VERSION}.tar.gz" \ + && mkdir -p /usr/src/postgis \ + && tar \ + --extract \ + --file postgis.tar.gz \ + --directory /usr/src/postgis \ + --strip-components 1 \ + && rm postgis.tar.gz \ + \ + && apk add --no-cache --virtual .build-deps \ + \ + gdal-dev~=${GDAL_ALPINE_VER} \ + geos-dev~=${GEOS_ALPINE_VER} \ + proj-dev~=${PROJ_ALPINE_VER} \ + \ + autoconf \ + automake \ + clang-dev \ + cunit-dev \ + file \ + g++ \ + gcc \ + gettext-dev \ + git \ + json-c-dev \ + libtool \ + libxml2-dev \ + llvm-dev \ + make \ + pcre-dev \ + perl \ + protobuf-c-dev \ + \ +# build PostGIS + \ + && cd /usr/src/postgis \ + && gettextize \ + && ./autogen.sh \ + && ./configure \ + --with-pcredir="$(pcre-config --prefix)" \ + && make -j$(nproc) \ + && make install \ + \ +# add .postgis-rundeps + && apk add --no-cache --virtual .postgis-rundeps \ + \ + gdal~=${GDAL_ALPINE_VER} \ + geos~=${GEOS_ALPINE_VER} \ + proj~=${PROJ_ALPINE_VER} \ + \ + json-c \ + libstdc++ \ + pcre \ + protobuf-c \ + \ + ca-certificates \ +# clean + && cd / \ + && rm -rf /usr/src/postgis \ + && apk del .fetch-deps .build-deps \ No newline at end of file diff --git a/Makefile b/Makefile index 3a4b605e..67fbd6d2 100644 --- a/Makefile +++ b/Makefile @@ -6,6 +6,7 @@ PG_VER=pg15 PG_VER_NUMBER=$(shell echo $(PG_VER) | cut -c3-) TS_VERSION=2.13.0 PG_CRON_VERSION=v1.6.0 +POSTGIS_VERSION=3.4.1 PREV_TS_VERSION=$(shell wget --quiet -O - https://raw.githubusercontent.com/timescale/timescaledb/${TS_VERSION}/version.config | grep update_from_version | sed -e 's!update_from_version = !!') PREV_TS_IMAGE="timescale/timescaledb:$(PREV_TS_VERSION)-pg$(PG_VER_NUMBER)$(PREV_EXTRA)" PREV_IMAGE=$(shell if docker pull $(PREV_TS_IMAGE) >/dev/null; then echo "$(PREV_TS_IMAGE)"; else echo "postgres:$(PG_VER_NUMBER)-alpine"; fi ) @@ -28,7 +29,8 @@ TAG_OSS=-t $(TAG_VERSION)-oss $(if $(PRE_RELEASE),,-t $(TAG_LATEST)-oss) DOCKER_BUILD_ARGS = --build-arg TS_VERSION=$(TS_VERSION) \ --build-arg PG_VERSION=$(PG_VER_NUMBER) \ --build-arg PREV_IMAGE=$(PREV_IMAGE) \ - --build-arg PG_CRON_VERSION=$(PG_CRON_VERSION) + --build-arg PG_CRON_VERSION=$(PG_CRON_VERSION) \ + --build-arg POSTGIS_VERSION=$(POSTGIS_VERSION) default: image diff --git a/bitnami/Dockerfile b/bitnami/Dockerfile index 1850e04f..873fa036 100644 --- a/bitnami/Dockerfile +++ b/bitnami/Dockerfile @@ -156,6 +156,58 @@ RUN set -e \ /tmp/* \ /var/tmp/* +# Add PostGIS Extension +ARG POSTGIS_VERSION + +RUN set -eux \ + && apt update \ + && apt install -y \ + ca-certificates \ + openssl \ + tar \ + wget \ + gettext \ + automake \ + libltdl-dev \ + libxml2-dev \ + libgeos-dev \ + libproj-dev \ + libprotobuf-c-dev \ + protobuf-c-compiler \ + g++\ + gcc \ + make \ + && wget -O postgis.tar.gz "https://github.com/postgis/postgis/archive/${POSTGIS_VERSION}.tar.gz" \ + && mkdir -p /usr/src/postgis \ + && tar \ + --extract \ + --file postgis.tar.gz \ + --directory /usr/src/postgis \ + --strip-components 1 \ + && rm postgis.tar.gz \ + \ +# build PostGIS + \ + && cd /usr/src/postgis \ + && gettextize \ + && ./autogen.sh \ + && ./configure \ + --with-pcredir="$(pcre-config --prefix)" --with-geosconfig="/usr/bin/geos-config"\ + && make -j$(nproc) \ + && make install \ + && cd / \ +# clean + && apt-get autoremove --purge -y \ + wget \ + g++\ + gcc \ + make \ + && apt-get clean -y \ + && rm -rf \ + /var/lib/apt/lists/* \ + /tmp/* \ + /var/tmp/* + USER 1001 ENTRYPOINT [ "/opt/bitnami/scripts/postgresql/timescaledb-bitnami-entrypoint.sh" ] diff --git a/bitnami/Makefile b/bitnami/Makefile index 0e1f9645..66d58dec 100644 --- a/bitnami/Makefile +++ b/bitnami/Makefile @@ -6,6 +6,7 @@ PG_VER=pg15 PG_VER_NUMBER=$(shell echo $(PG_VER) | cut -c3-) PG_CRON_VERSION=v1.6.0 TS_VERSION=2.13.0 +POSTGIS_VERSION=3.4.1 PREV_TS_VERSION=$(shell wget --quiet -O - https://raw.githubusercontent.com/timescale/timescaledb/${TS_VERSION}/version.config | grep update_from_version | sed -e 's!update_from_version = !!') PREV_TS_IMAGE="timescale/timescaledb:$(PREV_TS_VERSION)-pg$(PG_VER_NUMBER)-bitnami" PREV_IMAGE=$(shell if docker pull $(PREV_TS_IMAGE) >/dev/null; then echo "$(PREV_TS_IMAGE)"; else echo "bitnami/postgresql:$(PG_VER_NUMBER)"; fi ) @@ -25,7 +26,9 @@ TAG=-t $(TAG_VERSION) $(if $(PRE_RELEASE),,-t $(TAG_LATEST)) DOCKER_BUILD_ARGS = --build-arg PG_VERSION=$(PG_VER_NUMBER) \ --build-arg TS_VERSION=$(TS_VERSION) \ --build-arg PREV_IMAGE=$(PREV_IMAGE) \ - --build-arg PG_CRON_VERSION=$(PG_CRON_VERSION) + --build-arg PG_CRON_VERSION=$(PG_CRON_VERSION) \ + --build-arg POSTGIS_VERSION=$(POSTGIS_VERSION) + default: image