Skip to content

Commit

Permalink
Replace s3curl.pl with s3_file cookbook.
Browse files Browse the repository at this point in the history
  • Loading branch information
workeitel authored and Michael Gruenewald committed Jul 30, 2015
1 parent 8245b00 commit 9d4e72b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
32 changes: 28 additions & 4 deletions scm_helper/libraries/s3.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions scm_helper/metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
version "1.0.0"

depends "opsworks_commons"
depends "s3_file"

0 comments on commit 9d4e72b

Please sign in to comment.