Continuous deployment

This implements a github webhook which triggers an automated update.

## Workflow

The webhook at `web/github.php` is called. It checks if the update is targeted for our repository (dothiv) and the branch of the current clone. If all matches the file `app/cache/update` is created. This is done by the webserver user which has write permissions to the cache folder anyway.

A cronjob of `deployment/dothiv-web-01.dothiv.org.deploy.sh` is running every minute and checks for the existence of the `app/cache/update`. If it exists it creates a lockfile `app/cache/update.lock`, creates a symlink of the `web/index.php` to the `web/maintenance.php` and executs the update procedure. The user running this cronjob needs write permissions to the checkout. The lockfile is used to prevent multiple update jobs running at once.

If the update procedure succeeds the `app/cache/update[.lock]` is removed and the symlink of `web/index.php` to `web/app.php` is created.

## Maintenance page

The `web/maintenance.php` file contains a simple error page which returns a HTTP 503 error code and a `Retry-After: 60` header. It automatically refreshes itself after 60 seconds (including the hashbang if present).

## Result via email

The result of the update process is mailed via the cron deamon and looks like this:

    # Updating /var/www/preview.dothiv …

    # Writing lock file …
    /var/www/preview.dothiv/app/cache/update.lock

    # Activating maintenance page…
    `web/index.php' -> `maintenance.php'

    # Stashing changes …
    No local changes to save
    # Pulling …
    HEAD is now at a759b22 feat(continous-deployment): implement update of deployment via hook
    remote: Counting objects: 23, done.
    remote: Compressing objects: 100% (23/23), done.
    remote: Total 23 (delta 10), reused 0 (delta 0)
    Unpacking objects: 100% (23/23), done.
    From https://github.com/coderbyheart/dothiv
      a759b22..3cac207  continuous-deployment -> origin/continuous-deployment
    Updating a759b22..3cac207
    Fast-forward
    deployment/dothiv-web-01.dothiv.org.deploy.sh |   12 ++++++++----
    deployment/dothiv-web-01.dothiv.org.sh        |    3 ---
    deployment/update.sh                          |   12 ------------
    web/maintenance.php                           |   16 ++++++++--------
    4 files changed, 16 insertions(+), 27 deletions(-)
    delete mode 100755 deployment/dothiv-web-01.dothiv.org.sh
    delete mode 100644 deployment/update.sh

    Clearing the cache for the prod environment with debug false

    # composer install …
    Loading composer repositories with package information
    Installing dependencies (including require-dev) from lock file
    Nothing to install or update
    Generating autoload files
    Updating the "app/config/parameters.yml" file
    Clearing the cache for the dev environment with debug true
    Installing assets using the hard copy option
    Installing assets for Symfony\Bundle\FrameworkBundle into web/bundles/framework
    Installing assets for DotHiv\WebsiteCharityBundle into web/bundles/dothivwebsitecharity
    Installing assets for DotHiv\WebsiteCompanyBundle into web/bundles/dothivwebsitecompany
    Installing assets for DotHiv\WebsiteBaseBundle into web/bundles/dothivwebsitebase
    Installing assets for Sensio\Bundle\DistributionBundle into web/bundles/sensiodistribution
    Installing assets for Nelmio\ApiDocBundle into web/bundles/nelmioapidoc

    # npm install …

    # Updating assets_version to 1392232788
    # Updating assets
    Installing assets using the symlink option
    Installing assets for Symfony\Bundle\FrameworkBundle into web/bundles/framework
    Installing assets for DotHiv\WebsiteCharityBundle into web/bundles/dothivwebsitecharity
    Installing assets for DotHiv\WebsiteCompanyBundle into web/bundles/dothivwebsitecompany
    Installing assets for DotHiv\WebsiteBaseBundle into web/bundles/dothivwebsitebase
    Dumping all prod assets.
    Debug mode is off.

    19:58:22 [file+] /var/www/preview.dothiv/app/../web/css/bc084b6.css
    19:58:23 [file+] /var/www/preview.dothiv/app/../web/js/9c88add.min.js
    20:01:57 [file+] /var/www/preview.dothiv/app/../web/css/d66ce9a.css
    20:01:58 [file+] /var/www/preview.dothiv/app/../web/js/a15bfb4.min.js

    # Deactivating maintenance page…
    `web/index.php' -> `app.php'

    # Removing update flag and lock file …
    removed `/var/www/preview.dothiv/app/cache/update'
    removed `/var/www/preview.dothiv/app/cache/update.lock'

    # Done.