From bb64cc12822a0f69556fc87c3ab1908ec9a4c1c5 Mon Sep 17 00:00:00 2001 From: Joe Siewert Date: Wed, 20 Mar 2019 16:57:45 -0600 Subject: [PATCH] Debug AWS check --- deployments/aws_code_deploy_deployment_check | 67 ++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 deployments/aws_code_deploy_deployment_check diff --git a/deployments/aws_code_deploy_deployment_check b/deployments/aws_code_deploy_deployment_check new file mode 100644 index 0000000..41c9461 --- /dev/null +++ b/deployments/aws_code_deploy_deployment_check @@ -0,0 +1,67 @@ +#!/home/rof/.rvm/rubies/ruby-2.5.3/bin/ruby +require 'json' +require 'open3' + +module AWS + class CodeshipCodeDeployCheck + def initialize deployment_id_file + @deployment_id_file = deployment_id_file + end + + def check_deployment + while true do + deployment = Deployment.new(@deployment_id_file) + p deployment and return false if deployment.could_not_fetch? + + puts "Status is #{deployment.status}" + puts + + case deployment.status + when 'Aborted' then return false + when 'Failed' then return false + when 'Succeeded' then return true + + else print "."; sleep 3 + end + end + rescue Exception => e + puts e + return false + end + + class Deployment + attr_reader :could_not_fetch + + def initialize(deployment_id_file) + @deployment_id_file = deployment_id_file + stdout_str, stderr_str, status = Open3.capture3("codeship_aws deploy get-deployment --deployment-id #{id}") + @deployment_data = stdout_str + puts stderr_str if stderr_str != "" + @could_not_fetch = status != 0 + end + + def id + @id ||= JSON.parse(File.read(@deployment_id_file))['deploymentId'] + end + + def status + @status ||= JSON.parse(@deployment_data)['deploymentInfo']['status'] + end + + def could_not_fetch? + @could_not_fetch + end + + def inspect + @deployment_data + end + end + end +end + +if $0 == __FILE__ + puts "Waiting for result of deployment" + result = AWS::CodeshipCodeDeployCheck.new(ARGV[0]).check_deployment + puts "\nDeployment #{result ? 'Successful' : 'Failed'}" + exit result +end