はじめに

テストで使用しているGitLabのバージョンが古いのでアップグレードを実施してみる。

環境

1
2
3
4
5
6
7
Windows 10 Professional
WSL2 (Ubuntu22.04 LTS)
docker version 23.0.5
Docker Compose version v2.17.3

gitlab-ce:15.10.2-ce.0
gitlab-runner Version:      15.11.0

参考情報

以前の記事 で作成したGitLabの環境のため、下記の compose.ymlで動作している。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
services:
  gitlab:
    build: ./gitlab
    hostname: 'gitlab.example.com'
    environment:
      GITLAB_OMNIBUS_CONFIG:
        external_url 'http://gitlab.example.com/'
    volumes:
      - '$GITLAB_HOME/config:/etc/gitlab'
      - '$GITLAB_HOME/logs:/var/log/gitlab'
      - '$GITLAB_HOME/data:/var/opt/gitlab'
    ports:
      - '80:80'
      - '443:443'
      - '22:22'
    shm_size: '256m'
    restart: unless-stopped
  runner:
    image: 'gitlab/gitlab-runner:latest'
    restart: always
    volumes:
      - ./srv/gitlab-runner/config:/etc/gitlab-runner
      - /var/run/docker.sock:/var/run/docker/sock
    ports:
      - "8093:8093"

準備

下記を参考に、アップグレードを実施する。

バックアップの取得

GitLabをバックアップする

1
docker compose exec -t gitlab gitlab-backup create

