创建变量
GitLabServer='https://xxxx.com/' # gitlab服务器地址
GitLabToken='your_project_token' # gitlab 仓库token
GitLabRunnerNamePrefix='bonzersoft' # gitlab runner 前缀
GitLabRunnerTags='bonzersoft_dev' # gitlab runner tags
GitLabRunnerDesc='bonzersoft_dev your_ip' # gitlab runner desc
GitLabRunnerImg='gitlab/gitlab-runner:v14.10.1' # gitlab runner img
创建配置数据卷
docker volume create "$GitLabRunnerNamePrefix-gitlab-runner-conf"
创建runner
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
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:19.03.12 \
--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