diff --git a/Dockerfile b/Dockerfile index a95b3ee..d7a1a7c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,17 +1,19 @@ #--------- Generic stuff all our Dockerfiles should start with so we get caching ------------ +ARG DISTRO=debian ARG IMAGE_VERSION=buster -ARG IMAGE_VARIANT=-slim -FROM debian:$IMAGE_VERSION$IMAGE_VARIANT +ARG IMAGE_VARIANT=slim +FROM kartoza/postgis:$DISTRO-$IMAGE_VERSION-$IMAGE_VARIANT MAINTAINER Tim Sutton # Reset ARG for version ARG IMAGE_VERSION +ARG POSTGRES_MAJOR_VERSION=12 +ARG POSTGIS_MAJOR=3 + RUN set -eux \ && export DEBIAN_FRONTEND=noninteractive \ - && apt-get update \ - && apt-get -y --no-install-recommends install \ - locales gnupg2 wget ca-certificates rpl pwgen software-properties-common gdal-bin iputils-ping \ + && apt-get upgrade;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 - \ && apt-get -y --purge autoremove \ @@ -19,17 +21,6 @@ RUN set -eux \ && rm -rf /var/lib/apt/lists/* \ && dpkg-divert --local --rename --add /sbin/initctl -# Generating locales takes a long time. Utilize caching by runnig it by itself -# early in the build process. -COPY locale.gen /etc/locale.gen -RUN set -eux \ - && /usr/sbin/locale-gen - -ENV LANG=en_US.UTF-8 \ - LANGUAGE=en_US:en \ - LC_ALL=en_US.UTF-8 -RUN update-locale ${LANG} - #-------------Application Specific Stuff ---------------------------------------------------- # We add postgis as well to prevent build errors (that we dont see on local builds) @@ -37,12 +28,27 @@ RUN update-locale ${LANG} # The following packages have unmet dependencies: RUN set -eux \ && export DEBIAN_FRONTEND=noninteractive \ - && apt-get update \ - && apt-get -y --no-install-recommends install postgresql-client-12 \ - postgresql-common postgresql-12 postgresql-12-postgis-3 \ - netcat postgresql-12-ogr-fdw postgresql-12-postgis-3-scripts \ - postgresql-12-cron postgresql-plpython3-12 \ - && apt-get -y --purge autoremove \ + && apt-get update \ + && apt-get -y --no-install-recommends install postgresql-client-${POSTGRES_MAJOR_VERSION} \ + postgresql-common postgresql-${POSTGRES_MAJOR_VERSION} \ + postgresql-${POSTGRES_MAJOR_VERSION}-postgis-${POSTGIS_MAJOR} \ + netcat postgresql-${POSTGRES_MAJOR_VERSION}-ogr-fdw \ + postgresql-${POSTGRES_MAJOR_VERSION}-postgis-${POSTGIS_MAJOR}-scripts \ + postgresql-plpython3-${POSTGRES_MAJOR_VERSION} postgresql-${POSTGRES_MAJOR_VERSION}-pgrouting \ + postgresql-server-dev-${POSTGRES_MAJOR_VERSION} postgresql-${POSTGRES_MAJOR_VERSION}-cron + +RUN echo $POSTGRES_MAJOR_VERSION >/tmp/pg_version.txt + +# Compile pointcloud extension + +RUN wget -O- https://github.com/pgpointcloud/pointcloud/archive/master.tar.gz | tar xz && \ +cd pointcloud-master && \ +./autogen.sh && ./configure && make -j 4 && make install && \ +cd .. && rm -Rf pointcloud-master + + +# Cleanup resources +RUN apt-get -y --purge autoremove \ && apt-get clean \ && rm -rf /var/lib/apt/lists/* @@ -50,24 +56,15 @@ RUN set -eux \ EXPOSE 5432 # Copy scripts -COPY docker-entrypoint.sh \ - env-data.sh \ - setup.sh \ - setup-conf.sh \ - setup-database.sh \ - setup-pg_hba.sh \ - setup-replication.sh \ - setup-ssl.sh \ - setup-user.sh \ - / +ADD scripts /scripts +WORKDIR /scripts +RUN chmod +x *.sh # Run any additional tasks here that are too tedious to put in # this dockerfile directly. RUN set -eux \ - && chmod +x /setup.sh \ - && /setup.sh \ - && chmod +x /docker-entrypoint.sh + && /scripts/setup.sh VOLUME /var/lib/postgresql -ENTRYPOINT /docker-entrypoint.sh +ENTRYPOINT /scripts/docker-entrypoint.sh \ No newline at end of file diff --git a/scenario_tests/collations/tests/test.sh b/scenario_tests/collations/tests/test.sh index f1ad178..4b303df 100644 --- a/scenario_tests/collations/tests/test.sh +++ b/scenario_tests/collations/tests/test.sh @@ -2,7 +2,7 @@ set -e -source /env-data.sh +source /scripts/env-data.sh # execute tests pushd /tests diff --git a/scenario_tests/datadir_init/tests/test.sh b/scenario_tests/datadir_init/tests/test.sh index b30adf9..ae83323 100644 --- a/scenario_tests/datadir_init/tests/test.sh +++ b/scenario_tests/datadir_init/tests/test.sh @@ -2,7 +2,7 @@ set -e -source /env-data.sh +source /scripts/env-data.sh # execute tests pushd /tests diff --git a/scenario_tests/replications/tests/test_master.sh b/scenario_tests/replications/tests/test_master.sh index e9f0840..fdc4042 100644 --- a/scenario_tests/replications/tests/test_master.sh +++ b/scenario_tests/replications/tests/test_master.sh @@ -2,7 +2,7 @@ set -e -source /env-data.sh +source /scripts/env-data.sh # execute tests pushd /tests diff --git a/scenario_tests/replications/tests/test_node.sh b/scenario_tests/replications/tests/test_node.sh index ca2068e..b21e3d5 100644 --- a/scenario_tests/replications/tests/test_node.sh +++ b/scenario_tests/replications/tests/test_node.sh @@ -2,7 +2,7 @@ set -e -source /env-data.sh +source /scripts/env-data.sh # execute tests pushd /tests diff --git a/docker-entrypoint.sh b/scripts/docker-entrypoint.sh similarity index 81% rename from docker-entrypoint.sh rename to scripts/docker-entrypoint.sh index aa27599..6a61470 100755 --- a/docker-entrypoint.sh +++ b/scripts/docker-entrypoint.sh @@ -2,29 +2,29 @@ set -e -source /env-data.sh +source /scripts/env-data.sh # Setup postgres CONF file -source /setup-conf.sh +source /scripts/setup-conf.sh # Setup ssl -source /setup-ssl.sh +source /scripts/setup-ssl.sh # Setup pg_hba.conf -source /setup-pg_hba.sh +source /scripts/setup-pg_hba.sh if [[ -z "$REPLICATE_FROM" ]]; then # This means this is a master instance. We check that database exists echo "Setup master database" - source /setup-database.sh + source /scripts/setup-database.sh entry_point_script kill_postgres else # This means this is a slave/replication instance. echo "Setup slave database" - source /setup-replication.sh + source /scripts/setup-replication.sh fi diff --git a/env-data.sh b/scripts/env-data.sh similarity index 93% rename from env-data.sh rename to scripts/env-data.sh index 867b4ae..541c661 100644 --- a/env-data.sh +++ b/scripts/env-data.sh @@ -1,20 +1,20 @@ #!/usr/bin/env bash - -DATADIR="/var/lib/postgresql/12/main" -ROOT_CONF="/etc/postgresql/12/main" +POSTGRES_MAJOR_VERSION=$(cat /tmp/pg_version.txt) +DATADIR="/var/lib/postgresql/${POSTGRES_MAJOR_VERSION}/main" +ROOT_CONF="/etc/postgresql/${POSTGRES_MAJOR_VERSION}/main" PG_ENV="$ROOT_CONF/environment" CONF="$ROOT_CONF/postgresql.conf" WAL_ARCHIVE="/opt/archivedir" RECOVERY_CONF="$ROOT_CONF/recovery.conf" -POSTGRES="/usr/lib/postgresql/12/bin/postgres" -INITDB="/usr/lib/postgresql/12/bin/initdb" -SQLDIR="/usr/share/postgresql/12/contrib/postgis-3.0/" +POSTGRES="/usr/lib/postgresql/${POSTGRES_MAJOR_VERSION}/bin/postgres" +INITDB="/usr/lib/postgresql/${POSTGRES_MAJOR_VERSION}/bin/initdb" +SQLDIR="/usr/share/postgresql/${POSTGRES_MAJOR_VERSION}/contrib/postgis-3.0/" SETVARS="POSTGIS_ENABLE_OUTDB_RASTERS=1 POSTGIS_GDAL_ENABLED_DRIVERS=ENABLE_ALL" LOCALONLY="-c listen_addresses='127.0.0.1'" PG_BASEBACKUP="/usr/bin/pg_basebackup" PROMOTE_FILE="/tmp/pg_promote_master" PGSTAT_TMP="/var/run/postgresql/" -PG_PID="/var/run/postgresql/12-main.pid" +PG_PID="/var/run/postgresql/${POSTGRES_MAJOR_VERSION}-main.pid" # Read data from secrets into env variables. @@ -254,7 +254,7 @@ function restart_postgres { kill_postgres # Brought postgres back up again - source /env-data.sh + source /scripts/env-data.sh su - postgres -c "$SETVARS $POSTGRES -D $DATADIR -c config_file=$CONF &" # wait for postgres to come up diff --git a/locale.gen b/scripts/locale.gen similarity index 100% rename from locale.gen rename to scripts/locale.gen diff --git a/setup-conf.sh b/scripts/setup-conf.sh similarity index 98% rename from setup-conf.sh rename to scripts/setup-conf.sh index e0fe92d..3586a86 100644 --- a/setup-conf.sh +++ b/scripts/setup-conf.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -source /env-data.sh +source /scripts/env-data.sh SETUP_LOCKFILE="${ROOT_CONF}/.postgresql.conf.lock" if [ -f "${SETUP_LOCKFILE}" ]; then diff --git a/setup-database.sh b/scripts/setup-database.sh similarity index 98% rename from setup-database.sh rename to scripts/setup-database.sh index ca48dba..da3598e 100644 --- a/setup-database.sh +++ b/scripts/setup-database.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -source /env-data.sh +source /scripts/env-data.sh # test if DATADIR has content # Do initialization if DATADIR is empty, or RECREATE_DATADIR is true @@ -36,7 +36,7 @@ done echo "postgres ready" # Setup user -source /setup-user.sh +source /scripts/setup-user.sh # enable extensions in template1 if env variable set to true if [[ "$(boolean ${POSTGRES_TEMPLATE_EXTENSIONS})" == TRUE ]] ; then diff --git a/setup-pg_hba.sh b/scripts/setup-pg_hba.sh similarity index 98% rename from setup-pg_hba.sh rename to scripts/setup-pg_hba.sh index d6d3238..f695597 100644 --- a/setup-pg_hba.sh +++ b/scripts/setup-pg_hba.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -source /env-data.sh +source /scripts/env-data.sh SETUP_LOCKFILE="${ROOT_CONF}/.pg_hba.conf.lock" if [ -f "${SETUP_LOCKFILE}" ]; then diff --git a/setup-replication.sh b/scripts/setup-replication.sh similarity index 98% rename from setup-replication.sh rename to scripts/setup-replication.sh index cca6060..01db10a 100755 --- a/setup-replication.sh +++ b/scripts/setup-replication.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -source /env-data.sh +source /scripts/env-data.sh # This script will setup slave instance to use standby replication diff --git a/setup-ssl.sh b/scripts/setup-ssl.sh similarity index 97% rename from setup-ssl.sh rename to scripts/setup-ssl.sh index f134e9c..8ce2a6f 100644 --- a/setup-ssl.sh +++ b/scripts/setup-ssl.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -source /env-data.sh +source /scripts/env-data.sh SETUP_LOCKFILE="${ROOT_CONF}/.ssl.conf.lock" if [ -f "${SETUP_LOCKFILE}" ]; then diff --git a/setup-user.sh b/scripts/setup-user.sh similarity index 98% rename from setup-user.sh rename to scripts/setup-user.sh index 378f066..35b4d1c 100644 --- a/setup-user.sh +++ b/scripts/setup-user.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -source /env-data.sh +source /scripts/env-data.sh # This script will setup new configured user diff --git a/setup.sh b/scripts/setup.sh similarity index 96% rename from setup.sh rename to scripts/setup.sh index 83a9cd5..d64c2fd 100755 --- a/setup.sh +++ b/scripts/setup.sh @@ -3,7 +3,7 @@ chmod 600 /etc/ssl/private/ssl-cert-snakeoil.key # These tasks are run as root -source /env-data.sh +source /scripts/env-data.sh # Restrict subnet to docker private network