gitlab-ci部署實現持續集成(centos7)


一、gitlab安裝

1. 環境准備

// selinux和 firewall 關閉

$ setenforce 0

$ sed -i "/^SELINUX/s/enforcing/disabled/" /etc/selinux/config

$ systemctl stop firewalld

$ systemctl disable firewalld

2. 離線安裝

$ wget --content-disposition https://packages.gitlab.com/gitlab/gitlab-ce/packages/el/7/gitlab-ce-12.10.0-ce.0.el7.x86_64.rpm/download.rpm

$ EXTERNAL_URL="http://xxxxxxx" yum -y install gitlab-ce-12.10.0-ce.0.el7.x86_64.rpm  # EXTERNAL_URL為設置gitlab的訪問網址

3、更改 EXTERNAL_URL

$ vim /etc/gitlab/gitlab.rb

  external_url 'https://xxxxx'

$ gitlab-ctl reconfigure   #重新應用配置

二、Runner安裝

1、centos安裝runner:

  1)下載:https://gitlab-runner-downloads.s3.amazonaws.com/latest/index.html

  2)安裝:yum -y install gitlab-runner_amd64.rpm

  3)添加服務:gitlab-runner install --user=gitlab-runner --working-directory=/home/gitlab-runner

  4)啟動服務:gitlab-runner start

2、docker安裝runner:

  1)安裝docker:

    $ curl -L --output /etc/yum.repos.d/docker-ce.repo   https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

    $ yum -y install docker-ce

    $ mkdir /etc/docker

    $ tee /etc/docker/daemon.json <<-'EOF' {"registry-mirrors": ["https://g9ppwtqr.mirror.aliyuncs.com"] } EOF

    $ systemctl start docker && systemctl enable docker

  2)啟動docker鏡像的gitlab-runner:

    $ docker run -d --name gitlab-runner --restart always -v /var/run/docker.sock:/var/run/docker.sock -v /data/etc/gitlab-runner:/etc/gitlab-runner gitlab/gitlab-runner:latest

    $ docker logs gitlab-runner  # 讀取docker日志

三、Runner注冊

1、注冊一個全局 Runner

  //使用主機方式注冊(也可以使用docker注冊,詳情見下)

    $  注冊:gitlab-runner register
      Runtime platform arch=amd64 os=linux pid=23268 revision=c553af1a version=12.10.0
      Running in system-mode.

      Please enter the gitlab-ci coordinator URL (e.g. https://gitlab.com/):
      https://xxxx          # 寫入gitlab的地址
      Please enter the gitlab-ci token for this runner:
      zsy4iJK4-hPh8KctpVkM    # 寫入全局的token 
      Please enter the gitlab-ci description for this runner:
      [c720133.xiodi.cn]:       # 寫入概runner的描述
      Please enter the gitlab-ci tags for this runner (comma separated):
      host20133,host-shell     # 寫入使用標簽
      Registering runner... succeeded runner=zsy4iJK4
      Please enter the executor: virtualbox, docker+machine, docker-ssh, docker, parallels, shell, ssh, docker-ssh+machine, kubernetes, custom:
      shell            # 寫入使用執行器
      Runner registered successfully. Feel free to start it, but if it's running already the config should be automatically reloaded!

              

2、注冊一個用戶組 Runner

  //使用 docker 方式注冊(也可以使用主機注冊,詳情見上)

    $ 啟動docker:docker run -d --name gitlab-runner --restart always -v /var/run/docker.sock:/var/run/docker.sock -v /data/etc/gitlab-runner:/etc/gitlab-runner gitlab/gitlab-runner:latest

    $ 進入docker:docker exec -it gitlab-runner /bin/bash

    $ 注冊:gitlab-runner register      

      Runtime platform arch=amd64 os=linux pid=32 revision=c553af1a version=12.10.0
      Running in system-mode.

      Please enter the gitlab-ci coordinator URL (e.g. https://gitlab.com/):
      https://xxxx          # 寫入gitlab的地址
      Please enter the gitlab-ci token for this runner:
      Zz6yDBiRYLzdEBaHZL           # 寫入全局的token 
      Please enter the gitlab-ci description for this runner:
      [dfa0f083e588]: host20133-docker-gitlab-runner    # 寫入概runner的描述
      Please enter the gitlab-ci tags for this runner (comma separated):
      group-host20133-docker,docker     # 寫入使用標簽
      Registering runner... succeeded runner=Zz6yDBiR
      Please enter the executor: shell, ssh, virtualbox, docker-ssh+machine, docker+machine, kubernetes, custom, docker, docker-ssh, parallels:
      docker          # 寫入使用執行器
      Please enter the default Docker image (e.g. ruby:2.6):

      harbor.xiodi.cn/tools/alpine:3.11    #寫入默認鏡像
      Runner registered successfully. Feel free to start it, but if it's running already the config should be automatically reloaded!

      

3、注冊一個項目 Runner

  //(可使用 docker 方式注冊,也可以使用主機注冊,詳情見上)

    $ 啟動docker:docker run -d --name gitlab-runner2 --restart always -v /data/etc/gitlab-runner2:/etc/gitlab-runner -v /var/run/docker.sock:/var/run/docker.sock gitlab/gitlab-runner:latest

    $ 注冊:gitlab-runner register

     

三、Runner常用命令

1、查看可使用命令:gitlab-runner --help

2、查看子命令使用:gitlab-runner <command> --help

3、注冊:gitlab-runner register

4、列出配置文件中的所有runner:gitlab-runner list

5、驗證是否被 GitLab 使用:gitlab-runner verify  

6、注銷特定的 Runner:gitlab-runner unregister

7、服務安裝:gitlab-runner install

8、服務卸載:gitlab-runner uninstall

9、服務啟動-:gitlab-runner start

10、服務停止:gitlab-runner stop 

11、服務重啟:gitlab-runner restart

12、服務狀態:gitlab-runner status

13、從GitLab下載工件檔案:gitlab-runner artifacts-downloader

14、將工件檔案上傳到GitLab:gitlab-runner artifacts-uploader

15、創建緩存存檔,將其存儲在本地或將其上傳到外部服務器:gitlab-runner cache-archiver

16、從本地或外部存儲的文件還原緩存檔案:gitlab-runner cache-extractor

四、gitlab-runner配置參數詳解

https://www.cnblogs.com/wu-wu/p/13269950.html

五、代碼構建

https://www.cnblogs.com/wu-wu/p/13276400.html

 


免責聲明!

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



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