docker-compose方式安装的gitlab-ce升级到极狐gitlab

docker-compose方式安装的gitlab-ce升级到极狐gitlab

1. 安装gitlab-ce

创建目录:

mkdir -p /srv/gitlab/config
mkdir -p /srv/gitlab/logs
mkdir -p /srv/gitlab/data

vi gitlab/docker-compose.yml

version: '3.3'
services:
  web:
    image: 'gitlab/gitlab-ce:13.4.4-ce.0'
    restart: always
    hostname: 'gitlab.example.com'
    environment:
      GITLAB_OMNIBUS_CONFIG: |
        external_url 'http://gitlab.example.com'
        # Add any other gitlab.rb configuration here, each on its own line
    ports:
      - '80:80'
      - '443:443'
      - '22:22'
    volumes:
      - '/srv/gitlab/config:/etc/gitlab'
      - '/srv/gitlab/logs:/var/log/gitlab'
      - '/srv/gitlab/data:/var/opt/gitlab'
    shm_size: '256m'

启动:

docker-compose up -d

访问 http://gitlab.example.com/

第一登陆需要设置 root 密码

2. 升级gitlab-ce到极狐gitlab

升级路径:

gitlab-ce 13.4.4 --> gitlab-ce 13.8.8 --> gitlab-ce 13.12.15 --> gitlab-ce 14.0.12 --> gitlab-ce 14.3.6 --> gitlab-ce 14.9.5 --> gitlab-ce 14.10.5 --> gitlab-jh 14.10.5

升级路径查询:Upgrade Path (gitlab-com.gitlab.io)

2.1 拉取新镜像

根据升级路径,建议先把所有镜像提前拉取

docker pull gitlab/gitlab-ce:13.8.8-ce.0
docker pull gitlab/gitlab-ce:13.12.15-ce.0
docker pull gitlab/gitlab-ce:14.0.12-ce.0
docker pull gitlab/gitlab-ce:14.3.6-ce.0
docker pull gitlab/gitlab-ce:14.9.5-ce.0
docker pull gitlab/gitlab-ce:14.10.5-ce.0
docker pull registry.gitlab.cn/omnibus/gitlab-jh:14.10.5

2.2 升级前检查

升级前建议检查 gitlab 运行状况

# 通用检查
docker exec -t gitlab_web_1 gitlab-rake gitlab:check

# 密钥检查
docker exec -t gitlab_web_1 gitlab-rake gitlab:doctor:secrets
  • gitlab_web_1 为 gitlab 实例容器

2.3 备份数据

升级第一个版本 gitlab-ce 13.8.8 时,强烈建议先备份

docker exec -t gitlab_web_1 gitlab-rake gitlab:backup:create   # 备份数据
docker exec -t gitlab_web_1 gitlab-ctl backup-etc   # 备份配置文件

备份的数据:

[root@localhost backups]# pwd
/srv/gitlab/data/backups
[root@localhost backups]# 
[root@localhost backups]# ls -l
total 232
-rw------- 1 chrony polkitd 235520 Jul 13 12:25 1657686311_2022_07_13_13.4.4_gitlab_backup.tar

备份的配置:

[root@localhost config_backup]# pwd
/srv/gitlab/config/config_backup
[root@localhost config_backup]# ls -l
total 140
-rw------- 1 root root 143360 Jul 13 12:24 gitlab_config_1657686249_2022_07_13.tar

建议先把备份文件复制到其他主机

2.4 开始升级

2.4.1 首先停止部分服务

需要首先停止 puma 与 sidekiq 服务

docker exec -t gitlab_web_1 gitlab-ctl stop puma
docker exec -t gitlab_web_1 gitlab-ctl stop sidekiq

确认状态

docker exec -t gitlab_web_1 gitlab-ctl status

正常停止后,访问 gitlab 会出现 502

2.4.2 确认后台迁移任务

非常重要:为了确保升级的顺利进行,必须在升级前确认后台迁移任务均为 0 时,才可以开始升级。根据您当前版本的不同,操作方式可能不同,一共需要确认2种任务:Background migrations、Batched background migrations(14.0版本及以上)

2.4.2.1 Background migrations

gitlab version >= 15.1

docker exec -t gitlab_web_1 gitlab-rails runner -e production 'puts Gitlab::BackgroundMigration.remaining'

docker exec -t gitlab_web_1 gitlab-rails runner -e production 'puts Gitlab::Database::BackgroundMigration::BatchedMigration.queued.count'

14.8 <= gitlab version < 15.1

docker exec -t gitlab_web_1 gitlab-rails runner -e production 'puts Gitlab::BackgroundMigration.remaining'

docker exec -t gitlab_web_1 gitlab-rails runner -e production 'puts Gitlab::Database::BackgroundMigrationJob.pending.count'
  • 注意:puts Gitlab::BackgroundMigration.remainingputs Gitlab::Database::BackgroundMigrationJob.pending.count 为一行命令,未换行

gitlab version == 14.7

docker exec -t gitlab_web_1 gitlab-rails runner -e production 'puts Gitlab::BackgroundMigration.remaining'
docker exec -t gitlab_web_1 gitlab-rails runner -e production 'puts Gitlab::Database::BackgroundMigrationJob.pending'

gitlab version == 14.6

docker exec -t gitlab_web_1 gitlab-rails runner -e production 'puts Gitlab::BackgroundMigration.remaining'
docker exec -t gitlab_web_1 gitlab-rails runner -e production 'puts Gitlab::BackgroundMigration.pending'

12.9 <= gitlab version < 14.6

docker exec -t gitlab_web_1 gitlab-rails runner -e production 'puts Gitlab::BackgroundMigration.remaining'

gitlab version <= 12.8

参考:如何从GitLab CE/EE升级到极狐GitLab JH版本 - Docker | GitLab (gitlab-devops.com)

2.4.2.2 Batched background migrations

如果您 GitLab 版本高于14.0,还需要执行如下操作:

方法一:

docker exec -t gitlab_web_1 gitlab-psql -c 'select job_class_name, table_name, column_name, job_arguments from batched_background_migrations where status <> 3;'

方法二:

登陆web页面:Menu > Admin > Monitoring > Background Migrations

  • 当所有作业状态为 Finished 是即可以继续升级

2.4.3 编辑 docker-compose.yml

vi gitlab/docker-compose.yml

version: '3.3'
services:
  web:
    #image: 'gitlab/gitlab-ce:13.4.4-ce.0'
    image: 'gitlab/gitlab-ce:13.8.8-ce.0'
    restart: always
    hostname: 'gitlab.example.com'
    environment:
      GITLAB_OMNIBUS_CONFIG: |
        external_url 'http://gitlab.example.com'
        # Add any other gitlab.rb configuration here, each on its own line
    ports:
      - '80:80'
      - '443:443'
      - '22:22'
    volumes:
      - '/srv/gitlab/config:/etc/gitlab'
      - '/srv/gitlab/logs:/var/log/gitlab'
      - '/srv/gitlab/data:/var/opt/gitlab'
    shm_size: '256m'

将其中 image 修改为升级路径中下一个版本

2.4.4 正式升级

docker-compose pull
docker-compose up -d
  • 执行后会重建容器 gitlab_web_1

等待容器启动完成,然后根据 2.4.2 章节在确认下后台迁移任务是否都完成了,后台任务迁移完成才算正在完全升级完成。

升级完成后建议根据 2.2 章节检查一下。

后面版本根据升级路径按照 2.4 章节一直循环升级到极狐gitlab v14.10.5即可,不再赘述

posted @ 2022-07-14 08:19  leffss  阅读(884)  评论(0编辑  收藏  举报