diff --git a/.example.env b/.example.env index c821191..8cf6df7 100644 --- a/.example.env +++ b/.example.env @@ -16,3 +16,4 @@ LANGS="en_US.UTF-8,id_ID.UTF-8" POSTGRES_MAJOR_VERSION=14 POSTGIS_MAJOR_VERSION=3 POSTGIS_MINOR_RELEASE=2 +BUILD_TIMESCALE=true \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 5a40f56..4a09515 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,6 +12,7 @@ LABEL maintainer="Tim Sutton" LABEL cache.invalidation.number="1" ARG CACHE_INVALIDATION_NUMBER=1 + # Reset ARG for version ARG IMAGE_VERSION @@ -70,7 +71,8 @@ ARG IMAGE_VERSION ARG POSTGRES_MAJOR_VERSION=14 ARG POSTGIS_MAJOR_VERSION=3 ARG POSTGIS_MINOR_RELEASE=2 -ARG TIMESCALE_VERSION=2 +ARG TIMESCALE_VERSION=2-2.5.0 +ARG BUILD_TIMESCALE=false @@ -79,8 +81,6 @@ RUN set -eux \ && apt-get update \ && sh -c "echo \"deb http://apt.postgresql.org/pub/repos/apt/ ${IMAGE_VERSION}-pgdg main\" > /etc/apt/sources.list.d/pgdg.list" \ && wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc -O- | apt-key add - \ - && sh -c "echo \"deb [signed-by=/usr/share/keyrings/timescale.keyring] https://packagecloud.io/timescale/timescaledb/debian/ ${IMAGE_VERSION} main\" > /etc/apt/sources.list.d/timescaledb.list" \ - && wget --quiet -O - https://packagecloud.io/timescale/timescaledb/gpgkey | gpg --dearmor -o /usr/share/keyrings/timescale.keyring \ && apt-get -y --purge autoremove \ && apt-get clean \ && rm -rf /var/lib/apt/lists/* \ @@ -101,10 +101,17 @@ RUN set -eux \ netcat postgresql-${POSTGRES_MAJOR_VERSION}-ogr-fdw \ postgresql-${POSTGRES_MAJOR_VERSION}-postgis-${POSTGIS_MAJOR_VERSION}-scripts \ postgresql-plpython3-${POSTGRES_MAJOR_VERSION} postgresql-${POSTGRES_MAJOR_VERSION}-pgrouting \ - postgresql-server-dev-${POSTGRES_MAJOR_VERSION} postgresql-${POSTGRES_MAJOR_VERSION}-cron \ - timescaledb-${TIMESCALE_VERSION}-postgresql-${POSTGRES_MAJOR_VERSION} timescaledb-tools + postgresql-server-dev-${POSTGRES_MAJOR_VERSION} postgresql-${POSTGRES_MAJOR_VERSION}-cron +RUN if [ "${BUILD_TIMESCALE}" =~ [Tt][Rr][Uu][Ee] ]; then \ + export DEBIAN_FRONTEND=noninteractive && \ + sh -c "echo \"deb [signed-by=/usr/share/keyrings/timescale.keyring] https://packagecloud.io/timescale/timescaledb/debian/ ${IMAGE_VERSION} main\" > /etc/apt/sources.list.d/timescaledb.list" && \ + wget --quiet -O - https://packagecloud.io/timescale/timescaledb/gpgkey | gpg --dearmor -o /usr/share/keyrings/timescale.keyring && \ + apt-get update && \ + apt-get -y --no-install-recommends install timescaledb-${TIMESCALE_VERSION}-postgresql-${POSTGRES_MAJOR_VERSION} timescaledb-tools;\ + fi; + RUN echo $POSTGRES_MAJOR_VERSION >/tmp/pg_version.txt RUN echo $POSTGIS_MAJOR_VERSION >/tmp/pg_major_version.txt RUN echo $POSTGIS_MINOR_RELEASE >/tmp/pg_minor_version.txt diff --git a/README.md b/README.md index 4a9d05e..1741c7c 100644 --- a/README.md +++ b/README.md @@ -270,7 +270,8 @@ Some PostgreSQL extensions require shared_preload_libraries to be specified in t Using the environment variable `SHARED_PRELOAD_LIBRARIES` you can pass comma separated values that correspond to the extensions defined using the environment variable `POSTGRES_MULTIPLE_EXTENSIONS`. -The default libraries that are loaded are `pg_cron,timescaledb` +The default libraries that are loaded are `pg_cron,timescaledb` if the image is bulilt +with timescale support otherwise only `pg_cron` is loaded. You can pass the env variable ```bash -e SHARED_PRELOAD_LIBRARIES='pg_cron,timescaledb' diff --git a/build.sh b/build.sh index 3d5f058..95f1a73 100755 --- a/build.sh +++ b/build.sh @@ -6,3 +6,5 @@ if [[ ! -f .env ]]; then fi docker-compose -f docker-compose.build.yml build postgis-prod + +#docker-compose -f docker-compose.build-timescale.yml build postgis-prod diff --git a/docker-compose.build-timescale.yml b/docker-compose.build-timescale.yml new file mode 100644 index 0000000..23fddc3 --- /dev/null +++ b/docker-compose.build-timescale.yml @@ -0,0 +1,34 @@ +# Used solely for docker-compose build +version: '3.9' +services: + postgis-base: + image: kartoza/postgis:base-${DISTRO}-${IMAGE_VERSION}-${IMAGE_VARIANT} + build: + context: . + # Use yaml anchor for reusability + args: &build-args-anchor + DISTRO: ${DISTRO} + IMAGE_VERSION: ${IMAGE_VERSION} + IMAGE_VARIANT: ${IMAGE_VARIANT} + GENERATE_ALL_LOCALE: ${GENERATE_ALL_LOCALE} + POSTGRES_MAJOR_VERSION: ${POSTGRES_MAJOR_VERSION} + POSTGIS_MAJOR_VERSION: ${POSTGIS_MAJOR_VERSION} + POSTGIS_MINOR_RELEASE: ${POSTGIS_MINOR_RELEASE} + BUILD_TIMESCALE: ${BUILD_TIMESCALE} + target: postgis-base + + postgis-prod: + image: kartoza/postgis:${POSTGRES_MAJOR_VERSION}-${POSTGIS_MAJOR_VERSION}.${POSTGIS_MINOR_RELEASE}-timescale + build: + context: . + args: + <<: *build-args-anchor + target: postgis-prod + + postgis-test: + image: kartoza/postgis:manual-build + build: + context: . + args: + <<: *build-args-anchor + target: postgis-test diff --git a/scripts/env-data.sh b/scripts/env-data.sh index 279915a..38c578a 100644 --- a/scripts/env-data.sh +++ b/scripts/env-data.sh @@ -217,7 +217,11 @@ if [ -z "${SSL_KEY_FILE}" ]; then fi if [ -z "${POSTGRES_MULTIPLE_EXTENSIONS}" ]; then - POSTGRES_MULTIPLE_EXTENSIONS='postgis,hstore,postgis_topology,postgis_raster,pgrouting' + if [[ $(dpkg -l | grep "timescaledb") > /dev/null ]];then + POSTGRES_MULTIPLE_EXTENSIONS='postgis,hstore,postgis_topology,postgis_raster,pgrouting,timescaledb' + else + POSTGRES_MULTIPLE_EXTENSIONS='postgis,hstore,postgis_topology,postgis_raster,pgrouting' + fi fi @@ -261,7 +265,11 @@ if [ -z "$EXTRA_CONF" ]; then fi if [ -z "${SHARED_PRELOAD_LIBRARIES}" ]; then - SHARED_PRELOAD_LIBRARIES='pg_cron,timescaledb' + if [[ $(dpkg -l | grep "timescaledb") > /dev/null ]];then + SHARED_PRELOAD_LIBRARIES='pg_cron,timescaledb' + else + SHARED_PRELOAD_LIBRARIES='pg_cron' + fi fi if [ -z "$PASSWORD_AUTHENTICATION" ]; then diff --git a/scripts/setup-conf.sh b/scripts/setup-conf.sh index 484685a..0b00e48 100644 --- a/scripts/setup-conf.sh +++ b/scripts/setup-conf.sh @@ -93,7 +93,7 @@ fi # Timescale default tuning # TODO If timescale DB accepts reading from include directory then refactor code to remove line 97 - 112 (https://github.com/timescale/timescaledb-tune/issues/80) -if [[ ${ACCEPT_TIMESCALE_TUNING} =~ [Tt][Rr][Uu][Ee] ]];then +if [[ $(dpkg -l | grep "timescaledb") > /dev/null ]] && [[ ${ACCEPT_TIMESCALE_TUNING} =~ [Tt][Rr][Uu][Ee] ]] ;then if [[ -f ${ROOT_CONF}/postgis.conf ]];then sed -i '/postgis.conf/d' "${ROOT_CONF}"/postgresql.conf cat "${ROOT_CONF}"/postgis.conf >> "${ROOT_CONF}"/postgresql.conf