From a02fd8e935529f315a8a75a8089ecec24bd61f48 Mon Sep 17 00:00:00 2001 From: NimishaS Date: Fri, 15 Sep 2017 18:37:26 +0530 Subject: [PATCH] Added promote_single_region raketask for GOV Cloud Signed-off-by: NimishaS --- Rakefile | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/Rakefile b/Rakefile index 42dc6837..4e3a6b63 100644 --- a/Rakefile +++ b/Rakefile @@ -23,6 +23,8 @@ PESTER_VER_TAG = "2.0.4" # we lock down to specific tag version PESTER_GIT_URL = 'https://github.com/pester/Pester.git' PESTER_SANDBOX = './PESTER_SANDBOX' +GOV_REGIONS = ["USGov Iowa", "USGov Arizona", "USGov Texas", "USGov Virginia"] + # Array of hashes {src : dest} for files to be packaged LINUX_PACKAGE_LIST = [ {"ChefExtensionHandler/*.sh" => "#{CHEF_BUILD_DIR}/"}, @@ -114,6 +116,15 @@ def set_gov_env_vars(subscription_id) end end +def assert_promote_params(args) + assert_gov_environment_vars + error_and_exit! "`promote_single_region` task is supported on for deploy_type: \"#{GOV}\"" unless args.deploy_type == GOV + error_and_exit! "Invalid Region. Valid regions for GOV Cloud are: #{GOV_REGIONS}" unless GOV_REGIONS.include? args.region + + # assert build date since we form the build tag + error_and_exit! "Please specify the :build_date_yyyymmdd param used to identify the published build" if args.build_date_yyyymmdd.nil? +end + def assert_deploy_params(deploy_type, internal_or_public) assert_publish_env_vars @@ -409,6 +420,55 @@ CONFIRMATION end end +desc "Promotes the extension in single region for GOV Cloud" +task :promote_single_region, [:deploy_type, :target_type, :extension_version, :build_date_yyyymmdd, :region, :confirmation_required] do |t, args| + args.with_defaults( + :deploy_type => GOV, + :target_type => "windows", + :extension_version => EXTENSION_VERSION, + :build_date_yyyymmdd => nil, + :region => "USGov Virginia", + :confirmation_required => "true") + + puts "**Promote_single_region called with args:\n#{args}\n\n" + + assert_publish_env_vars + subscription_id, subscription_name = load_publish_settings + set_gov_env_vars(subscription_id) + assert_promote_params(args) + definitionXmlFile = get_definition_xml_name(args) + + puts <<-CONFIRMATION + +***************************************** +This task promotes the chef extension package to '#{args.region}' region. + Details: + ------- + Publish To: ** #{args.deploy_type.gsub(/deploy_to_/, "")} ** + Subscription Name: #{subscription_name} + Extension Version: #{args.extension_version} + Build Date: #{args.build_date_yyyymmdd} + Region: #{args.region} +**************************************** +CONFIRMATION + # Get user confirmation, since we are publishing a new build to Azure. + if args.confirmation_required == "true" + confirm!("update") + end + + puts "Promoting the extension to #{args.region}..." + + begin + cli_cmd = Mixlib::ShellOut.new("#{ENV['azure_extension_cli']} promote-single-region --manifest #{definitionXmlFile} --region-1 '#{args.region}'") + result = cli_cmd.run_command + result.error! + puts "The extension has been successfully published in #{args.region}." + rescue Mixlib::ShellOut::ShellCommandFailed => e + puts "Failure while running `#{ENV['azure_extension_cli']} promote-single-region`: #{e}" + exit + end +end + desc "Deletes the azure chef extension package which was publised as internal Ex: publish[deploy_type, platform, extension_version], default is build[preview,windows]." task :delete, [:deploy_type, :target_type, :chef_deploy_namespace, :full_extension_version, :confirmation_required] do |t, args|