GitLab Runner


GitLab Runner是一個開源項目,用於運行你的作業(jobs)並將結果發送回GitLab。它與GitLab CI結合使用,GitLab CI是GitLab用於協調jobs的開源持續集成服務。

1. Install

Install GitLab Runner using the official GitLab repositories (首選

1、添加GitLab的官方倉庫:

# For RHEL/CentOS/Fedora
curl -L https://packages.gitlab.com/install/repositories/runner/gitlab-runner/script.rpm.sh | sudo bash

2、安裝最新版本的GitLab Runner

# For RHEL/CentOS/Fedora
sudo yum install gitlab-runner

3、為了安裝特定版本

# For RHEL/CentOS/Fedora
yum list gitlab-runner --showduplicates | sort -r
sudo yum install gitlab-runner-10.0.0-1

4、升級Runner

# For RHEL/CentOS/Fedora
sudo yum update
sudo yum install gitlab-runner

Install GitLab Runner manually on GNU/Linux (手動安裝) 

# For CentOS or Red Hat Enterprise Linux
curl -LJO https://gitlab-runner-downloads.s3.amazonaws.com/latest/rpm/gitlab-runner_.rpm

# 例如:    
curl -LJO https://s3.amazonaws.com/gitlab-runner-downloads/master/rpm/gitlab-runner_arm.rpm
curl -LJO https://s3.amazonaws.com/gitlab-runner-downloads/master/rpm/gitlab-runner_amd64.rpm
curl -LJO https://s3.amazonaws.com/gitlab-runner-downloads/master/rpm/gitlab-runner_i686.rpm 

下載完以后即可安裝

# For CentOS or Red Hat Enterprise Linux
rpm -i gitlab-runner_<arch>.rpm

# 例如:    
rpm -i gitlab-runner_arm.rpm

# 升級:    
rpm -Uvh gitlab-runner_arm.rpm 

手動安裝

1、下載二進制文件

# Linux x86-64
sudo curl -L --output /usr/local/bin/gitlab-runner https://gitlab-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-runner-linux-amd64
# Linux x86
sudo curl -L --output /usr/local/bin/gitlab-runner https://gitlab-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-runner-linux-386
# Linux x86
sudo curl -L --output /usr/local/bin/gitlab-runner https://gitlab-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-runner-linux-arm
# Linux x86
sudo curl -L --output /usr/local/bin/gitlab-runner https://gitlab-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-runner-linux-arm64

2、添加可執行權限

sudo chmod +x /usr/local/bin/gitlab-runner

3、創建GitLab CI用戶

sudo useradd --comment 'GitLab Runner' --create-home gitlab-runner --shell /bin/bash

4、安裝並作為服務運行

sudo gitlab-runner install --user=gitlab-runner --working-directory=/home/gitlab-runner
sudo gitlab-runner start
sudo gitlab-runner stop

2. Register

一個Runner可以特定於某個項目,也可以在GitLab CI中服務於任何項目。服務於所有項目的Runner稱為共享Runner。

理想情況下,不應將GitLab Runner與GitLab安裝在同一台機器上。

  • Shared Runners :顧名思義,共享Runner。對於具有相似要求的作業,可以考慮用Shared Runners。你可以用一個或少量幾個Runner處理多個項目,而不是讓多個Runner空閑着。這樣可以更輕松地維護和更新它們。Shared Runners使用公平隊列處理作業,與使用FIFO隊列的Specific Runners相比,這可以防止項目創建數百個作業,而導致耗盡所有可用的共享Runner資源。
  • Specific Runners :顧名思義,對於有特殊要求的作業,可以考慮用Specific Runners。
  • Group Runners :顧名思義,當一個小組中有多個項目,並且希望這些項目都可以訪問一組job時,可以考慮用Group Runners。Group Runners也是用FIFO隊列處理作業的。 

(PS:怎么理解Shared Runners用的公平隊列和Specific Runners用的FIFO隊列呢?舉個例子:

假設有這個一個隊列

Job 1 for Project 1
Job 2 for Project 1
Job 3 for Project 1
Job 4 for Project 2
Job 5 for Project 2
Job 6 for Project 3

那么,Shared Runner執行作業的順序會是146253,而Specific Runner執行作業的順序是123456

Specific Runners 僅針對特定的項目運行,Shared Runners 則可以為每一個啟用了“運行shared Runners”的項目執行作業。通過Settings > CI/CD 下進行設置。

如果你是GitLab實例管理員的話,你可以注冊一個Shared Runner

1、在admin/runners頁面獲取shared-Runner token

2、注冊Runner,如前所述

3. Executors

GitLab Runner implements a number of executors that can be used to run your builds in different scenarios.

GitLab Runner 實現了許多executors,用於在不同場景下運行你的構建。 

3.1. 選擇Executor

executors支持不同的平台和方法來構建項目

 

Shell executor :Shell是最簡單的executor,但是,它需要將構建所需的所有依賴手動安裝到安裝了Runner的同一台計算機上。

Virtual Machine executor :這種executor使得你可以使用已創建的虛擬機,該虛擬機將被克隆並用於運行你的構建。它提供了兩個完整的系統虛擬化選項:VirtualBox和Parallels。如果你想在不同的操作系統上運行構建,它們將非常有用,因為它允許在Windows,Linux,macOS或FreeBSD上創建虛擬機,然后GitLab Runner連接到虛擬機並在其上運行構建。它的用法對於降低基礎架構成本也很有用。

Docker executor :使用Docker executor是一個非常不錯的選擇,因為它提供了一個干凈的構建環境,並且具有輕松的依賴關系管理(用於構建項目的所有依賴關系都可以放在Docker鏡像中)。Docker executor允許你可以輕松地使用依賴服務(例如MySQL)創建構建環境。

Docker Machine executor :Docker Machine是Docker executor的特殊版本,支持自動伸縮。它像普通的Docker executor一樣工作,但具有Docker Machine按需創建的構建主機。

Kubernetes executor :Kubernetes executor允許你使用現有的Kubernetes集群進行構建。executor將調用Kubernetes集群API並為每個GitLab CI作業創建一個新的Pod(帶有構建容器和服務容器)。

 

在與GitLab CI一起使用時,Docker executor將連接到Docker Engine,並使用在.gitlab-ci.yml中設置的預定義鏡像在單獨的隔離容器中運行每個構建。這樣,你可以擁有一個簡單且可復制的構建環境。

當與GitLab CI一起使用時,Kubernetes executor將連接到集群中的Kubernetes API,為每個GitLab CI Job創建一個Pod。該Pod至少由一個構建容器,一個輔助容器以及一個用於.gitlab-ci.yml文件定義的每個服務的附加容器組成。 

詳細配置請看文檔

4. Docs

https://docs.gitlab.com/runner/

https://docs.gitlab.com/runner/install/

https://docs.gitlab.com/runner/register/ 

https://docs.gitlab.com/runner/executors/README.html

https://docs.gitlab.com/runner/executors/kubernetes.html

https://docs.gitlab.com/ee/ci/runners/ 

https://docs.gitlab.com/runner/commands/README.html 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM