lib/capistrano/tasks/stretcher.rake in capistrano-stretcher-0.3.0 vs lib/capistrano/tasks/stretcher.rake in capistrano-stretcher-0.4.0

- old
+ new

@@ -37,10 +37,26 @@ def consul_roles roles(fetch(:consul_roles, [:consul])) end + # upload to s3 + def upload_s3(local_src_path, remote_dst_path) + execute :aws, :s3, :cp, local_src_path, remote_dst_path + end + + # upload to resource server with rsync + def upload_resource(local_src_path, remote_dst_path) + rsync_ssh_command = "ssh" + rsync_ssh_command << " " + fetch(:rsync_ssh_option) if fetch(:rsync_ssh_option) + rsync_ssh_user = fetch(:rsync_ssh_user) { capture(:whoami).strip } + + execute :rsync, "-ave", %Q("#{rsync_ssh_command}"), + local_src_path, + "#{rsync_ssh_user}@#{fetch(:rsync_host)}:#{remote_dst_path}" + end + task :mark_deploying do set :deploying, true end desc "Create a tarball that is set up for deploy" @@ -98,11 +114,19 @@ end task :upload_tarball do on application_builder_roles do as 'root' do - execute :aws, :s3, :cp, "#{local_tarball_path}/current/#{fetch(:local_tarball_name)}", fetch(:stretcher_src) + local_tarball_file = "#{local_tarball_path}/current/#{fetch(:local_tarball_name)}" + + if fetch(:stretcher_src).start_with?("s3://") + # upload to s3 + upload_s3(local_tarball_file, fetch(:stretcher_src)) + else + # upload to resource server with rsync + upload_resource(local_tarball_file, fetch(:rsync_stretcher_src_path)) + end end end end task :create_and_upload_manifest do @@ -118,11 +142,22 @@ yml = ERB.new(template).result(binding) tempfile_path = Tempfile.open("manifest_#{role}") do |t| t.write yml t.path end - upload! tempfile_path, "#{local_tarball_path}/current/manifest_#{role}_#{fetch(:stage)}.yml" - execute :aws, :s3, :cp, "#{local_tarball_path}/current/manifest_#{role}_#{fetch(:stage)}.yml", "#{fetch(:manifest_path)}/manifest_#{role}_#{fetch(:stage)}.yml" + + local_manifest_file = "#{local_tarball_path}/current/manifest_#{role}_#{fetch(:stage)}.yml" + + upload! tempfile_path, local_manifest_file + + if fetch(:manifest_path).start_with?("s3://") + # upload to s3 + upload_s3(local_manifest_file, "#{fetch(:manifest_path)}/manifest_#{role}_#{fetch(:stage)}.yml") + else + # upload to resource server with rsync + execute :chmod, "644", local_manifest_file + upload_resource(local_manifest_file, "#{fetch(:rsync_manifest_path)}/manifest_#{role}_#{fetch(:stage)}.yml") + end end end end end