2021-01-27 18:06:59 +00:00
##############################################################################
# Base stage #
##############################################################################
2020-04-20 10:05:39 +00:00
ARG DISTRO = debian
2023-07-29 13:07:11 +00:00
ARG IMAGE_VERSION = bookworm
2020-10-01 15:55:53 +00:00
ARG IMAGE_VARIANT = slim
2021-01-27 18:06:59 +00:00
FROM $DISTRO:$IMAGE_VERSION-$IMAGE_VARIANT AS postgis-base
2021-01-30 00:13:10 +00:00
LABEL maintainer = "Tim Sutton<tim@kartoza.com>"
2021-11-26 12:15:51 +00:00
# Cache invalidation number is used to invalidate a cache.
# Simply increment the number by 1 to reset the cache in local and GitHub Action
# This is added because we can't purge GitHub Action cache manually
LABEL cache.invalidation.number= "1"
2021-11-26 12:18:45 +00:00
ARG CACHE_INVALIDATION_NUMBER = 1
2021-01-27 18:06:59 +00:00
2022-02-11 10:03:44 +00:00
2021-01-27 18:06:59 +00:00
# Reset ARG for version
ARG IMAGE_VERSION
RUN apt-get -qq update --fix-missing && apt-get -qq --yes upgrade
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 iputils-ping \
2023-08-06 03:02:07 +00:00
apt-transport-https curl gettext pgxnclient cmake && \
apt-get -y install build-essential autoconf libxml2-dev zlib1g-dev netcat-openbsd gdal-bin \
2023-02-01 04:42:32 +00:00
figlet toilet gosu; \
# verify that the binary works
2023-08-06 03:02:07 +00:00
gosu nobody true && \
dpkg-divert --local --rename --add /sbin/initctl
2021-01-27 18:06:59 +00:00
# Generating locales takes a long time. Utilize caching by runnig it by itself
# early in the build process.
# Generate all locale only on deployment mode build
# Set to empty string to generate only default locale
ARG GENERATE_ALL_LOCALE = 1
2021-01-27 18:59:12 +00:00
ARG LANGS = "en_US.UTF-8,id_ID.UTF-8"
2021-01-27 18:06:59 +00:00
ARG LANG = en_US.UTF-8
ENV LANG = en_US.UTF-8 \
LANGUAGE = en_US:en \
LC_ALL = en_US.UTF-8
2021-11-28 05:38:57 +00:00
COPY ./base_build/scripts/locale.gen /etc/all.locale.gen
COPY ./base_build/scripts/locale-filter.sh /etc/locale-filter.sh
2021-01-27 18:06:59 +00:00
RUN if [ -z " ${ GENERATE_ALL_LOCALE } " ] || [ $GENERATE_ALL_LOCALE -eq 0 ] ; \
then \
cat /etc/all.locale.gen | grep " ${ LANG } " > /etc/locale.gen; \
2021-01-27 18:59:12 +00:00
/bin/bash /etc/locale-filter.sh; \
2021-01-27 18:06:59 +00:00
else \
cp -f /etc/all.locale.gen /etc/locale.gen; \
fi ; \
set -eux \
&& /usr/sbin/locale-gen
RUN update-locale ${ LANG }
2023-08-06 03:02:07 +00:00
2021-01-27 18:06:59 +00:00
# Cleanup resources
RUN apt-get -y --purge autoremove \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
##############################################################################
# Production Stage #
##############################################################################
FROM postgis-base AS postgis-prod
2021-01-02 21:34:42 +00:00
2014-05-04 19:14:46 +00:00
2019-07-30 07:50:52 +00:00
# Reset ARG for version
ARG IMAGE_VERSION
2023-10-08 15:31:55 +00:00
ARG POSTGRES_MAJOR_VERSION = 16
2021-01-27 18:06:59 +00:00
ARG POSTGIS_MAJOR_VERSION = 3
2023-08-19 18:22:21 +00:00
ARG POSTGIS_MINOR_RELEASE = 4
2023-08-20 21:27:11 +00:00
# https://packagecloud.io/timescale/timescaledb
ARG TIMESCALE_VERSION = 2 -2.11.2
2022-02-11 10:03:44 +00:00
ARG BUILD_TIMESCALE = false
2021-01-02 21:34:42 +00:00
2020-10-09 06:09:56 +00:00
2014-05-04 19:14:46 +00:00
2020-02-20 18:08:49 +00:00
RUN set -eux \
&& export DEBIAN_FRONTEND = noninteractive \
2021-01-02 21:34:42 +00:00
&& apt-get update \
2023-08-20 21:27:11 +00:00
&& wget -O- https://www.postgresql.org/media/keys/ACCC4CF8.asc | gpg --dearmor | sh -c 'cat > /usr/share/keyrings/postgresql.gpg' > /dev/null \
2023-10-10 20:53:00 +00:00
&& echo deb [ signed-by= /usr/share/keyrings/postgresql.gpg] https://apt.postgresql.org/pub/repos/apt/ ${ IMAGE_VERSION } -pgdg main | tee /etc/apt/sources.list.d/pgdg.list 2>/dev/null \
2020-02-20 18:08:49 +00:00
&& apt-get -y --purge autoremove \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* \
&& dpkg-divert --local --rename --add /sbin/initctl
2019-01-30 19:06:28 +00:00
2014-05-04 19:14:46 +00:00
#-------------Application Specific Stuff ----------------------------------------------------
2015-08-08 21:46:13 +00:00
# We add postgis as well to prevent build errors (that we dont see on local builds)
# on docker hub e.g.
# The following packages have unmet dependencies:
2023-07-29 13:07:11 +00:00
2020-02-20 18:08:49 +00:00
RUN set -eux \
&& export DEBIAN_FRONTEND = noninteractive \
2020-10-09 06:09:56 +00:00
&& apt-get update \
&& apt-get -y --no-install-recommends install postgresql-client-${ POSTGRES_MAJOR_VERSION } \
postgresql-common postgresql-${ POSTGRES_MAJOR_VERSION } \
2021-01-27 18:06:59 +00:00
postgresql-${ POSTGRES_MAJOR_VERSION } -postgis-${ POSTGIS_MAJOR_VERSION } \
2023-07-29 13:07:11 +00:00
postgresql-${ POSTGRES_MAJOR_VERSION } -ogr-fdw \
2021-01-27 18:06:59 +00:00
postgresql-${ POSTGRES_MAJOR_VERSION } -postgis-${ POSTGIS_MAJOR_VERSION } -scripts \
2020-10-09 06:09:56 +00:00
postgresql-plpython3-${ POSTGRES_MAJOR_VERSION } postgresql-${ POSTGRES_MAJOR_VERSION } -pgrouting \
2022-12-06 17:05:26 +00:00
postgresql-server-dev-${ POSTGRES_MAJOR_VERSION } postgresql-${ POSTGRES_MAJOR_VERSION } -cron \
2023-08-06 03:02:07 +00:00
postgresql-${ POSTGRES_MAJOR_VERSION } -mysql-fdw && \
pgxn install h3
2022-02-11 10:03:44 +00:00
2022-08-18 08:40:41 +00:00
# TODO a case insensitive match would be more robust
RUN if [ " ${ BUILD_TIMESCALE } " = "true" ] ; then \
2022-02-11 10:03:44 +00:00
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 ;
2020-10-09 06:09:56 +00:00
2023-08-19 18:22:21 +00:00
RUN echo $POSTGRES_MAJOR_VERSION >/tmp/pg_version.txt && echo $POSTGIS_MAJOR_VERSION >/tmp/pg_major_version.txt && \
echo $POSTGIS_MINOR_RELEASE >/tmp/pg_minor_version.txt
2021-01-02 21:34:42 +00:00
ENV \
PATH = " $PATH :/usr/lib/postgresql/ ${ POSTGRES_MAJOR_VERSION } /bin "
2020-06-20 16:24:20 +00:00
# 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 \
2020-02-20 18:08:49 +00:00
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
2014-05-04 19:14:46 +00:00
2014-08-05 08:45:28 +00:00
# Open port 5432 so linked containers can see them
2014-05-04 19:14:46 +00:00
EXPOSE 5432
2020-01-21 11:03:14 +00:00
2020-02-20 18:08:49 +00:00
# Copy scripts
2021-11-28 05:38:57 +00:00
ADD ./scripts /scripts
2020-04-14 17:00:36 +00:00
WORKDIR /scripts
RUN chmod +x *.sh
2020-02-20 18:08:49 +00:00
2014-05-04 19:14:46 +00:00
# Run any additional tasks here that are too tedious to put in
# this dockerfile directly.
2020-02-20 18:08:49 +00:00
RUN set -eux \
2022-04-27 06:30:16 +00:00
&& /scripts/setup.sh; rm /scripts/.pass_*
2021-06-10 16:27:48 +00:00
RUN echo 'figlet -t "Kartoza Docker PostGIS"' >> ~/.bashrc
2018-03-21 20:53:39 +00:00
2023-02-01 04:42:32 +00:00
ENTRYPOINT [ "/bin/bash" , "/scripts/docker-entrypoint.sh" ]
2021-01-27 18:06:59 +00:00
##############################################################################
# Testing Stage #
##############################################################################
FROM postgis-prod AS postgis-test
2021-11-28 05:38:57 +00:00
COPY ./scenario_tests/utils/requirements.txt /lib/utils/requirements.txt
2021-01-27 18:06:59 +00:00
RUN set -eux \
&& export DEBIAN_FRONTEND = noninteractive \
&& apt-get update \
2023-02-01 04:42:32 +00:00
&& apt-get -y --no-install-recommends install python3-pip procps \
2021-01-27 18:06:59 +00:00
&& apt-get -y --purge autoremove \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
2023-08-06 03:02:07 +00:00
RUN pip3 install -r /lib/utils/requirements.txt --break-system-packages