CI白話來講,就是讓有人Push Reposity時,
自動部屬到測試環境上,並且Compile,Build,Test..等,
第一步就是將Project Code從gitlab上pull下來.
這邊僅記錄如何用web hook建立第一步.
(web hook有很多功能,但此僅用到push觸發的url post)
環境
gitlab 192.168.0.111, member gituser, reposity test
測試環境 192.168.0.100
測試環境
安裝git
yum install git -y
設定git帳號
git config --global user.name "gituser"
git config --global user.email mis@mypay.tw
檢查
git config --list
產生ssh金鑰,並匯入gitlab gituser帳號
ssh-keygen -t rsa
顯示公鑰內容
cat ~/.ssh/id_rsa.pub
將內容貼到gitlab -> (gituser)profile settings -> SSH Keys -> Add SSH Key
測試git clone
cd /path/reposities
git clone 'git@192.168.0.100:gituser/test.git'
安裝 olipo186/Git-Auto-Deploy (可支援多reposities)
git clone https://github.com/olipo186/Github-Gitlab-Auto-Deploy.git auto-git-deploy && cd auto-git-deploy
配置reposities部署設定
cp GitAutoDeploy.conf.json.example GitAutoDeploy.conf.json
vi GitAutoDeploy.conf.json
{
"pidfilepath": "~/.gitautodeploy.pid",
"host": "0.0.0.0",
"port": 8001,
"global_deploy": [
"echo Deploy started!",
"echo Deploy completed!"
],
"repositories":
[{
"url": "git@192.168.0.100:gituser/test.git",
"branch": "master",
"remote": "origin",
"path": "/path/reposities/group_project_test",
"deploy": "echo test deploying"
}]
}
測試啟動git auto deploy
python GitAutoDeploy.py
(此刻就會先pull reposities, 而 /path/reposities目錄需能讓root寫入,執行git指令)
設定開機背景執行在/etc/rc.local新增一行
vi /etc/rc.local
python /opt/auto-git-deploy/GitAutoDeploy.py --daemon-mode --quiet --config /opt/auto-git-deploy/GitAutoDeploy.conf.json
檢查git auto deploy服務是否有開
netstat -anpl | grep 8001
開啟gitlab網頁,掛起web hook
Projects -> Settings -> Web Hooks
填入http://192.168.0.100:8001/
並且test hook(可以啟用SSL)