Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 22 additions & 6 deletions lib/capistrano/recipes/deploy/strategy/s3_copy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,32 @@ def check!
def distribute!
package_path = filename
package_name = File.basename(package_path)
s3_push_cmd = "#{aws_environment} s3cmd put #{bucket_name}:#{rails_env}/#{package_name} #{package_path} x-amz-server-side-encryption:AES256 2>&1"

if bucket_override_url.nil?
s3_push_cmd = "#{aws_environment} s3cmd put #{bucket_name}:#{rails_env}/#{package_name} #{package_path} x-amz-server-side-encryption:AES256 2>&1"
else
s3_push_cmd = "s3cmd put #{package_path} #{bucket_override_url}/#{package_name} 2>&1"
end

if configuration.dry_run
logger.debug s3_push_cmd
else
system(s3_push_cmd)
raise Capistrano::Error, "shell command failed with return code #{$?}" if $? != 0
end

run "#{aws_environment} s3cmd get #{bucket_name}:#{rails_env}/#{package_name} #{remote_filename} 2>&1"

if bucket_override_url.nil?
run "#{aws_environment} s3cmd get #{bucket_name}:#{rails_env}/#{package_name} #{remote_filename} 2>&1"
else
run "s3cmd get #{bucket_override_url}/#{package_name} #{remote_filename} 2>&1"
end
run "cd #{configuration[:releases_path]} && #{decompress(remote_filename).join(" ")} && rm #{remote_filename}"
logger.debug "done!"

build_aws_install_script
end

def build_aws_install_script
logger.debug "Building installation script"
template_text = configuration[:aws_install_script]
template_text = File.read(File.join(File.dirname(__FILE__), "aws_install.sh.erb")) if template_text.nil?
template_text = template_text.gsub("\r\n?", "\n")
Expand All @@ -59,9 +68,16 @@ def build_aws_install_script
File.open(local_output_file, "w") do |f|
f.write(output)
end
configuration[:s3_copy_aws_install_cmd] = "#{aws_environment} s3cmd put #{bucket_name}:#{rails_env}/aws_install.sh #{local_output_file} x-amz-server-side-encryption:AES256 2>&1"

if bucket_override_url.nil?
configuration[:s3_copy_aws_install_cmd] = "#{aws_environment} s3cmd put #{bucket_name}:#{rails_env}/aws_install.sh #{local_output_file} x-amz-server-side-encryption:AES256 2>&1"
else
configuration[:s3_copy_aws_install_cmd] = "s3cmd put #{local_output_file} #{bucket_override_url}/aws_install.sh 2>&1"
end
logger.debug "Installation script sent to S3"

end

def binding
super
end
Expand Down