如何使用 docker-compose 安装 gitlab-runner
首先,选择服务将驻留的目录。我推荐 /opt/gitlab-runner。然后在所述目录中创建具有此内容的 docker-compose.yml:
example-13.yaml
gitlab-runner:
image: 'gitlab/gitlab-runner:latest'
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- ./config:/etc/gitlab-runner
restart: unless-stopped然后运行此命令配置 runner:
example-12.sh
docker-compose exec gitlab-runner gitlab-runner register它会询问你要附加到的 GitLab 实例的详细信息。你可以在 https://<你的-gitlab-域名>/admin/runners 找到此信息。此示例适用于我的 GitLab 实例:
example-11.txt
Running in system-mode.
Enter the GitLab instance URL (for example, https://gitlab.com/):
https://gitlab.techoverflow.net/
Enter the registration token:
Loo2lahf9Shoogheiyae
Enter a description for the runner:
[148a53203df8]: My-Runner
Enter tags for the runner (comma-separated):
Registering runner... succeeded runner=oc-oKWMH
Enter an executor: custom, docker-ssh, shell, virtualbox, docker-ssh+machine, docker, parallels, ssh, docker+machine, kubernetes:
shell
Runner registered successfully. Feel free to start it, but if it's running already the config should be automatically reloaded!现在,重启使用旧配置(即没有附加 gitlab 实例)运行的 runner:
example-10.sh
完成后,你可以在 docker-compose.yml 所在的目录中运行我们之前文章在 10 秒内为你的 docker-compose 项目创建 systemd 服务中的脚本。
example-9.sh
这将自动生成 systemd 服务并启动 runner(也在开机时)。有关更多详细信息,请参见相应的博文。如果你的目录名为 gitlab-runner,服务文件将存储在 /etc/systemd/systemd/gitlab-runner.service,因此这些是你可以用来控制服务的命令:
注意创建 systemd 服务的脚本会自动启动 runner,所以你不需要手动 start 它!
启动使用
example-8.sh
重启使用
example-7.sh
停止使用
example-6.sh
查看状态:
example-5.sh
查看并跟踪日志:
example-4.sh
在 less 中查看日志:
example-3.sh
另请参见迷你 systemd 速查表
另请参见如何为多个 GitLab 实例注册 gitlab runner。
注意你也可以使用
example-2.sh
查看日志(从 docker-compose.yml 所在的目录运行此命令)。
如果你看到类似这样的错误消息
example-1.txt
Check out similar posts by category:
Gitlab
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow