Skip to content

Instantly share code, notes, and snippets.

@Maniacal
Created October 14, 2014 01:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Maniacal/baf48edf29cfba541db3 to your computer and use it in GitHub Desktop.
Save Maniacal/baf48edf29cfba541db3 to your computer and use it in GitHub Desktop.
define :deploy_archive, :type => "zip" do
module_name = params[:name]
destination = params[:destination]
bundle_path = "#{Chef::Config[:file_cache_path]}/#{node['deployment']['id']}"
execute "Clean out destination" do
user 'root'
command "rm -rf #{destination}/*"
action :run
end
# Set extract command based on data read in from the deployment manifest
ruby_block "Set extract command" do
block do
module_file = node['deployment']['manifest']['packages'][module_name]
archive = "#{Chef::Config[:file_cache_path]}/#{node['deployment']['id']}/#{module_name}/#{module_file}"
# Obtain the desired resource from resource_collection
execute_res = run_context.resource_collection.find(:execute => "Extract archive")
# Update the command attribute
case params[:type]
when 'zip'
execute_res.command "unzip -oq #{archive}"
when 'tar_gz'
execute_res.command "tar -xzf #{archive}"
end
end
end
execute "Extract archive" do
cwd destination
user 'root'
# 'command' parameter set to "true" to get through convergence. Is overwritten during
# the run by the ruby_block above
command "true"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment