Skip to content

Commit 516070a

Browse files
authored
Merge pull request #11 from OpenVoxProject/standardize_tasks
Standardize rake tasks
2 parents add98d4 + 05df6ab commit 516070a

File tree

4 files changed

+28
-17
lines changed

4 files changed

+28
-17
lines changed

Rakefile

+14-2
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,27 @@
11
require 'rake'
22
require 'open3'
33

4-
def run_command(cmd, silent = false)
4+
RED = "\033[31m"
5+
GREEN = "\033[32m"
6+
RESET = "\033[0m"
7+
8+
def run_command(cmd, silent: true, print_command: false, report_status: false)
9+
puts "#{GREEN}Running #{cmd}#{RESET}" if print_command
510
output = ''
611
Open3.popen2e(cmd) do |_stdin, stdout_stderr, thread|
712
stdout_stderr.each do |line|
813
puts line unless silent
914
output += line
1015
end
1116
exitcode = thread.value.exitstatus
12-
abort "Command failed!" unless exitcode.zero?
17+
unless exitcode.zero?
18+
err = "#{RED}Command failed! Command: #{cmd}, Exit code: #{exitcode}"
19+
# Print details if we were running silent
20+
err += "\nOutput:\n#{output}" if silent
21+
err += RESET
22+
abort err
23+
end
24+
puts "#{GREEN}Command finished with status #{exitcode}#{RESET}" if report_status
1325
end
1426
output.chomp
1527
end

tasks/build.rake

+8-9
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,17 @@ end
2828
def teardown
2929
if container_exists
3030
puts "Stopping #{@container}"
31-
run_command("docker stop #{@container}")
32-
run_command("docker rm #{@container}")
31+
run_command("docker stop #{@container}", silent: false, print_command: true)
32+
run_command("docker rm #{@container}", silent: false, print_command: true)
3333
end
3434
end
3535

3636
def start_container(ezbake_dir)
37-
run_command("docker run -d --name #{@container} -v .:/code -v #{ezbake_dir}:/ezbake #{@image} /bin/sh -c 'tail -f /dev/null'")
37+
run_command("docker run -d --name #{@container} -v .:/code -v #{ezbake_dir}:/ezbake #{@image} /bin/sh -c 'tail -f /dev/null'", silent: false, print_command: true)
3838
end
3939

4040
def run(cmd)
41-
puts "\033[32mRunning #{cmd}\033[0m"
42-
run_command("docker exec #{@container} /bin/bash --login -c '#{cmd}'")
41+
run_command("docker exec #{@container} /bin/bash --login -c '#{cmd}'", silent: false, print_command: true)
4342
end
4443

4544
namespace :vox do
@@ -53,15 +52,15 @@ namespace :vox do
5352
# delete all containers and do `docker rmi ezbake-builder`
5453
unless image_exists
5554
puts "Building ezbake-builder image"
56-
run_command("docker build -t ezbake-builder .")
55+
run_command("docker build -t ezbake-builder .", silent: false, print_command: true)
5756
end
5857

5958
puts "Checking out ezbake"
6059
tmp = Dir.mktmpdir("ezbake")
6160
ezbake_dir = "#{tmp}/ezbake"
62-
run_command("git clone https://github.com/openvoxproject/ezbake #{ezbake_dir}")
61+
run_command("git clone https://github.com/openvoxproject/ezbake #{ezbake_dir}", silent: false, print_command: true)
6362
ezbake_branch = ENV['EZBAKE_BRANCH'] || 'main'
64-
Dir.chdir(ezbake_dir) { |_| run_command("git checkout #{ezbake_branch}") }
63+
Dir.chdir(ezbake_dir) { |_| run_command("git checkout #{ezbake_branch}", silent: false, print_command: true) }
6564

6665
puts "Starting container"
6766
teardown if container_exists
@@ -73,7 +72,7 @@ namespace :vox do
7372
puts "Building openvoxdb"
7473
run("cd /code && rm -rf ruby && rm -rf output && bundle install --without test && lein install")
7574
run("cd /code && COW=\"#{@debs}\" MOCK=\"#{@rpms}\" GEM_SOURCE='https://rubygems.org' EZBAKE_ALLOW_UNREPRODUCIBLE_BUILDS=true EZBAKE_NODEPLOY=true LEIN_PROFILES=ezbake lein with-profile user,ezbake,provided,internal ezbake local-build")
76-
run_command("sudo chown -R $USER output")
75+
run_command("sudo chown -R $USER output", print_command: true)
7776
Dir.glob('output/**/*i386*').each { |f| FileUtils.rm_rf(f) }
7877
Dir.glob('output/puppetdb-*.tar.gz').each { |f| FileUtils.mv(f, f.sub('puppetdb','openvoxdb'))}
7978
ensure

tasks/tag.rake

+4-4
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ namespace :vox do
1818
set_version(version)
1919

2020
# Run git command to get short SHA and one line description of the commit on HEAD
21-
branch = run_command('git rev-parse --abbrev-ref HEAD', true)
22-
sha = run_command('git rev-parse --short HEAD', true)
23-
msg = run_command('git log -n 1 --pretty=%B', true)
21+
branch = run_command('git rev-parse --abbrev-ref HEAD')
22+
sha = run_command('git rev-parse --short HEAD')
23+
msg = run_command('git log -n 1 --pretty=%B')
2424

2525
puts "Branch: #{branch}"
2626
puts "SHA: #{sha}"
@@ -31,7 +31,7 @@ namespace :vox do
3131
puts "Setting version after tag to #{snapshot_version}"
3232
set_version("#{snapshot_version}-SNAPSHOT")
3333

34-
unless !ENV['NOPUSH'].nil?
34+
if ENV['NOPUSH'].nil?
3535
puts "Pushing to origin"
3636
run_command("git push origin && git push origin #{args[:tag]}")
3737
end

tasks/upload.rake

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ namespace :vox do
2020
s3 = "aws s3 --endpoint-url=#{endpoint}"
2121

2222
# Ensure the AWS CLI isn't going to fail with the given parameters
23-
run_command("#{s3} ls s3://#{bucket}/", true)
23+
run_command("#{s3} ls s3://#{bucket}/")
2424

2525
glob = "#{__dir__}/../output/**/*#{munged_tag}*"
2626
if os
@@ -32,7 +32,7 @@ namespace :vox do
3232

3333
path = "s3://#{bucket}/#{component}/#{args[:tag]}"
3434
files.each do |f|
35-
run_command("#{s3} cp #{f} #{path}/#{File.basename(f)}")
35+
run_command("#{s3} cp #{f} #{path}/#{File.basename(f)}", silent: false)
3636
end
3737
end
3838
end

0 commit comments

Comments
 (0)