gitlab-runner docker-compose安装使用

时间:2022-10-17 12:03:50

gitlab-runner docker-compose安装使用

docker-copose.yml
version: "3.1"                                                                                                                                           
services:
gitlab-runner:
image: gitlab/gitlab-runner:latest
restart: always
container_name: gitlab-runner
privileged: true
volumes:
- ./config:/etc/gitlab-runner
- /var/run/docker.sock:/var/run/docker.sock

启动后登录容器注册,然后生成参数

concurrent = 1                                                                                                                                           
check_interval = 0

[session_server]
session_timeout = 1800

[[runners]]
name = "k8s-runner-docker"
url = "http://gitlab.ops.xxxxx.com/"
token = "afef1c118460f0c02281c8de167ed3"
executor = "docker"
[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
问题解决:

1.docker in docker打包镜像报错,挂载socket

volumes = ["/cache", "/var/run/docker.sock:/var/run/docker.sock"]   
  1. gitlab runner写k8s配置,其中变量的双引号很重要
.deploy_script: &deploy_script
script:
- whoami
# - sleep 3600
- mkdir /root/.kube/ -pv
- echo "$KUBECONFIG_JOUBEI" > /root/.kube/config-joubei
- cat /root/.kube/config-joubei
- kubectl --kubeconfig=/root/.kube/config-joubei set image deployment/${DEPLOY_NAME} ${CONTAINER_NAME}=${REGISTRY_REGION_VPC}/${REGISTRY_NAMESPACE}/${REGISTRY_NAME}:${REGISTRY_VERSION} -n ${NAMESPACE}
- kubectl --kubeconfig=/root/.kube/config-joubei -n ${NAMESPACE} rollout status --timeout=300s deploy/${DEPLOY_NAME} || { kubectl --kubeconfig=/root/.kube/config-joubei -n ${NAMESPACE} describe pod -lapp=${LABEL_APP}; exit 1; }