建置docker-compose.yaml ====================== * 內容: ``` version: '3.1' services: gitlab-runner: image: 'gitlab/gitlab-runner:latest' container_name: GitLab-Runner-AP privileged: true volumes: - C:/API-Runner/config:/etc/gitlab-runner - /var/run/docker.sock:/var/run/docker.sock restart: always ``` ## 執行以下步驟 * 開啟windows PowerShell ![](https://hackmd.io/_uploads/B140njsq3.png) * 輸入下列文字依照docker-compose.yaml文件內容建置GitLabRunner Images ``` docker-compose up -d ``` * 輸入下列文字註冊GitLabRunner ``` docker-compose exec gitlab-runner gitlab-runner register ``` <font color="#f00">備註:如找不到路徑則輸入以下指令</font> ```` $Env:COMPOSE_CONVERT_WINDOWS_PATHS=1 ```` ### 按照下述步驟註冊GitLabRunner 1. Runtime platform arch=amd64 os=linux pid=43 revision=b72e108d version=16.1.0 Running in system-mode. Enter the GitLab instance URL (for example, https://gitlab.com/): <font color="#f00">請輸入GitLab instance URL</font> 2. Enter the registration token: <font color="#f00">請輸入GitLab registration token</font> #### URL與Token可參考下圖位置[Project > settings > CI/CD > Runners > Specific runners] ![](https://hackmd.io/_uploads/ByeIQNS9n.png) 3. Enter a description for the runner: <font color="#f00">請輸入GitLab Runner備註</font>[可不填] 4. Enter tags for the runner (comma-separated): <font color="#f00">請輸入GitLab Runner標籤</font>[可不填] 備註:tag需與CI.yaml設定的tag相同 5. Enter optional maintenance note for the runner:: <font color="#f00">請輸入GitLab Runner維護說明</font>[可不填] 7. Enter the executor: ssh, docker+machine, docker-ssh+machine, kubernetes, docker, parallels, virtualbox, docker-ssh, shell:: <font color="#f00">請輸入GitLab Runner執行者</font> 輸入 -> Docker 8. Enter the Docker image (eg. alpine:latest):: <font color="#f00">第8步驟輸入Docker則會跳出第九步驟,請輸入Docker圖像</font> 輸入 -> alpine:latest #### 成功-如下圖 ![](https://hackmd.io/_uploads/B1eTVVS92.png) ![](https://hackmd.io/_uploads/HJYQU4Bch.png) ### 成功後需修改config.toml檔案,修改後內容如下 * 修改部分->runners底下url,image與privileged * 新增pull_policy ```` concurrent = 1 check_interval = 0 shutdown_timeout = 0 [session_server] session_timeout = 1800 [[runners]] name = "bizfam" url = "http://10.20.30.241/" id = 90 token = "sjxGLQv9P4B-k54EGuRX" token_obtained_at = 2023-07-23T06:16:45Z token_expires_at = 0001-01-01T00:00:00Z executor = "docker" [runners.cache] MaxUploadedArchiveSize = 0 [runners.docker] tls_verify = false image = "docker:20.10.16" privileged = true disable_entrypoint_overwrite = false oom_kill_disable = false disable_cache = false volumes = ["/cache"] shm_size = 0 pull_policy = "if-not-present" ```` * 參數說明 #### 🔧 基本設定 | 參數 | 說明 | | -------- | -------- | | concurrent | 同時可以執行的 job 數量(Runner 層級)。此設定代表同一時間最多只能有 x 個 job 被處理。 | | check_interval | 幾秒檢查一次有無新的 job,設為 0 表示使用預設行為(通常會是長輪詢)。 | | shutdown_timeout | Runner 在關閉時等待中的時間(秒)。0 表示無等待時間,會立即強制停止任務。 | #### 🧑‍💼 Session Server 設定 | 參數 | 說明 | | -------- | -------- | | session_timeout | CI Job Web Terminal(例如使用 gitlab-runner exec)的連線逾時時間(秒)。 | #### 🚀 Runner 個別設定 | 參數 | 說明 | | -------- | -------- | | name | Runner 顯示名稱。 | | url | GitLab 伺服器的 URL(API 連線用)。 | | id | Runner 的唯一 ID,由 GitLab 指派。 | | token | 註冊 Runner 使用的認證 Token(請注意保密)。 | | token_obtained_at | Token 取得的時間。 | | token_expires_at | Token 到期時間。0001-01-01 表示不會過期。 | | executor | 指定執行的方式,此處使用 Docker。其他常見的有 shell, ssh, kubernetes 等。 | #### 📦 Runner Cache 設定 | 參數 | 說明 | | -------- | -------- | | MaxUploadedArchiveSize | 限制最大可上傳的快取大小(0 表示不限) | #### 🐳 Docker Executor 設定 | 參數 | 說明 | | -------- | -------- | | tls_verify | 不驗證 Docker TLS,通常用於本機或自簽憑證。 | | image | 預設使用的 Docker image。這是執行 CI script 的 base image。 | | privileged | 啟用 Docker 的特權模式,讓容器有更高權限(例如可執行 Docker in Docker)。 | | disable_entrypoint_overwrite | 是否允許覆寫 image 預設 entrypoint。 | | oom_kill_disable | 是否禁用 OOM-killer(當記憶體不足時保護 job 被殺掉)。 | | disable_cache | 是否關閉 GitLab CI cache 功能。false 表示啟用。 | | volumes | 掛載的 volume,/cache 為 GitLab 用來暫存快取的路徑。 | | shm_size | 設定容器的共享記憶體大小(0 表示使用預設)。 | | pull_policy | image 下載策略:只有當本地沒有 image 時才拉取。選項如if-not-present、always、never。 |