From 7bcc7c094919237384598f995916399bc47ebaac Mon Sep 17 00:00:00 2001 From: John Stainsby Date: Thu, 6 Feb 2025 14:55:22 +0000 Subject: [PATCH] Add post install notifications in case of unexpected errors --- codebase-pipelines/buildspec-deploy.yml | 20 +++++++++++++++----- codebase-pipelines/codepipeline.tf | 1 - codebase-pipelines/tests/unit.tftest.hcl | 4 ++-- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/codebase-pipelines/buildspec-deploy.yml b/codebase-pipelines/buildspec-deploy.yml index 76a901a4..34d4645b 100644 --- a/codebase-pipelines/buildspec-deploy.yml +++ b/codebase-pipelines/buildspec-deploy.yml @@ -7,6 +7,11 @@ env: SLACK_TOKEN: /codebuild/slack_oauth_token phases: + install: + commands: + - pip install yq dbt-platform-helper --quiet + - curl -s -L https://github.com/regclient/regclient/releases/latest/download/regctl-linux-amd64 > /usr/local/bin/regctl + - chmod +x /usr/local/bin/regctl build: commands: - set -e @@ -25,11 +30,6 @@ phases: exit 1 fi - # Install tools - - pip install yq dbt-platform-helper --quiet - - curl -s -L https://github.com/regclient/regclient/releases/latest/download/regctl-linux-amd64 > /usr/local/bin/regctl - - chmod +x /usr/local/bin/regctl - # Extract timestamp from image config and check if it exists - aws ecr get-login-password --region ${AWS_REGION} | docker login --username AWS --password-stdin ${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_REGION}.amazonaws.com @@ -162,3 +162,13 @@ phases: echo "Error: deployment status is ${deploy_status}" exit 1 fi + + post_build: + commands: + - | + if [ "${CODEBUILD_BUILD_SUCCEEDING}" != "1" ]; then + BUILD_ID_PREFIX=$(echo $CODEBUILD_BUILD_ID | cut -d':' -f1) + MESSAGE=":red_circle::warning: ERROR - Deployment of ${UPPERCASE_TAG} to ${UPPERCASE_SERVICE} service - FAILED " + + platform-helper notify add-comment "${SLACK_CHANNEL_ID}" "${SLACK_TOKEN}" "${SLACK_REF}" "${MESSAGE}" + fi diff --git a/codebase-pipelines/codepipeline.tf b/codebase-pipelines/codepipeline.tf index 0b88a9d5..e767a4d7 100644 --- a/codebase-pipelines/codepipeline.tf +++ b/codebase-pipelines/codepipeline.tf @@ -194,7 +194,6 @@ resource "terraform_data" "update_pipeline" { } triggers_replace = [ aws_codepipeline.codebase_pipeline, - aws_codepipeline.manual_release_pipeline, file("${path.module}/custom_pipeline_update/update_pipeline.py") ] depends_on = [ diff --git a/codebase-pipelines/tests/unit.tftest.hcl b/codebase-pipelines/tests/unit.tftest.hcl index 4194e3e2..dea79f27 100644 --- a/codebase-pipelines/tests/unit.tftest.hcl +++ b/codebase-pipelines/tests/unit.tftest.hcl @@ -1741,7 +1741,7 @@ run "test_pipeline_update_script" { command = plan assert { - condition = length(terraform_data.update_pipeline.triggers_replace) == 3 - error_message = "Should be: 3" + condition = length(terraform_data.update_pipeline.triggers_replace) == 2 + error_message = "Should be: 2" } }