GitLab Runner

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

1. Installlinux

Install GitLab Runner using the official GitLab repositories (首選ios

一、添加GitLab的官方倉庫:git

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

二、安裝最新版本的GitLab Runnershell

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

三、爲了安裝特定版本bash

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

四、升級Runner架構

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

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

# 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 

下載完之後便可安裝gitlab

# 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 

手動安裝ui

一、下載二進制文件

# 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

二、添加可執行權限

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

三、建立GitLab CI用戶

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

四、安裝並做爲服務運行

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

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

二、註冊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 

相關文章
相關標籤/搜索