接上回
启动docker
[root@guilin ~]# systemctl start docker
[root@guilin ~]# systemctl enable docker
准备repo
[root@guilin ~]# curl -s https://packages.gitlab.com/install/repositories/runner/gitlab-runner/script.rpm.sh | bash
Detected operating system as centos/7.
Checking for curl...
Detected curl...
Downloading repository file: https://packages.gitlab.com/install/repositories/runner/gitlab-runner/config_file.repo?os=centos&dist=7&source=script
done.
Installing pygpgme to verify GPG signatures...
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
runner_gitlab-runner-source/signature | 836 B 00:00:00
Retrieving key from https://packages.gitlab.com/runner/gitlab-runner/gpgkey
Importing GPG key 0xE15E78F4:
Userid : "GitLab B.V. (package repository signing key) <packages@gitlab.com>"
Fingerprint: 1a4c 919d b987 d435 9396 38b9 1421 9a96 e15e 78f4
From : https://packages.gitlab.com/runner/gitlab-runner/gpgkey
Retrieving key from https://packages.gitlab.com/runner/gitlab-runner/gpgkey/runner-gitlab-runner-366915F31B487241.pub.gpg
runner_gitlab-runner-source/signature | 951 B 00:00:01 !!!
runner_gitlab-runner-source/primary | 175 B 00:00:01
Package pygpgme-0.3-9.el7.x86_64 already installed and latest version
Nothing to do
Installing yum-utils...
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
Package yum-utils-1.1.31-50.el7.noarch already installed and latest version
Nothing to do
Generating yum cache for runner_gitlab-runner...
Importing GPG key 0xE15E78F4:
Userid : "GitLab B.V. (package repository signing key) <packages@gitlab.com>"
Fingerprint: 1a4c 919d b987 d435 9396 38b9 1421 9a96 e15e 78f4
From : https://packages.gitlab.com/runner/gitlab-runner/gpgkey
Generating yum cache for runner_gitlab-runner-source...
The repository is setup! You can now install packages.
安装gitlab-runner
[root@guilin ~]# yum install gitlab-runner -y
启动gitlab-runner
[root@guilin ~]# systemctl start gitlab-runner
[root@guilin ~]# systemctl status gitlab-runner
注册
[root@guilin ~]# gitlab-runner register
Runtime platform arch=amd64 os=linux pid=33111 revision=a987417a version=12.2.0
Running in system-mode.
Please enter the gitlab-ci coordinator URL (e.g. https://gitlab.com/):
http://10.150.7.5/
Please enter the gitlab-ci token for this runner:
RBmTj7Joyn-GNQ1m2QDY
Please enter the gitlab-ci description for this runner:
[guilin]: blog.ct99.cn.test.runner
Please enter the gitlab-ci tags for this runner (comma separated):
test-tag
Registering runner... succeeded runner=RBmTj7Jo
Please enter the executor: docker-ssh, ssh, docker-ssh+machine, shell, virtualbox, docker+machine, kubernetes, custom, docker, parallels:
docker
Please enter the default Docker image (e.g. ruby:2.6):
golang:latest
Runner registered successfully. Feel free to start it, but if it's running already the config should be automatically reloaded!
注册后的配置文件
[root@guilin ~]# cat /etc/gitlab-runner/config.toml
concurrent = 1
check_interval = 0
[session_server]
session_timeout = 1800
[[runners]]
name = "blog.ct99.cn.test.runner"
url = "http://10.150.7.5/"
token = "iAG5ykaGMQzxiVDAF9xS"
executor = "docker"
[runners.custom_build_dir]
[runners.docker]
tls_verify = false
image = "golang:latest"
privileged = false
disable_entrypoint_overwrite = false
oom_kill_disable = false
disable_cache = false
volumes = ["/cache"]
shm_size = 0
[runners.cache]
[runners.cache.s3]
[runners.cache.gcs]
将这个runner改为私有的。
新建一个项目在根目录下建立一个.gitlab-ci.yml
文件
job:
tags:
- test-tag ##注意这个是选择指定的runner
services:
- php:7
- node:latest
- golang:1.10
image: alpine:3.7
script:
- echo '========== hello gitlab-runner'
把项目添加到gitlab-runner里
可以在jobs里面查看执行结果
参考资料
https://docs.gitlab.com/ee/ci/yaml/README.html
https://docs.gitlab.com/runner/register/
https://docs.gitlab.com/runner/install/index.html
https://docs.gitlab.com/ee/ci/runners/
GitLab 允许我们给 runner 设置标签,设置好后该 runner 只会执行拥有相同标签的任务。由于我们的 runner 只为我们自己的代码库服务,所以此处不做过多配置。留空即可。