Skip to content

7. Auto update server on commit (Webhooks)

spaceface777 edited this page May 1, 2019 · 2 revisions

In this tutorial you will set up a webhook for your server so that it updates automatically every time a commit is made.

DISCLAIMERS

  • These instructions are optional, and not necessary for your server to function.

  • However, it will save you a lot of time of updating it manually, so I recommend you do it.

  • These instructions are written for Debian-based Linux distributions (Debian, Ubuntu, Raspbian...). You may need to change some of the commands for them to work in other Linux distros, and Windows is unsupported and will most likely not work.

  • You should already have a Hermes server already running before following these instructions! (Although it isn't required, why would you set up automatic updates if you don't even have a server?) Follow the previous guides to get this.

  • You need to have port 3000 open in your router, since this is the port used to receive commit information. The instructions for this are at the bottom of page 4.

CREATING THE WEBHOOK

First of all, go to the Webhook configuration page on GitHub.

Click on Add Webhook, and enter your server information into the page using this format:

Payload URL - http://{YOUR_DOMAIN}:3000/ (Replace {YOUR_DOMAIN) with the domain of your server)
Content Type - application/json
Secret - Leave this blank.
Events - Send me everything

When you're done, click Add Webhook to create it.

DOWNLOADING THE CODE

First of all, we need to uninstall the Hermes server running in order to replace it with the auto updating version. To do this, enter these commands:

pm2 stop "Hermes Server"
rm -rf ~/Hermes/

Now, we can install the new scripts.

The code for the Webhook is saved in another repo of the organization. To download it we can use git:

git clone https://github.com/HermesMessenger/GithubHooks.git ~/Hermes/

cd ~/Hermes/
npm install

Now, to use the Webhook:

pm2 start github.js --name "GitHub Hooks"

bash hook.sh 
bash hook-testing.sh

pm2 save

The last two commands might give you some warnings; however, this is normal because the scripts are designed to update the server, not create it.


You are done setting up your server! If you want, you can create a secondary server to host a testing server, you can create a new domain for it.

Then, edit the Nginx config file (sudo nano /etc/nginx/sites-available/default) and duplicate the text inside the file.

Then, replace the new server_name entry with your new testing domain, and port 8080 to 8081.

Clone this wiki locally