📔 透過 Docker 設定 Gitlab Runner

📔 透過 Docker 設定 Gitlab Runner
Photo by Pankaj Patel / Unsplash

1. 使用 System Volumn 掛載 Runner Container,執行 Gitlab Runner。

docker run -d --name gitlab-runner --restart always \
  -v /srv/gitlab-runner/config:/etc/gitlab-runner \
  -v /var/run/docker.sock:/var/run/docker.sock \
  gitlab/gitlab-runner:latest

2. 建立一個新的 Group runner。

group runner

👉 _新增 Group runner 標籤_

Add tag

👉 _獲取 token_

Get authentication token

更詳細的步驟可以參考這篇文章

3. 註冊 Runner
別忘了將 Token 換成上一步得到的。

RUNNER_TOKEN="glrt-vTJPYBaajfypaShJH2xx"

docker run --rm -v /srv/gitlab-runner/config:/etc/gitlab-runner gitlab/gitlab-runner register \
  --non-interactive \
  --url "https://gitlab.com/" \
  --token "$RUNNER_TOKEN" \
  --executor "docker" \
  --docker-image docker:stable-dind \
  --description "docker-runner"

4. 編輯 /srv/gitlab-runner/config/config.toml

修改以下配置:

  • concurrent:可選
  • privileged
  • volumes:docker 內部的 docker
  • network_mode:可選
concurrent = 4 # change
check_interval = 0
shutdown_timeout = 0

[session_server]
  session_timeout = 1800

[[runners]]
  name = "docker-runner"
  url = "https://gitlab.com/"
  id = 28470179
  token = "glrt-vTJPYBaajfypaShJH2Ge"
  token_obtained_at = 2023-10-14T12:45:43Z
  token_expires_at = 0001-01-01T00:00:00Z
  executor = "docker"
  [runners.cache]
    MaxUploadedArchiveSize = 0
  [runners.docker]
    tls_verify = false
    image = "docker:stable-dind"
    privileged = true # change
    disable_entrypoint_overwrite = false
    oom_kill_disable = false
    disable_cache = false
    #volumes = ["/cache"] # change
    volumes = ["/cache", "/var/run/docker.sock:/run/docker.sock"]
    shm_size = 0
    network_mode = "host" # add

/srv/gitlab-runner/config/config.toml

6. 重新啟動 Runner

docker restart gitlab-runner

參考資料