Skip to content

Commit 83bdbcd

Browse files
committed
Modify rake tasks for OpenVox build
1 parent 22bf466 commit 83bdbcd

File tree

4 files changed

+92
-54
lines changed

4 files changed

+92
-54
lines changed

Rakefile

Lines changed: 4 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,7 @@
1-
require 'json'
2-
3-
begin
4-
require 'packaging'
5-
Pkg::Util::RakeUtils.load_packaging_tasks
6-
rescue LoadError => e
7-
puts "Error loading packaging rake tasks: #{e}"
1+
def run_command(cmd)
2+
output, status = Open3.capture2e(cmd)
3+
abort "Command failed! Command: #{cmd}, Output: #{output}" unless status.exitstatus.zero?
4+
return output.chomp
85
end
96

107
Dir.glob(File.join('tasks/**/*.rake')).each { |file| load file }
11-
12-
namespace :package do
13-
task :bootstrap do
14-
puts 'Bootstrap is no longer needed, using packaging-as-a-gem'
15-
end
16-
task :implode do
17-
puts 'Implode is no longer needed, using packaging-as-a-gem'
18-
end
19-
end
20-
21-
namespace :component do
22-
desc "Display currently promoted ref for component"
23-
task :check, [:component] do |t,args|
24-
abort 'USAGE: rake component:check[component]' unless args[:component]
25-
26-
config = get_component_config(args[:component])
27-
28-
puts config["ref"]
29-
end
30-
31-
desc "Update component config to promote a new version"
32-
task :promote, [:component, :version, :ref] do |t,args|
33-
abort 'USAGE: rake component:promote[component,version,ref]' unless args[:component] && args[:version] && args[:ref]
34-
35-
config = get_component_config(args[:component])
36-
config["version"] = args[:version]
37-
config["ref"] = args[:ref]
38-
39-
File.open(component_config_file(args[:component]), 'w') do |f|
40-
f.write(JSON.pretty_generate(config))
41-
end
42-
end
43-
end
44-
45-
# Legacy task name.
46-
task :promote_component, [:component, :version, :ref] => "component:promote"
47-
48-
def component_config_file(component)
49-
"configs/components/#{component}.json"
50-
end
51-
52-
def get_component_config(component)
53-
conf = component_config_file(component)
54-
abort "No component config file '#{conf}'" unless File.exist?(conf)
55-
56-
JSON.parse(File.read(conf))
57-
end

tasks/build.rake

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
require 'open3'
2+
3+
namespace :vox do
4+
desc 'Build vanagon project with Docker'
5+
task :build, [:project, :platform] do |t, args|
6+
# This is not currently really any different than 'bundle exec build agent-runtime-main <platform> --engine docker',
7+
# but adding this machinery so we can make it fancier later and have a common way to build
8+
# locally and in an action.
9+
args.with_defaults(project: 'agent-runtime-main')
10+
project = args[:project]
11+
12+
if args[:platform].nil? || args[:platform].empty?
13+
abort 'You must provide a platform.'
14+
return
15+
end
16+
platform = args[:platform]
17+
18+
cmd = "bundle exec build #{project} #{platform} --engine docker"
19+
puts "Running #{cmd}"
20+
exitcode = nil
21+
Open3.popen2e(cmd) do |stdin, stdout_stderr, thread|
22+
stdout_stderr.each { |line| puts line }
23+
exitcode = thread.value.exit_status
24+
puts "Command finished with status #{exit_status.exitcode}"
25+
end
26+
exit exitcode
27+
end
28+
end

tasks/tag.rake

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
require 'open3'
2+
3+
namespace :vox do
4+
desc "Create tag and push to origin"
5+
task :tag, [:tag] do |t, args|
6+
if args[:tag].nil? || args[:tag].empty?
7+
abort "You must provide a tag."
8+
return
9+
end
10+
11+
# Run git command to get short SHA and one line description of the commit on HEAD
12+
branch = run_command('git rev-parse --abbrev-ref HEAD')
13+
sha = run_command('git rev-parse --short HEAD')
14+
msg = run_command('git log -n 1 --pretty=%B')
15+
16+
puts "Branch: #{branch}"
17+
puts "SHA: #{sha}"
18+
puts "Commit: #{msg}"
19+
20+
run_command("git tag -a #{args[:tag]} -m '#{args[:tag]}'")
21+
puts "Pushing #{args[:tag]} to origin"
22+
run_command("git push origin #{args[:tag]}")
23+
end
24+
end

tasks/upload.rake

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
require 'open3'
2+
3+
namespace :vox 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, :platform] do |t, args|
6+
endpoint = ENV['ENDPOINT_URL']
7+
bucket = ENV['BUCKET_NAME']
8+
repo = 'puppet-runtime'
9+
platform = args[:platform] || ''
10+
11+
if endpoint.nil? || endpoint.empty?
12+
abort "You must set the ENDPOINT_URL environment variable to the S3 server you want to upload to."
13+
end
14+
if bucket.nil? || bucket.empty?
15+
abort "You must set the BUCKET_NAME environment variable to the S3 bucket you are uploading to."
16+
end
17+
if args[:tag].nil? || args[:tag].empty?
18+
abort "You must provide a tag."
19+
end
20+
munged_tag = args[:tag].gsub('-','.')
21+
s3 = "aws s3 --endpoint-url=#{endpoint}"
22+
23+
# Ensure the AWS CLI isn't going to fail with the given parameters
24+
run_command("#{s3} ls s3://#{bucket}/")
25+
26+
files = Dir.glob("#{__dir__}/../output/*#{munged_tag}*#{platform}*")
27+
if files.empty?
28+
puts "No files for the given tag found in the output directory."
29+
end
30+
path = "s3://#{bucket}/#{repo}/#{args[:tag]}"
31+
files.each do |f|
32+
puts "Uploading #{File.basename(f)}"
33+
run_command("#{s3} cp #{f} #{path}/#{File.basename(f)} --endpoint-url=#{endpoint}")
34+
end
35+
end
36+
end

0 commit comments

Comments
 (0)