This repo should be cloned into your GOPATH
at
${GOPATH%%:*}/src/github.com/travis-ci/pudding
.
If you don't know what GOPATH
is or are unsure if the top entry
is in a non-volatile location, you should Ask Someone ™
go get github.com/hamfist/deppy
go get github.com/golang/lint/golint
go get golang.org/x/tools/cmd/cover
gometalinter --install
Do everything:
make
Only clean and build, with less output:
make clean build GOBUILD_FLAGS=
As with other heroku apps:
foreman start
The same, but without rerun
in the mix:
DYNO=1 foreman start
The web API exposes the following resources, with most requiring authentication via token:
Provides a friendly greeting
Gracefully shut down the server
Simulate a panic. No body expected.
Provide a list of instances, optionally filtered with env
and site
query params.
Provide a list containing a single instance matching the given
instance_id
, if it exists.
Terminate an instance that matches the given instance_id
, if it
exists.
Start an instance build, which will result in an EC2 instance being
created. The expected body is a jsonapi singular collection of
"instance_build"
, like so:
{
"instance_builds": {
"role": "worker",
"site": "org",
"env": "staging",
"instance_type": "c3.2xlarge",
"slack_channel": "#general",
"count": 4,
"queue": "docker",
"boot_instance": true
}
}
Note: You can prevent pudding from booting an instance by setting the
boot_instance
flag tofalse
-- in this case it will only create a cloud-init script.
"Update" an instance build; currently used to send notifications to
Slack upon completion of a build. Expects
application/x-www-form-urlencoded
params in the body, a la:
state=finished&instance-id=i-abcd1234&slack-channel=general
This route accepts both token auth and "init script auth", which is
basic auth specific to the instance build and is kept in a redis
key with expiry. This is the route hit by the cloud-init
#include
set in EC2 instance user data when the instance is
created. It responds with a content type of text/x-shellscript; charset=utf-8
, which is expected (but not enforced) by cloud-init.
Provide a list of images per role, denoting which is active. Example response:
{
"images": [
{
"ami": "ami-00aabbcc",
"active": true,
"role": "web"
},
{
"ami": "ami-00aabbcd",
"active": false,
"role": "web"
}
]
}
The background job workers are started as a separate process and
communicate with the web server via redis. The sidekiq-compatible
workers are built using
go-workers
. There are
also non-evented "mini workers" that run in a simple run-sleep loop
in a separate goroutine.
Jobs handled on the instance-builds
queue perform the following
actions:
- resolve the
ami
id, using the most recent available if absent - create a custom security group and authorize inbound port 22
- prepare a cloud-init script and store it in redis
- prepare an
#include
statement with custom URL to be used in the instance user-data - create an instance with the resolved ami id,
#include <url>
user-data, custom security group, and specified instance type - tag the instance with
role
,Name
,site
,env
, andqueue
- send slack notification that the instance has been created
Jobs handled on the instance-terminations
queue perform the
following actions:
- terminate the instance by id, e.g.
i-abcd1234
- remove the instance from the redis cache