mozilla/openbadges — pull request #157 by brianloveswords (2012-05-04 06:26:11+00:00)
Title: 156 continuous devployment

Here's how this works:

`bin/deployer` is a webhook listener that detects test completion payloads coming from Travis. Here's the usage information:

```
± bin/deployer --help

Usage: deployer [options]

Options:

-h, --help output usage information
-V, --version output the version number
-p, --port port the webhook endpoint should listen on
-a, --auth authorization key to expect in the header
-b, --branch branch to watch
-e, --script file to execute on a successful test run
```

(`auth` is a secret token that travis provides so payloads can't be spoofed.)

`bin/start` is a process supervisor that starts the server and is designed to do just one thing: restart the server when it crashes. After a certain number of crashes in a certain time frame (five crashes in five seconds), it gives up trying to restart the server as a failsafe against an endless cycle of crashing. It also crashes the server and automatically spawns a new one if it catches a SIGHUP. Usage for that is simple:

```
± bin/start --help

Usage: start [options]

Options:

-h, --help output usage information
-V, --version output the version number
-e, --env [env] run under specified environment
-f, --pidfile [file] save a pidfile
```

`bin/update.sh` is the workhorse: it `git pull`s, `npm install`s, `npm test`s (for good measure), and sends a SIGHUP to the supervisor.

Altogether, we have a song and dance that goes like this:

`± bin/start -f var/server.pid #that's where update.sh expects the pidfile`

`± bin/deployer -p 9999 -a secretzomg -b development -e bin/update.sh`

Whenever Travis sends a payload with `status: 0` && `status_message: 'passed'` && `branch: 'development'`, the `bin/update.sh` script will run and the output will be logged, both to the console and retrievable by GET request at `:9999`.