GitLab Runner 15.1 からDocker Executorでpodmanが動作するようになったので、動かし方のメモを書いておきます。
環境
項目 | バージョン |
---|---|
GitLab EE | 16.10.1 |
GitLab Runner | 16.10.0-1 |
前提条件
- GitLabとGitLab Runnerは既に構築済みとします
- ここではGitLab RunnerはShared Runnerとして登録します
- GitLab Runnerのホストにはpodmanが既にインストール済みとします
GitLab Runner 登録
以下の作業をする前にGitLabの Admin Area
にある Runners
の New instance runner
で登録するトークンを発行しておいてください。
登録作業
GitLab Runnerで以下のコマンドを実行します。
ExecutorはDokcerを選択します。
1 2 3 4 5 6 7 |
# gitlab-runner register --url http://192.168.10.63 --token TOKEN (snip) Enter an executor: virtualbox, docker+machine, kubernetes, docker-autoscaler, instance, custom, shell, ssh, parallels, docker, docker-windows: docker Enter the default Docker image (for example, ruby:2.7): python:3.9 |
gitlab-runner
ユーザーのuidを確認します。
1 2 3 |
# id gitlab-runner uid=994(gitlab-runner) gid=991(gitlab-runner) groups=991(gitlab-runner) |
/etc/gitlab-runner/config.toml
の設定を変更します。
1 2 3 4 5 6 7 8 9 |
# vi /etc/gitlab-runner/config.toml (snip) [runners.docker] host = "unix:///var/run/user/994/podman/podman.sock" # 追加(gitlab-runnerユーザーのuidのパスにする) tls_verify = false (snip) privileged = true # 変更 (snip) |
GitLab Runnerを再起動します。
1 2 |
# systemctl restart gitlab-runner |
コンテナ内のユーザーをpodmanホストの非特権ユーザーにマップするための設定を追加します。
1 2 3 |
# vi /etc/subuid gitlab-runner:100000:65536 |
1 2 3 |
# vi /etc/subgid gitlab-runner:100000:65536 |
上記の設定を反映します。
1 2 3 4 |
# su - gitlab-runner $ podman system migrate $ exit |
config.toml
で設定したソケットを有効化するにはgitlab-runnerでSSHログインして作業をする必要があるためパスワードを設定します。
1 2 3 4 5 6 |
# passwd gitlab-runner (snip) New password: Retype new password: passwd: all authentication tokens updated successfully. |
gitlab-runnerでsshログインします。
1 2 3 4 5 |
# ssh gitlab-runner@localhost $ systemctl --user enable --now podman.socket Created symlink /home/gitlab-runner/.config/systemd/user/sockets.target.wants/podman.socket → /usr/lib/systemd/user/podman.socket. $ exit |
gitlab-runnerから抜けるとソケットが削除されるため以下のコマンドを実行して恒久的な設定します。
1 2 |
# loginctl enable-linger gitlab-runner |
動作確認
適当なプロジェクトを作成して .gitlab-ci.yml
を作成して動作確認をします。
1 2 3 4 5 6 7 |
# mkdir test # cd test # git init # git config --global user.name root # git config --global user.email root@example.com # vi .gitlab-ci.yml |
1 2 3 4 5 |
--- test: script: - ls |
1 2 3 4 5 6 7 |
# git add . # git commit -m first # git remote add origin http://192.168.10.63/root/test.git # git push origin main Username for 'http://192.168.10.63': root Password for 'http://root@192.168.10.63': |
問題なく動作すれば完了です 🙂