LoginSignup
2
0

More than 1 year has passed since last update.

Ubuntuの自動のアップデートでgitlab-runnerをアップデートする

Last updated at Posted at 2020-10-26

毎度、ググっても出てこない小ネタを取り扱っております。
本記事は個人的な見解であり、筆者の所属するいかなる団体にも関係ございません。

0. はじめに

GitLabサーバーは毎日自動的にアップデートするようにしていて、Ubuntu OSの方も自動的にアップデートしていたのですが、GitLab Runnerは自動アップデートになっていなかったので対応してみました。
GitLab Runnerサーバーのアップデートは時々なので手作業でやってもよかったのですが、台数も多く13系になって以降トラブルもなかったので、自動アップデートにすることにしました。
(と言っても2台分は自動アップデートにしていません)

1. 前提条件

OSのunattended-upgradeが設定されていること
※unattended-upgradeの機構を使うのでこれが設定されていなければ動きません。

第173回 管理者の操作を待たずにアップデートするPolicyKitの設定・unattended-upgrade:Ubuntu Weekly Recipe|gihyo.jp … 技術評論社
https://gihyo.jp/admin/serial/01/ubuntu-recipe/0173

2. GitLab RunnerのOriginとSuiteを見つける

以下を参照するとパッケージのOriginとSuiteが必要と言うことなので調べる
Upgrading External Packages with unattended-upgrade - Linux Audit
https://linux-audit.com/upgrading-external-packages-with-unattended-upgrade/

2-1. パッケージの詳細を探す

以下のディレクトリから
/var/lib/apt/lists/
GitLab Runnerに関するファイルを探す

# ls -la /var/lib/apt/lists/  | grep gitlab
-rw-r--r-- 1 root root    23433 10月 20 21:52 packages.gitlab.com_runner_gitlab-runner_ubuntu_dists_bionic_InRelease
-rw-r--r-- 1 root root    60718 10月 20 21:52 packages.gitlab.com_runner_gitlab-runner_ubuntu_dists_bionic_main_binary-amd64_Packages
-rw-r--r-- 1 root root    60574 10月 20 21:52 packages.gitlab.com_runner_gitlab-runner_ubuntu_dists_bionic_main_binary-i386_Packages

InReleaseで終わるファイルを閲覧する

less /var/lib/apt/lists/packages.gitlab.com_runner_gitlab-runner_ubuntu_dists_bionic_InRelease
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

Origin: packages.gitlab.com/runner/gitlab-runner
Label: gitlab-runner
Date: Tue, 20 Oct 2020 12:52:32 +0000
Suite: bionic
Codename: bionic
----以下略----

Originはpackages.gitlab.com/runner/gitlab-runnerで、
Suiteは、bionicのようだ

3. 50unattended-upgradesファイルを修正する

/etc/apt/apt.conf.d/50unattended-upgradesファイルのUnattended-Upgrade::Allowed-Origins { に以下の1行を追加する

        "packages.gitlab.com/runner/gitlab-runner:${distro_codename}";

こんな風になるはず

image.png

4. テストしてみる


$ sudo unattended-upgrade --dry-run -v -d
Initial blacklisted packages:
Initial whitelisted packages:
Starting unattended upgrades script
Allowed origins are: o=Ubuntu,a=bionic, o=Ubuntu,a=bionic-security, o=UbuntuESMApps,a=bionic-apps-security, o=UbuntuESM,a=bionic-infra-security, o=Ubuntu,a=bionic-updates, o=packages.gitlab.com/runner/gitlab-runner,a=bionic
----Kernerlについては省略----
Checking: gitlab-runner ([<Origin component:'main' archive:'bionic' origin:'packages.gitlab.com/runner/gitlab-runner' label:'gitlab-runner' site:'packages.gitlab.com' isTrusted:True>])
pkgs that look like they should be upgraded: gitlab-runner
Fetched 0 B in 0s (0 B/s)
fetch.run() result: 0
<apt_pkg.AcquireItem object:Status: 2 Complete: 1 Local: 1 IsTrusted: 1 FileSize: 59789620 DestFile:'/var/cache/apt/archives/gitlab-runner_13.5.0_amd64.deb' DescURI:'https://packages.gitlab.com/runner/gitlab-runner/ubuntu/pool/bionic/main/g/gitlab-runner/gitlab-runner_13.5.0_amd64.deb' ID:0 ErrorText: ''>
check_conffile_prompt(/var/cache/apt/archives/gitlab-runner_13.5.0_amd64.deb)
found pkg: gitlab-runner
No conffiles in deb /var/cache/apt/archives/gitlab-runner_13.5.0_amd64.deb (There is no member named 'conffiles')
blacklist: []
whitelist: []
Option --dry-run given, *not* performing real actions
Packages that will be upgraded: gitlab-runner
Writing dpkg log to /var/log/unattended-upgrades/unattended-upgrades-dpkg.log
applying set ['gitlab-runner']
/usr/bin/dpkg --status-fd 11 --no-triggers --unpack --auto-deconfigure /var/cache/apt/archives/gitlab-runner_13.5.0_amd64.deb
/usr/bin/dpkg --status-fd 11 --configure --pending
left to upgrade set()
All upgrades installed
InstCount=0 DelCount=0 BrokenCount=0

よさそうなので、--dry-runを外す
(dry-runと変更があった部分)

Packages that will be upgraded: gitlab-runner
Writing dpkg log to /var/log/unattended-upgrades/unattended-upgrades-dpkg.log
applying set ['gitlab-runner']
(データベースを読み込んでいます ... 現在 105088 個のファイルとディレクトリがインストールされています。)
.../gitlab-runner_13.5.0_amd64.deb を展開する準備をしています ...
gitlab-runner (13.5.0) で (13.4.1 に) 上書き展開しています ...
gitlab-runner (13.5.0) を設定しています ...
GitLab Runner: detected user gitlab-runner
WARNING: gitlab-runner belongs to group docker which is insecure, because allows to have root access to host
Runtime platform                                    arch=amd64 os=linux pid=24526 revision=ece86343 version=13.5.0
gitlab-runner: Service is not running.
Runtime platform                                    arch=amd64 os=linux pid=24537 revision=ece86343 version=13.5.0
gitlab-ci-multi-runner: Service is not running.
Runtime platform                                    arch=amd64 os=linux pid=24572 revision=ece86343 version=13.5.0
Runtime platform                                    arch=amd64 os=linux pid=24652 revision=ece86343 version=13.5.0
Clearing docker cache...
left to upgrade set()
All upgrades installed
InstCount=0 DelCount=0 BrokenCount=0
Extracting content from /var/log/unattended-upgrades/unattended-upgrades-dpkg.log since 2020-10-26 11:41:04

5. まとめ

これでいつも気にしておかなくてもよくなりそう
注意: 全てのRunnerを自動アップデートにして何かあっても当方は一切関知しないのでそのつもりで。

6. 参考

Upgrading External Packages with unattended-upgrade - Linux Audit
https://linux-audit.com/upgrading-external-packages-with-unattended-upgrade/

unattended-upgradeでサードパーティリポジトリも自動アップデートする | コはコンピューターのコ
https://tech.matchy.net/archives/1281

第173回 管理者の操作を待たずにアップデートするPolicyKitの設定・unattended-upgrade:Ubuntu Weekly Recipe|gihyo.jp … 技術評論社
https://gihyo.jp/admin/serial/01/ubuntu-recipe/0173?page=2

2
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0