Skip to content

Commit 6888547

Browse files
committed
Robustness improvements
1 parent 709d7c9 commit 6888547

4 files changed

Lines changed: 70 additions & 15 deletions

File tree

Dockerfile

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,15 @@ COPY --from=trimmed-all /usr/share/postgresql/${PG_MAJOR_PREVIOUS} /usr/share/po
4646
# with OR_DISABLE_REINDEX=true
4747
ARG OR_REINDEX_COUNTER=1
4848

49-
ENTRYPOINT ["/bin/sh", "-c", "/or-entrypoint.sh postgres -c max_connections=${POSTGRES_MAX_CONNECTIONS}"]
50-
#postgres -c "max_connections=${POSTGRES_MAX_CONNECTIONS}"
49+
# This is important otherwise connections will prevent a graceful shutdown
50+
STOPSIGNAL SIGINT
51+
52+
#ENTRYPOINT ["/bin/sh", "-c", "/or-entrypoint.sh postgres -c max_connections=${POSTGRES_MAX_CONNECTIONS}"]
53+
ENTRYPOINT ["/or-entrypoint.sh"]
54+
55+
# Use exec form of CMD with exec call so kill signals are correctly forwarded whilst allowing variable expansion
56+
# see: https://github.com/moby/moby/issues/5509#issuecomment-890126570
57+
CMD ["postgres"]
5158

5259
ENV PGROOT=/var/lib/postgresql \
5360
PGDATA=/var/lib/postgresql/data \

Dockerfile.alpine

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# -----------------------------------------------------------------------------------------------
2+
# POSTGIS and TimescaleDB (inc. toolkit for hyperfunctions) image built for aarch64 support
3+
# using alpine base image.
4+
#
5+
# timescale/timescaledb-ha image is ubuntu based and only currently supports amd64; they are
6+
# working on ARM64 support in timescaledev/timescaledb-ha see:
7+
#
8+
# https://github.com/timescale/timescaledb-docker-ha/pull/355
9+
#
10+
# See this issue for POSTGIS base image aarch64 support discussion:
11+
#
12+
# https://github.com/postgis/docker-postgis/issues/216
13+
# ------- ----------------------------------------------------------------------------------------
14+
15+
# We get POSTGIS and timescale+toolkit from this image
16+
FROM timescaledev/timescaledb-ha:pg15-multi as timescale-ha
17+
18+
19+
# This base image is alpine based - timescale toolkit requires glibc 2.3+ so we install it into alpine image
20+
# This still doesn't work as timescale code is compiled against glibc and some references don't match with gcompat
21+
22+
FROM timescale/timescaledb:latest-pg15
23+
MAINTAINER support@openremote.io
24+
25+
ENV GLIBC_VERSION 2.35-r0
26+
ENV TZ ${TZ:-Europe/Amsterdam}
27+
ENV PGTZ ${PGTZ:-Europe/Amsterdam}
28+
ENV POSTGRES_DB ${POSTGRES_DB:-openremote}
29+
ENV POSTGRES_USER ${POSTGRES_USER:-postgres}
30+
ENV POSTGRES_PASSWORD ${POSTGRES_PASSWORD:-postgres}
31+
32+
# Add glibc
33+
RUN apk add gcompat
34+
35+
36+
COPY --from=timescale-ha /usr/lib/postgresql/15/lib/bitcode/postgis-3/ /usr/local/lib/postgresql/bitcode/
37+
COPY --from=timescale-ha /usr/lib/postgresql/15/lib/postgis* /usr/local/lib/postgresql/
38+
COPY --from=timescale-ha /docker-entrypoint-initdb.d/010_install_timescaledb_toolkit.sh /docker-entrypoint-initdb.d/010_install_timescaledb_toolkit.sh
39+
COPY --from=timescale-ha /usr/lib/postgresql/15/lib/timescaledb* /usr/local/lib/postgresql/
40+
COPY --from=timescale-ha /usr/bin/timescale* /usr/local/bin/
41+
COPY --from=timescale-ha /usr/share/postgresql/15/extension/postgis* /usr/local/share/postgresql/extension/
42+
COPY --from=timescale-ha /usr/share/postgresql/15/extension/timescale* /usr/local/share/postgresql/extension/
43+
44+
HEALTHCHECK --interval=3s --timeout=3s --start-period=2s --retries=30 CMD pg_isready

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
POSTGIS and TimescaleDB (inc. toolkit for hyperfunctions) image built for aarch64 support using `timescaledev/timescaledb-ha` base image with:
55