こんな感じでできている↓

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
2023-06-11 04:21:47 UTC -- Dumping database ... 
Dumping PostgreSQL database gitlabhq_production ... [DONE]
2023-06-11 04:21:51 UTC -- Dumping database ... done
2023-06-11 04:21:51 UTC -- Dumping repositories ... 
{"command":"create","gl_project_path":"gitlab-instance-295fc39a/Monitoring","level":"info","msg":"started create","relative_path":"@hashed/6b/86/6b86b273ff34fce19d6b804eff5a3f5747ada4eaa22f1d49c01e52ddb7875b4b.git","storage_name":"default","time":"2023-06-11T04:21:52.040Z"}
{"command":"create","error":"manager: repository empty: repository skipped","gl_project_path":"gitlab-instance-295fc39a/Monitoring","level":"warning","msg":"skipped create","relative_path":"@hashed/6b/86/6b86b273ff34fce19d6b804eff5a3f5747ada4eaa22f1d49c01e52ddb7875b4b.git","storage_name":"default","time":"2023-06-11T04:21:52.108Z"}
{"command":"create","gl_project_path":"gitlab-instance-295fc39a/Monitoring.wiki","level":"info","msg":"started create","relative_path":"@hashed/6b/86/6b86b273ff34fce19d6b804eff5a3f5747ada4eaa22f1d49c01e52ddb7875b4b.wiki.git","storage_name":"default","time":"2023-06-11T04:21:52.201Z"}
{"command":"create","gl_project_path":"gitlab-instance-295fc39a/Monitoring","level":"info","msg":"started create","relative_path":"@hashed/6b/86/6b86b273ff34fce19d6b804eff5a3f5747ada4eaa22f1d49c01e52ddb7875b4b.design.git","storage_name":"default","time":"2023-06-11T04:21:52.203Z"}
{"command":"create","error":"manager: repository empty: repository skipped","gl_project_path":"gitlab-instance-295fc39a/Monitoring","level":"warning","msg":"skipped create","relative_path":"@hashed/6b/86/6b86b273ff34fce19d6b804eff5a3f5747ada4eaa22f1d49c01e52ddb7875b4b.design.git","storage_name":"default","time":"2023-06-11T04:21:52.211Z"}
{"command":"create","gl_project_path":"gitlab-instance-295fc39a/test-runner","level":"info","msg":"started create","relative_path":"@hashed/d4/73/d4735e3a265e16eee03f59718b9b5d03019c07d8b6c51f90da3a666eec13ab35.git","storage_name":"default","time":"2023-06-11T04:21:52.211Z"}
{"command":"create","error":"manager: repository empty: repository skipped","gl_project_path":"gitlab-instance-295fc39a/Monitoring.wiki","level":"warning","msg":"skipped create","relative_path":"@hashed/6b/86/6b86b273ff34fce19d6b804eff5a3f5747ada4eaa22f1d49c01e52ddb7875b4b.wiki.git","storage_name":"default","time":"2023-06-11T04:21:52.211Z"}
{"command":"create","gl_project_path":"gitlab-instance-295fc39a/test-runner.wiki","level":"info","msg":"started create","relative_path":"@hashed/d4/73/d4735e3a265e16eee03f59718b9b5d03019c07d8b6c51f90da3a666eec13ab35.wiki.git","storage_name":"default","time":"2023-06-11T04:21:52.212Z"}
{"command":"create","error":"manager: repository empty: repository skipped","gl_project_path":"gitlab-instance-295fc39a/test-runner.wiki","level":"warning","msg":"skipped create","relative_path":"@hashed/d4/73/d4735e3a265e16eee03f59718b9b5d03019c07d8b6c51f90da3a666eec13ab35.wiki.git","storage_name":"default","time":"2023-06-11T04:21:52.218Z"}
{"command":"create","gl_project_path":"gitlab-instance-295fc39a/test-runner","level":"info","msg":"started create","relative_path":"@hashed/d4/73/d4735e3a265e16eee03f59718b9b5d03019c07d8b6c51f90da3a666eec13ab35.design.git","storage_name":"default","time":"2023-06-11T04:21:52.218Z"}
{"command":"create","error":"manager: repository empty: repository skipped","gl_project_path":"gitlab-instance-295fc39a/test-runner","level":"warning","msg":"skipped create","relative_path":"@hashed/d4/73/d4735e3a265e16eee03f59718b9b5d03019c07d8b6c51f90da3a666eec13ab35.design.git","storage_name":"default","time":"2023-06-11T04:21:52.222Z"}
{"command":"create","gl_project_path":"gitlab-instance-295fc39a/test-runner","level":"info","msg":"completed create","relative_path":"@hashed/d4/73/d4735e3a265e16eee03f59718b9b5d03019c07d8b6c51f90da3a666eec13ab35.git","storage_name":"default","time":"2023-06-11T04:21:52.307Z"}
2023-06-11 04:21:52 UTC -- Dumping repositories ... done
2023-06-11 04:21:52 UTC -- Dumping uploads ... 
2023-06-11 04:21:52 UTC -- Dumping uploads ... done
2023-06-11 04:21:52 UTC -- Dumping builds ... 
2023-06-11 04:21:52 UTC -- Dumping builds ... done
2023-06-11 04:21:52 UTC -- Dumping artifacts ... 
2023-06-11 04:21:52 UTC -- Dumping artifacts ... done
2023-06-11 04:21:52 UTC -- Dumping pages ... 
2023-06-11 04:21:52 UTC -- Dumping pages ... done
2023-06-11 04:21:52 UTC -- Dumping lfs objects ... 
2023-06-11 04:21:52 UTC -- Dumping lfs objects ... done
2023-06-11 04:21:52 UTC -- Dumping terraform states ... 
2023-06-11 04:21:52 UTC -- Dumping terraform states ... done
2023-06-11 04:21:52 UTC -- Dumping container registry images ... [DISABLED]
2023-06-11 04:21:52 UTC -- Dumping packages ... 
2023-06-11 04:21:52 UTC -- Dumping packages ... done
2023-06-11 04:21:52 UTC -- Creating backup archive: 1686457307_2023_06_11_15.10.2_gitlab_backup.tar ... 
2023-06-11 04:21:52 UTC -- Creating backup archive: 1686457307_2023_06_11_15.10.2_gitlab_backup.tar ... done
2023-06-11 04:21:52 UTC -- Uploading backup archive to remote storage  ... [SKIPPED]
2023-06-11 04:21:52 UTC -- Deleting old backups ... [SKIPPED]
2023-06-11 04:21:52 UTC -- Deleting tar staging files ... 
2023-06-11 04:21:52 UTC -- Cleaning up /var/opt/gitlab/backups/backup_information.yml
2023-06-11 04:21:52 UTC -- Cleaning up /var/opt/gitlab/backups/db
2023-06-11 04:21:52 UTC -- Cleaning up /var/opt/gitlab/backups/repositories
2023-06-11 04:21:52 UTC -- Cleaning up /var/opt/gitlab/backups/uploads.tar.gz
2023-06-11 04:21:52 UTC -- Cleaning up /var/opt/gitlab/backups/builds.tar.gz
2023-06-11 04:21:52 UTC -- Cleaning up /var/opt/gitlab/backups/artifacts.tar.gz
2023-06-11 04:21:52 UTC -- Cleaning up /var/opt/gitlab/backups/pages.tar.gz
2023-06-11 04:21:52 UTC -- Cleaning up /var/opt/gitlab/backups/lfs.tar.gz
2023-06-11 04:21:52 UTC -- Cleaning up /var/opt/gitlab/backups/terraform_state.tar.gz
2023-06-11 04:21:52 UTC -- Cleaning up /var/opt/gitlab/backups/packages.tar.gz
2023-06-11 04:21:52 UTC -- Deleting tar staging files ... done
2023-06-11 04:21:52 UTC -- Deleting backups/tmp ... 
2023-06-11 04:21:52 UTC -- Deleting backups/tmp ... done
2023-06-11 04:21:52 UTC -- Warning: Your gitlab.rb and gitlab-secrets.json files contain sensitive data 
and are not included in this backup. You will need these files to restore a backup.
Please back them up manually.
2023-06-11 04:21:52 UTC -- Backup 1686457307_2023_06_11_15.10.2 is done.
2023-06-11 04:21:52 +0000 -- Deleting backup and restore lock file

