How to use gitlab-runner to execute CI?

  1. Download a gitlab-runner docker image
bash 复制代码
docker pull gitlab/gitlab-runner:latest
  1. Run the GitLab Runner Container
bash 复制代码
docker run \
    -v /your-path/gitlab-runner/config:/etc/gitlab-runner \
    -v /your-path/gitlab-runner/cache:/cache \
	-v /var/run/docker.sock:/var/run/docker.sock \
    --name gitlab-runner gitlab/gitlab-runner:latest
  • --name gitlab-runner:设置容器名称。
  • --restart always:设置容器在 Docker 重启后自动启动。
  • -v /your-path/gitlab-runner/config:/etc/gitlab-runner:将本地路径 /your-path/gitlab-runner/config 挂载到容器中的 /etc/gitlab-runner,用来存储 GitLab Runner 的配置文件。
  • -v /var/run/docker.sock:/var/run/docker.sock:挂载 Docker socket,用以支持Docker执行器。
  1. Register a runner
bash 复制代码
docker run -it --rm -v /your-path/gitlab-runner/config:/etc/gitlab-runner gitlab/gitlab-runner register \
  --non-interactive \
  --executor "docker" \
  --docker-image alpine:latest \
  --url "https://your-gitlab.com/" \
  --registration-token "your token from gitlab" \
  --description "runner" \
  --tag-list "runner-01"
  1. config.toml
bash 复制代码
concurrent = 10
check_interval = 0
connection_max_age = "15m0s"
shutdown_timeout = 0

[session_server]
  session_timeout = 1800

[[runners]]
  name = "runner"
  url = "https://your-gitlab.com/"
  id = 1
  token = "your token"
  token_obtained_at = 2024-11-13T06:53:07Z
  token_expires_at = 0001-01-01T00:00:00Z
  executor = "docker"
  [runners.custom_build_dir]
  [runners.cache]
    MaxUploadedArchiveSize = 0
    [runners.cache.s3]
    [runners.cache.gcs]
    [runners.cache.azure]
  [runners.docker]
    tls_verify = false
    #image = "alpine:latest"
    image = "your-harbor.com/base_image/alpine:latest"
    privileged = false
    disable_entrypoint_overwrite = false
    oom_kill_disable = false
    disable_cache = false
    volumes = [
      "/cache",
      #"/your-path/gitlab-runner/npm_cache:/root/.npm",
      "/your-path/gitlab-runner/npm_cache:/tmp/.npm",
      "/your-path/gitlab-runner/nuget_cache:/root/.nuget/packages",
      "/var/run/docker.sock:/var/run/docker.sock",
      "/your-path/gitlab-runner/config/certs:/certs"
      ]
    shm_size = 0
    network_mtu = 0
  1. Stop gitlab-runner
bash 复制代码
docker stop gitlab-runner
docker rm gitlab-runner
相关推荐
Ticnix5 天前
别再手动上线了:一条命令带备份、健康检查和自动回滚
后端·python·ci/cd
zoutao985 天前
Gitea Actions 自定义 Runner 镜像与自动化部署实战
ci/cd·docker·gitea
troy1286 天前
Codex 安全盲区:代码漏洞生成实测
windows·python·ci/cd·pycharm·django·github·fastapi
daemon.qiang6 天前
国内虚拟机对接 Freedesktop:Fork xserver、自建 Runner 与提交 MR 实战
linux·ubuntu·centos·gitlab·开源软件
极小狐8 天前
CI 算力饥渴症:Runner 弹性伸缩的架构权衡与落地
ci/cd·kubernetes·devops·弹性伸缩
szephyr10 天前
GitHub Actions 实战:给个人项目接上免费的自动部署流水线
ci/cd·github·devops·自动化部署·github actions
Patrick_Wilson10 天前
桌面端发布的真实成本:签名、公证和那支不能共享的 USB Key
ci/cd·electron·客户端
极小狐10 天前
极狐GitLab 关键补丁版本:19.3.2、19.2.6、19.1.8
ci/cd·devops·极狐gitlab·安全修复·补丁版本
梦帮科技10 天前
从提示词到可复现音乐工作流:RNOISE 2.0 的 Prompt Engineering 架构
人工智能·python·mysql·ci/cd·架构·node.js·numpy
snow@li11 天前
服务器运维:K3S 下 Jenkins ↔ GitLab 的 CI/CD 闭环 / 访问成功
运维·gitlab·jenkins