class Qops::Cookbook
Public Instance Methods
cleanup()
click to toggle source
# File lib/qops/cookbook/cookbook.rb, line 106 def cleanup Dir.chdir(config.cookbook_dir) do remove_zip_files FileUtils.remove_dir('vendor') if File.directory?('vendor') say("Cleaned up directory '#{config.cookbook_dir}/vendor'", :green) end end
package()
click to toggle source
# File lib/qops/cookbook/cookbook.rb, line 16 def package initialize_run move_custom_templates Dir.chdir(config.cookbook_dir) do remove_zip_files system("zip -r #{artifact_name} vendor/*") end end
release()
click to toggle source
# File lib/qops/cookbook/cookbook.rb, line 74 def release vendor && package && upload && update_custom_cookbooks && update_stack_cookbooks ping_slack('Quandl::Slack::Cookbook', 'Cookbook updated', 'success', command: 'opsworks cookbook release', status: 'success', name: config.cookbook_name, version: config.cookbook_version, stack: config.stack_id) say('Released!', :green) end
update_custom_cookbooks()
click to toggle source
# File lib/qops/cookbook/cookbook.rb, line 88 def update_custom_cookbooks if yes?("Are you sure you want to update the custom the custom cookbook for opsworks stack #{config.stack_id}?", :yellow) config.opsworks.update_stack( stack_id: config.stack_id, use_custom_cookbooks: true, custom_cookbooks_source: { type: 's3', url: "https://s3.amazonaws.com/#{config.cookbook_s3_bucket}/#{remote_artifact_file}" } ) say('Cookbooks updated', :green) else say('You said no, so we\'re done here.', :yellow) exit(-1) end end
update_custom_json()
click to toggle source
# File lib/qops/cookbook/cookbook.rb, line 37 def update_custom_json initialize_run raw_json = File.read(File.join(config.cookbook_dir, config.cookbook_json)) json = JSON.parse(raw_json) say(JSON.pretty_generate(json), :yellow) if yes?("Are you sure you want to update the custom JSON for opsworks stack #{config.stack_id}?", :yellow) config.opsworks.update_stack( stack_id: config.stack_id, custom_json: JSON.pretty_generate(json) ) say('Updated!', :green) else say('You said no, so we\'re done here.', :yellow) end rescue JSON::ParserError say('Check your JSON for errors!', :red) end
update_stack_cookbooks()
click to toggle source
# File lib/qops/cookbook/cookbook.rb, line 57 def update_stack_cookbooks initialize_run if yes?("Are you sure you want to run the 'Update Custom Cookbooks' command on stack #{config.stack_id}?", :yellow) run_opsworks_command( stack_id: config.stack_id, command: { name: 'update_custom_cookbooks' } ) say('Updated!', :green) else say('You said no, so we\'re done here.', :yellow) exit(-1) end end
upload()
click to toggle source
# File lib/qops/cookbook/cookbook.rb, line 26 def upload initialize_run s3.put_object( bucket: config.cookbook_s3_bucket, acl: 'private', key: remote_artifact_file, body: IO.read(local_artifact_file) ) end
vendor()
click to toggle source
# File lib/qops/cookbook/cookbook.rb, line 7 def vendor initialize_run cleanup Dir.chdir(config.cookbook_dir) do system('berks vendor vendor -e opsworks') end end
Private Instance Methods
artifact_name()
click to toggle source
# File lib/qops/cookbook/cookbook.rb, line 140 def artifact_name "#{config.cookbook_name}-#{config.cookbook_version}.zip" end
aws_configs()
click to toggle source
# File lib/qops/cookbook/cookbook.rb, line 125 def aws_configs aws_config = { region: 'us-east-1' } # use the profile if found options[:profile] ? aws_config[:profile] = options[:profile] : aws_config[:credentials] = config.opsworks.config.credentials.credentials aws_config end
initialize_run()
click to toggle source
Calls superclass method
# File lib/qops/cookbook/cookbook.rb, line 116 def initialize_run super config end
local_artifact_file()
click to toggle source
# File lib/qops/cookbook/cookbook.rb, line 132 def local_artifact_file File.join(config.cookbook_dir, artifact_name) end
move_custom_templates()
click to toggle source
# File lib/qops/cookbook/cookbook.rb, line 148 def move_custom_templates Dir.chdir(config.cookbook_dir) do custom_template_directory = File.join('vendor', config.cookbook_name, 'overridden_built_in_templates') if File.directory?(custom_template_directory) say('Moving Custom Templates:', :green) system("mv #{custom_template_directory}/* vendor") system("rm -rf #{custom_template_directory}") end end end
remote_artifact_file()
click to toggle source
# File lib/qops/cookbook/cookbook.rb, line 136 def remote_artifact_file File.join(config.cookbook_s3_path, artifact_name) end
remove_zip_files()
click to toggle source
# File lib/qops/cookbook/cookbook.rb, line 159 def remove_zip_files FileUtils.rm Dir.glob("#{config.cookbook_name}*.zip") say("Cleaned up directory '#{config.cookbook_dir}/*.zip'", :green) end
s3()
click to toggle source
# File lib/qops/cookbook/cookbook.rb, line 121 def s3 @s3 ||= Aws::S3::Client.new(**aws_configs) end
vendor_dir()
click to toggle source
# File lib/qops/cookbook/cookbook.rb, line 144 def vendor_dir File.join(config.cookbook_dir, 'vendor') end