※リストアについては下記

データベースのバックアップを作成する

1
docker compose exec -t gitlab gitlab-backup create SKIP=artifacts,repositories,registry,uploads,builds,pages,lfs,packages,terraform_state

こんな感じでできた。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
2023-06-11 04:30:47 UTC -- Dumping database ... 
Dumping PostgreSQL database gitlabhq_production ... [DONE]
2023-06-11 04:30:51 UTC -- Dumping database ... done
2023-06-11 04:30:51 UTC -- Dumping repositories ... [SKIPPED]
2023-06-11 04:30:51 UTC -- Dumping uploads ... [SKIPPED]
2023-06-11 04:30:51 UTC -- Dumping builds ... [SKIPPED]
2023-06-11 04:30:51 UTC -- Dumping artifacts ... [SKIPPED]
2023-06-11 04:30:51 UTC -- Dumping pages ... [SKIPPED]
2023-06-11 04:30:51 UTC -- Dumping lfs objects ... [SKIPPED]
2023-06-11 04:30:51 UTC -- Dumping terraform states ... [SKIPPED]
2023-06-11 04:30:51 UTC -- Dumping container registry images ... [DISABLED]
2023-06-11 04:30:51 UTC -- Dumping packages ... [SKIPPED]
2023-06-11 04:30:51 UTC -- Creating backup archive: 1686457847_2023_06_11_15.10.2_gitlab_backup.tar ... 
2023-06-11 04:30:51 UTC -- Creating backup archive: 1686457847_2023_06_11_15.10.2_gitlab_backup.tar ... done
2023-06-11 04:30:51 UTC -- Uploading backup archive to remote storage  ... [SKIPPED]
2023-06-11 04:30:51 UTC -- Deleting old backups ... [SKIPPED]
2023-06-11 04:30:51 UTC -- Deleting tar staging files ... 
2023-06-11 04:30:51 UTC -- Cleaning up /var/opt/gitlab/backups/backup_information.yml
2023-06-11 04:30:51 UTC -- Cleaning up /var/opt/gitlab/backups/db
2023-06-11 04:30:51 UTC -- Deleting tar staging files ... done
2023-06-11 04:30:51 UTC -- Deleting backups/tmp ... 
2023-06-11 04:30:51 UTC -- Deleting backups/tmp ... done
2023-06-11 04:30:51 UTC -- Warning: Your gitlab.rb and gitlab-secrets.json files contain sensitive data 
and are not included in this backup. You will need these files to restore a backup.
Please back them up manually.
2023-06-11 04:30:51 UTC -- Backup 1686457847_2023_06_11_15.10.2 is done.
2023-06-11 04:30:51 +0000 -- Deleting backup and restore lock file

