Convert DockerHub webhook to Slack notification
A short example on integrating two services directly by utilizing Functions.
Many Docker registries provide a way to notify team in chat channels when new images are pushed (if you are waiting for a build complete). Let’s add this capability to the official DockerHub registry! :)
Prerequisites:
Docker
Create a bucket and configure DockerHub notification
Create a bucket here https://my.webhookrelay.com/buckets
Once you have it, in the inputs section you will find your public input endpoint, copy it:
Add a new DockerHub webhook setting pointing at our public input endpoint (DockerHub docs):
Get a sample of DockerHub webhook
Push a new Docker image:
We should be able to see a new incoming webhook. It looks like this:
Create a Function to transform the webhook
Go to the Functions page and click on a “Create Function” button. Enter a name, for example “dockerhub-to-slack” and click “Submit”.
You can now copy/paste webhook payload into the “request body” area for later tests. In the code editor let’s add a function to get repository name and prepare a Slack webhook payload (currently functions have to be written in Lua but more examples for WebAssembly will be added soon):
Click “Save” and then try testing it with the “Send” button:
Connect everything together
Navigate to https://api.slack.com/messaging/webhooks and click “Create your Slack app”. Select your workspace, enter a name that you will remember.
Create a new incoming webhook configuration, copy “Webhook URL” (it starts with
https://hooks.slack.com/services/T3...
), we will need to supply it to Webhook Relay.Open your bucket details (via https://my.webhookrelay.com/buckets)
Open “OUTPUT DESTINATIONS” tab and create a new output called “Slack” with the Slack URL from step 2:
Once created, click on the “code” symbol and from the dropdown select
dockerhub_to_slack
function:
Push new image to DockerHub, you should see a new notification in your Slack channel:
That’s it, feel free to continue modifying Lua function to include pusher’s name and message format. Following this process you can transform any webhook into any other webhook.
Have fun!
Last updated