Skip to content

Instantly share code, notes, and snippets.

@tabletcorry
Last active September 15, 2023 18:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tabletcorry/7e51ee6bafa7fd3c0dac3f9be61c12a3 to your computer and use it in GitHub Desktop.
Save tabletcorry/7e51ee6bafa7fd3c0dac3f9be61c12a3 to your computer and use it in GitHub Desktop.
Mastodon upgrade to nightly. Call upgrade.sh as root
#!/bin/bash
export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"
set -euxo pipefail
cd /home/mastodon/live
RAILS_ENV=production bundle exec rails db:migrate
#!/bin/bash
export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"
set -euxo pipefail
nightly_sha=$1
#tag=$(echo $2 | sed -E 's/([0-9]{4})-([0-9]{2})-([0-9]{2})/\1\2\3/')
tag=$2
echo $tag
# The upgrade process consumes a great deal of CPU/Memory/IO so tell the system this script is not a priority
renice -n 19 $$
ionice -c 3 -p $$
cd /home/mastodon/live
git checkout main
git pull
git checkout $nightly_sha
# Check if there is a new Ruby version required
if ! rbenv version; then
git -C /home/mastodon/.rbenv/plugins/ruby-build pull
RUBY_CONFIGURE_OPTS=--with-jemalloc rbenv install $(cat .ruby_version)
fi
# Install dependencies
bundle install
yarn install --production --frozen-lockfile
#RAILS_ENV=production bundle exec rails assets:precompile
SKIP_POST_DEPLOYMENT_MIGRATIONS=true RAILS_ENV=production bundle exec rails db:migrate
sed -i "s/MASTODON_VERSION_SUFFIX=.*/MASTODON_VERSION_SUFFIX='+$tag'/" .env.production
#!/usr/bin/env bash
set -euxo pipefail
# The upgrade process consumes a great deal of CPU/Memory/IO so tell the system this script is not a priority
renice -n 19 $$
ionice -c 3 -p $$
systemctl stop mastodon-streaming mastodon-sidekiq
tag=$1
if [ $# -eq 1 ]; then
# Requires installation of the following packages: podman jq
podman pull ghcr.io/mastodon/mastodon:$tag
nightly_sha=$(podman inspect ghcr.io/mastodon/mastodon:$tag | jq -r '.[0].Config.Labels."org.opencontainers.image.revision"')
image_tag=$(podman image list --format="{{.ID}}")
mount_path=$(podman image mount $image_tag)
rsync -r $mount_path/opt/mastodon/public/packs/ /home/mastodon/live/public/packs/
podman image unmount $image_tag
podman image prune -af
else
nightly_sha=$2
fi
sudo -i -u mastodon /home/mastodon/upgrade-user.sh $nightly_sha $tag
# This is broad because asset precompilation swaps out most of my memory on a small box
# So we reload nginx/redis to keep everything snappy (and they restart instantly anyways)
systemctl restart redis nginx mastodon-web mastodon-streaming mastodon-sidekiq
sudo -i -u mastodon /home/mastodon/upgrade-user-2.sh
systemctl start mastodon-streaming mastodon-sidekiq
echo "All Done"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment