Skip to content

Commit

Permalink
Add post install notifications in case of unexpected errors
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnStainsby committed Feb 6, 2025
1 parent 00e8d16 commit 7bcc7c0
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
20 changes: 15 additions & 5 deletions codebase-pipelines/buildspec-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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 <https://eu-west-2.console.aws.amazon.com/codesuite/codebuild/${AWS_ACCOUNT_ID}/projects/${BUILD_ID_PREFIX}/build/${CODEBUILD_BUILD_ID}/?region=eu-west-2|Build log>"
platform-helper notify add-comment "${SLACK_CHANNEL_ID}" "${SLACK_TOKEN}" "${SLACK_REF}" "${MESSAGE}"
fi
1 change: 0 additions & 1 deletion codebase-pipelines/codepipeline.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down
4 changes: 2 additions & 2 deletions codebase-pipelines/tests/unit.tftest.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}

0 comments on commit 7bcc7c0

Please sign in to comment.