Skip to content

Commit 27f332c

Browse files
committed
Add upload task
1 parent 80e4875 commit 27f332c

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

tasks/upload.rake

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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

0 commit comments

Comments
 (0)