バックアップがあることを確認する

1
2
3
4
5
6
root@gitlab:/var/opt/gitlab/backups# ls -al
total 860
drwx------  2 git  root   4096 Jun 11 04:30 .
drwxr-xr-x 20 root root   4096 Jun 11 04:16 ..
-rw-------  1 git  git  450560 Jun 11 04:21 1686457307_2023_06_11_15.10.2_gitlab_backup.tar
-rw-------  1 git  git  419840 Jun 11 04:30 1686457847_2023_06_11_15.10.2_gitlab_backup.tar

docker cp でホスト側にコピーをしたいので、 docker ps でコンテナIDを取得する。

1
2
3
CONTAINER ID   IMAGE                         COMMAND                  CREATED        STATUS                    PORTS                                                          NAMES
6141a64b13f0   gitlab/gitlab-runner:latest   "/usr/bin/dumb-init …"   21 hours ago   Up 59 minutes             0.0.0.0:8093->8093/tcp                                         gitlab-docker-runner-1
ae3a14305e26   gitlab-docker-gitlab          "/assets/wrapper"        21 hours ago   Up 53 minutes (healthy)   0.0.0.0:22->22/tcp, 0.0.0.0:80->80/tcp, 0.0.0.0:443->443/tcp   gitlab-docker-gitlab-1

gitlab-docker-gitlabが本体なので、ae3a14305e26 を控える。

1
2
docker cp ae3a14305e26:/var/opt/gitlab/backups/1686457307_2023_06_11_15.10.2_gitlab_backup.tar .
docker cp ae3a14305e26:/var/opt/gitlab/backups/1686457847_2023_06_11_15.10.2_gitlab_backup.tar .

アップグレード 15.10.x→15.11.x

アップグレードパスの確認

そのまま最新にアップデートということはできないことがあり、アップグレードパスを確認する必要がある。

今回は、15.10系から16.x系にアップグレードするので、 15.11.x を経由する必要がある。

GitLab 15: 15.0.5> 15.1.6(複数の Web ノードを持つ GitLab インスタンスの場合) > 15.4.6>15.11.x GitLab 16:最新16.Y.Z

を参照した。

イメージタグの変更

1
2
-FROM gitlab/gitlab-ce:15.10.2-ce.0
+FROM gitlab/gitlab-ce:15.11.0-ce.0

アップグレードの実施

1
2
3
4
5
# イメージをプルする
docker compose pull

# コンテナの立ち上げ
docker compose up -d --build

※公式の手順では docker compose up -d だが、 GitLabymlではなくDockerfileに記載しているので、 --build を付ける必要があった。

アップグレードの確認

↓できた。 upgrade-15.11.0 15.11.0-runner-active.png

アップグレード (15.11.x→16.x)

イメージタグの変更

1
2
-FROM gitlab/gitlab-ce:15.11.0-ce.0
+FROM gitlab/gitlab-ce:16.0.4-ce.0

アップグレードの実施

1
2
3
4
5
# イメージをプルする
docker compose pull

# コンテナの立ち上げ
docker compose up -d --build

アップグレードの確認

↓できた。 upgrade-16.04.0 15.11.0-runner-active.png

後始末

下記で、不要なリソースを削除する。

1
docker system prune

参考

おわりに

DockerでのGitLabのアップデートは初めてだったので手順の確認の意味も含めて実施した。
次回もGitLabを使用した何かをやりたい。