From 4a74729b73fc564801ef2c22d8ec36455177d6f4 Mon Sep 17 00:00:00 2001 From: Cyril Rohr Date: Mon, 12 Jul 2021 16:00:40 +0200 Subject: [PATCH 1/6] Introduce upgrade scripts for compose installation (here for postgres-13) (#6) --- .gitignore | 2 + compose/control/Dockerfile | 11 ++++ compose/control/README.md | 47 +++++++++++++++++ compose/control/backup/entrypoint.sh | 13 +++++ compose/control/upgrade/entrypoint.sh | 8 +++ .../control/upgrade/scripts/00-db-upgrade.sh | 32 ++++++++++++ compose/docker-compose.control.yml | 51 +++++++++++++++++++ compose/docker-compose.yml | 2 +- 8 files changed, 165 insertions(+), 1 deletion(-) create mode 100644 .gitignore create mode 100644 compose/control/Dockerfile create mode 100644 compose/control/README.md create mode 100755 compose/control/backup/entrypoint.sh create mode 100755 compose/control/upgrade/entrypoint.sh create mode 100755 compose/control/upgrade/scripts/00-db-upgrade.sh create mode 100644 compose/docker-compose.control.yml diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..82b0cd2 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*.swp +*.tar.gz diff --git a/compose/control/Dockerfile b/compose/control/Dockerfile new file mode 100644 index 0000000..69154b9 --- /dev/null +++ b/compose/control/Dockerfile @@ -0,0 +1,11 @@ +FROM debian:10 + +RUN apt-get update -qq && apt-get install wget gnupg2 -y && rm -rf /var/lib/apt/lists/* +RUN wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - +RUN echo "deb http://apt.postgresql.org/pub/repos/apt buster-pgdg main" > /etc/apt/sources.list.d/pgdg.list +RUN apt-get update -qq && apt-get install postgresql-9.6 postgresql-10 postgresql-13 -y && rm -rf /var/lib/apt/lists/* +RUN localedef -i en_US -c -f UTF-8 -A /usr/share/locale/locale.alias en_US.UTF-8 + +ENV LANG en_US.utf8 + +ADD . /control diff --git a/compose/control/README.md b/compose/control/README.md new file mode 100644 index 0000000..b46cf0a --- /dev/null +++ b/compose/control/README.md @@ -0,0 +1,47 @@ +# Control your OpenProject installation + +## Backup + +Switch off your current installation: + + docker-compose down + +Build the control scripts: + + docker-compose -f docker-compose.yml -f docker-compose.control.yml build + +Take a backup of your existing PostgreSQL data and OpenProject assets: + + docker-compose -f docker-compose.yml -f docker-compose.control.yml run backup + +Restart your OpenProject installation + + docker-compose up -d + +## Upgrade + +Switch off your current installation (using the outdated postgres engine): + + docker-compose down + +Fetch the latest changes from this repository: + + git pull origin stable/12 # adjust if needed + +Build the control plane: + + docker-compose -f docker-compose.yml -f docker-compose.control.yml build + +Take a backup of your existing postgresql data and openproject assets: + + docker-compose -f docker-compose.yml -f docker-compose.control.yml run backup + +Run the upgrade: + + docker-compose -f docker-compose.yml -f docker-compose.control.yml run upgrade + +Relaunch your OpenProject installation, using the normal Compose command: + + docker-compose up -d + +Test that everything works again, the database container should now be running postgres 13. diff --git a/compose/control/backup/entrypoint.sh b/compose/control/backup/entrypoint.sh new file mode 100755 index 0000000..f81abe2 --- /dev/null +++ b/compose/control/backup/entrypoint.sh @@ -0,0 +1,13 @@ +#!/bin/bash +set -e + +timestamp=$(date +%s) +mkdir -p /backups +cd /backups +filename="${timestamp}-pgdata.tar.gz" +echo "Backing up PostgreSQL data into backups/${filename}..." +tar czf "${filename}" -C "$PGDATA" . +filename="${timestamp}-opdata.tar.gz" +echo "Backing up OpenProject assets into backups/${filename}..." +tar czf "${filename}" -C "$OPDATA" . +echo "DONE" diff --git a/compose/control/upgrade/entrypoint.sh b/compose/control/upgrade/entrypoint.sh new file mode 100755 index 0000000..71a8f78 --- /dev/null +++ b/compose/control/upgrade/entrypoint.sh @@ -0,0 +1,8 @@ +#!/bin/bash +set -e +set -o pipefail + +/control/upgrade/scripts/00-db-upgrade.sh + +echo "Please restart your installation by issuing the following command:" +echo " docker-compose up -d" diff --git a/compose/control/upgrade/scripts/00-db-upgrade.sh b/compose/control/upgrade/scripts/00-db-upgrade.sh new file mode 100755 index 0000000..1e89bad --- /dev/null +++ b/compose/control/upgrade/scripts/00-db-upgrade.sh @@ -0,0 +1,32 @@ +#!/bin/bash +set -e +set -o pipefail + +CURRENT_PGVERSION="$(cat $PGDATA/PG_VERSION)" +NEW_PGVERSION="13" +PGWORKDIR=${PGWORKDIR:=/var/lib/postgresql/work} + +if [ ! "$CURRENT_PGVERSION" -lt "$NEW_PGVERSION" ]; then + echo "Current PG version is higher or equal to the PG version to be installed ($CURRENT_PGVERSION > $NEW_PGVERSION). Ignoring." + exit 0 +fi + +export PGBINOLD="/usr/lib/postgresql/$CURRENT_PGVERSION/bin" +export PGBINNEW="/usr/lib/postgresql/$NEW_PGVERSION/bin" +export PGDATAOLD="$PGDATA" +export PGDATANEW="$PGWORKDIR/datanew" + +rm -rf "$PGWORKDIR" && mkdir -p "$PGWORKDIR" "$PGDATANEW" +chown -R postgres.postgres "$PGDATA" "$PGWORKDIR" +cd "$PGWORKDIR" +# initialize new db +su -m postgres -c "$PGBINNEW/initdb --pgdata=$PGDATANEW --encoding=unicode --auth=trust" +echo "Performing a dry-run migration to PostgreSQL $NEW_PGVERSION..." +su -m postgres -c "$PGBINNEW/pg_upgrade -c" +echo "Performing the real migration to PostgreSQL $NEW_VERSION..." +su -m postgres -c "$PGBINNEW/pg_upgrade" +su -m postgres -c "rm -rf $PGDATAOLD/* && mv $PGDATANEW/* $PGDATAOLD/" +# as per docker hub documentation +su -m postgres -c "echo \"listen_addresses = '*'\" >> $PGDATAOLD/postgresql.conf" +su -m postgres -c "echo \"host all all all md5\" >> $PGDATAOLD/pg_hba.conf" +echo "DONE" diff --git a/compose/docker-compose.control.yml b/compose/docker-compose.control.yml new file mode 100644 index 0000000..95635e3 --- /dev/null +++ b/compose/docker-compose.control.yml @@ -0,0 +1,51 @@ +version: "3.7" + +volumes: + pgupgrade: + +services: + db: + restart: "no" + entrypoint: ["echo", "disabled"] + upgrade: + restart: "no" + build: + context: ./control + environment: + PGDATA: /var/lib/postgresql/data + volumes: + - "pgdata:/var/lib/postgresql/data" + - "./control:/control" + entrypoint: ["/control/upgrade/entrypoint.sh"] + backup: + restart: "no" + build: + context: ./control + environment: + PGDATA: /var/lib/postgresql/data + OPDATA: /var/openproject/assets + volumes: + - "pgdata:/var/lib/postgresql/data" + - "opdata:/var/openproject/assets" + - "./backups:/backups" + - "./control:/control" + entrypoint: ["/control/backup/entrypoint.sh"] + web: + restart: "no" + entrypoint: ["echo", "disabled"] + worker: + restart: "no" + entrypoint: ["echo", "disabled"] + cron: + restart: "no" + entrypoint: ["echo", "disabled"] + seeder: + restart: "no" + entrypoint: ["echo", "disabled"] + proxy: + restart: "no" + entrypoint: ["echo", "disabled"] + cache: + restart: "no" + entrypoint: ["echo", "disabled"] + diff --git a/compose/docker-compose.yml b/compose/docker-compose.yml index 6b3c1af..4c2da6e 100644 --- a/compose/docker-compose.yml +++ b/compose/docker-compose.yml @@ -30,7 +30,7 @@ x-op-app: &app services: db: - image: postgres:10 + image: postgres:13 <<: *restart_policy stop_grace_period: "3s" volumes: From 1d2c5a4f3d5f4432a1e5f95600c13f03ac2570e3 Mon Sep 17 00:00:00 2001 From: Markus Kahl Date: Fri, 20 Aug 2021 10:24:19 +0100 Subject: [PATCH 2/6] allow db url override from env --- compose/docker-compose.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compose/docker-compose.yml b/compose/docker-compose.yml index 4c2da6e..ed02aca 100644 --- a/compose/docker-compose.yml +++ b/compose/docker-compose.yml @@ -19,7 +19,7 @@ x-op-app: &app RAILS_CACHE_STORE: "memcache" OPENPROJECT_CACHE__MEMCACHE__SERVER: "cache:11211" OPENPROJECT_RAILS__RELATIVE__URL__ROOT: "${OPENPROJECT_RAILS__RELATIVE__URL__ROOT:-}" - DATABASE_URL: "postgres://postgres:p4ssw0rd@db/openproject?pool=20&encoding=unicode&reconnect=true" + DATABASE_URL: "${DATABASE_URL:-postgres://postgres:p4ssw0rd@db/openproject?pool=20&encoding=unicode&reconnect=true}" RAILS_MIN_THREADS: 4 RAILS_MAX_THREADS: 16 USE_PUMA: "true" From 44a239ded5a2a290e5e461642751905926c6896a Mon Sep 17 00:00:00 2001 From: Markus Kahl Date: Tue, 31 Aug 2021 14:03:45 +0100 Subject: [PATCH 3/6] automatically restart unhealthy containers (#8) --- compose/docker-compose.yml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/compose/docker-compose.yml b/compose/docker-compose.yml index ed02aca..7a959ce 100644 --- a/compose/docker-compose.yml +++ b/compose/docker-compose.yml @@ -71,6 +71,18 @@ services: - db - cache - seeder + healthcheck: + test: ["CMD", "curl", "-f", "http://localhost:80/health_checks/default"] + interval: 10s + timeout: 3s + retries: 3 + start_period: 30s + autoheal: + image: willfarrell/autoheal + volumes: + - "/var/run/docker.sock:/var/run/docker.sock" + environment: + AUTOHEAL_CONTAINER_LABEL: all worker: <<: *app From 9f0643dad1ee27832b56562846f1962a80efe7fe Mon Sep 17 00:00:00 2001 From: Markus Kahl Date: Fri, 17 Dec 2021 09:38:10 +0000 Subject: [PATCH 4/6] puma is the default now --- compose/docker-compose.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/compose/docker-compose.yml b/compose/docker-compose.yml index 7a959ce..eb2c191 100644 --- a/compose/docker-compose.yml +++ b/compose/docker-compose.yml @@ -22,7 +22,6 @@ x-op-app: &app DATABASE_URL: "${DATABASE_URL:-postgres://postgres:p4ssw0rd@db/openproject?pool=20&encoding=unicode&reconnect=true}" RAILS_MIN_THREADS: 4 RAILS_MAX_THREADS: 16 - USE_PUMA: "true" # set to true to enable the email receiving feature. See ./docker/cron for more options IMAP_ENABLED: "${IMAP_ENABLED:-false}" volumes: From 740bc09395d1bbe5180b1499d5b38bdf93d8cf18 Mon Sep 17 00:00:00 2001 From: Markus Kahl Date: Fri, 17 Dec 2021 09:39:24 +0000 Subject: [PATCH 5/6] use latest OpenProject version --- compose/docker-compose.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compose/docker-compose.yml b/compose/docker-compose.yml index eb2c191..12ae6bf 100644 --- a/compose/docker-compose.yml +++ b/compose/docker-compose.yml @@ -11,7 +11,7 @@ volumes: x-op-restart-policy: &restart_policy restart: unless-stopped x-op-image: &image - image: openproject/community:${TAG:-11} + image: openproject/community:${TAG:-12} x-op-app: &app <<: *image <<: *restart_policy From 8d30ae89f2b1f62bc4cc1cc6564fc5749b7eba5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20G=C3=BCnther?= Date: Wed, 10 Nov 2021 13:13:27 +0100 Subject: [PATCH 6/6] Add stable/12 branch --- compose/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/compose/README.md b/compose/README.md index 5a91a4d..5989931 100644 --- a/compose/README.md +++ b/compose/README.md @@ -4,7 +4,7 @@ Clone this repository: - git clone https://github.com/opf/openproject-deploy --depth=1 --branch=stable/11 openproject + git clone https://github.com/opf/openproject-deploy --depth=1 --branch=stable/12 openproject Go to the compose folder: @@ -42,7 +42,7 @@ Go to the compose folder: Retrieve any changes from the `openproject-deploy` repository: - git pull origin stable/11 + git pull origin stable/12 Make sure you are using the latest version of the Docker images: