Skip to content

Commit

Permalink
Update Mattermost + postgres
Browse files Browse the repository at this point in the history
  • Loading branch information
NicolasDorier committed Jun 12, 2021
1 parent 0e12bd3 commit e29b1ee
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 2 deletions.
7 changes: 5 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
46 changes: 46 additions & 0 deletions postgres/migrate-docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -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 "$@"

0 comments on commit e29b1ee

Please sign in to comment.