服务器原有使用 docker 部署的 gitlab,
需要将其从版本 14.1.0 升级到 15.0.0,
升级过程中还需要解决升级14.10.0版本的报错问题。
# 原 yml 文件
# docker stack deploy --with-registry-auth -c /data/gitlab/gitlab.yml arno
# https://docs.docker.com/compose/compose-file/compose-versioning/
# https://github.com/compose-spec/compose-spec/blob/master/spec.md
# Compose file format 3.8, Docker Engine release 19.03.0+
version: "3.8"
services:
gitlab:
image: gitlab/gitlab-ce:14.1.0-ce.0
networks:
- default
volumes:
- "/data/config/Shanghai:/etc/localtime"
- "/data/gitlab/config:/etc/gitlab"
- "/data/gitlab/data:/var/opt/gitlab"
- "/data/gitlab/logs:/var/log/gitlab"
deploy:
labels:
host: your-swarm-host
replicas: 1
restart_policy:
condition: on-failure
networks:
default:
external: true
name: your-swarm-net
# 备份 gitlab 配置文件
cd /data/gitlab
tar -czvf gitlab-config-20220524.tar.gz config
# 备份 gitlab 数据
DOCKER_ID=`docker ps | grep gitlab | awk '{print $1}'`
docker exec -it ${DOCKER_ID} gitlab-rake gitlab:backup:create
# 升级 14.1.0 > latest
# 获取最新镜像 gitlab/gitlab-ce:latest
sed -i 's/14.1.0-ce.0/latest/g' /data/gitlab/gitlab.yml
docker pull gitlab/gitlab-ce:latest
docker stack deploy --with-registry-auth -c /data/gitlab/gitlab.yml arno
docker service logs -f arno_gitlab
docker service ls
# 升级完成后为 4.6.1 的版本
# 再按照如下顺序逐步升级
# 过程中可能需要重新启动 nginx 容器
# 再升级为 14.8.0
sed -i 's/latest/14.8.0-ce.0/g' /data/gitlab/gitlab.yml
docker pull gitlab/gitlab-ce:14.8.0-ce.0
docker stack deploy --with-registry-auth -c /data/gitlab/gitlab.yml arno
# 再升级为 14.9.0
sed -i 's/14.8.0/14.9.0/g' /data/gitlab/gitlab.yml
docker pull gitlab/gitlab-ce:14.9.0-ce.0
docker stack deploy --with-registry-auth -c /data/gitlab/gitlab.yml arno
# 再升级为 14.9.4
sed -i 's/14.9.0/14.9.4/g' /data/gitlab/gitlab.yml
docker pull gitlab/gitlab-ce:14.9.4-ce.0
docker stack deploy --with-registry-auth -c /data/gitlab/gitlab.yml arno
直接升级会报错:
Running handlers:
There was an error running gitlab-ctl reconfigure:
rails_migration[gitlab-rails] (gitlab::database_migrations line 51) had an error: Mixlib::ShellOut::ShellCommandFailed: bash[migrate gitlab-rails database]
(/opt/gitlab/embedded/cookbooks/cache/cookbooks/gitlab/resources/rails_migration.rb line 16)
had an error: Mixlib::ShellOut::ShellCommandFailed: Command execution failed. STDOUT/STDERR suppressed for sensitive resource Running handlers complete Chef Infra Client failed. 161 resources updated in 01 minutes 44 seconds
参考如下文章:
- 2022-05-18 Failed to upgrade GitLab ee 14.9.4 –> 14.10.X (Docker)
- 2022-04-25 rails_migration[gitlab-rails] action run fails from 14.8.2 to 14.10.0 (Ubuntu 20.04)
# 再升级为 14.10.0
docker service rm arno_gitlab
# 修改 /data/gitlab/config/gitlab.rb
# 在 # gitlab_rails['auto_migrate'] = true 下面增加: gitlab_rails['auto_migrate'] = false
# 增加一个空文件 /data/gitlab/config/skip-auto-reconfigure
sed -i 's/14.9.4/14.10.0/g' /data/gitlab/gitlab.yml
docker pull gitlab/gitlab-ce:14.10.0-ce.0
docker stack deploy --with-registry-auth -c /data/gitlab/gitlab.yml arno
# 等待 3分钟左右待gitlab容器启动
docker service ls
DOCKER_ID=`docker ps | grep gitlab | awk '{print $1}'`
docker exec -it ${DOCKER_ID} /bin/bash
# 手动升级
gitlab-rake db:migrate
gitlab-rake gitlab:background_migrations:finalize[ProjectNamespaces::BackfillProjectNamespaces,projects,id,'[null\,"up"]']
gitlab-rake db:migrate
gitlab-rake db:migrate:status
# 出行 gitlab Reconfigured! 提示
# 确认所有升级项全部是 up 状态后
gitlab-ctl reconfigure
# 退出容器
docker service rm arno_gitlab
# 修改 /data/gitlab/config/gitlab.rb
# 去掉 gitlab_rails['auto_migrate'] = false
# 删除 空文件 /data/gitlab/config/skip-auto-reconfigure
# 便于后续自动升级
docker stack deploy --with-registry-auth -c /data/gitlab/gitlab.yml arno
# 再升级为 15.0.0
sed -i 's/14.10.0/15.0.0/g' /data/gitlab/gitlab.yml
docker pull gitlab/gitlab-ce:15.0.0-ce.0
docker stack deploy --with-registry-auth -c /data/gitlab/gitlab.yml arno
# 再升级为 15.0.0
sed -i 's/14.10.0/15.0.0/g' /data/gitlab/gitlab.yml
docker pull gitlab/gitlab-ce:15.0.0-ce.0
docker stack deploy --with-registry-auth -c /data/gitlab/gitlab.yml arno
# 删除多余的docker gitlab镜像文件
docker rmi bb81563932ce b6d52c0ee5cf 6de118597222 50a2f66dea2b 47e6c191a128 467b0e5b3fe1 46cd6954564a