From ee7eff4a9841ad5a03ac6b7715828c21ce3b2816 Mon Sep 17 00:00:00 2001 From: ssdevopsio Date: Sun, 7 Mar 2021 11:56:28 -0500 Subject: [PATCH 01/10] Resolve substring error --- .../redhat/modules/mysql_database_restore.sh | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/provisioners/redhat/modules/mysql_database_restore.sh b/provisioners/redhat/modules/mysql_database_restore.sh index 5ebfc67b..cfa1a492 100644 --- a/provisioners/redhat/modules/mysql_database_restore.sh +++ b/provisioners/redhat/modules/mysql_database_restore.sh @@ -39,8 +39,8 @@ if ([ ! -z "${software}" ]); then else echo -e "\t* ~/_sql directory exists, looking for a valid database dump to restore from" filenewest_lock=$(ls "/var/www/repositories/apache/${domain}/_sql" | grep -E ^[0-9]{8}\.sql\.lock$ | sort --numeric-sort | tail -1) - filenewest=${filenewest_lock::-5} - if ([ -f "/var/www/repositories/apache/${domain}/_sql/${filenewest}" ] && [ -f "/var/www/repositories/apache/${domain}/_sql/${filenewest_lock}" ]); then + if ([ -f "/var/www/repositories/apache/${domain}/_sql/${filenewest_lock::-5}" ] && [ -f "/var/www/repositories/apache/${domain}/_sql/${filenewest_lock}" ]); then + filenewest=${filenewest_lock::-5} # drop the database for database in $(mysql --defaults-extra-file=$dbconf -e "show databases" | egrep -v "Database|mysql|information_schema|performance_schema"); do if [ ${database} = ${1}_${domain_valid_db_name} ]; then @@ -111,7 +111,7 @@ if ([ ! -z "${software}" ]); then || [ "${software}" = "xenforo1" ] \ || [ "${software}" = "xenforo2" ] \ || [ "${software}" = "zendframework2" ]); then - echo -e "\t- replacing URLs in the database to align with the enivronment..." + echo -e "\t- replacing URLs in the database to align with the environment..." replacements=$(grep --extended-regexp --only-matching --regexp=":\/\/(www\.)?(dev\.|test\.|qc\.)?(${domain_url_replace})" "/var/www/repositories/apache/${domain}/_sql/${filenewest}" | wc --lines) sed --regexp-extended --expression="s/:\/\/(www\.)?(dev\.|test\.|qc\.)?(${domain_url_replace})/:\/\/\1${domain_url}/g" "/var/www/repositories/apache/${domain}/_sql/${filenewest}" > "/var/www/repositories/apache/${domain}/_sql/${1}.${filenewest}" echo -e "\t- found and replaced ${replacements} occurrences" @@ -127,11 +127,11 @@ if ([ ! -z "${software}" ]); then # necessary for PHP serialized arrays # for software with a cli tool for database url reference replacements, use cli tool to post-process database and replace url references if ([ "${software}" = "wordpress4" ]); then - echo -e "\t- replacing URLs in the database to align with the enivronment..." + echo -e "\t- replacing URLs in the database to align with the environment..." wp-cli-php71 --allow-root --path="/var/www/repositories/apache/${domain}/${webroot}" search-replace ":\/\/(www\.)?(dev\.|test\.|qc\.)?(${domain_url_replace})" "://\$1${domain_url}" --regex | sed "s/^/\t\t/" fi if ([ "${software}" = "wordpress5" ]); then - echo -e "\t- replacing URLs in the database to align with the enivronment..." + echo -e "\t- replacing URLs in the database to align with the environment..." wp-cli-php72 --allow-root --path="/var/www/repositories/apache/${domain}/${webroot}" search-replace ":\/\/(www\.)?(dev\.|test\.|qc\.)?(${domain_url_replace})" "://\$1${domain_url}" --regex | sed "s/^/\t\t/" fi fi @@ -143,8 +143,8 @@ if ([ ! -z "${software}" ]); then # we look for the newest possible _software_dbtable_retain database sql file and restore if ([ ! -z "${software}" ] && [ "${software_workflow}" = "upstream" ] && [ "${software_db}" != "" ] && [ "${software_db_tables}" != "0" ]); then filenewest_lock=$(ls "/var/www/repositories/apache/${domain}/_sql" | grep -E ^[0-9]{8}_software_dbtable_retain\.sql\.lock$ | sort --numeric-sort | tail -1) - filenewest=${filenewest_lock::-5} - if ([ -f "/var/www/repositories/apache/${domain}/_sql/${filenewest}" ] && [ -f "/var/www/repositories/apache/${domain}/_sql/${filenewest_lock}" ]); then + if ([ -f "/var/www/repositories/apache/${domain}/_sql/${filenewest_lock::-5}" ] && [ -f "/var/www/repositories/apache/${domain}/_sql/${filenewest_lock}" ]); then + filenewest=${filenewest_lock::-5} echo -e "\t- found ${filenewest_lock}" echo -e "\t- found ${filenewest}" echo -e "\t- restoring..." From 2ea3cff058d276d8ca387fce6002c8a082602e4c Mon Sep 17 00:00:00 2001 From: ssdevopsio Date: Sun, 7 Mar 2021 11:57:12 -0500 Subject: [PATCH 02/10] Query APIs to properly configure trigger with inbound webhook IP ranges --- catapult/catapult.rb | 54 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 50 insertions(+), 4 deletions(-) diff --git a/catapult/catapult.rb b/catapult/catapult.rb index 56f51f36..ae65f4a6 100644 --- a/catapult/catapult.rb +++ b/catapult/catapult.rb @@ -1025,10 +1025,56 @@ def Command::getSignatureKey(key, dateStamp, regionName, serviceName) # https://developer.github.com/changes/2019-03-29-webhooks-ip-changes/ # https://api.github.com/meta if plan.include?("TEST") - api_bamboo_cli_result_plan_triggers = `#{@api_bamboo_cli} --server #{@configuration["company"]["bamboo_base_url"]} --password #{@configuration["company"]["bamboo_password"]} --user #{@configuration["company"]["bamboo_username"]} --action getTriggerList --plan "#{plan}" #{@api_bamboo_cli_redirect}`; result=$?.success? - if ! api_bamboo_cli_result_plan_triggers.strip.include?("18.205.93.0/25,18.234.32.128/25,13.52.5.0/25,192.30.252.0/22,185.199.108.0/22,140.82.112.0/20") - api_bamboo_cli_result_plan_triggers = `#{@api_bamboo_cli} --server #{@configuration["company"]["bamboo_base_url"]} --password #{@configuration["company"]["bamboo_password"]} --user #{@configuration["company"]["bamboo_username"]} --action addTrigger --plan "#{plan}" --type "remote" --ipRestriction "18.205.93.0/25,18.234.32.128/25,13.52.5.0/25,192.30.252.0/22,185.199.108.0/22,140.82.112.0/20" #{@api_bamboo_cli_redirect}`; result=$?.success? - puts " - #{api_bamboo_cli_result_plan_triggers.strip}" + @ip_ranges_bitbucket = [] + uri = URI("https://ip-ranges.atlassian.com/") + Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https') do |http| + request = Net::HTTP::Get.new uri.request_uri + response = http.request(request) + if response.code.to_f.between?(399,600) + puts " - BitBucket IP Ranges API appears to be offline.".color(Colors::RED) + else + puts " - BitBucket IP Ranges loaded successfully." + @api_ip_bitbucket = JSON.parse(response.body) + if @api_ip_bitbucket + @api_ip_bitbucket['items'].each do |iprange| + @ip_ranges_bitbucket.push "#{iprange["cidr"]}" + end + end + end + end + + @ip_ranges_github = [] + uri = URI("https://api.github.com/meta") + Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https') do |http| + request = Net::HTTP::Get.new uri.request_uri + response = http.request(request) + if response.code.to_f.between?(399,600) + puts " - GitHub Meta API appears to be offline.".color(Colors::RED) + else + puts " - GitHub Meta API loaded successfully." + @api_ip_github = JSON.parse(response.body) + if @api_ip_github + @api_ip_github['hooks'].each do |iprange| + @ip_ranges_github.push "#{iprange}" + end + end + end + end + + @ip_ranges_bitbucket_formatted = @ip_ranges_bitbucket.join(",") + @ip_ranges_github_formatted = @ip_ranges_github.join(",") + + # configure webhook ip ranges only when both API calls have succeeded + if @ip_ranges_bitbucket_formatted and @ip_ranges_github_formatted + @ip_ranges_formatted = @ip_ranges_bitbucket_formatted + "," + @ip_ranges_github_formatted + + api_bamboo_cli_result_plan_triggers = `#{@api_bamboo_cli} --server #{@configuration["company"]["bamboo_base_url"]} --password #{@configuration["company"]["bamboo_password"]} --user #{@configuration["company"]["bamboo_username"]} --action getTriggerList --plan "#{plan}" #{@api_bamboo_cli_redirect}`; result=$?.success? + if ! api_bamboo_cli_result_plan_triggers.strip.include?(@ip_ranges_formatted) + api_bamboo_cli_result_plan_triggers = `#{@api_bamboo_cli} --server #{@configuration["company"]["bamboo_base_url"]} --password #{@configuration["company"]["bamboo_password"]} --user #{@configuration["company"]["bamboo_username"]} --action addTrigger --plan "#{plan}" --type "remote" --ipRestriction "#{@ip_ranges_formatted}" #{@api_bamboo_cli_redirect}`; result=$?.success? + puts " - #{api_bamboo_cli_result_plan_triggers.strip}" + end + else + puts " - Webhook configuration will be skipped until both IP range APIs are available.".color(Colors::RED) end end # configure: tasks From 06919e741563bbabec92e630c3821052f6e3a6cb Mon Sep 17 00:00:00 2001 From: ssdevopsio Date: Sat, 20 Mar 2021 10:36:00 -0400 Subject: [PATCH 03/10] Ignore dynamically-generated script --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index ba78f7f5..f75f99f6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ /*.lock +/catapult/installers/run-test-build.rb /provisioners/redhat/certs/ /secrets/configuration.yml /secrets/configuration.yml.compare From 4eeb710988bf51bb7cd74ec479a05c99a138602b Mon Sep 17 00:00:00 2001 From: ssdevopsio Date: Sat, 20 Mar 2021 10:39:37 -0400 Subject: [PATCH 04/10] Implement post-commit hook to automatically queue test environment build --- catapult/catapult.rb | 54 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) diff --git a/catapult/catapult.rb b/catapult/catapult.rb index ae65f4a6..84087920 100644 --- a/catapult/catapult.rb +++ b/catapult/catapult.rb @@ -2145,6 +2145,44 @@ def Command::getSignatureKey(key, dateStamp, regionName, serviceName) end end + working_dir = Dir.pwd + File.write('catapult/installers/run-test-build.rb', + "#!/usr/bin/env ruby + require 'yaml' + + if File.exist?(File.expand_path('#{working_dir}/secrets/configuration.yml')) + @configuration = YAML.load_file('#{working_dir}/secrets/configuration.yml') + + if (RbConfig::CONFIG['host_os'] =~ /mswin|msys|mingw|cygwin|bccwin|wince|emc/) + @environment = :windows + else (RbConfig::CONFIG['host_os'] =~ /darwin|mac os|linux|solaris|bsd/) + @environment = :posix + end + + if @environment == :posix + @api_bamboo_cli = '#{working_dir}/catapult/installers/atlassian-cli-9.5.0/acli.sh bamboo' + @api_bamboo_cli_redirect = '2>&1' + elsif @environment == :windows + @api_bamboo_cli = '#{working_dir}/catapult/installers/atlassian-cli-9.5.0/acli.bat bamboo' + @api_bamboo_cli_redirect = '2>' + end + + api_bamboo_cli_result = `\#{@api_bamboo_cli} --server \#{@configuration['company']['bamboo_base_url']} --password \#{@configuration['company']['bamboo_password']} --user \#{@configuration['company']['bamboo_username']} --action queueBuild --plan CAT-TEST \#{@api_bamboo_cli_redirect}`; result=$?.success? + if api_bamboo_cli_result.strip.include?('Connection refused') + puts 'The Bamboo CLI seems to be down. Skipping attempt to queue build job for TEST environment...' + elsif api_bamboo_cli_result.strip.include?('401') + puts \"The Bamboo CLI could not authenticate. This likely means you need to login to Bamboo as \#{@configuration['company']['bamboo_username']} at \#{@configuration['company']['bamboo_base_url']} and provide an answer to a CAPTCHA challenge.\" + elsif ! result + puts 'The attempt to queue a build for the TEST environment failed. This likely means a build is already running.' + else + puts \"Bamboo build for test environment queued successfully: \#{api_bamboo_cli_result}\" + end + else + puts 'The Catapult configuration is not decrypted. Skipping attempt to queue build job for TEST environment...' + end + ") + File.chmod(0755,'catapult/installers/run-test-build.rb') + # remove unique lock file @@ -2733,7 +2771,7 @@ def Command::getSignatureKey(key, dateStamp, regionName, serviceName) - # create arrays of domains for localdev hosts file + # create arrays of domains for localdev hosts file & setup post-commit hook to queue test environment build @dev_redhat_hosts = Array.new unless @configuration["websites"]["apache"] == nil @configuration["websites"]["apache"].each do |instance| @@ -2744,6 +2782,13 @@ def Command::getSignatureKey(key, dateStamp, regionName, serviceName) @dev_redhat_hosts.push("dev.#{instance["domain"]}.#{instance["domain_tld_override"]}") @dev_redhat_hosts.push("www.dev.#{instance["domain"]}.#{instance["domain_tld_override"]}") end + + FileUtils.mkdir_p("repositories/apache/#{instance['domain']}/.git/hooks") + File.write("repositories/apache/#{instance['domain']}/.git/hooks/post-commit", + "#!/usr/bin/env ruby + system('#{working_dir}/catapult/installers/run-test-build.rb') + ") + File.chmod(0777,"repositories/apache/#{instance['domain']}/.git/hooks/post-commit") end end @dev_windows_hosts = Array.new @@ -2756,6 +2801,13 @@ def Command::getSignatureKey(key, dateStamp, regionName, serviceName) @dev_windows_hosts.push("dev.#{instance["domain"]}.#{instance["domain_tld_override"]}") @dev_windows_hosts.push("www.dev.#{instance["domain"]}.#{instance["domain_tld_override"]}") end + + FileUtils.mkdir_p("repositories/iis/#{instance['domain']}/.git/hooks") + File.write("repositories/iis/#{instance['domain']}/.git/hooks/post-commit", + "#!/usr/bin/env ruby + system('#{working_dir}/catapult/installers/run-test-build.rb') + ") + File.chmod(0777,"repositories/iis/#{instance['domain']}/.git/hooks/post-commit") end end From c8d60ecae0dcac1243243666776fb6957a433bb6 Mon Sep 17 00:00:00 2001 From: ssdevopsio Date: Sat, 20 Mar 2021 10:47:54 -0400 Subject: [PATCH 05/10] Remove broken webhooks and supporting operations --- catapult/catapult.rb | 160 +------------------------------------------ 1 file changed, 2 insertions(+), 158 deletions(-) diff --git a/catapult/catapult.rb b/catapult/catapult.rb index 84087920..04853ed7 100644 --- a/catapult/catapult.rb +++ b/catapult/catapult.rb @@ -1017,66 +1017,6 @@ def Command::getSignatureKey(key, dateStamp, regionName, serviceName) api_bamboo_cli_result_plan_triggers = `#{@api_bamboo_cli} --server #{@configuration["company"]["bamboo_base_url"]} --password #{@configuration["company"]["bamboo_password"]} --user #{@configuration["company"]["bamboo_username"]} --action addTrigger --plan "#{plan}" --type "scheduled" --schedule "#{@api_bamboo_cli_environment_trigger_time}" --field "custom.triggerrCondition.plansGreen.plan=#{@api_bamboo_cli_environment_trigger_conditions}" #{@api_bamboo_cli_redirect}`; result=$?.success? puts " - #{api_bamboo_cli_result_plan_triggers.strip}" end - # configure: trigger: remote - # bitbucket - # https://confluence.atlassian.com/bitbucket/what-are-the-bitbucket-cloud-ip-addresses-i-should-use-to-configure-my-corporate-firewall-343343385.html - # https://ip-ranges.atlassian.com/ - # github - # https://developer.github.com/changes/2019-03-29-webhooks-ip-changes/ - # https://api.github.com/meta - if plan.include?("TEST") - @ip_ranges_bitbucket = [] - uri = URI("https://ip-ranges.atlassian.com/") - Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https') do |http| - request = Net::HTTP::Get.new uri.request_uri - response = http.request(request) - if response.code.to_f.between?(399,600) - puts " - BitBucket IP Ranges API appears to be offline.".color(Colors::RED) - else - puts " - BitBucket IP Ranges loaded successfully." - @api_ip_bitbucket = JSON.parse(response.body) - if @api_ip_bitbucket - @api_ip_bitbucket['items'].each do |iprange| - @ip_ranges_bitbucket.push "#{iprange["cidr"]}" - end - end - end - end - - @ip_ranges_github = [] - uri = URI("https://api.github.com/meta") - Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https') do |http| - request = Net::HTTP::Get.new uri.request_uri - response = http.request(request) - if response.code.to_f.between?(399,600) - puts " - GitHub Meta API appears to be offline.".color(Colors::RED) - else - puts " - GitHub Meta API loaded successfully." - @api_ip_github = JSON.parse(response.body) - if @api_ip_github - @api_ip_github['hooks'].each do |iprange| - @ip_ranges_github.push "#{iprange}" - end - end - end - end - - @ip_ranges_bitbucket_formatted = @ip_ranges_bitbucket.join(",") - @ip_ranges_github_formatted = @ip_ranges_github.join(",") - - # configure webhook ip ranges only when both API calls have succeeded - if @ip_ranges_bitbucket_formatted and @ip_ranges_github_formatted - @ip_ranges_formatted = @ip_ranges_bitbucket_formatted + "," + @ip_ranges_github_formatted - - api_bamboo_cli_result_plan_triggers = `#{@api_bamboo_cli} --server #{@configuration["company"]["bamboo_base_url"]} --password #{@configuration["company"]["bamboo_password"]} --user #{@configuration["company"]["bamboo_username"]} --action getTriggerList --plan "#{plan}" #{@api_bamboo_cli_redirect}`; result=$?.success? - if ! api_bamboo_cli_result_plan_triggers.strip.include?(@ip_ranges_formatted) - api_bamboo_cli_result_plan_triggers = `#{@api_bamboo_cli} --server #{@configuration["company"]["bamboo_base_url"]} --password #{@configuration["company"]["bamboo_password"]} --user #{@configuration["company"]["bamboo_username"]} --action addTrigger --plan "#{plan}" --type "remote" --ipRestriction "#{@ip_ranges_formatted}" #{@api_bamboo_cli_redirect}`; result=$?.success? - puts " - #{api_bamboo_cli_result_plan_triggers.strip}" - end - else - puts " - Webhook configuration will be skipped until both IP range APIs are available.".color(Colors::RED) - end - end # configure: tasks # https://bobswift.atlassian.net/wiki/display/BCLI/Examples+for+AddTask+Action if plan.include?("BUILD") @@ -2193,7 +2133,7 @@ def Command::getSignatureKey(key, dateStamp, regionName, serviceName) # validate @configuration["websites"] if ["provision","status"].include?(ARGV[0]) && @configuration_user["settings"]["admin"] puts "\nVerification of configuration[\"websites\"]:".color(Colors::WHITE) - # temporarily add catapult to verify repo and add bamboo webhooks + # temporarily add catapult to verify repo @configuration["websites"]["catapult"] = *(["domain" => "#{@repo}", "repo" => "#{@repo}"]) # validate @configuration["websites"] @configuration["websites"].each do |service,data| @@ -2205,7 +2145,7 @@ def Command::getSignatureKey(key, dateStamp, regionName, serviceName) domains_sorted = Array.new unless @configuration["websites"]["#{service}"] == nil puts "\n[#{service}] #{@configuration["websites"]["#{service}"].nil? ? "0" : @configuration["websites"]["#{service}"].length} total" - puts "[domain]".ljust(40) + "[repo]".ljust(12) + "[repo size]".ljust(12) + "[repo write access]".ljust(20) + "[develop]".ljust(16) + "[release]".ljust(16) + "[master]".ljust(16) + "[bamboo webhook]".ljust(18) + puts "[domain]".ljust(40) + "[repo]".ljust(12) + "[repo size]".ljust(12) + "[repo write access]".ljust(20) + "[develop]".ljust(16) + "[release]".ljust(16) + "[master]".ljust(16) puts "\n" @configuration["websites"]["#{service}"].each do |instance| # start new row @@ -2658,102 +2598,6 @@ def Command::getSignatureKey(key, dateStamp, regionName, serviceName) end end end - # create bamboo webhook per bitbucket repo - if "#{repo_split_2[0]}" == "bitbucket.org" - @api_bitbucket_repo_hook = false - uri = URI("https://api.bitbucket.org/2.0/repositories/#{repo_split_3[0]}/hooks") - Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https') do |http| - request = Net::HTTP::Get.new uri.request_uri - request.basic_auth "#{@configuration["company"]["bitbucket_username"]}", "#{@configuration["company"]["bitbucket_password"]}" - response = http.request(request) - if response.code.to_f.between?(399,600) - puts " - The Bitbucket API seems to be down, skipping... (this may impact provisioning, deployments, and dashboard reporting)".color(Colors::RED) - else - api_github_repo_hooks = JSON.parse(response.body) - api_github_repo_hooks["values"].each do |hook| - if hook["description"] == "bamboo:CAT-TEST" && hook["url"] == "#{@configuration["company"]["bamboo_base_url"]}rest/triggers/1.0/remote/changeDetection?planKey=CAT-TEST&skipBranches=false" - @api_bitbucket_repo_hook = true - end - end - unless @api_bitbucket_repo_hook - uri = URI("https://api.bitbucket.org/2.0/repositories/#{repo_split_3[0]}/hooks") - Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https') do |http| - request = Net::HTTP::Post.new uri.request_uri - request.basic_auth "#{@configuration["company"]["bitbucket_username"]}", "#{@configuration["company"]["bitbucket_password"]}" - request.add_field "Content-Type", "application/json" - request.body = ""\ - "{"\ - "\"description\":\"bamboo:CAT-TEST\","\ - "\"url\":\"#{@configuration["company"]["bamboo_base_url"]}rest/triggers/1.0/remote/changeDetection?planKey=CAT-TEST&skipBranches=false\","\ - "\"active\":true,"\ - "\"events\":"\ - "["\ - "\"repo:push\""\ - "]"\ - "}" - response = http.request(request) - if response.code.to_f.between?(500,600) - puts " - The Bitbucket API seems to be down, skipping... (this may impact provisioning, deployments, and dashboard reporting)".color(Colors::RED) - elsif response.code.to_f.between?(399,499) - catapult_exception("Unable to configure Bitbucket Bamboo webhook for websites => #{service} => domain => #{instance["domain"]}. Ensure the bitbucket_username defined in secrets/configuration.yml has correct access to the repository.") - else - row.push("configured".ljust(17)) - end - end - else - row.push("configured".ljust(17)) - end - end - end - end - # create bamboo webhook per github repo - if "#{repo_split_2[0]}" == "github.com" - @api_github_repo_hook = false - uri = URI("https://api.github.com/repos/#{repo_split_3[0]}/hooks") - Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https') do |http| - request = Net::HTTP::Get.new uri.request_uri - request.basic_auth "#{@configuration["company"]["github_username"]}", "#{@configuration["company"]["github_personal_access_token"]}" - response = http.request(request) - if response.code.to_f.between?(399,600) - puts " - The GitHub API seems to be down, skipping... (this may impact provisioning, deployments, and dashboard reporting)".color(Colors::RED) - else - api_github_repo_hooks = JSON.parse(response.body) - api_github_repo_hooks.each do |hook| - if hook["config"]["url"] == "#{@configuration["company"]["bamboo_base_url"]}rest/triggers/1.0/remote/changeDetection?planKey=CAT-TEST&skipBranches=false" - @api_github_repo_hook = true - end - end - unless @api_github_repo_hook - uri = URI("https://api.github.com/repos/#{repo_split_3[0]}/hooks") - Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https') do |http| - request = Net::HTTP::Post.new uri.request_uri - request.basic_auth "#{@configuration["company"]["github_username"]}", "#{@configuration["company"]["github_personal_access_token"]}" - request.add_field "Content-Type", "application/json" - request.body = ""\ - "{"\ - "\"name\":\"web\","\ - "\"active\":true,"\ - "\"config\":"\ - "{"\ - "\"url\":\"#{@configuration["company"]["bamboo_base_url"]}rest/triggers/1.0/remote/changeDetection?planKey=CAT-TEST&skipBranches=false \","\ - "\"content_type\":\"json\""\ - "}"\ - "}" - response = http.request(request) - if response.code.to_f.between?(500,600) - puts " - The GitHub API seems to be down, skipping... (this may impact provisioning, deployments, and dashboard reporting)".color(Colors::RED) - elsif response.code.to_f.between?(399,499) - catapult_exception("Unable to configure GitHub Bamboo webhook for websites => #{service} => domain => #{instance["domain"]}. Ensure the github_username defined in secrets/configuration.yml has correct access to the repository.") - else - row.push("configured".ljust(17)) - end - end - else - row.push("configured".ljust(17)) - end - end - end - end puts row.join(" ") From 1c2be954f2a7b934e7b34f25094fb6ec1d98483e Mon Sep 17 00:00:00 2001 From: ssdevopsio Date: Sat, 20 Mar 2021 13:10:38 -0400 Subject: [PATCH 06/10] Change location for utility script --- catapult/catapult.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/catapult/catapult.rb b/catapult/catapult.rb index 04853ed7..15e4824f 100644 --- a/catapult/catapult.rb +++ b/catapult/catapult.rb @@ -2086,7 +2086,7 @@ def Command::getSignatureKey(key, dateStamp, regionName, serviceName) end working_dir = Dir.pwd - File.write('catapult/installers/run-test-build.rb', + File.write('catapult/catapult-build.rb', "#!/usr/bin/env ruby require 'yaml' @@ -2121,7 +2121,7 @@ def Command::getSignatureKey(key, dateStamp, regionName, serviceName) puts 'The Catapult configuration is not decrypted. Skipping attempt to queue build job for TEST environment...' end ") - File.chmod(0755,'catapult/installers/run-test-build.rb') + File.chmod(0755,'catapult/catapult-build.rb') @@ -2630,7 +2630,7 @@ def Command::getSignatureKey(key, dateStamp, regionName, serviceName) FileUtils.mkdir_p("repositories/apache/#{instance['domain']}/.git/hooks") File.write("repositories/apache/#{instance['domain']}/.git/hooks/post-commit", "#!/usr/bin/env ruby - system('#{working_dir}/catapult/installers/run-test-build.rb') + system('#{working_dir}/catapult/catapult-build.rb') ") File.chmod(0777,"repositories/apache/#{instance['domain']}/.git/hooks/post-commit") end @@ -2649,7 +2649,7 @@ def Command::getSignatureKey(key, dateStamp, regionName, serviceName) FileUtils.mkdir_p("repositories/iis/#{instance['domain']}/.git/hooks") File.write("repositories/iis/#{instance['domain']}/.git/hooks/post-commit", "#!/usr/bin/env ruby - system('#{working_dir}/catapult/installers/run-test-build.rb') + system('#{working_dir}/catapult/catapult-build.rb') ") File.chmod(0777,"repositories/iis/#{instance['domain']}/.git/hooks/post-commit") end From fa15f6b4e61f6e044b98ce55234c5e5f859a69d8 Mon Sep 17 00:00:00 2001 From: ssdevopsio Date: Sat, 20 Mar 2021 13:11:19 -0400 Subject: [PATCH 07/10] Update ignored path for utility script --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index f75f99f6..efdc8f54 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ /*.lock -/catapult/installers/run-test-build.rb +/catapult/calcium-build.rb /provisioners/redhat/certs/ /secrets/configuration.yml /secrets/configuration.yml.compare From 7041e80db9ea23a8ada605a86292ccd2e733084c Mon Sep 17 00:00:00 2001 From: ssdevopsio Date: Sat, 20 Mar 2021 13:12:16 -0400 Subject: [PATCH 08/10] Fix ignore path --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index efdc8f54..353a706b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ /*.lock -/catapult/calcium-build.rb +/catapult/catapult-build.rb /provisioners/redhat/certs/ /secrets/configuration.yml /secrets/configuration.yml.compare From 182da142c7ee5d7e05785e5066b77da99c9e5a47 Mon Sep 17 00:00:00 2001 From: ssdevopsio Date: Sat, 20 Mar 2021 13:20:45 -0400 Subject: [PATCH 09/10] Increment version --- VERSION.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION.yml b/VERSION.yml index 074418e8..39914303 100644 --- a/VERSION.yml +++ b/VERSION.yml @@ -1,5 +1,5 @@ --- -version: 4.1.3 +version: 4.2.0 major: description: "Catapult uses Semantic Versioning. During a MAJOR increment, incompatable API changes are made which require a manual upgrade path. Please follow these directions:" notice: "NEW MAJOR VERSION OF CATAPULT AVAILABLE" From 75c927b9ec0eb3efbfd65aa767b672e13501bd01 Mon Sep 17 00:00:00 2001 From: ssdevopsio Date: Wed, 7 Apr 2021 09:48:35 -0400 Subject: [PATCH 10/10] Set and correct cache configurations in spite of committed wp-config.php --- provisioners/redhat/modules/software_operations_file.sh | 6 ++++++ provisioners/redhat/modules/software_operations_meta.sh | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/provisioners/redhat/modules/software_operations_file.sh b/provisioners/redhat/modules/software_operations_file.sh index 98ee7651..53eff744 100644 --- a/provisioners/redhat/modules/software_operations_file.sh +++ b/provisioners/redhat/modules/software_operations_file.sh @@ -339,6 +339,9 @@ if hash composer 2>/dev/null && hash drush 2>/dev/null && hash wp-cli 2>/dev/nul cd "/var/www/repositories/apache/${domain}/${webroot}${softwareroot}" && wp-cli-php71 --allow-root plugin install w3-total-cache cd "/var/www/repositories/apache/${domain}/${webroot}${softwareroot}" && wp-cli-php71 --allow-root plugin activate w3-total-cache cd "/var/www/repositories/apache/${domain}/${webroot}${softwareroot}" && wp-cli-php71 --allow-root w3-total-cache fix_environment apache + else + sed -i "/\/\*\* Enable W3 Total Cache \*\//d" "/var/www/repositories/apache/${domain}/${webroot}${softwareroot}/wp-config.php" + sed -i "/define( 'WP_CACHE' , true ); \/\/ Added by W3 Total Cache/d" "/var/www/repositories/apache/${domain}/${webroot}${softwareroot}/wp-config.php" fi else @@ -360,6 +363,9 @@ if hash composer 2>/dev/null && hash drush 2>/dev/null && hash wp-cli 2>/dev/nul cd "/var/www/repositories/apache/${domain}/${webroot}${softwareroot}" && wp-cli-php72 --allow-root plugin install w3-total-cache cd "/var/www/repositories/apache/${domain}/${webroot}${softwareroot}" && wp-cli-php72 --allow-root plugin activate w3-total-cache cd "/var/www/repositories/apache/${domain}/${webroot}${softwareroot}" && wp-cli-php72 --allow-root w3-total-cache fix_environment apache + else + sed -i "/\/\*\* Enable W3 Total Cache \*\//d" "/var/www/repositories/apache/${domain}/${webroot}${softwareroot}/wp-config.php" + sed -i "/define( 'WP_CACHE' , true ); \/\/ Added by W3 Total Cache/d" "/var/www/repositories/apache/${domain}/${webroot}${softwareroot}/wp-config.php" fi else diff --git a/provisioners/redhat/modules/software_operations_meta.sh b/provisioners/redhat/modules/software_operations_meta.sh index 1dbfa23b..a502eae8 100644 --- a/provisioners/redhat/modules/software_operations_meta.sh +++ b/provisioners/redhat/modules/software_operations_meta.sh @@ -430,11 +430,14 @@ elif [ "${software}" = "wordpress4" ]; then cd "/var/www/repositories/apache/${domain}/${webroot}${softwareroot}" && wp-cli-php71 --allow-root w3-total-cache option set dbcache.enabled false --type=boolean cd "/var/www/repositories/apache/${domain}/${webroot}${softwareroot}" && wp-cli-php71 --allow-root w3-total-cache option set objectcache.enabled false --type=boolean cd "/var/www/repositories/apache/${domain}/${webroot}${softwareroot}" && wp-cli-php71 --allow-root w3-total-cache option set browsercache.enabled false --type=boolean + sed -i "/\/\*\* Enable W3 Total Cache \*\//d" "/var/www/repositories/apache/${domain}/${webroot}${softwareroot}/wp-config.php" + sed -i "/define( 'WP_CACHE' , true ); \/\/ Added by W3 Total Cache/d" "/var/www/repositories/apache/${domain}/${webroot}${softwareroot}/wp-config.php" else cd "/var/www/repositories/apache/${domain}/${webroot}${softwareroot}" && wp-cli-php71 --allow-root w3-total-cache option set pgcache.enabled true --type=boolean cd "/var/www/repositories/apache/${domain}/${webroot}${softwareroot}" && wp-cli-php71 --allow-root w3-total-cache option set dbcache.enabled false --type=boolean cd "/var/www/repositories/apache/${domain}/${webroot}${softwareroot}" && wp-cli-php71 --allow-root w3-total-cache option set objectcache.enabled false --type=boolean cd "/var/www/repositories/apache/${domain}/${webroot}${softwareroot}" && wp-cli-php71 --allow-root w3-total-cache option set browsercache.enabled false --type=boolean + cd "/var/www/repositories/apache/${domain}/${webroot}${softwareroot}" && wp-cli-php71 --allow-root w3-total-cache fix_environment apache fi elif [ "${software}" = "wordpress5" ]; then @@ -450,11 +453,14 @@ elif [ "${software}" = "wordpress5" ]; then cd "/var/www/repositories/apache/${domain}/${webroot}${softwareroot}" && wp-cli-php72 --allow-root w3-total-cache option set dbcache.enabled false --type=boolean cd "/var/www/repositories/apache/${domain}/${webroot}${softwareroot}" && wp-cli-php72 --allow-root w3-total-cache option set objectcache.enabled false --type=boolean cd "/var/www/repositories/apache/${domain}/${webroot}${softwareroot}" && wp-cli-php72 --allow-root w3-total-cache option set browsercache.enabled false --type=boolean + sed -i "/\/\*\* Enable W3 Total Cache \*\//d" "/var/www/repositories/apache/${domain}/${webroot}${softwareroot}/wp-config.php" + sed -i "/define( 'WP_CACHE' , true ); \/\/ Added by W3 Total Cache/d" "/var/www/repositories/apache/${domain}/${webroot}${softwareroot}/wp-config.php" else cd "/var/www/repositories/apache/${domain}/${webroot}${softwareroot}" && wp-cli-php72 --allow-root w3-total-cache option set pgcache.enabled true --type=boolean cd "/var/www/repositories/apache/${domain}/${webroot}${softwareroot}" && wp-cli-php72 --allow-root w3-total-cache option set dbcache.enabled false --type=boolean cd "/var/www/repositories/apache/${domain}/${webroot}${softwareroot}" && wp-cli-php72 --allow-root w3-total-cache option set objectcache.enabled false --type=boolean cd "/var/www/repositories/apache/${domain}/${webroot}${softwareroot}" && wp-cli-php72 --allow-root w3-total-cache option set browsercache.enabled false --type=boolean + cd "/var/www/repositories/apache/${domain}/${webroot}${softwareroot}" && wp-cli-php72 --allow-root w3-total-cache fix_environment apache fi elif [ "${software}" = "xenforo1" ]; then