GitHub Webhook receiver
This example shows how to build a simple GitHub Webhook receiver using Node.js with Express and run it on Unikraft Cloud. A webhook, also called a reverse API, is a way for a server to send real-time data to other applications when a specific event occurs. In this case, the webhook receiver listens for GitHub events, such as push events or pull request events, and logs them to the console. To run this it, follow these steps:
-
Install the CLI and a container runtime engine, for example Docker. Use the unikraft CLI or the legacy kraft CLI.
-
Clone the
examplesrepository andcdinto theexamples/github-webhook-node/directory:
Code
Make sure to log into Unikraft Cloud and pick a metro close to you.
This guide uses fra (Frankfurt, 🇩🇪):
When done, invoke the following command to deploy this app on Unikraft Cloud:
GITHUB_WEBHOOK_SECRET is the secret used to verify incoming webhook requests from GitHub.
Set it to a string with high entropy.
The output shows the instance address and other details:
Code
In this case, the instance name is github-webhook-node-bzq7u and the address is https://dry-cloud-uuw0qlb6.fra.unikraft.app.
They're different for each run.
Use curl to query the Unikraft Cloud instance of the Node.js webhook server's health endpoint:
Code
Code
The uptime field is so small because Unikraft Cloud scales the instance to zero when no connections are active.
When a request comes in, Unikraft Cloud automatically starts the instance.
To see the incoming webhook events (you set up the webhook in GitHub), you can retrieve the logs of the instance by running:
Code
GitHub sends the ping event when you set up the webhook.
You can list information about the instance by running:
Code
When done, you can remove the instance:
Test GitHub webhooks
To test the GitHub webhook receiver, you must set up a webhook in a GitHub repository.
Make sure to set the payload address to the Unikraft Cloud instance webhook, in this case https://dry-cloud-uuw0qlb6.fra.unikraft.app/webhook/github.
You should also set the content type to application/json and select the events you want to receive.
Lastly, you should set the secret to verify that the requests come from GitHub and weren't tampered with.
Now, once you make changes in the repository (that you are listening to), you should see the webhook events logged in the instance logs:
Code
Customize your app
To customize the app, update the files in the repository, listed below:
server.js: The Node.js Express web server that handles GitHub webhook eventsKraftfile: the Unikraft Cloud specificationDockerfile: the Docker-specified app filesystem
Learn more
Use the --help option for detailed information on using Unikraft Cloud:
Or visit the CLI Reference or the legacy CLI Reference.