gitlab-runner 配置

gitlab-runner安装

目录结构

1
2
3
4
5
[docker@yl-mac gitlab-runner]# tree
.
├── config
│ └── config.toml
└── docker-compose.yml

docker-compose.xml

1
2
3
4
5
6
7
8
9
10
11
12
version: '3.8'

services:
gitlab-runner:
image: gitlab/gitlab-runner:alpine-v14.0.1
container_name: gitlab-runner
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- ./config:/etc/gitlab-runner
# ports:
# - "8093:8083"
restart: always

注册 runner 实例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# 进入容器
docker exec -it gitlab-runner sh

# 注册 java 编译类型实例,支持 maven 环境的编译
gitlab-runner register --non-interactive --executor "docker" --docker-image maven:3.6.1-jdk-8-alpine --docker-volumes '/root/.m2:/root/.m2' --url "gitlab 服务地址" --registration-token "gitlab token" --description "maven" --tag-list "maven" --run-untagged="true" --locked="false" --output-limit="40960"
# --docker-privileged

# 注册 docker 编译类型实例,支持 docker 镜像打包等环境的编译
gitlab-runner register --non-interactive --executor "docker" --docker-image docker:20.10.7 --docker-volumes '/var/run/docker.sock:/var/run/docker.sock' --url "gitlab 服务地址" --registration-token "gitlab token" --description "docker" --tag-list "docker" --run-untagged="true" --locked="false" --output-limit="40960"

# 取消注册:通过 name
# gitlab-runner unregister --name docker
# 取消所有注册
# gitlab-runner unregister --all-runners

注册后,会生成以下gitlab-runnerconfig.toml配置文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
concurrent = 1
check_interval = 0

[session_server]
#listen_address = "[::]:8093" # listen on all available interfaces on port 8093
#advertise_address = "ip:8093" # gitlab-runner 服务
session_timeout = 1800

[[runners]]
name = "maven"
url = "gitlab 服务地址"
token = "gitlab token"
executor = "docker"
# 默认是4096
output_limit = 40960
[runners.custom_build_dir]
[runners.cache]
[runners.cache.s3]
[runners.cache.gcs]
[runners.cache.azure]
[runners.docker]
tls_verify = false
image = "maven:3.3.3-jdk-8"
privileged = false
disable_entrypoint_overwrite = false
oom_kill_disable = false
disable_cache = false
volumes = ["/root/.m2:/root/.m2", "/cache"]
shm_size = 0

[[runners]]
name = "docker"
url = "gitlab 服务地址"
token = "gitlab token"
executor = "docker"
# 默认是4096
output_limit = 40960
[runners.custom_build_dir]
[runners.cache]
[runners.cache.s3]
[runners.cache.gcs]
[runners.cache.azure]
[runners.docker]
tls_verify = false
image = "docker:stable"
privileged = false
disable_entrypoint_overwrite = false
oom_kill_disable = false
disable_cache = false
volumes = ["/cache", "/var/run/docker.sock:/var/run/docker.sock"]
shm_size = 0

下载 gitlab-runner 执行 .gitlab-ci.yml 流水线可能需要使用到的镜像

1
2
3
4
5
6
7
8
# 必须
docker pull gitlab/gitlab-runner-helper:x86_64-c1edb478
docker pull registry.gitlab.com/gitlab-org/gitlab-runner/gitlab-runner-helper:x86_64-c1edb478
# 可能使用到
docker pull docker:20.10.7
docker pull maven:3.6.1-jdk-8-alpine
docker pull node:xxxx
docker pull openjdk:xxxx

问题

  1. Maven 加速问题

    解决:注册gitlab-runner的时候,指定--docker-volumes '~/.m2:/root/.m2'配置,并在宿主机~/.m2/下配置settings.xml。默认:三方包会保存在~/.m2/repository中。

    注意:经测试启动容器指定-v /data/docker/gitlab/runner/.m2:/root/.m2映射,在其中放入settings.xml不生效

  2. Job’s log exceeded limit of 4194304 bytes.

    解决:在gitlab-runnerconfig.toml加上output_limit配置,默认是4096(4MB)

  3. ERROR: Uploading artifacts as “archive” to coordinator… too large archive

    解决:admin area -> settings -> ci/cd -> Continuous Integration and Deployment -> Maximum artifacts size (MB)

  • 本文作者: forever杨
  • 本文链接: https://blog.yl-online.top/posts/504f0829.html
  • 版权声明: 本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。如果文章内容对你有用,请记录到你的笔记中。本博客站点随时会停止服务,请不要收藏、转载!