简体   繁体   中英

Deploy Github release to Node server with webhooks

I've setup a webhook for a repository on Github. When I create a new release in Github, my webhook receiver (on a Node server) receives a request. It works like this (using Express):

app.post("/", function(req, res){  

  //request is not a github event
  if (req.headers["x-github-event"] != "release") return;

  //request is a pre-release
  else if (req.body.release.prerelease) deployToDev();

  //request is full release
  else if (!req.body.release.prerelease) deployToLive();

});

As you can see, it first checks if the request includes a header of a github event with a value of release . If that's all good, it checks whether it's a prerelease or a full release and fires a function to either deploy to dev or live.

The webhook works great, but I'm struggling to find out how to actually deploy the files. Do I do this with some kind of FTP connection or shell script? The dev and live directories are on the same server as the webhook receiver. What is the best way to do this?

If you're already using github, a simple way to deploy is by checking out the code on the target machine.

A trade off is that the target machine needs to have git installed and have credentials to read from your repository.

Another option is to do what you suggested in your question: download archive using your node program above and transferring it to the machine you are deploying on using your protocol of choice: FTP/ssh/rsync/scp, etc..

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM