File tree Expand file tree Collapse file tree 1 file changed +40
-0
lines changed
Expand file tree Collapse file tree 1 file changed +40
-0
lines changed Original file line number Diff line number Diff line change 1+ require 'open3'
2+
3+ namespace :overlookinfra do
4+ desc "Upload artifacts from the output directory to S3. Requires the AWS CLI to be installed and configured appropriately."
5+ task :upload , [ :tag ] do |t , args |
6+ endpoint = ENV [ 'ENDPOINT_URL' ]
7+ bucket = ENV [ 'BUCKET_NAME' ]
8+
9+ if endpoint . nil? || endpoint . empty?
10+ abort "You must set the ENDPOINT_URL environment variable to the S3 server you want to upload to."
11+ end
12+ if bucket . nil? || bucket . empty?
13+ abort "You must set the BUCKET_NAME environment variable to the S3 bucket you are uploading to."
14+ end
15+ if args [ :tag ] . nil? || args [ :tag ] . empty?
16+ abort "You must provide a tag."
17+ end
18+ munged_tag = args [ :tag ] . gsub ( '-' , '.' )
19+ s3 = "aws s3 --endpoint-url=#{ endpoint } "
20+
21+ # Ensure the AWS CLI isn't going to fail with the given parameters
22+ run_command ( "#{ s3 } ls s3://#{ bucket } /" )
23+
24+ files = Dir . glob ( "#{ __dir__ } /../output/*#{ munged_tag } *" )
25+ if files . empty?
26+ puts "No files for the given tag found in the output directory."
27+ end
28+ path = "s3://#{ bucket } /puppet-runtime/#{ args [ :tag ] } "
29+ files . each do |f |
30+ puts "Uploading #{ File . basename ( f ) } "
31+ run_command ( "#{ s3 } cp #{ f } #{ path } /#{ File . basename ( f ) } --endpoint-url=#{ endpoint } " )
32+ end
33+ end
34+ end
35+
36+ def run_command ( cmd )
37+ output , status = Open3 . capture2e ( cmd )
38+ abort "Command failed! Command: #{ cmd } , Output: #{ output } " unless status . exitstatus . zero?
39+ return output . chomp
40+ end
You can’t perform that action at this time.
0 commit comments