Skip to content

Instantly share code, notes, and snippets.

@henrypoydar
Created May 12, 2010 14:04
Show Gist options
  • Select an option

  • Save henrypoydar/398616 to your computer and use it in GitHub Desktop.

Select an option

Save henrypoydar/398616 to your computer and use it in GitHub Desktop.
# Cookbooks and DNA stored within app codebase
# Pro: no separate repo for deploy config/setup
# Con: keeping sync'd with changes to eycloud-recipes repo harder (solve w/ subtree?)
# Structure
railsapp
|-- deploy
| |-- after_restart.rb
| |-- before_migrate.rb
| |-- chef
| | |-- config
| | | |-- dna.json
| | | `-- solo.rb
| | `-- cookbooks
# before_migrate.rb
Chef::Log.info "[railsapp] Running before_migrate hook"
Chef::Log.info "[railsapp] Loading custom chef recipes"
require 'json/pure'
custom_chef_run_path = File.join(release_path, 'deploy', 'chef', 'config', 'solo.rb')
custom_chef_dna_path = File.join(release_path, 'deploy', 'chef', 'config', 'dna.json')
consolidated_dna_path = File.join(release_path, 'deploy', 'chef', 'config', 'combined_dna.json')
chef_solo_path = `which chef-solo`.chomp
begin
consolidated_dna = self.node.attribute.merge(JSON.parse(File.read(custom_chef_dna_path)))
f = File.open(consolidated_dna_path, 'w') {|f| f << JSON.pretty_generate(consolidated_dna)}
rescue
Chef::Log.info "[railsapp] Failed to generate consolidated DNA!"
end
sudo "#{chef_solo_path} -l info -c #{custom_chef_run_path} -j #{consolidated_dna_path}"
# ... do bundle, other stuff ...
Chef::Log.info "[railsapp] Completed running before_migrate hook"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment