Code Monkey home page Code Monkey logo

autoupdateserver-node.js's Introduction

AutoUpdateServer-Node.js

这是一个简单的post服务,可部署于服务器/云服务器,用于执行自动化部署。主要利用GitHub Webhooks

GitHub Webhooks

利用GitHub Webhooks来执行自动化部署。

webhooks

在仓库的Settings -> Webhooks中设置了请求地址后,该仓库的每次push操作(当然具体的操作类型可选择)结束后GitHub会向设置的地址发送一个post请求,请求中包括本次操作的仓库、更新的文件等等。

这个post请求相当于一个通知,我们收到post请求后可以对服务器端的本地仓库进行更新,拉取 GitHub上的最新代码,从而实现一次提交,服务器端自动化部署

使用

1.设置config.js

...
module.exports = {
  HOST: "127.0.0.1",// 云服务器要填写该服务器的内网IP
  PORT: 9000,
  logger: logger// 日志
};
...

config.js中设置该服务的IP和端口,HOST为服务的IP,PORT填写服务的端口。

注意项:

  • 需要确保填写的端口正确开通并暴露在公网,需设置防火墙(Windows)或安全组(云服务器);
  • 云服务器的话HOST需要填写服务器的内网地址,填写公网地址可能会报以下错误。 error

2.设置server.js

这里需要配置服务器上的本地仓库的绝对地址

...
const repoName = JSON.parse(request.body.payload).repository.name
const cmd = `/documents/GitHub/${repoName}`;// 本地仓库地址
...

3.开发环境部署

进入文件夹根目录:

npm install # 安装依赖
npm run server # 启动服务

4.服务器端常驻

安装pm2并运行server.js:

npm install pm2 -g
# 进入static文件夹
pm2 start server.js

autoupdateserver-node.js's People

Contributors

starlightunion avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.