Skip to content

Commit

Permalink
Merge branch 'schema-change-2024-q2'
Browse files Browse the repository at this point in the history
* schema-change-2024-q2:
  Bump musicbrainz build sequence to 2
  MBVM-42 (2/2): Prebuild db service image
  MBVM-42 (1/2): Prebuild musicbrainz service image
  Upgrade Server to v-2024-05-13-schema-change (#278)
  Pass POSTGRES_VERSION ARG in development setup too
  Update installed extensions after Postgres upgrade
  Replace analyze_new_cluster with vacuumdb (PG 14)
  Fix copying Postgres upgrade script to container
  Fix showing server version during Postgres upgrade
  Fix compiling pg_amqp during Postgres upgrade
  Hide expected and harmless error message
  MBS-13361 (mirror): Upgrade to PostgreSQL 16
  Install Perl module dependencies with Carton
  MBS-13358 (III): Upgrade Perl version to 5.38.2
  Install cpanm from source instead of using apt-get
  Install local::lib using cpanm instead of apt-get
  • Loading branch information
yvanzo committed May 14, 2024
2 parents 513b155 + c7e126e commit f362446
Show file tree
Hide file tree
Showing 23 changed files with 411 additions and 142 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ If you use [UFW](https://help.ubuntu.com/community/UFW) to manage your firewall:

## Components version

* Current MB Branch: [v-2024-04-09](build/musicbrainz/Dockerfile#L54)
* Current DB_SCHEMA_SEQUENCE: [28](build/musicbrainz/Dockerfile#L85)
* Postgres Version: [12](docker-compose.yml)
* Current MB Branch: [v-2024-05-13-schema-change](build/musicbrainz/Dockerfile#L88)
* Current DB_SCHEMA_SEQUENCE: [29](build/musicbrainz/Dockerfile#L125)
* Postgres Version: [16](docker-compose.yml)
(can be changed by setting the environment variable `POSTGRES_VERSION`)
* MB Solr search server: [3.4.2](docker-compose.yml#L88)
(can be changed by setting the environment variable `MB_SOLR_VERSION`)
Expand Down Expand Up @@ -152,7 +152,7 @@ tables, the server will generally fall back to slower queries in their place.
If you wish to configure the materialized tables, you can run:

```bash
sudo docker-compose exec musicbrainz bash -c './admin/BuildMaterializedTables --database=MAINTENANCE all'
sudo docker-compose exec musicbrainz bash -c 'carton exec -- ./admin/BuildMaterializedTables --database=MAINTENANCE all'
```

### Start website
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ set -e
shopt -s extglob

PGDATA=/var/lib/postgresql/data
PGDATA_OLD="$PGDATA"/9.5
PGDATA_NEW="$PGDATA"/12
PGDATA_OLD="$PGDATA"/12
PGDATA_NEW="$PGDATA"/16
PGAMQP_DIR=/tmp/pg_amqp

function cleanup() {
Expand All @@ -15,8 +15,8 @@ function cleanup() {
fi

if [[ -d "$PGDATA_OLD" ]]; then
echo "Clean $PG_DATA_OLD off but 9.5 data"
rm -rf "$PGDATA"/!(9.5)
echo "Clean $PG_DATA_OLD off but 12 data"
rm -rf "$PGDATA"/!(12)
mv -v "$PGDATA_OLD"/* "$PGDATA"
rmdir "$PGDATA_OLD"
fi
Expand All @@ -28,35 +28,38 @@ function cleanup() {
}
trap cleanup EXIT

sudo -u postgres /usr/lib/postgresql/9.5/bin/pg_ctl stop -w -D "$PGDATA" \
sudo -u postgres /usr/lib/postgresql/12/bin/pg_ctl stop -w -D "$PGDATA" 2>/dev/null \
|| echo 'Assuming server is stopped...'

# We use the --link flag on pg_upgrade below to make hard links instead of
# copying files, drastically improving the speed of the upgrade. Hard links,
# of course, require the linked files to be on the same file system, but
# $PGDATA is the volume *root*. To work around that, we have to move the
# existing v9.5 cluster to a '9.5' subdir, and create the new v12 cluster in
# a '12' subdir. Once we're finished, we'll move the new cluster's files
# existing v12 cluster to a '12' subdir, and create the new v16 cluster in
# a '16' subdir. Once we're finished, we'll move the new cluster's files
# back into $PGDATA.
cd "$PGDATA"
sudo -u postgres mkdir -p 9.5 12
chmod 700 9.5 12
sudo -u postgres mv !(9.5|12) 9.5
sudo -u postgres mkdir -p 12 16
chmod 700 12 16
sudo -u postgres mv !(12|16) 12

sudo -u postgres /usr/lib/postgresql/12/bin/initdb \
sudo -u postgres /usr/lib/postgresql/16/bin/initdb \
--encoding utf8 \
--username musicbrainz \
"$PGDATA_NEW"

git clone -b "v0.4.1" --depth=1 https://github.com/omniti-labs/pg_amqp.git "$PGAMQP_DIR"
# There is no tag v0.4.2 (or 0.5.0) yet
PG_AMQP_GIT_REF="240d477d40c5e7a579b931c98eb29cef4edda164"
git clone https://github.com/omniti-labs/pg_amqp.git "$PGAMQP_DIR"
cd "$PGAMQP_DIR"
make PG_CONFIG=/usr/lib/postgresql/12/bin/pg_config
git checkout "$PG_AMQP_GIT_REF"
make PG_CONFIG=/usr/lib/postgresql/16/bin/pg_config PG_CPPFLAGS=-Wno-error=implicit-int
make install
cd "$PGDATA"

sudo -u postgres /usr/lib/postgresql/12/bin/pg_upgrade \
--old-bindir=/usr/lib/postgresql/9.5/bin/ \
--new-bindir=/usr/lib/postgresql/12/bin/ \
sudo -u postgres /usr/lib/postgresql/16/bin/pg_upgrade \
--old-bindir=/usr/lib/postgresql/12/bin/ \
--new-bindir=/usr/lib/postgresql/16/bin/ \
--old-datadir="$PGDATA_OLD" \
--new-datadir="$PGDATA_NEW" \
--jobs=3 \
Expand All @@ -72,9 +75,5 @@ mv "$PGDATA_NEW"/* "$PGDATA"/
rmdir "$PGDATA_NEW"
cp -a "$PGDATA_OLD"/{postgresql.conf,pg_hba.conf} .

# Start the new cluster in the background, so we can apply
# 20200518-pg12-after-upgrade.sql via the website container.
sudo -u postgres /usr/lib/postgresql/12/bin/pg_ctl start -w -D "$PGDATA"

./delete_old_cluster.sh
rm delete_old_cluster.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ services:
db:
build:
args:
- POSTGRES_VERSION=9.5
image: musicbrainz-docker_db:9.5
- POSTGRES_VERSION=12
image: musicbrainz-docker_db:12
command: /bin/sleep infinity

musicbrainz:
Expand Down
104 changes: 104 additions & 0 deletions admin/repository/prebuild-db
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
#!/usr/bin/env bash

set -e -u

# shellcheck source=admin/lib/common.inc.bash
source "$(dirname "${BASH_SOURCE[0]}")/../lib/common.inc.bash"

HELP=$(cat <<EOH
Usage: $SCRIPT_NAME
or: $SCRIPT_NAME --help
Build a new image for the db service
from the source code repository of pg_amqp (AMQP Support for Postgres)
and push it as metabrainz/musicbrainz-docker-db:<tag>
where tag is based on Postgres major version and a build sequence number.
Prerequisites:
The version of Postgres must be up-to-date in:
README.md
build/postgres/Dockerfile
build/postgres-prebuilt/Dockerfile
The build sequence must be incremented, if image tag exists already
(for example when only files under build/postgres/ have changed), in:
build/postgres-prebuilt/Dockerfile
EOH
)

if [[ $# -ne 0 && $1 =~ -*h(elp)? ]]
then
echo "$HELP"
exit 0 # EX_OK
elif [[ $# -ne 0 ]]
then
echo >&2 "$SCRIPT_NAME: unrecognized argument: $1"
echo >&2 "Try '$SCRIPT_NAME help' for usage."
exit 64 # EX_USAGE
fi

# Retrieve destination image tag from the default Dockerfile

POSTGRES_VERSION=$(sed -n 's/^ARG POSTGRES_VERSION=\([^ ]*\).*$/\1/p' build/postgres-prebuilt/Dockerfile)
# shellcheck disable=SC2034 # as it used in eval below
DB_BUILD_SEQUENCE=$(sed -n 's/^ARG DB_BUILD_SEQUENCE=\([^ ]*\).*$/\1/p' build/postgres-prebuilt/Dockerfile)
DEST_IMAGE_TAG=$(eval echo "$(sed -n 's/^FROM \([^ ]*\).*$/\1/p' build/postgres-prebuilt/Dockerfile)")

# Check that the Postgres major version is the same in all other files

README_POSTGRES_VERSION=$(sed -n 's/^.*Postgres Version: \[\([^]]*\)\].*$/\1/p' README.md)

if [[ $POSTGRES_VERSION != "$README_POSTGRES_VERSION" ]]
then
echo >&2 "$SCRIPT_NAME: File differs in Postgres major version:"
echo >&2 "$SCRIPT_NAME: * build/postgres-prebuilt/Dockerfile: '$POSTGRES_VERSION'"
echo >&2 "$SCRIPT_NAME: * README.md: '$README_POSTGRES_VERSION'"
echo >&2 "Try '$SCRIPT_NAME help' for usage."
exit 65 # EX_DATAERR
fi

SOURCE_POSTGRES_VERSION=$(sed -n 's/^ARG POSTGRES_VERSION=\([^ ]*\).*$/\1/p' build/postgres/Dockerfile)

if [[ $POSTGRES_VERSION != "$SOURCE_POSTGRES_VERSION" ]]
then
echo >&2 "$SCRIPT_NAME: File differs in Postgres major version:"
echo >&2 "$SCRIPT_NAME: * build/postgres-prebuilt/Dockerfile: '$POSTGRES_VERSION'"
echo >&2 "$SCRIPT_NAME: * build/postgres/Dockerfile: '$SOURCE_POSTGRES_VERSION'"
echo >&2 "Try '$SCRIPT_NAME help' for usage."
exit 65 # EX_DATAERR
fi

# Check that the image tag doesn’t exist already

if $DOCKER_CMD image pull "$DEST_IMAGE_TAG" 2>/dev/null \
|| $DOCKER_CMD image ls "$DEST_IMAGE_TAG" 2>/dev/null | grep -Eq "$DEST_IMAGE_TAG"
then
echo >&2 "$SCRIPT_NAME: image tag exists already: $DEST_IMAGE_TAG"
echo >&2 "Try '$SCRIPT_NAME help' for usage."
exit 65 # EX_DATAERR
fi

# Do the thing

echo Building...

DOCKER_COMPOSE_OPTS='-f docker-compose.yml -f compose/db-own-build.yml'

# shellcheck disable=SC2086 # intentional word splitting of options
$DOCKER_COMPOSE_CMD $DOCKER_COMPOSE_OPTS build --progress=plain --pull db

echo Tagging...

# shellcheck disable=SC2086 # intentional word splitting of options
LOCAL_IMAGE_TAG=$($DOCKER_COMPOSE_CMD $DOCKER_COMPOSE_OPTS config --images | grep -o "musicbrainz-docker_db:$POSTGRES_VERSION$")

$DOCKER_CMD tag "$LOCAL_IMAGE_TAG" "$DEST_IMAGE_TAG"

echo Pushing...

$DOCKER_CMD push "$DEST_IMAGE_TAG"

echo Done.

# vi: set et sts=2 sw=2 ts=2 :
104 changes: 104 additions & 0 deletions admin/repository/prebuild-musicbrainz
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
#!/usr/bin/env bash

set -e -u

# shellcheck source=admin/lib/common.inc.bash
source "$(dirname "${BASH_SOURCE[0]}")/../lib/common.inc.bash"

HELP=$(cat <<EOH
Usage: $SCRIPT_NAME
or: $SCRIPT_NAME --help
Build a new image for the musicbrainz service
from the MusicBrainz Server source code repository
and push it as metabrainz/musicbrainz-docker-musicbrainz:<tag>
where tag is based on MusicBrainz Server version and a build sequence number.
Prerequisites:
The version of MusicBrainz Server must be up-to-date in:
README.md
build/musicbrainz/Dockerfile
build/musicbrainz-prebuilt/Dockerfile
The build sequence must be incremented, if image tag exists already
(for example when only files under build/musicbrainz/ have changed), in:
build/musicbrainz-prebuilt/Dockerfile
EOH
)

if [[ $# -ne 0 && $1 =~ -*h(elp)? ]]
then
echo "$HELP"
exit 0 # EX_OK
elif [[ $# -ne 0 ]]
then
echo >&2 "$SCRIPT_NAME: unrecognized argument: $1"
echo >&2 "Try '$SCRIPT_NAME help' for usage."
exit 64 # EX_USAGE
fi

# Retrieve destination image tag from the default Dockerfile

MUSICBRAINZ_SERVER_VERSION=$(sed -n 's/^ARG MUSICBRAINZ_SERVER_VERSION=\([^ ]*\).*$/\1/p' build/musicbrainz-prebuilt/Dockerfile)
# shellcheck disable=SC2034 # as it used in eval below
MUSICBRAINZ_BUILD_SEQUENCE=$(sed -n 's/^ARG MUSICBRAINZ_BUILD_SEQUENCE=\([^ ]*\).*$/\1/p' build/musicbrainz-prebuilt/Dockerfile)
DEST_IMAGE_TAG=$(eval echo "$(sed -n 's/^FROM \([^ ]*\).*$/\1/p' build/musicbrainz-prebuilt/Dockerfile)")

# Check that the MusicBrainz Server version is the same in all other files

README_MUSICBRAINZ_SERVER_VERSION=$(sed -n 's/^.*Current MB Branch: \[\([^]]*\)\].*$/\1/p' README.md)

if [[ $MUSICBRAINZ_SERVER_VERSION != "$README_MUSICBRAINZ_SERVER_VERSION" ]]
then
echo >&2 "$SCRIPT_NAME: File differs in MusicBrainz Server version:"
echo >&2 "$SCRIPT_NAME: * build/musicbrainz-prebuilt/Dockerfile: '$MUSICBRAINZ_SERVER_VERSION'"
echo >&2 "$SCRIPT_NAME: * README.md: '$README_MUSICBRAINZ_SERVER_VERSION'"
echo >&2 "Try '$SCRIPT_NAME help' for usage."
exit 65 # EX_DATAERR
fi

SOURCE_MUSICBRAINZ_SERVER_VERSION=$(sed -n 's/^ARG MUSICBRAINZ_SERVER_VERSION=\([^ ]*\).*$/\1/p' build/musicbrainz/Dockerfile)

if [[ $MUSICBRAINZ_SERVER_VERSION != "$SOURCE_MUSICBRAINZ_SERVER_VERSION" ]]
then
echo >&2 "$SCRIPT_NAME: File differs in MusicBrainz Server version:"
echo >&2 "$SCRIPT_NAME: * build/musicbrainz-prebuilt/Dockerfile: '$MUSICBRAINZ_SERVER_VERSION'"
echo >&2 "$SCRIPT_NAME: * build/musicbrainz/Dockerfile: '$SOURCE_MUSICBRAINZ_SERVER_VERSION'"
echo >&2 "Try '$SCRIPT_NAME help' for usage."
exit 65 # EX_DATAERR
fi

# Check that the image tag doesn’t exist already

if $DOCKER_CMD image pull "$DEST_IMAGE_TAG" 2>/dev/null \
|| $DOCKER_CMD image ls "$DEST_IMAGE_TAG" 2>/dev/null | grep -Eq "$DEST_IMAGE_TAG"
then
echo >&2 "$SCRIPT_NAME: image tag exists already: $DEST_IMAGE_TAG"
echo >&2 "Try '$SCRIPT_NAME help' for usage."
exit 65 # EX_DATAERR
fi

# Do the thing

echo Building...

DOCKER_COMPOSE_OPTS='-f docker-compose.yml -f compose/musicbrainz-own-build.yml'

# shellcheck disable=SC2086 # intentional word splitting of options
$DOCKER_COMPOSE_CMD $DOCKER_COMPOSE_OPTS build --progress=plain --pull musicbrainz

echo Tagging...

# shellcheck disable=SC2086 # intentional word splitting of options
LOCAL_IMAGE_TAG=$($DOCKER_COMPOSE_CMD $DOCKER_COMPOSE_OPTS config --images | grep -o '[^ ]*musicbrainz$')

$DOCKER_CMD tag "$LOCAL_IMAGE_TAG" "$DEST_IMAGE_TAG"

echo Pushing...

$DOCKER_CMD push "$DEST_IMAGE_TAG"

echo Done.

# vi: set et sts=2 sw=2 ts=2 :
Loading

0 comments on commit f362446

Please sign in to comment.