Skip to content

Commit

Permalink
add postgis extension with smoke test
Browse files Browse the repository at this point in the history
  • Loading branch information
PiyushRaj927 committed Feb 6, 2024
1 parent 7344e6a commit f865274
Show file tree
Hide file tree
Showing 5 changed files with 163 additions and 3 deletions.
10 changes: 10 additions & 0 deletions .github/workflows/smoke-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
95 changes: 94 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
&& 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
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand All @@ -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
Expand Down
52 changes: 52 additions & 0 deletions bitnami/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \