This is an example Delivery cookbook and how-to guide that shows you how to use
the delivery_github
resource to tag your repo during the publish
phase.
You'll notice that this cookbook has no functional code other than what's needed
to update the repo tag -- it's a freshly initialized delivery cookbook. This has
been tested on Bitbucket and GitHub, not extensively, but it seems to work well
for both.
- Read this post by my colleague Jerry Aldrich to get a better understanding of how Chef vaults work in Workflow. Seriously, this is important, so read it!
- Following GitHub/Bitbucket instructions, create an ssh keypair.
- Create a
<workflow-enterprise>-<workflow-org>.json
file with the following contents, replace the contents ofkey
with the private key you generated in step 2, also be sure to use onlygithub
orbitbucket
as the remote name:
{
"id":"<workflow-enterprise>-<workflow-org>",
"publish": {
"<github|bitbucket>": {
"key": "-----BEGIN RSA PRIVATE KEY-----\nPRIVATEKEY WITH NEWLINES REPLACED BY SO IT'S ALL ONE LINE\n-----END RSA PRIVATE KEY-----"
}
}
}
A note on <workflow-enterprise>-<workflow-org>
, if my Workflow Enterprise is
called "BallJoints", and my Workflow org is called "web-frontends", my id's in
this guide would be BallJoints-web-frontends
.
- Before the next step, let's make sure our
knife.rb
is configured properly, make surevault_mode='client'
is somewhere in your config, also note that you will need to add the-M client
switch to allknife vault
commands. - Run the following command, changing everything in
< >
's.
$ knife vault create \
workflow-vaults \
<workflow-enterprise>-<workflow-org> \
-J /path/to/json/you/created/in/step/3/<workflow-enterprise>-<workflow-org>.json \
-A 'delivery' \
-S 'tags:delivery-job-runner' \
-M client
- Run the following to make sure you see your newly created vault:
$ knife vault show workflow-vaults -M client
- Now, on to the
publish.rb
, open the.delivery/build_cookbook/recipes/publish.rb
file and add the following belowinclude_recipe 'delivery-truck::publish'
, replacing everything between< >
's.:
require 'chef/cookbook/metadata'
# Read in Metadata file in current cookbook
cookbook_name = node['delivery']['change']['project']
metadata = Chef::Cookbook::Metadata.new
metadata.from_file("/var/opt/delivery/workspace/<automate-hostname.fqdn>/<enterprise-name>/<org-name>/#{cookbook_name}/master/build/publish/repo/metadata.rb")
cookbook_version = "#{metadata.version}"
vault_data = get_workflow_vault_data
execute "Set git username information" do
command "git config --global user.email \"<you@email.com>\" && git config --global user.name \"<Your Name>\""
live_stream true
end
delivery_github 'tag' do
deploy_key vault_data['publish']['<github|bitbucket>']['key']
tag '<v1.0>'
branch node['delivery']['change']['pipeline']
remote_url 'ssh://git@<HOSTNAME:PORT>/<somepath>.git'
repo_path node['delivery']['workspace']['repo']
cache_path node['delivery']['workspace']['cache']
action :push
end
- Do your usual
git add, commit, push
+delivery review
process, and if all is successful, you will see your tag applied to the latest commit to your repo!
It's a little finicky to setup at first, so I recommend editing the
config.json
and adding the following to the 'skip_phases' section to skip some
tests while your testing it out:
"smoke",
"unit",
"lint",
"syntax"
Bug reports and pull requests are welcome on GitHub at https://github.com/danielcbright/workflow-tag-example.
- Add support for automatically pulling git origin information to push tag (for shared build cookbooks)
Apache 2.0 (see LICENSE)