创建变量
1 2 3 4 5 6 7
| GitLabServer='https://git.xxx.com/' # gitlab服务器地址 GitLabToken='xxxxx' # gitlab 仓库token GitLabRunnerNamePrefix='xxxx' # gitlab runner 前缀 GitLabRunnerTags='xxx' # gitlab runner tags GitLabRunnerDesc='xxx' # gitlab runner desc GitLabRunnerImg='gitlab/gitlab-runner:v14.10.1' # gitlab runner img
|
创建配置数据卷
1
| docker volume create "$GitLabRunnerNamePrefix-gitlab-runner-conf"
|
创建runner
1 2 3 4 5
| docker run --network host -d --restart always \ -e TZ=Asia/Beijing \ -v /var/run/docker.sock:/var/run/docker.sock \ -v "$GitLabRunnerNamePrefix-gitlab-runner-conf":/etc/gitlab-runner \ --name "$GitLabRunnerNamePrefix-gitlab-runner" $GitLabRunnerImg
|
注册runner
https://docs.gitlab.com/runner/examples/gitlab.html
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| docker run --rm \ -v "$GitLabRunnerNamePrefix-gitlab-runner-conf":/etc/gitlab-runner \ -v /var/run/docker.sock:/var/run/docker.sock \ --name "$GitLabRunnerNamePrefix-gitlab-runner-register" $GitLabRunnerImg register \ --url "$GitLabServer" \ --registration-token "$GitLabToken" \ --description "$GitLabRunnerDesc" \ --tag-list "$GitLabRunnerTags" \ --non-interactive \ --executor "docker" \ --docker-image docker:23.0.2 \ --docker-privileged="true" \ --docker-volumes "/certs/client" \ --run-untagged="true" \ --locked="false" \ --access-level="not_protected" \ --docker-volumes /var/run/docker.sock:/var/run/docker.sock
|
删除runner
1 2 3
| docker stop "$GitLabRunnerNamePrefix-gitlab-runner" docker rm "$GitLabRunnerNamePrefix-gitlab-runner" docker volume rm "$GitLabRunnerNamePrefix-gitlab-runner-conf"
|