MyNixOS website logo
Description

Wai Middleware for Consul.

Proxies data to/from Consul. Watches for updates.

WAI Consul Middleware

TravisCI Hackage

This library assists you in monitoring Consul k/v data & with proxying data to Consul safely from the Internet. The first use case is receiving Github 'push' notifications when a repository is updated and doing a git pull on all webservers to update content. The example app shows GitHub Webhooks working.

      ┌─────────┐      ┌─────────┐
      │ Github  │      │         │
      │  Repo   │─────▶│ AWS ELB │
      │ Webhook │      │         │
      └─────────┘      └─────────┘
                            │
        ┌────────────┬──────┘─ ─ ─
        │                         │
        ▼            ▼            ▼
   ┌─────────┐  ┌─────────┐  ┌─────────┐
   │         │  │         │  │         │
┌──│ WAI App │  │ WAI App │  │ WAI App │
│  │         │  │         │  │         │
│  └─────────┘  └─────────┘  └─────────┘
│                    ▲            ▲
│                    │            │
│       ┌────────────┴────────────┘
│       │
│       │
│  ┌─────────┐  ┌─────────┐  ┌─────────┐
│  │         │  │         │  │         │
└─▶│ Consul  │──│ Consul  │──│ Consul  │
   │         │  │         │  │         │
   └─────────┘  └─────────┘  └─────────┘

Install

cabal install wai-middleware-consul

Or if you want to play with the example github webhook web-app:

cabal install -fexample wai-middleware-consul

Example

You'll need to launch a small Consul cluster to try the example app. It's easy to do with Docker. Please use the following steps:

Launch 4 containers of Docker w/ Consul running on each

docker run -d --name node1 -h node1 progrium/consul -server -bootstrap-expect 3
sleep 10
JOIN_IP="$(docker inspect -f '{{.NetworkSettings.IPAddress}}' node1)"
docker run -d --name node2 -h node2 progrium/consul -server -join $JOIN_IP
docker run -d --name node3 -h node3 progrium/consul -server -join $JOIN_IP
docker run -d -p 8400:8400 -p 8500:8500 -p 8600:53/udp --name node4 -h node4 progrium/consul -join $JOIN_IP
sleep 10
  1. Try out all the interfaces of Consul

    1. Browse the Web UI Interface

    2. Query Consul at the command line

      consul members
      
    3. Query the HTTP Interface

      curl 0.0.0.0:8500/v1/catalog/nodes
      
    4. Query the DNS Interface

      dig @0.0.0.0 -p 8600 node1.node.consul
      

Setting up a Github Webhook

First we start `ngrok` to proxy HTTP requests from the Internet to our local machine (most likely behind a firewall). Then we'll start the example web application to receive webhooks from Github.

Run the example application (in the root Github directory for wai-middleware-consul). We need to be in this directory so our example app can find/read cabal & Github version status.

./.cabal-sandbox/bin/wai-middleware-consul-example

Try navigating to the example app page. http://0.0.0.0:8080

Run ngrok to expose the example application to the Internet:

ngrok 8080 ;# take note of this public web address for Github

Set up the webhook for the repo on Github. Point it to the ngrok web address and add the path /github onto that URL ( eg, https://be2f75d.ngrok.com/github ). This is the specific route in the example application for Github->Consul data updates.

Now that we have the application running and a proxy to the public Internet established, we can receive webhook events.

Try pushing to the repository. You should see notifications that an event was received in the web application STDOUT log. The event should be pushed into Consul also. The web application will be listening to events from Consul & this will fire also. You should see it try to `git pull` the repository & you should see the changes if you refresh the home page of the example app.

Cleanup (kill & remove Consul containers)

for n in $(seq 1 4); do
    docker kill node$n
    docker rm node$n
done
Metadata

Version

0.1.0.2

License

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows