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 //packages.gitlab.com/gitlab/gitlab-ce/packages/el/7/gitlab-ce-12.10.0-ce.0.el7.x86_64.rpm/download.rpm //有的時候會下載報錯,建議使用瀏覽器下載完成後,再拷貝
$ EXTERNAL_URL=”//xxxxxxx” yum -y install gitlab-ce-12.10.0-ce.0.el7.x86_64.rpm
二、Runner安裝
1、centos安裝runner:
1)下載://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 //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”: [“//g9ppwtqr.mirror.aliyuncs.com”] } EOF
$ systemctl start docker && systemctl enable docker
2)啟動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 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. //gitlab.com/):
//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
$ 註冊: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. //gitlab.com/):
//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配置參數詳解
//www.cnblogs.com/wu-wu/p/13269950.html
五、程式碼構建
未完待續。。。。。