使用git hook进行自动化代码部署
在服务器上使用git部署代码,然后通过设置一个git-hook实现项目的自动部署。即代码变更后,自动拉取新代码并执行相应的操作
基于Node.js,无需依赖其他package,开箱即用,方便部署git-hook进行自动部署
其中8105替换成所需端口
生产环境最好不要使用这种方法,要用的话,也得把.git
文件夹的访问权限禁用
另外,从req
中可以获取更多的参数,如代码分支等
const http = require('http');
const exec = require('child_process').exec;
const server = http.createServer((req, res) => {
res.end('success');
exec(`
git pull --no-edit origin master
npm stop
npm start
`);
});
server.listen(8105);
文章原始链接:https://sijie.wang/posts/git-hook-auto-deploy
本站文章除特别声明外,均采用
CC BY-NC-SA 4.0
许可协议,转载请保留原始链接
发表评论