Skip to content

Instantly share code, notes, and snippets.

@tbarbette
Last active December 2, 2025 13:52
Show Gist options
  • Select an option

  • Save tbarbette/f1ab27f4f25125f7a482823761c778c3 to your computer and use it in GitHub Desktop.

Select an option

Save tbarbette/f1ab27f4f25125f7a482823761c778c3 to your computer and use it in GitHub Desktop.
Simply upgrade Gitlab when using docker-compose
#!/bin/bash
# GitLab is very picky on upgrade path. There is a manual online tool to get the
# upgrade path but I don't want to do it manually. This script will look for the
# current version and upgrade gitlab version to the next one.
# There are tools like renovate or maybe watchtower to do that in a "pro" way but
# they seemed quite complex. This simply works.
set -e
SERVICE_NAME="tom-gitlab"
COMPOSE_FILE="docker-compose.yml"
export GITLAB_HOME="/srv/gitlab"
UPGRADE_PATH_URL="https://gitlab-com.gitlab.io/support/toolbox/upgrade-path/path.json"
echo "Creating backup..."
docker compose exec -t $SERVICE_NAME gitlab-backup create
echo "Getting current running version"
q=$(docker compose ps -q)
echo "Container id is $q"
CURRENT_VERSION=$(docker exec $q \
cat /opt/gitlab/version-manifest.json | jq -r '.build_version')
echo "Current version: $CURRENT_VERSION"
if [ -z "$CURRENT_VERSION" -o "$CURRENT_VERSION" = "null" ] ; then
exit 1
fi
echo "Fetching GitLab upgrade path..."
TMP_JSON=path.json
wget "$UPGRADE_PATH_URL"
#Function to compare versions numerically
echo "Searching for the next valid upgrade from path.json..."
# Find the next version greater than current_version
NEXT_VERSION=$(jq -r --arg cur "$CURRENT_VERSION" '
def natural_sort($a; $b):
($a | split(".") | map(tonumber)) as $a_parts |
($b | split(".") | map(tonumber)) as $b_parts |
($a_parts | length) as $a_len |
($b_parts | length) as $b_len |
($a_len as $len | range(0; $len) |
. as $i |
($a_parts[$i] // 0) as $a_part |
($b_parts[$i] // 0) as $b_part |
($a_part - $b_part)) |
first;
.all
| map(select(. > $cur))
| sort_by(natural_sort)
| .[0]
' path.json)
echo "Next allowed upgrade: $NEXT_VERSION"
rm "$TMP_JSON"
if [[ -z "$NEXT_VERSION" ]]; then
echo "🎉 You are already on the latest known GitLab version."
exit 0
fi
# Update docker-compose.yml
sed -i "s/gitlab-ce:[0-9.]*/gitlab-ce:$NEXT_VERSION/" $COMPOSE_FILE
echo "Updated docker-compose.yml → $NEXT_VERSION"
docker compose pull $SERVICE_NAME
docker compose up -d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment