-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #23 from traderjoe-xyz/ivan/add-ci-cd-alerts
Add ci-cd alerts and optimize build by using cache
- Loading branch information
Showing
3 changed files
with
81 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
#!/bin/bash | ||
|
||
# Start: Remove this if you want successful alerts | ||
if [[ $CODEBUILD_BUILD_SUCCEEDING == "1" ]]; then | ||
exit 0 | ||
fi | ||
# End: Remove this if you want successful alerts | ||
|
||
ACCOUNT_ID=$(echo "$CODEBUILD_BUILD_ARN" | cut -d ':' -f 5) | ||
PROJECT_NAME=$(echo "$CODEBUILD_BUILD_ID" | cut -d ':' -f 1) | ||
|
||
ACTION=$(echo "$PROJECT_NAME" | rev | cut -d '-' -f 1 | rev) | ||
|
||
RESULT=succeeded | ||
COLOR=3669879 | ||
if [[ $CODEBUILD_BUILD_SUCCEEDING == "0" ]]; then | ||
RESULT=failed | ||
COLOR=16712294 | ||
fi | ||
|
||
CODEBUILD_URL="https://${AWS_REGION}.console.aws.amazon.com/codesuite/codebuild/${ACCOUNT_ID}/projects/${PROJECT_NAME}/build/$CODEBUILD_BUILD_ID/?region=${AWS_REGION}" | ||
|
||
CODEBUILD_START_TIME_S=$((CODEBUILD_START_TIME / 1000)) | ||
START_TIME=$(date -d "@${CODEBUILD_START_TIME_S}" +"%b %d, %Y %I:%M %p %z") | ||
|
||
DATA=$(cat << EOF | ||
{ | ||
"username": "[${ENVIRONMENT^^}] ${ACTION^} ${RESULT}", | ||
"embeds": [ | ||
{ | ||
"title": "Build Logs", | ||
"url": "${CODEBUILD_URL}", | ||
"color": $COLOR, | ||
"fields": [ | ||
{ | ||
"name": "Project", | ||
"value": "${PROJECT_NAME}" | ||
}, | ||
{ | ||
"name": "Build Number", | ||
"value": "${CODEBUILD_BUILD_NUMBER}" | ||
}, | ||
{ | ||
"name": "Triggered By", | ||
"value": "${CODEBUILD_WEBHOOK_TRIGGER}", | ||
"inline": true | ||
}, | ||
{ | ||
"name": "Start Time", | ||
"value": "${START_TIME}" | ||
}, | ||
{ | ||
"name": "Repo URL", | ||
"value": "${CODEBUILD_SOURCE_REPO_URL}" | ||
}, | ||
{ | ||
"name": "Commit Hash", | ||
"value": "${CODEBUILD_RESOLVED_SOURCE_VERSION}" | ||
} | ||
] | ||
} | ||
] | ||
} | ||
EOF | ||
) | ||
|
||
curl --location $DISCORD_URL \ | ||
--header 'Content-Type: application/json' \ | ||
--data "$DATA" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,15 @@ | ||
version: 0.2 | ||
|
||
phases: | ||
pre_build: | ||
build: | ||
on-failure: ABORT | ||
commands: | ||
- REPOSITORY_URI=194943407731.dkr.ecr.eu-west-1.amazonaws.com/joeapi | ||
- IMAGE_TAG=${IMAGE_TAG:-$(echo $CODEBUILD_WEBHOOK_TRIGGER | awk -F/ {'print $2'})} | ||
- aws eks update-kubeconfig --name $ENVIRONMENT-trader-joe-eks | ||
build: | ||
on-failure: ABORT | ||
commands: | ||
- kubectl set image -n $ENVIRONMENT deployment/joeapi joeapi=$REPOSITORY_URI:$IMAGE_TAG | ||
- | | ||
for d in $(kubectl get deploy -n $ENVIRONMENT -l app=joepai --no-headers -o custom-columns=_:metadata.name); do | ||
kubectl set image -n $ENVIRONMENT deployment/$d $d=$REPOSITORY_URI:$IMAGE_TAG | ||
done | ||
finally: | ||
- bin/discord.sh |