During the last exercise we moved the Environment variables used by the deployment to our pipeline manifest so they could be referenced by each job. The obvious problem here is that we had to set each variable for each job, so if one thing changes you may need to change it in multiple places. For a larger deployment this makes managing these variables painful and error prone. Let's DRY things up a bit.
Up until this point we've been using spruce merge
to prune and join the lab yaml file with a settings yaml. If you haven't looked at "settings.yml" yet, now would be a good time to do that.
---
meta:
name: (( concat release.name "-demo" ))
target: training
url: https://pipes.starkandwayne.com
pipeline: (( grab meta.name ))
release:
name: (( concat github.username "-nginx" ))
github:
username: (( grab $GITHUB_USERNAME ))
branch: master
repository: (( concat "https://github.com/" github.username "/sw-concourse-training.git" ))
Throughout the file you'll notice special directives encapsulated by a double parenthesis (( ... ))
. Let's explore some of these:
(( grab $GITHUB_USERNAME ))
This sets the github.username to the value of the local Environmment variable GITHUB_USERNAME which was set in Lab-1 using the set_env.sh script.
(( concat github.username "-nginx" ))
This sets the release.name to the github/username attribute set in the YAML by (( grab $GITHUB_USERNAME ))
and concatenated with "-nginx".
(( concat release.name "-demo" ))
This will set the value of meta.name to release.name concatenated with "-demo".
If your github username were "arthurdent" you might have a fondness for Vogon poetry and the spruce merge
of "settings.yml" would be:
---
meta:
name: arthurdent-nginx-demo
target: training
url: https://pipes.starkandwayne.com
pipeline: arthurdent-nginx-demo
release:
name: arthurdent-nginx
github:
username: arthurdent
branch: master
repository: https://github.com/arthurdent/sw-concourse-training.git
The "ci/lab7.yml" file has had all those params we manually set before redefined using the following variables.
- bosh.deployment
- bosh.client_user
- bosh.client_secret
- bosh.url
- bosh.ca_cert
Edit the settings.yml to define these variables; where possible, use the Spruce syntax, to grab variables from other settings that exist in the YAML or that have been set as environment variables. Three of the variables can be set based on existing settings or environment variables, two will be written directly as strings.
There is more than one correct solution; one possible approach can be found below (hardcoded strings will vary):
Solution
bosh:
deployment: (( grab release.name ))
client_user: (( grab $BOSH_CLIENT ))
client_secret: (( grab $BOSH_CLIENT_SECRET ))
url: https://10.4.1.4:25555/
ca_cert: |
-----BEGIN CERTIFICATE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vk0CZslS/3CwR3Nan/ddBE+oyRmqH5l1PZcv+pv/J3
hV/gviXX71Y8LrwT2nMzBjs44ps89ZsZoSEpVKgi+l662LxEt3LvjSjsv3TlE9Ar
mKpfkXZ6fLz+1BXdnvPcxfuam16E7bwel4pG5TnVkirbz1nw9G5Peq7S5SVYsqZd
UebdH6mXguA30dkj9tlF1TBz7RqsPCWN8160VCKynzIRPD13YtxBtwAP+IZYxEip
FyVZG0BOY5ATOAhjjiBNSte28fRY4koFjx5Xfiw9Gdvyz10wXalSnx4fvjHUgryO
6p0J+t8zUAq4qJmosDl40vy+r1qWv9JC7a45riXdD18E9XAqxJriOwUNBh41XCln
ntOBVWga1fejq+WdJP+E1+77C0bRQZqRnqG/OoqDn3FL7PV5i/yG2OwSMhuScf16
ZAZjG2DoYFlpcy2h3VZ/MPnLTUsnDQVYWEbVRYRNtTe0Y2QrULlSyxatI4V5h20R
SSn1tQiwixxfQyTz4psO8r9uxxgPnGFVY1gWAqWDP3TwIAslqTx5NS7Y5xEKVcm3
YvlVPTIm4YPba9BqNY1kf0W//QhxSOmnqUs0xDEotgMs887/YRyoJPKYZT3lTHte
q0Di9/oGTshOV94=
-----END CERTIFICATE-----
Ok, let's do a merge and see if everything worked as expected.
spruce merge --prune release ci/settings.yml ci/lab7.yml > ci/pipeline.yml
Now we'll commit and push our changes
git commit -am 'updating codebase for lab 7'
git push
Once again we set the pipeline
fly -t training set-pipeline -c ci/pipeline.yml -p ${GITHUB_USERNAME}-pipeline
Wait for your pipeline to process and ensure everything works as expected; then you can move on to Lab-8.