GitLab で CI を行う場合、GitLab Runner があると便利なので、それを docker-compose で動かしてみます。
Docker イメージは Docker Hub で公開されています。
前提
当初、GitLab と GitLab Runner は Docker for Windows で同じホストで動作させる予定でした。
しかし、どうも GitLab Runner がジョブを開始しないので、GitLab Runner だけは CentOS で動作させることにしました。
CentOS だと何の問題もなく動作しました。
何故 GitLab も CentOS で動作させないのかというと、社内のネットワーク事情です。
docker-compose.yml の作成
設定は docker-compose を使って行います。
以下のような docker-compose.yml
を作成しました。
version: '2'
services:
gitlab-runner:
image: gitlab/gitlab-runner
restart: unless-stopped
volumes:
- config:/etc/gitlab-runner
- /var/run/docker.sock:/var/run/docker.sock
network_mode: host
volumes:
config:
プロキシ環境下で動かすので、network_mode: host
を指定して、ホストのプロキシ設定を使って通信するようにしました。
あとは docker-compose で起動します。
docker-compose up -d
登録処理
gitlab-runner 起動後、コンテナの中に入って、登録処理を行います。
詳細は以下の記事を参考にしてください。
参考 URL
- https://docs.gitlab.com/runner/install/docker.html
- https://qiita.com/toe/items/f47f383b9931a840a25c
- https://docs.gitlab.com/runner/install/docker.html#docker-image-installation-and-configuration
- https://about.gitlab.com/features/gitlab-ci-cd/
- https://qiita.com/toe/items/f47f383b9931a840a25c#gitlab-runner%E3%82%B3%E3%83%B3%E3%83%86%E3%83%8A%E3%82%92%E8%B5%B7%E5%8B%95%E3%81%99%E3%82%8B
- http://blog.hawksnowlog.cf/2017/09/build-specific-runner-for-gitlabci.html#%E3%83%A9%E3%83%B3%E3%83%8A%E3%83%BC%E3%82%92%E7%99%BB%E9%8C%B2%E3%81%99%E3%82%8B
- https://kore1server.com/353/GitLab+CI%E3%81%A8%E3%83%A9%E3%83%B3%E3%83%8A%E3%83%BC%E3%81%A7%E3%83%87%E3%83%97%E3%83%AD%E3%82%A4%E3%81%99%E3%82%8B