11# -----------------------------------------------------------------------------------------------
22# POSTGIS and TimescaleDB (inc. toolkit for hyperfunctions) image built for aarch64 support
3- # using alpine base image.
3+ # using timescaledev/timescaledb-ha base image with:
4+ #
5+ # - OR specific ENV variables and a healthcheck added
6+ # - PGDATA path set to match old Alpine image (for ease of DB migration)
7+ # - POSTGRES user UID and GID changed to match old Alpine image (for ease of DB migration)
8+ # - OR_DISABLE_REINDEX env variable with associated scripts to determine if a REINDEX of the entire DB should be carried
9+ # out at first startup with existing DB (checks whether or not $PGDATA/OR_REINDEX_COUNTER.$OR_REINDEX_COUNTER exists).
10+ # This is used when a collation change has occurred (glibc version change, muslc <-> glibc) which can break the indexes;
11+ # migration can either be manually handled or auto handled depending on OR_DISABLE_REINDEX env variable value.
12+ # NOTE THAT A REINDEX CAN TAKE A LONG TIME DEPENDING ON THE SIZE OF THE DB! And startup will be delayed until completed
13+ # This functionality is intended to simplify migration for basic users; advanced users with large DBs should take care of this
14+ # themselves.
15+ #
16+ #
17+ #
418#
519# timescale/timescaledb-ha image is ubuntu based and only currently supports amd64; they are
620# working on ARM64 support in timescaledev/timescaledb-ha see:
@@ -25,18 +39,33 @@ RUN usermod -u 70 postgres \
2539 && (find / -group 1000 -exec chgrp -h postgres {} \; || true) \
2640 && (find / -user 1000 -exec chown -h postgres {} \; || true)
2741
28-
2942# Set PGDATA to the same location as our old alpine image
3043RUN mkdir -p /var/lib/postgresql && mv /home/postgres/pgdata/* /var/lib/postgresql/ && chown -R postgres:postgres /var/lib/postgresql
3144
32- # Below is copied from https://github.com/timescale/timescaledb-docker-ha/blob/master/Dockerfile
33- # to minimise the size of this image
45+ # Add custom entry point (see file header for details)
46+ COPY or-entrypoint.sh /
47+ RUN chmod +x /or-entrypoint.sh
48+
49+ # Add custom initdb script(s)
50+ COPY docker-entrypoint-initdb.d/ /docker-entrypoint-initdb.d/
51+ RUN chmod +x /docker-entrypoint-initdb.d/*
52+
53+
54+ # Below is mostly copied from https://github.com/timescale/timescaledb-docker-ha/blob/master/Dockerfile (with OR specific entrypoint,
55+ # workdir and OR env defaults)
56+
57+
3458# # Create a smaller Docker image from the builder image
3559FROM scratch
3660COPY --from=trimmed / /
3761
3862ARG PG_MAJOR=14
39- ENTRYPOINT ["/docker-entrypoint.sh" ]
63+
64+ # Increment this to indicate that a re-index should be carried out on first startup with existing data; REINDEX can still be overidden
65+ # with OR_DISABLE_REINDEX=true
66+ ARG OR_REINDEX_COUNTER=1
67+
68+ ENTRYPOINT ["/or-entrypoint.sh" ]
4069CMD ["postgres" ]
4170
4271ENV PGROOT=/var/lib/postgresql \
@@ -50,17 +79,18 @@ ENV PGROOT=/var/lib/postgresql \
5079 LC_ALL=C.UTF-8 \
5180 LANG=C.UTF-8 \
5281 # When having an interactive psql session, it is useful if the PAGER is disable
53- PAGER=""
82+ PAGER="" \
83+ # OR ENV DEFAULTS
84+ TZ=${TZ:-Europe/Amsterdam} \
85+ PGTZ=${PGTZ:-Europe/Amsterdam} \
86+ POSTGRES_DB=${POSTGRES_DB:-openremote} \
87+ POSTGRES_USER=${POSTGRES_USER:-postgres} \
88+ POSTGRES_PASSWORD=${POSTGRES_PASSWORD:-postgres} \
89+ OR_REINDEX_COUNTER=${OR_REINDEX_COUNTER} \
90+ OR_DISABLE_REINDEX=${OR_DISABLE_REINDEX:-false}
5491
5592WORKDIR /var/lib/postgresql
5693EXPOSE 5432 8008 8081
5794USER postgres
5895
59- # # ADD OR convenience default ENV values and healthcheck
60- ENV TZ ${TZ:-Europe/Amsterdam}
61- ENV PGTZ ${PGTZ:-Europe/Amsterdam}
62- ENV POSTGRES_DB ${POSTGRES_DB:-openremote}
63- ENV POSTGRES_USER ${POSTGRES_USER:-postgres}
64- ENV POSTGRES_PASSWORD ${POSTGRES_PASSWORD:-postgres}
65-
6696HEALTHCHECK --interval=3s --timeout=3s --start-period=2s --retries=30 CMD pg_isready
0 commit comments