I know it isn’t cool these days to just have a build-script, but you really don’t have to follow the trend of making CI more and more comlicated. Jenkins and Docker both have their respective places, but these powerful tools should be used with care, and only whenever the complexity of a project actually justifies and necessitates complex CI-pipelines.
Cue Webhooks. GitLab and GitHub have an inbuilt feature called Webooks. Whenever a certain event, for example a push on the master branch, occurs, a remote URL is automaticly queried to inform a remote server of this event.
First, you need to think about the steps required to redeploy your application with a new version. The simplest form might just be a script which looks like this:
#!/bin/bash cd /path/to/project/ git pull sudo systemctl restart project.service
If you want to do a restart via systemctl as a normal user, you can allow it in /etc/sudoers like this:
webhookListenerUsername ALL=(root) NOPASSWD: /bin/systemctl restart SERVICE.service
Obviously if the buildscript is contained within the respective project, something like this might be more appropriate:
webhookListenerUsername ALL=(otherUser) NOPASSWD: /path/to/build/script.sh
I wrote a very simple and easy to use Webhook Listener and Handler. Clone the project and setup an autostart, either via systemd or cron. Create a config file as described in the README.md and enter the script that should be executed. Select a secure token or password which you will later enter in the GitLab- or GitHub-Webinterface. If you want your application to be available through HTTPS you have to set up a reverse proxy and certificate. A nginx-proxy config snippet can be found within the README.md aswell.
On GitHub, select the project or organization you want to create a webhook for, navigate to Settings -> Webhooks, enter your server’s adress, select application/json, enter the secret token or password you chose before and select which events should trigger a webhook. The reponse to an automated check of your settings should be availible shortly after.
On Gitlab, select the project you want to create a webhook for, navigate to Settings -> Integrations, enter your server’s address, enter the secret token or password you chose before and select which events should trigger a webhook. For this example we choose Push-events on the master-branch. Save and scroll down to test your settings.
Feel free to send me a mail to share your thoughts!