问题描述
GitLab CI/CD 已经集成到 GitLab 服务中。除此之外,我们还需要安装 GitLab Runner 服务;
解决方案
参考 Install GitLab Runner | GitLab 页面
通过 APT / RPM 部署(推荐)
Install GitLab Runner manually on GNU/Linux | GitLab
Install GitLab Runner using the official GitLab repositories | GitLab
建议参考官方文档,这里仅作记录:
# --------------------------------------------------------- # 方法一、手动安装:每次下载 .deb 文件并安装 wget https://gitlab-runner-downloads.s3.amazonaws.com/latest/deb/gitlab-runner_amd64.deb dpkg -i gitlab-runner_amd64.deb # --------------------------------------------------------- # 方法二、仓库安装:添加仓库,并进行安装; # for Ubuntu curl -L "https://packages.gitlab.com/install/repositories/runner/gitlab-runner/script.deb.sh" | sudo bash apt-cache madison gitlab-runner apt-get install gitlab-runner=16.4.0
通过 Docker Compose 部署
Run GitLab Runner in a container | GitLab
version: '3' services: gitlab-runner: image: gitlab/gitlab-runner:alpine-v12.6.0 restart: always volumes: - ./config/${HOSTNAME}/:/etc/gitlab-runner/ - ./config/ssh-key/:/ssh-key/ - /var/run/docker.sock:/var/run/docker.sock - /etc/localtime:/etc/localtime
1)./config/${HOSTNAME}:鉴于该文件需要在很多主机中复用,所以才将主机名作为配置目录名;
2)./config/ssh-key:SSH 类型的 Executor 需要密钥来访问远程主机,所以需要进行挂载;
3)/var/run/docker.sock:Docker 类型的 Executor 需要访问 Docker Daemon,所以需要挂载;
注意事项:
- 如果采用该方式部署 GitLab Runner,则当重启 Docker 服务后,由于 sock 文件变换,需要重新创建容器;
Fatal error loading the DB: Permission denied # 检查 redis 文件权限;
参考文献
Run GitLab Runner in a container | GitLab
Install GitLab Runner manually on GNU/Linux | GitLab