GitLab Docker 升级
实验场景:自建的 GitLab 代码仓库,使用的是 CentOS7 平台的 Docker 容器中,现需要作服务器迁移并将其版本从【13.3.5】升级至【15.5.3】,建议每升一个版本都作备份,并且升级前最好是查看每个版本之间的兼容问题;
1)确认版本的升级路线,详细可查看 官网,官方下图仅显示了部分示例,具体为每次升级都需要小版本升至最后一个,不能跨版本升级
现版本升级路线情况如下:
13.3.5 -> 13.8.8
-> 13.12.15
-> 14.0.12
-> 14.3.6
-> 14.9.5
-> 14.10.Z
-> 15.0.Z
-> 15.1.Z
(for GitLab instances with multiple web nodes) -> 15.4.0
-> latest 15.Y.Z
PS:经测试在实际操作中 14.0.12
-> 14.3.6
是失败的,需要先升至 14.1.0 -> 14.1.8 -> 14.3.0 -> 14.3.6,通过低版本的数据库转换方可操作
Docker 镜像可提前在 dockerhub 查找
2)升级前先确认版本和备份数据,以防止升级发生意外
| $ docker exec -it gitlab cat /opt/gitlab/embedded/service/gitlab-rails/VERSION
13.3.5
$ docker exec -ti gitlab gitlab-rake gitlab:backup:create
$ docker cp gitlab:/etc/gitlab .
Preparing to copy...
Copying from container - 32.77kB
Copying from container - 65.54kB
Copying from container - 98.3kB
Copying from container - 131.1kB
Copying from container - 140.8kB
Successfully copied 140.8kB to /home/.
$ pwd
/opt/gitlab/config
[Mon Feb 27 admin@pbe config]$ ls -l
total 164
-rw------- 1 root root 121051 Feb 25 11:16 gitlab.rb
-rw------- 1 root root 19515 Feb 27 15:22 gitlab-secrets.json
-rw------- 1 root root 513 Feb 25 11:16 ssh_host_ecdsa_key
-rw-r--r-- 1 root root 179 Feb 25 11:16 ssh_host_ecdsa_key.pub
-rw------- 1 root root 411 Feb 25 11:16 ssh_host_ed25519_key
-rw-r--r-- 1 root root 99 Feb 25 11:16 ssh_host_ed25519_key.pub
-rw------- 1 root root 2602 Feb 25 11:16 ssh_host_rsa_key
-rw-r--r-- 1 root root 571 Feb 25 11:16 ssh_host_rsa_key.pub
drwxr-xr-x 2 root root 6 Feb 25 11:17 trusted-certs
|
3)因本地已作映射,直接停止服务并删除容器
| $ docker stop gitlab;docker rm gitlab
$ docker run --detach \
--hostname 188.188.4.44 \
--publish 443:443 --publish 80:80 --publish 220:22 \
--name gitlab \
--restart always \
--volume /opt/gitlab/config:/etc/gitlab:Z \
--volume /opt/gitlab/logs:/var/log/gitlab:Z \
--volume /opt/gitlab/data:/var/opt/gitlab:Z \
--shm-size 256m \
gitlab/gitlab-ce:13.8.8-ce.0
|
操作前可提前将要升级的镜像下载,以便更快的升级,另注意:每升一个版本都需要确认容器状态和是否成功登录和代码是否正常使用!
| # 注意磁盘容量的控制
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
gitlab/gitlab-ce 15.5.3-ce.0 eec20347402c 3 months ago 2.75GB
gitlab/gitlab-ce 15.4.0-ce.0 fb9eec4d6128 5 months ago 2.72GB
gitlab/gitlab-ce 15.1.6-ce.0 4d1f8cc4f9bc 6 months ago 2.55GB
gitlab/gitlab-ce 15.1.0-ce.0 37bddafb036f 8 months ago 2.54GB
gitlab/gitlab-ce 15.0.2-ce.0 d3223c529831 8 months ago 2.49GB
gitlab/gitlab-ce 14.10.5-ce.0 3d036870c870 8 months ago 2.46GB
gitlab/gitlab-ce 14.9.5-ce.0 c99393c4ee7f 9 months ago 2.45GB
gitlab/gitlab-ce 14.6.2-ce.0 508bfaaaf273 13 months ago 2.36GB
gitlab/gitlab-ce 14.3.6-ce.0 7e6628afc6ac 14 months ago 2.29GB
gitlab/gitlab-ce 14.3.0-ce.0 ca616a263319 17 months ago 2.29GB
gitlab/gitlab-ce 14.1.8-ce.0 de882dcdb543 15 months ago 2.23GB
gitlab/gitlab-ce 14.1.0-ce.0 75d591b81fd7 19 months ago 2.23GB
gitlab/gitlab-ce 14.0.12-ce.0 e799befc0722 15 months ago 2.21GB
gitlab/gitlab-ce 13.12.15-ce.0 c2fd584fe872 16 months ago 2.25GB
gitlab/gitlab-ce 13.8.8-ce.0 0bbf0a4493ba 22 months ago 2.17GB
gitlab/gitlab-ce 13.3.5-ce.0 0c78ed7cea0a 2 years ago 1.92GB
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
3136e2f7f4bf gitlab/gitlab-ce:15.5.3-ce.0 "/assets/wrapper" 45 minutes ago Up 45 minutes (healthy) 0.0.0.0:80->80/tcp, 0.0.0.0:443->443/tcp, 0.0.0.0:220->22/tcp gitlab
$ docker exec -it gitlab cat /opt/gitlab/embedded/service/gitlab-rails/VERSION
15.5.3
|
4)浏览器登录并查看所有用户、项目组、项目是否均可正常使用;
再次重申,升级前请先备份相关数据、配置等,逐级升级前都需要作备份处理,并且查看跨版本之间的更新内容;