2012-05-06 08:03:35 +04:00
|
|
|
Deployment system for Yesod (and other Haskell) web apps.
|
|
|
|
|
2012-10-24 18:54:26 +04:00
|
|
|
## Quick Start
|
|
|
|
|
|
|
|
Do get Keter up-and-running quickly on an Ubuntu system, run:
|
|
|
|
|
2012-12-28 18:27:55 +04:00
|
|
|
wget -O - https://raw.github.com/snoyberg/keter/master/setup-keter.sh | bash
|
2012-10-24 18:54:26 +04:00
|
|
|
|
|
|
|
(Note: you may need to run the above command twice, if the shell exits after
|
|
|
|
`apt-get` but before running the rest of its instructions.) This will download
|
|
|
|
and build Keter from source and get it running with a
|
|
|
|
default configuration.
|
|
|
|
|
2012-05-18 09:50:51 +04:00
|
|
|
## Setup
|
|
|
|
|
|
|
|
Instructions are for an Ubuntu system. Eventually, I hope to provide a PPA for
|
|
|
|
this (please contact me if you would like to assist with this). For now, the
|
|
|
|
following steps should be sufficient:
|
|
|
|
|
2012-09-14 07:26:47 +04:00
|
|
|
First, install PostgreSQL
|
2012-05-18 09:50:51 +04:00
|
|
|
|
2012-09-14 07:26:47 +04:00
|
|
|
sudo apt-get install postgresql
|
2012-05-18 09:50:51 +04:00
|
|
|
|
2012-10-24 18:30:14 +04:00
|
|
|
Second, build the `keter` binary and place it at `/opt/keter/bin`. To do so,
|
|
|
|
you'll need to install the Haskell Platform, and can then build with `cabal`.
|
|
|
|
This would look something like:
|
|
|
|
|
|
|
|
sudo apt-get install haskell-platform
|
|
|
|
cabal update
|
|
|
|
cabal install keter
|
|
|
|
sudo mkdir -p /opt/keter/bin
|
|
|
|
sudo cp ~/.cabal/bin/keter /opt/keter/bin
|
2012-05-18 09:50:51 +04:00
|
|
|
|
2012-09-14 07:26:47 +04:00
|
|
|
Third, create a Keter config file:
|
|
|
|
|
|
|
|
```yaml
|
|
|
|
# /opt/keter/etc/keter-config.yaml
|
|
|
|
root: ..
|
|
|
|
# host: host to bind to
|
|
|
|
# port: port to listen on
|
2012-10-24 18:31:18 +04:00
|
|
|
# setuid: myname
|
2012-09-14 07:26:47 +04:00
|
|
|
# ssl:
|
|
|
|
# host:
|
|
|
|
# port:
|
|
|
|
# key:
|
|
|
|
# certificate:
|
2013-03-17 01:39:38 +04:00
|
|
|
# reverse-proxy:
|
|
|
|
# - reversed-host: some-internal-site
|
|
|
|
# reversed-port: 80
|
|
|
|
# reversing-host: internal.example.com
|
2013-03-20 09:24:48 +04:00
|
|
|
# ssl: whether the reversed host uses SSL (defaults to False)
|
|
|
|
# # response headers can be rewritten as follows:
|
|
|
|
# rewrite-response:
|
2013-03-20 09:09:42 +04:00
|
|
|
# - header: Location
|
2013-03-20 09:24:48 +04:00
|
|
|
# from: ^http://internal-service.example.com
|
|
|
|
# to: https://service.example.com
|
|
|
|
# # request headers can be rewritten as well, though less likely
|
|
|
|
# # to be used.
|
|
|
|
# rewrite-request:
|
|
|
|
# - header: X-SomeApplicationHeader
|
|
|
|
# from: ^https://internal-service.example.com
|
|
|
|
# to: http://service.example.com
|
|
|
|
# # Header rewriting supports POSIX regular expressions in the "from" and
|
|
|
|
# # supports referencing matched groups in the "to" with "\1", "\2", ...
|
2012-09-14 07:26:47 +04:00
|
|
|
```
|
|
|
|
|
|
|
|
Fourth, set up an Upstart job to start `keter` when your system boots.
|
2012-05-18 09:50:51 +04:00
|
|
|
|
|
|
|
```
|
|
|
|
# /etc/init/keter.conf
|
|
|
|
start on (net-device-up and local-filesystems and runlevel [2345])
|
|
|
|
stop on runlevel [016]
|
|
|
|
respawn
|
|
|
|
|
|
|
|
console none
|
|
|
|
|
2012-10-23 22:48:55 +04:00
|
|
|
exec /opt/keter/bin/keter /opt/keter/etc/keter-config.yaml
|
2012-05-18 09:50:51 +04:00
|
|
|
```
|
|
|
|
|
|
|
|
Finally, start the job for the first time:
|
|
|
|
|
|
|
|
sudo start keter
|
|
|
|
|
2012-10-24 18:30:14 +04:00
|
|
|
Optionally, you may wish to change the owner on the `/opt/keter/incoming`
|
|
|
|
folder to your user account, so that you can deploy without `sudo`ing.
|
|
|
|
|
|
|
|
sudo mkdir -p /opt/keter/incoming
|
|
|
|
sudo chown $USER /opt/keter/incoming
|
|
|
|
|
2012-05-18 09:50:51 +04:00
|
|
|
## Bundles
|
|
|
|
|
|
|
|
An application needs to be set up as a keter bundle. This is a GZIPed tarball
|
|
|
|
with a `.keter` filename extension and which has one special file:
|
|
|
|
`config/keter.yaml`. A sample file is:
|
|
|
|
|
|
|
|
```yaml
|
|
|
|
exec: ../dist/build/yesodweb/yesodweb
|
|
|
|
args:
|
|
|
|
- production
|
2013-01-02 20:33:30 +04:00
|
|
|
host: www.yesodweb.com # can replace with "*" to be the default app
|
2012-09-14 07:29:03 +04:00
|
|
|
ssl: false # true would use https scheme for approot
|
2012-10-14 20:17:01 +04:00
|
|
|
|
|
|
|
# Additional hosts your app will listen on, without affecting approot.
|
|
|
|
extra-hosts:
|
|
|
|
- www1.yesodweb.com
|
|
|
|
|
|
|
|
# Static file hosts. Keter handles the serving for you.
|
|
|
|
static-hosts:
|
|
|
|
- host: static.yesodweb.com
|
|
|
|
root: ../static # relative to config file, just like the executable
|
2012-10-21 09:07:26 +04:00
|
|
|
|
|
|
|
# Host name redirects.
|
|
|
|
redirects:
|
|
|
|
- from: yesodweb.com
|
|
|
|
to: www.yesodweb.com
|
2012-05-18 09:50:51 +04:00
|
|
|
```
|
|
|
|
|
2012-09-14 07:26:47 +04:00
|
|
|
A sample Bash script for producing a Keter bundle is:
|
2012-05-18 09:50:51 +04:00
|
|
|
|
|
|
|
```bash
|
|
|
|
#!/bin/bash -ex
|
|
|
|
|
|
|
|
cabal build
|
|
|
|
strip dist/build/yesodweb/yesodweb
|
|
|
|
rm -rf static/tmp
|
|
|
|
tar czfv yesodweb.keter dist/build/yesodweb/yesodweb config static
|
|
|
|
```
|
|
|
|
|
2012-09-14 07:26:47 +04:00
|
|
|
For users of Yesod, The `yesod` executable provides a `keter` command for
|
|
|
|
creating the bundle, and the scaffolded site provides a `keter.yaml` file.
|
|
|
|
|
2012-05-18 09:50:51 +04:00
|
|
|
## Deploying
|
|
|
|
|
|
|
|
In order to deploy, you simply copy the keter bundle to `/opt/keter/incoming`.
|
|
|
|
To update an app, copy in the new version. The old process will only be
|
|
|
|
terminated after the new process has started answering requests. To stop an
|
|
|
|
application, delete the file from incoming.
|