66
- OR specific ENV variables and a healthcheck added
7+
- Easy configuration of `max_connections` using `POSTGRES_MAX_CONNECTIONS` environment variable (set to `-1` to disable this setting)
78
- PGDATA path set to match old Alpine image (for ease of DB migration)
89
- POSTGRES user UID and GID changed to match old Alpine image (for ease of DB migration)
910
- Auto upgrade of database with PG major version changes from previous PG major version; can be disabled using

or-entrypoint.sh

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
source /docker-entrypoint.sh
88
docker_setup_env
99

10+
# Append max connections arg if needed
11+
if [ $POSTGRES_MAX_CONNECTIONS -gt 0 ]; then
12+
set -- "$@" -c max_connections=${POSTGRES_MAX_CONNECTIONS}
13+
fi
1014

1115
# Check for presence of old/new directories, indicating a failed previous autoupgrade
1216
echo "----------------------------------------------------------------------"
@@ -30,26 +34,15 @@ echo "--------------------------------------------------------------------------
3034
echo "No artifacts found from a failed previous autoupgrade. Continuing the process."
3135
echo "-------------------------------------------------------------------------------"
3236

33-
echo "DB STATUS: "
34-
pg_ctl -D "$PGDATA" status
35-
3637
if [ -n "$DATABASE_ALREADY_EXISTS" ]; then
3738

3839
echo "-----------------------------------------"
3940
echo "Performing checks on existing database..."
4041
echo "-----------------------------------------"
4142

42-
# Just make sure postgres isn't still running for some reason
43-
set +e
44-
pg_ctl -D "$PGDATA" -m immedate stop
45-
set -e
46-
47-
# Remove any stale PID file
48-
rm -f "${PGDATA}/postmaster.pid"
49-
5043
# Make sure timescaledb library is set to preload (won't work otherwise)
5144
echo "---------------------------------------------------------------------------------------"
52-
echo "Existing postgresql.conf found checking for shared_preload_libraries = 'timescaledb'..."
45+
echo "Existing postgresql.conf found checking for shared_preload_libraries = 'timescaledb'..."
5346
echo "---------------------------------------------------------------------------------------"
5447
RESULT=$(cat "$PGDATA/postgresql.conf" | grep "^shared_preload_libraries = 'timescaledb'" || true)
5548

@@ -88,8 +81,18 @@ if [ -n "$DATABASE_ALREADY_EXISTS" ]; then
8881
echo "Postgres major version is newer than the existing DB, performing auto upgrade..."
8982
echo "---------------------------------------------------------------------------------"
9083

84+
if [ -f "${PGDATA}/postmaster.pid" ]; then
85+
echo "-----------------------------------------------------------------------------------------------------"
86+
echo "Looks like the server did not previously shutdown properly which will prevent pg_upgrade from working"
87+
echo "try stopping the whole stack, bringing only the postgresql container up and then stopping it again"
88+
echo "-----------------------------------------------------------------------------------------------------"
89+
exit 1
90+
fi
91+
9192
if [ ! -d "/usr/lib/postgresql/${DB_VERSION}" ]; then
93+
echo "--------------------------------------------------------------------------------------------------"
9294
echo "Postgres executable version '$DB_VERSION' is not included in this image so cannot auto upgrade"
95+
echo "--------------------------------------------------------------------------------------------------"
9396
exit 1
9497
fi
9598

@@ -194,7 +197,7 @@ if [ -n "$DATABASE_ALREADY_EXISTS" ]; then
194197
echo "Copying reindex and TS version files across"
195198
echo "--------------------------------------------------------------"
196199
cp -f ${OLD}/OR_REINDEX_* ${PGDATA}
197-
cp -f ${OLD}/TS_VERSION ${PGDATA}
200+
cp -f ${OLD}/OR_TS_VERSION ${PGDATA}
198201
echo "-------------------------------------------------------------------"
199202
echo "Copying reindex files is complete"
200203
echo "-------------------------------------------------------------------"

0 commit comments

Comments
 (0)