git - Webhook让部署自动化

我们现在有一个需求,将项目打包上传到gitlab或者github后,程序能自动部署,不用手动地去服务器中进行项目更新并运行,如何做到?这里我们可以使用gitlabgithub的挂钩,挂钩的原理就是,每当我们有请求到gitlabgithub服务器时,这时他俩会根据我们配置的挂钩地扯进行访问,webhook挂钩程序会一直监听着某个端口请求,一但收到他们发过来的请求,这时就知道用户有请求提交了,这时我们就可以用webhook程序执行部署脚本命令了。

使用指南

Gitlab 方式

下载项目

git clone https://github.com/dounine/gitlab-webhook.git

自行修改第9行读取密码文件的位置

fs.readFile('/root/issp/gitlab-webhook/password.txt', 'utf8',....

修改第65行执行shell脚本位置

cmd.get('/root/issp/docker/' + event.mode + '/run.sh',....

运行

cd gitlab-webhook && ./start.sh

gitlab配置

URL:http://xxxxx:7777/webhook
Secret Token:password.txt里面的密码

Github 方式

下载项目

git clone https://github.com/dounine/github-webhook.git

自行修改第3行密码文件的位置

var secretPassword = 'abc123' //github secret安全密码

修改第7行执行shell脚本位置

var bash = '/root/xxx/test.sh' //执行的脚本

运行

cd github-webhook && ./start.sh

gitlab配置

Payload URL:http://xxxxx:7777/webhook
Secret:安全密码

9028759-5619fe0d9edd7a1b.png

猜你喜欢

转载自blog.csdn.net/weixin_34261415/article/details/90840116
今日推荐