一、安装gitlab-runner
1.可以是linux也可以是docker的
2.本文说的是docker安装部署的。
二、直接上.gitlab-ci.yml
stages: # List of stages for jobs, and their order of execution
- build-image
build-image-job:
stage: build-image
image: harbor.com:543/docker/docker:20.10.16
tags:
- docker
variables:
CI_REGISTRY_PROJETY: harbor.com:543/spring_boot-ci
DOCKER_IMAGE_NAME: ci-java-web
DOCKER_IMAGE_TAG: v1
DOCKER_REGISTRY: harbor.com:543
DOCKER_REGISTRY_PASS: VMware1!
DOCKER_REGISTRY_USER: admin
before_script:
- mkdir -p $HOME/.docker
- echo $DOCKER_AUTH_CONFIG > $HOME/.docker/config.json
script:
-
docker pull harbor.com:543/maven/maven:latest
-
docker image ls
-
docker tag maven:latest harbor.com:543/maven/maven:v1
-
docker push harbor.com:543/maven/maven:v1
三、runer的配置文件config.toml
[[runners]]
name = "My Docker Runner"
url = "http://10.10.2.183:8929/"
id = 9
token = "pjBVsQMaMT8WkypuubXy"
token_obtained_at = 2023-08-09T12:03:56Z
token_expires_at = 0001-01-01T00:00:00Z
executor = "docker"
environment = ["DOCKER_AUTH_CONFIG={\"auths\":{\"harbor.com:543\": {\"auth\":\"YWRtaW46Vk13YXJlMSE=\"}}}"]
[runners.cache]
MaxUploadedArchiveSize = 0
Insecure = false
[runners.docker]
tls_verify = false
image = "docker:20.10.16"
privileged = false
disable_entrypoint_overwrite = false
oom_kill_disable = false
disable_cache = false
shm_size = 0
volumes = ["/var/run/docker.sock:/var/run/docker.sock", "/cache"]
四、验证
五、重点
1、DOCKER_AUTH_CONFIG 使用了这个变量来传入私有harbor的信息,来进行登录。
2、docker 的image必须是docker:20.10.16
3、如果注册了runner修改了config.toml,一定要重启docker容器不是在容器内部执行gitlab-runner restart
4、替换上面的variables,DOCKER_AUTH_CONFIG,变量你可以直接拿来用。