docker部署 gitlab Runner 运行

gitlabrunner

gitlab runner性能优化

runner注册

创建变量

1
2
3
4
5
6
GitLabServer='https://git\.gct\-china\.com/' # gitlab服务器地址
GitLabToken='xxxx' # gitlab 仓库地址token
GitLabRunnerNamePrefix='g' # gitlab runner 前缀
GitLabRunnerTags='gct-mooc-develop' # gitlab runner tags
GitLabRunnerDesc='gct-mooc-develop' # 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: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

删除runner

1
2
3
docker stop "$GitLabRunnerNamePrefix-gitlab-runner"
docker rm "$GitLabRunnerNamePrefix-gitlab-runner"
docker volume rm "$GitLabRunnerNamePrefix-gitlab-runner-conf"

runner清理

删除玄虚镜像

玄虚镜像是未标记且未被任何容器使用的镜像。 -a 未使用的镜像

1
docker image prune -a

运行此命令时要小心。如果你构建的图像没有标签,它将被删除。