From e29b1eec6c5129b9fde1bf04b549a623128e1d3e Mon Sep 17 00:00:00 2001 From: "nicolas.dorier" Date: Sat, 12 Jun 2021 23:08:47 +0900 Subject: [PATCH] Update Mattermost + postgres --- docker-compose.yml | 7 ++-- postgres/migrate-docker-entrypoint.sh | 46 +++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 2 deletions(-) create mode 100755 postgres/migrate-docker-entrypoint.sh diff --git a/docker-compose.yml b/docker-compose.yml index 61939ec..4d3a2d2 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -68,10 +68,13 @@ services: expose: - 80 mattermost_db: - image: mattermost/mattermost-prod-db:v5.31.4 + image: mattermost/mattermost-prod-db:v5.31.6 + entrypoint: ./migrate-docker-entrypoint.sh + command: postgres volumes: - mm-dbdata:/var/lib/postgresql/data - /etc/localtime:/etc/localtime:ro + - "./postgres/migrate-docker-entrypoint.sh:/migrate-docker-entrypoint.sh:ro" environment: - POSTGRES_USER=mmuser - POSTGRES_PASSWORD=mmuser_password @@ -83,7 +86,7 @@ services: - mattermost_app mattermost_app: restart: unless-stopped - image: mattermost/mattermost-prod-app:v5.31.4 + image: mattermost/mattermost-prod-app:v5.31.6 volumes: - mm-config:/mattermost/config:rw - mm-data:/mattermost/data:rw diff --git a/postgres/migrate-docker-entrypoint.sh b/postgres/migrate-docker-entrypoint.sh new file mode 100755 index 0000000..be276c0 --- /dev/null +++ b/postgres/migrate-docker-entrypoint.sh @@ -0,0 +1,46 @@ +#!/usr/bin/env bash +set -Eeo pipefail +shopt -s extglob + +CURRENT_PGVERSION="" +EXPECTED_PGVERSION="$PG_MAJOR" +if [[ -f "/var/lib/postgresql/data/PG_VERSION" ]]; then + CURRENT_PGVERSION="$(cat /var/lib/postgresql/data/PG_VERSION)" +fi + +if [[ "$CURRENT_PGVERSION" != "$EXPECTED_PGVERSION" ]] && \ + [[ "$CURRENT_PGVERSION" != "" ]]; then + sed -i "s/$/ $CURRENT_PGVERSION/" /etc/apt/sources.list.d/pgdg.list + apt-get update && apt-get install -y --no-install-recommends \ + postgresql-$CURRENT_PGVERSION \ + postgresql-contrib-$CURRENT_PGVERSION \ + && rm -rf /var/lib/apt/lists/* + + export PGBINOLD="/usr/lib/postgresql/$CURRENT_PGVERSION/bin" + export PGDATABASE="/var/lib/postgresql/data" + export PGDATAOLD="/var/lib/postgresql/data/$CURRENT_PGVERSION" + export PGDATANEW="/var/lib/postgresql/data/$EXPECTED_PGVERSION" + + mkdir -p "$PGDATANEW" "$PGDATAOLD" + find "$PGDATABASE" -maxdepth 1 -mindepth 1 \ + -not -wholename "$PGDATAOLD" \ + -not -wholename "$PGDATANEW" \ + -exec mv {} "$PGDATAOLD/" \; + + chmod 700 "$PGDATAOLD" "$PGDATANEW" + chown postgres . + chown -R postgres "$PGDATAOLD" "$PGDATANEW" "$PGDATABASE" + if [ ! -s "$PGDATANEW/PG_VERSION" ]; then + PGDATA="$PGDATANEW" eval "gosu postgres initdb $POSTGRES_INITDB_ARGS" + fi + + gosu postgres pg_upgrade + rm $PGDATANEW/*.conf + mv $PGDATANEW/* "$PGDATABASE" + mv $PGDATAOLD/*.conf "$PGDATABASE" + rm -r "$PGDATANEW" + ./delete_old_cluster.sh + rm ./analyze_new_cluster.sh +fi + +exec ./entrypoint.sh "$@" \ No newline at end of file