Webhook Relay
PricingLogin
  • Introduction
  • Quick Start - Forwarding
  • Quick Start - Tunnels
  • 🛠️Installation
    • Relay CLI
      • Install
      • Auto-start
      • Run config.yaml reference
    • Containerized
      • Kubernetes Installation
      • Podman
      • Docker
      • Docker Compose
  • Products
    • 🛰️Webhook Forwarding
      • Glossary
      • WebSocket Server
      • Authentication
      • Custom Domains
    • ⚡Functions
      • Managing functions
      • Edit request/response
      • Working with JSON
      • 🦾Advanced
        • Working with time
        • Testing functions in CLI
        • Making HTTP Requests
        • Multipart Form Data
        • URLEncoded Form Data
        • GCP BigQuery
        • Sending Emails
        • JWT authentication
        • Base64, Hashes, Encryption
      • 🤖Integrating into CI/CD
    • 🔃Tunnels
      • Using tunnels
      • Custom Domains
      • Encryption (HTTPS)
      • Regions
  • 📝Examples
    • Intro to examples
    • Webhooks
      • Receiving webhooks on localhost
      • Receive webhooks inside your JavaScript app
      • Execute shell scripts on remote machines
    • Functions
      • Enrich webhooks from 3rd party APIs
      • Convert DockerHub webhook to Slack notification
      • Allowing only POST requests through
      • Manipulate webhook request body
    • Tunnels
      • Ingress for any Kubernetes environment
      • Demoing your website
    • 🏠Home Automation
      • Home Assistant
      • Node-RED
      • Raspberry Pi
  • Platform
    • CLI Basics
    • Using CLI Behind Proxy
    • Self-hosting Server
      • Server deployment
      • Client configuration
    • Security & Tech
Powered by GitBook
On this page
  • Create a bucket and configure DockerHub notification
  • Get a sample of DockerHub webhook
  • Create a Function to transform the webhook
  • Connect everything together

Was this helpful?

  1. Examples
  2. Functions

Convert DockerHub webhook to Slack notification

A short example on integrating two services directly by utilizing Functions.

PreviousEnrich webhooks from 3rd party APIsNextAllowing only POST requests through

Last updated 3 years ago

Was this helpful?

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

  1. Create a bucket here

  2. Once you have it, in the inputs section you will find your public input endpoint, copy it:

  3. Add a new DockerHub webhook setting pointing at our public input endpoint ():

Get a sample of DockerHub webhook

Push a new Docker image:

$ docker push karolisr/demo-webhook:latest
The push refers to repository [docker.io/karolisr/demo-webhook]
48bd38e03c42: Mounted from karolisr/webhook-demo
fd9f9fbd5947: Mounted from karolisr/webhook-demo
5216338b40a7: Mounted from karolisr/webhook-demo
latest: digest: sha256:703f2bab2ce8df0c5ec4e45e26718954b09bf4a625ab831c6556fd27d60f1325 size: 949

We should be able to see a new incoming webhook. It looks like this:

{
    "push_data": {
        "pushed_at": 1582839308,
        "images": [],
        "tag": "latest",
        "pusher": "karolisr"
    },
    "callback_url": "https://registry.hub.docker.com/u/karolisr/demo-webhook/hook/242ii4ddc2jji4a0cc44fbcdbcdecj1ab/",
    "repository": {
        "status": "Active",
        "description": "",
        "is_trusted": false,
        "full_description": "",
        "repo_url": "https://hub.docker.com/r/karolisr/demo-webhook",
        "owner": "karolisr",
        "is_official": false,
        "is_private": true,
        "name": "demo-webhook",
        "namespace": "karolisr",
        "star_count": 0,
        "comment_count": 0,
        "date_created": 1524557040,
        "repo_name": "karolisr/demo-webhook"
    }
}

Create a Function to transform the webhook

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):

local json = require("json")

local body, err = json.decode(r.RequestBody)
if err then error(err) end

local message = "New image pushed at: " .. body["repository"]["repo_name"] .. ":" .. body["push_data"]["tag"]

-- Preparing Slack payload
local slack = {
    response_type= "in_channel", 
    text= message}

local result, err = json.encode(slack)

-- Set request header to application/json
r:SetRequestHeader("Content-Type", "application/json")
-- Set request method to POST
r:SetRequestMethod("POST")
-- Set modified request body
r:SetRequestBody(result)

Click “Save” and then try testing it with the “Send” button:

Connect everything together

  1. 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.

  2. Open “OUTPUT DESTINATIONS” tab and create a new output called “Slack” with the Slack URL from step 2:

  3. 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!

Go to the and click on a “Create Function” button. Enter a name, for example “dockerhub-to-slack” and click “Submit”.

Function invoke example

Navigate to and click “Create your Slack app”. Select your workspace, enter a name that you will remember.

Open your bucket details (via )

Slack channel msg
📝
Functions page
https://api.slack.com/messaging/webhooks
https://my.webhookrelay.com/buckets
Webhook Relay account
DockerHub account
https://my.webhookrelay.com/buckets
DockerHub docs
Create destination
Dockerhub webhook config
Select function
Input endpoint URL