Created
November 28, 2017 03:04
-
-
Save cunnie/794b45120dbc7a3b08078dcc24067dea to your computer and use it in GitHub Desktop.
Description of a terse script to deploy a BOSH director to AWS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# We abort the script as soon as we hit an error (as soon as a command exits | |
# with a non-zero exit status) | |
set -e | |
# `cunnie-deployments` is the checked-out GitHub repo that contains our BOSH | |
# manifests and our directors' `-state.json` files; it also contains this | |
# script (task script) and task definition. | |
pushd cunnie-deployments | |
# We attempt to deploy our BOSH director. We prepare a git commit message | |
# regardless whether our attempt succeeds or fails because we need to retain any | |
# change to the BOSH director's `-state.json` file. This is necessary in cases | |
# where a deploy proceeds far enough to create a broken director VM, for | |
# subsequent deploys must be able to destroy the broken director VM in order to | |
# free up its IP address so that the current deploy will succeed. The crucial | |
# information needed to destroy the broken director VM is its VM's ID, which is | |
# recorded in the `-state.json` file. | |
# Note that `set -e` does not trigger an abort if the command that returns a | |
# non-zero exit code is the subject of an `if` block, i.e. `if bosh create-env`; | |
# this gives us the breathing room to commit our results regardless of whether | |
# `bosh create-env` succeeded or failed | |
if bosh create-env ../bosh-deployment/bosh.yml \ | |
-l <(echo "$DEPLOYMENTS_YML") \ | |
-l <(curl https://raw.githubusercontent.com/cunnie/sslip.io/master/conf/sslip.io%2Bnono.io.yml) \ | |
-o $DEPLOYMENTS_DIR/../bosh-deployment/aws/cpi.yml \ | |
-o $DEPLOYMENTS_DIR/../bosh-deployment/external-ip-with-registry-not-recommended.yml \ | |
-o $DEPLOYMENTS_DIR/../bosh-deployment/jumpbox-user.yml \ | |
-o etc/aws.yml \ | |
-o etc/nginx.yml \ | |
-o etc/ntp.yml \ | |
-o etc/pdns.yml \ | |
--var-errs \ | |
--vars-store=creds.yml \ | |
--var-file nono_io_crt=etc/nono.io.crt \ | |
-v region=us-east-1 \ | |
-v az=us-east-1a \ | |
-v default_key_name=bosh_deployment_no_ecdsa \ | |
-v default_security_groups=[bosh] \ | |
-v subnet_id=subnet-1c90ef6b \ | |
-v director_name=bosh-aws \ | |
-v internal_cidr=10.0.0.0/24 \ | |
-v internal_gw=10.0.0.1 \ | |
-v internal_ip=10.0.0.6 \ | |
-v external_ip=52.0.56.137 | |
then | |
GIT_COMMIT_MESSAGE="CI PASS: $IAAS BOSH deploy :airplane:" | |
DEPLOY_EXIT_STATUS=0 | |
else | |
GIT_COMMIT_MESSAGE="CI FAIL: $IAAS BOSH deploy :airplane:" | |
DEPLOY_EXIT_STATUS=1 | |
fi | |
# Do we need to commit anything? If a new director hasn't been deployed (most | |
# often because there's been no change to the manifest, releases, or stemcell), | |
# then we don't need to commit | |
if ! git diff --quiet HEAD --; then | |
# If we're in this block, then there has been a deployment. Let's set our | |
# git author to avoid git's `*** Please tell me who you are.` error. | |
git config --global user.name "Concourse CI" | |
git config --global user.email [email protected] | |
# We check out our branch's HEAD because Concourse's git-resource leaves us | |
# in `detached HEAD` state. ${DEPLOYMENTS_BRANCH} is typically set to | |
# `master`, but may be set to something else (usually while testing). | |
git checkout $DEPLOYMENTS_BRANCH | |
git add . | |
git commit -m"$GIT_COMMIT_MESSAGE" | |
fi | |
popd | |
# We copy our repo with its new commit to a new directory. The Concourse job, | |
# after it finishes running this task, will push the new commit to GitHub. | |
# Note that `cp -R` works as well as `rsync`; we use `rsync` by force of | |
# habit. | |
rsync -aH cunnie-deployments/ cunnie-deployments-with-state/ | |
# We exit with the return code of `bosh create-env`; if the deploy failed, then | |
# this Concourse task failed | |
exit $DEPLOY_EXIT_STATUS |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment