Scripts and keys needed to initialize docks provisioned via Shiva.
The dock-init
repository lives on docks and contains the required scripts and
keys needed fully provision and start a dock in a production environment. The
project's primarily used to create new EC2 AMIs that are referenced by
shiva during dock provisioning.
This document will cover the basics of what the initialization scripts do, and how to create a new dock AMI.
Docks are instantiated on EC2 by running specialized dock AMIs. These AMIs are
expected to have an /opt/runnable
path containing all required dock service
repositories along with dock-init
.
The dock-init scripts are run in response to the provisioning of a new dock via shiva:
First, a cluster-instance-provision
event is picked up by a shiva worker
server. Shiva then selects the appropriate dock AMI, and constructs a special
User Data Script
that sets the correct environment variables (/opt/runnable/env
), and host tags
(/opt/runnable/host_tags
) for the dock and finally executes the init.sh
script.
The logs for the dock init scripts can be found on a dock at the following location:
/var/log/user-script-dock-init.log.log
This should be the first place to look if a dock was provisioned but did not register itself with the rest of the system correctly. Also pay careful attention to the version numbers for each of the projects when they are pulled.
First, install shellcheck. It is a linter for shell scripts and it is used for helping us conform to the style guide. Here's the command you'll need to run (OSX):
brew install shellcheck
Second, you'll need to install shpec locally as well. Shpec is a spec based unit testing framework specifically geared to test scripts, here's how to install (OSX):
sh -c "$(curl -L https://raw.github.com/rylnd/shpec/master/install.sh)"
A few other tools are required to test locally, here's how to install them:
brew install jq
To run the test suite use the following command: bash unit.sh
. This will setup
the test environment and run the unit test suites. The test suites can be found
under the test/
directory.
The project's main script is init.sh
. This performs the following actions:
- Connect to consul
- Check the version of dock-init itself (via consul)
- If needed, perform a pull to the correct version of dock-init
- Execute the
dock::init
method defined inlib/dock.sh
The rest of the implementation for the project lives in the lib/
directory.
For the most part the filenames have been chosen to give as much context as
possible to make the project easy to navigate.
Dock-init uses consul and the wonderful consul-template
utility to generate
service upstart scripts via values found in consul. These templates and other
resources associated with consul live in the consul-resources/
directory.
Each of the services lives on the dock as git repository. When the init.sh
script fetches all repository information for a service it uses one or more
of the deploy keys given in the key/
directory.
NOTE: On an actual dock the private keys require access rights of at least 600.
Use the util/lock-keys.sh
script to ensure that all private keys are, well,
locked down.
The project also comes equipped with a slew of development utility scripts under
the util/
directory. These scripts make it easy to test dock-init on an ec2
instance, pull specific versions of the library, and perform other tasks.
This is the easy way to build a new AMI for use by shiva. To do so find the
id of the AMI used by shiva (configs/.env.production[-beta]
) and spin up a
new instance with that AMI in AWS (do not provide a user-data script).
The resulting instance will be a perfect snapshot of the last AMI that was built. You can then modify it how you wish, and create a new AMI from the running instance.
- log into base dock
ssh 10.20.1.33
- cd to dock-init utils
cd /opt/runnable/dock-init
- checkout your branch
sudo ./util/checkout.sh <your_branch>
- pull your branch
sudo ./util/pull.sh <your_branch>
- find
beta-example
on amazon ec2 console - right click and
beta-example
go to image -> create image - use these settings
- Image name = beta-build-run-dock-<your_branch>
- Image description =
- Change all volumes to SSD
- click create image and not ami id
- create branch in astral/shiva with the same name as <your_branch>
- deploy your branch of astral/shiva to beta
- spin up new docks using helper scripts on
beta-services
in folder~/ryan
- ensure the dock comes up and you can run/build on them
NOTE: we should turn this into ansible script so we can auto generate AMIs.
- Create an EC2 Instance (of any type) with the following EBS Volumes
- xvdb (1000 GB)
- xvdc (50 GB)
- xvdd (50 GB)
- Mount the EBS volumes to the following root folders:
/docker
-> xvdb/git-cache
-> xvdc/layer-cache
-> xvdd
- Install docker 1.9.2, and weave 0.14.0
- Place the TLS certificate files in
/etc/ssl/docker
:
ca-key.pem
ca.pem
- Download the following repositories to
/opt/runnable
:
/opt/runnable/dock-init
/opt/runnable/krain
- Place the service upstart scripts:
/etc/init/krain.conf
- Place the upstart override "manual" files to prevent start on boot:
echo "manual" > /etc/init/krain.override
echo "manual" > /etc/init/docker.override
- Save an AMI of the Instance via the AWS Web Admin Panel