Skip to content

This is an example Chef Workflow-enabled cookbook in which you can specify a tag for Automate to apply during publish

License

Notifications You must be signed in to change notification settings

danielcbright/workflow-tag-example

Repository files navigation

workflow-tag-example

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.

1. Create ssh keys & workflow-vault

  1. 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!
  2. Following GitHub/Bitbucket instructions, create an ssh keypair.
  3. Create a <workflow-enterprise>-<workflow-org>.json file with the following contents, replace the contents of key with the private key you generated in step 2, also be sure to use only github or bitbucket 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.

  1. Before the next step, let's make sure our knife.rb is configured properly, make sure vault_mode='client' is somewhere in your config, also note that you will need to add the -M client switch to all knife vault commands.
  2. 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
  1. Run the following to make sure you see your newly created vault:
$ knife vault show workflow-vaults -M client

2. Edit the publish.rb

  1. Now, on to the publish.rb, open the .delivery/build_cookbook/recipes/publish.rb file and add the following below include_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
  1. 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!

Tips

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"

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/danielcbright/workflow-tag-example.

ToDo

  • Add support for automatically pulling git origin information to push tag (for shared build cookbooks)

License

Apache 2.0 (see LICENSE)

About

This is an example Chef Workflow-enabled cookbook in which you can specify a tag for Automate to apply during publish

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages