Introduce upgrade scripts for compose installation (here for postgres-13) (#6)

This commit is contained in:
Cyril Rohr
2021-07-12 16:00:40 +02:00
committed by Markus Kahl
parent 44c005cd81
commit 4a74729b73
8 changed files with 165 additions and 1 deletions

2
.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
*.swp
*.tar.gz

View File

@@ -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

47
compose/control/README.md Normal file
View File

@@ -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.

View File

@@ -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"

View File

@@ -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"

View File

@@ -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"

View File

@@ -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"]

View File

@@ -30,7 +30,7 @@ x-op-app: &app
services:
db:
image: postgres:10
image: postgres:13
<<: *restart_policy
stop_grace_period: "3s"
volumes: