diff --git a/scm_helper/libraries/s3.rb b/scm_helper/libraries/s3.rb index 358d38188d..7d4ead4efa 100644 --- a/scm_helper/libraries/s3.rb +++ b/scm_helper/libraries/s3.rb @@ -3,6 +3,23 @@ module OpsWorks module SCM module S3 + def self.parse_uri(uri) + uri = URI.parse(uri) + uri_path_components = uri.path.split("/").reject{|p| p.empty?} + virtual_host_match = uri.host.match(/\A(.+)\.s3(?:-(?:ap|eu|sa|us)-.+-\d)?\.amazonaws\.com/i) + if virtual_host_match + # virtual-hosted-style: http://bucket.s3.amazonaws.com or http://bucket.s3-aws-region.amazonaws.com + bucket = virtual_host_match[1] + remote_path = uri_path_components.join("/") + else + # path-style: http://s3.amazonaws.com/bucket or http://s3-aws-region.amazonaws.com/bucket + bucket = uri_path_components[0] + remote_path = uri_path_components[1..-1].join("/") + end + + [bucket, remote_path] + end + def prepare_s3_checkouts(scm_options) template "/root/.s3curl" do cookbook "scm_helper" @@ -16,10 +33,17 @@ def prepare_s3_checkouts(scm_options) mode 0755 end - execute "Download application from S3: #{scm_options[:repository]}" do - command "#{node[:opsworks_agent][:current_dir]}/bin/s3curl.pl --id opsworks -- -o #{tmpdir}/archive #{scm_options[:repository]}" - retries 2 - retry_delay 10 + bucket, remote_path = OpsWorks::SCM::S3.parse_uri(scm_options[:repository]) + + s3_file "#{tmpdir}/archive" do + bucket bucket + remote_path remote_path + aws_access_key_id scm_options[:user] + aws_secret_access_key scm_options[:password] + owner "root" + group "root" + mode "0600" + action :create end execute 'extract files' do diff --git a/scm_helper/metadata.rb b/scm_helper/metadata.rb index 16dcddd2f2..ac2eb8b9e3 100644 --- a/scm_helper/metadata.rb +++ b/scm_helper/metadata.rb @@ -5,3 +5,4 @@ version "1.0.0" depends "opsworks_commons" +depends "s3_file"