Skip to content

Docker image that listens to and logs requests. Useful for testing webhooks.

Notifications You must be signed in to change notification settings

Coveros/webhook-tester

Repository files navigation

webhook-tester

Docker image that listens to and logs requests. Useful for testing webhooks.

Overview

This image is intended to be used as a simple endpoint to check webhook functionality. It is used to test and verify events causing webhooks to be fired and to review the data sent in the request body. It runs a basic Node.js Express application that listens to and logs requests. Currently, it responds to two routes:

  1. GET /healthcheck
    • This will return a 200 OK response
  2. POST /json-hook
    • This will output the JSON request body and headers, and return a 200 OK response

All other requests will be logged and return a 404 Not Found response.

How to use this image

Run the image

By default, the Node.js application in the image listens on port 8080. Map this port to a host port using -p.

$ docker run --name webhook-tester -p 8080:8080 coveros/webhook-tester 

Monitoring the requests

If running the image in the foreground, the logged requests will display as they occur. Alternatively, run the image in detached mode, and follow the logs.

$ docker logs -f CONTAINER

Where CONTAINER is either the container ID or the container name (In the example above, it was defined using the --name argument)

Make requests

Requests can be made any number of ways, either from the command-line or from an external tool.

$ curl -d '{"test": "123"}' -H "Content-Type: application/json" -X POST http://localhost:8080/json-hook

Example log output

$ docker logs -f webhook-tester

Listening on 8080
POST /json-hook request received at 1570827503221
Webhook Request Body:
{
  "test": "123"
}
Webhook Request Headers:
{
  "connection": "keep-alive",
  "content-length": "0"
}

Configure the Port

The container port is configurable with an environment variable setting. There is no need to change this from the default 8080, but by setting the PORT environment variable, you can define the port on which the Node.js application listens. Changing this value necessitates updating the port mapping configuration.

$ docker run --rm -e PORT=3000 -p 8080:3000 --name webhook-tester coveros/webhook-tester

Deploy to Kubernetes cluster

There are a number of options to deploy the webhook-tester into a Kubernetes cluster. One option is to use kubectl to create and expose a simple webhook-tester deployment. These commands will create the deployment and service into the default namespace, and internally expose it. For external access, you will either need to use an Ingress, or change the service from ClusterIP to NodePort or LoadBalancer type.

Create Deployment

$ kubectl create deploy webhook-tester --image=ghcr.io/coveros/webhook-tester:edge 

Expose Deployment

$ kubectl expose deploy webhook-tester --port=8080

Alternatively, you can apply this file

# webhook-tester.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: webhook-tester
  name: webhook-tester
spec:
  replicas: 1
  selector:
    matchLabels:
      app: webhook-tester
  template:
    metadata:
      labels:
        app: webhook-tester
    spec:
      containers:
        - image: ghcr.io/coveros/webhook-tester:edge
          name: webhook-tester
---
apiVersion: v1
kind: Service
metadata:
  name: webhook-tester
  labels:
    app: webhook-tester
spec:
  selector:
    app: webhook-tester
  ports:
    - protocol: TCP
      port: 8080
      targetPort: 8080
  type: ClusterIP
$ kubectl apply -f webhook-tester.yaml

Helm chart release

...Upcoming instructions....

About

Docker image that listens to and logs requests. Useful for testing webhooks.

Resources

Stars

Watchers

Forks

Packages