Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Pin postgresql to 9.6 for the all-in-one docker image (#8640)

Cyril Rohr246e20bbd3d8
diff --git a/Dockerfile b/Dockerfile
index 190d5fa1ce3..c4de4503bfd 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -19,7 +19,6 @@ ENV APP_USER=app
ENV APP_PATH=/app
ENV APP_DATA_PATH=/var/openproject/assets
ENV APP_DATA_PATH_LEGACY=/var/db/openproject
-ENV PGBIN="/usr/lib/postgresql/9.6/bin"
ENV PGDATA=/var/openproject/pgdata
ENV PGDATA_LEGACY=/var/lib/postgresql/9.6/main
diff --git a/docker/setup/postinstall.sh b/docker/setup/postinstall.sh
index 42911b8bdd6..9ac36ae1112 100755
--- a/docker/setup/postinstall.sh
+++ b/docker/setup/postinstall.sh
@@ -1,6 +1,9 @@
#!/bin/bash
set -e
+set -o pipefail
+
+PGBIN="$(pg_config --bindir)"
display_error() {
echo " !--> ERROR on postinstall:"
@@ -26,6 +29,8 @@ fi
echo " ---> Precompiling assets. This will take a while..."
(
+ set -e
+ set -o pipefail
pushd "${APP_PATH}/frontend"
export NG_CLI_ANALYTICS=ci # so angular cli doesn't block waiting for user input
diff --git a/docker/setup/preinstall-on-prem.sh b/docker/setup/preinstall-on-prem.sh
index 5d75f67c98a..adbd18c4af7 100755
--- a/docker/setup/preinstall-on-prem.sh
+++ b/docker/setup/preinstall-on-prem.sh
@@ -1,5 +1,6 @@
#!/bin/bash
set -e
+set -o pipefail
apt-get install -y \
memcached \
diff --git a/docker/setup/preinstall.sh b/docker/setup/preinstall.sh
index b9b11cd22e4..6d15d80c52e 100755
--- a/docker/setup/preinstall.sh
+++ b/docker/setup/preinstall.sh
@@ -1,5 +1,6 @@
#!/bin/bash
set -e
+set -o pipefail
echo " ---> PREINSTALL"
@@ -10,28 +11,30 @@ display_error() {
}
echo " ---> Setting up common dependencies. This will take a while..."
-apt-get update -qq
(
+ set -e
+ set -o pipefail
+
# install node + npm
curl -s https://nodejs.org/dist/v${NODE_VERSION}/node-v${NODE_VERSION}-linux-x64.tar.gz | \
tar xzf - -C /usr/local --strip-components=1
+ wget --quiet -O- https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add -
+ echo "deb http://apt.postgresql.org/pub/repos/apt buster-pgdg main" > /etc/apt/sources.list.d/pgdg.list
+
+ apt-get update -qq
apt-get install -y \
apt-transport-https \
- postgresql-client \
pandoc \
poppler-utils \
unrtf \
tesseract-ocr \
catdoc \
- postgresql
+ postgresql-9.6 \
+ postgresql-client-9.6
- # Set up pg defaults
- echo "host all all 0.0.0.0/0 md5" >> /etc/postgresql/9.6/main/pg_hba.conf
- echo "listen_addresses='*'" >> /etc/postgresql/9.6/main/postgresql.conf
- echo "data_directory='$PGDATA'" >> /etc/postgresql/9.6/main/postgresql.conf
- rm -rf "$PGDATA_LEGACY" && rm -rf "$PGDATA" && mkdir -p "$PGDATA" && chown -R postgres:postgres "$PGDATA"
+ rm -rf "$PGDATA_LEGACY"
# Specifics for BIM edition
wget -qO- https://packages.microsoft.com/keys/microsoft.asc | apt-key add -
diff --git a/docker/supervisord b/docker/supervisord
index 5e73ce7b0be..77dda1bbf22 100755
--- a/docker/supervisord
+++ b/docker/supervisord
@@ -14,6 +14,8 @@ if [ "$PGDATA" == "" ]; then
exit 2
fi
+export PGBIN="$(pg_config --bindir)"
+export PGCONF_FILE="/etc/postgresql/9.6/main/postgresql.conf"
PGUSER=${PGUSER:=postgres}
PGPASSWORD=${PGPASSWORD:=postgres}
PG_STARTUP_WAIT_TIME=${PG_STARTUP_WAIT_TIME:=10}
@@ -74,34 +76,56 @@ migrate() {
popd >/dev/null
}
+check_postgres_connection() {
+ su postgres -c "$PGBIN/psql $DATABASE_URL -c 'select 1;'"
+}
+
wait_for_postgres() {
retries=${PG_STARTUP_WAIT_TIME}
echo "Trying to contact PostgreSQL server instance or waiting for it to come online."
- until su postgres -c "$PGBIN/psql $DATABASE_URL -c 'select 1;' > /dev/null 2>&1" || [ $retries -eq 0 ]; do
- echo "Waiting for postgres server, $((retries--)) remaining attempts..."
- sleep 3
+ while ! check_postgres_connection &> /dev/null ; do
+ if [ $retries -eq 0 ]; then
+ echo "Unable to contact postgres server:"
+ check_postgres_connection
+ else
+ echo "Waiting for postgres server, $((retries--)) remaining attempts..."
+ sleep 3
+ fi
done
}
+configure_local_postgres() {
+ mkdir -p "$PGDATA"
+ chown -R postgres:postgres "$PGDATA"
+ # remove any dangling pid
+ rm -f $PGDATA/postmaster.pid
+
+ # Set up pg defaults
+ echo "host all all 0.0.0.0/0 md5" >> /etc/postgresql/9.6/main/pg_hba.conf
+ echo "listen_addresses='0.0.0.0'" >> "$PGCONF_FILE"
+ echo "data_directory='$PGDATA'" >> "$PGCONF_FILE"
+}
+
if [ "$dbhost" = "127.0.0.1" ]; then
+ configure_local_postgres
+
# initialize cluster if it does not exist yet
if [ -f "$PGDATA/PG_VERSION" ]; then
echo "-----> Database cluster already exists, not modifying."
- /etc/init.d/postgresql start | indent
+ su - postgres -c "$PGBIN/pg_ctl -w -l /dev/null -o '-c config_file=$PGCONF_FILE' -D '$PGDATA' start" | indent
(install_plugins && migrate) | indent
- /etc/init.d/postgresql stop | indent
+ su - postgres -c "$PGBIN/pg_ctl -D '$PGDATA' stop" | indent
else
echo "-----> Database cluster not found. Creating a new one in $PGDATA..."
- chown -R postgres:postgres $PGDATA
su postgres -c "$PGBIN/initdb --pgdata=${PGDATA} --username=${PGUSER} --encoding=unicode --auth=trust --pwfile=$pwfile" | indent
su postgres -c "rm -f $pwfile"
- /etc/init.d/postgresql start | indent
+ su - postgres -c "$PGBIN/pg_ctl -w -l /dev/null -o '-c config_file=$PGCONF_FILE' -D '$PGDATA' start" | indent
su postgres -c "$PGBIN/psql --command \"CREATE USER openproject WITH SUPERUSER PASSWORD 'openproject';\"" | indent
su postgres -c "$PGBIN/createdb -O openproject openproject" | indent
(install_plugins && migrate) | indent
- /etc/init.d/postgresql stop | indent
+ su - postgres -c "$PGBIN/pg_ctl -D '$PGDATA' stop" | indent
fi
else
echo "-----> You're using an external database. Not initializing a local database cluster."
diff --git a/docker/supervisord.conf b/docker/supervisord.conf
index 8709601ab09..940cbf6f1c6 100644
--- a/docker/supervisord.conf
+++ b/docker/supervisord.conf
@@ -79,7 +79,7 @@ stderr_logfile_maxbytes = 0
[program:postgres]
user=postgres
priority=1
-command=/usr/lib/postgresql/9.6/bin/postgres -D %(ENV_PGDATA)s -c config_file=/etc/postgresql/9.6/main/postgresql.conf
+command=%(ENV_PGBIN)s/postgres -D %(ENV_PGDATA)s -c config_file=%(ENV_PGCONF_FILE)s
autorestart=true
stderr_logfile = /dev/stderr
stdout_logfile = /dev/stdout