Skip to content

Instantly share code, notes, and snippets.

@johnduarte
Last active May 23, 2019 18:57
Show Gist options
  • Save johnduarte/133df86fc791dd1430b2c7d60bcac46f to your computer and use it in GitHub Desktop.
Save johnduarte/133df86fc791dd1430b2c7d60bcac46f to your computer and use it in GitHub Desktop.
Experiment with command line arguments in Rake task
➜ jrd-gplt git:(master) ✗ git diff <<<
diff --git a/rakefile b/rakefile
index 41f6ecd..af067a8 100644
--- a/rakefile
+++ b/rakefile
@@ -253,7 +253,40 @@ rototiller_task :performance_without_provision do |t|
end
desc 'Run Performance setup for clamps'
-rototiller_task :performance_clamps do |t|
+task :performance_clamps do
+ require 'optparse'
+
+ options = {}
+ opts = OptionParser.new do |o|
+ o.banner = "Usage: rake performance_clamps -- [options]"
+ o.on("--puppet_type=PUPPET_TYPE", "'pe' or 'foss'") { |a| options[:beaker_install_type] = a }
+ o.on("--beaker_pe_dir=BEAKER_PE_DIR", "Mandadory if puppet_type is 'pe'") { |a| options[:beaker_pe_dir] = a }
+ o.on("--beaker_pe_ver=BEAKER_PE_VER", "Mandadory if puppet_type is 'pe'") { |a| options[:beaker_pe_ver] = a }
+ o.on("--tests=TESTS", "Beaker tests") { |a| options[:tests] = a }
+ o.on( '-h', '--help') do
+ puts opts
+ exit
+ end
+ end
+
+ # return `ARGV` with the intended arguments
+ args = opts.order!(ARGV) {}
+
+ opts.parse!(args)
+
+ # Ensure mandatory arguments
+ abort(opts.help) unless ['pe', 'foss'].include? options[:beaker_install_type]
+
+ if options[:beaker_install_type] == 'pe' then
+ if options[:beaker_pe_dir].nil? || options[:beaker_pe_ver].nil?
+ abort(opts.help)
+ end
+ end
+
+ options.each do |k,v|
+ ENV["#{k.upcase}"] = "#{v}"
+ end
+
ENV['ENVIRONMENT_TYPE'] = 'clamps'
Rake::Task["performance"].execute
end
➜ jrd-gplt git:(master) ✗ bundle exec rake performance_clamps <<<
Usage: rake performance_clamps -- [options]
--puppet_type=PUPPET_TYPE 'pe' or 'foss'
--beaker_pe_dir=BEAKER_PE_DIR
Mandadory if puppet_type is 'pe'
--beaker_pe_ver=BEAKER_PE_VER
Mandadory if puppet_type is 'pe'
--tests=TESTS Beaker tests
-h, --help
➜ jrd-gplt git:(master) ✗ bundle exec rake performance_clamps -- --puppet_type pe --beaker_pe_dir "http://enterprise.delivery.puppetlabs.net/2019.0/ci-ready" --beaker_pe_ver $(curl http://getpe.delivery.puppetlabs.net/latest/2019.0) <<<
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 24 100 24 0 0 1277 0 --:--:-- --:--:-- --:--:-- 1333
Attempting to provision ABS hosts: [{:role=>"mom", :size=>"c5.2xlarge", :volume_size=>"80"}, {:role=>"metrics", :size=>"c5.2xlarge", :volume_size=>"80"}]
Host_to_request: {:role=>"mom", :size=>"c5.2xlarge", :volume_size=>"80"}
sending request body:
{"platform":"centos-7-x86_64","image_id":"ami-01ed306a12b7d1c96","size":"c5.2xlarge","region":"us-west-2","reap_time":"86400","tags":{"role":"mom","pe_version":"2019.0.3-rc1-637-g14bd591"},"volume_size":"80"}
to uri: https://cinext-abs.delivery.puppetlabs.net/api/v2/awsdirect
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment