wai-middleware-consul: Wai Middleware for Consul

[ library, mit, network ] [ Propose Tags ]

Proxies data to/from Consul. Watches for updates.


[Skip to Readme]

Flags

Automatic Flags
NameDescriptionDefault
example

enable example-app executable

Disabled

Use -f <flag> to enable a flag, or -f -<flag> to disable that flag. More info

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.1.0.0, 0.1.0.1, 0.1.0.2
Dependencies async, base (>=4.6 && <5), base-prelude, bytestring, conduit, conduit-extra, consul-haskell, enclosed-exceptions, http-client, http-types, monad-control, monad-logger, network, process (>=1.2), resourcet, text, transformers, void, wai, wai-app-static, wai-conduit, wai-extra, wai-middleware-consul, warp [details]
License MIT
Author FP Complete Developers
Maintainer dev@fpcomplete.com
Category Network
Home page https://github.com/fpco/wai-middleware-consul
Source repo head: git clone https://github.com/fpco/wai-middleware-consul
Uploaded by dysinger at 2015-04-01T07:37:50Z
Distributions
Reverse Dependencies 1 direct, 0 indirect [details]
Executables wai-middleware-consul-example
Downloads 2398 total (11 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2015-04-01 [all 1 reports]

Readme for wai-middleware-consul-0.1.0.2

[back to package description]

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