Last active
September 29, 2023 16:41
-
-
Save ijin/7e260c1fd56869881ac7 to your computer and use it in GitHub Desktop.
Deploy to Elastic Beanstalk and notify via Slack
This file contains hidden or 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
#!/bin/bash | |
set -x | |
export SHA1=`echo ${CIRCLE_SHA1} | cut -c1-7` | |
export ENV=`echo $1 | rev | cut -d \- -f1 | rev` | |
function dd_mute() { | |
if [[ ${DD_MUTE_ID+x} ]]; then | |
echo "muting DD monitor id: ${DD_MUTE_ID}" | |
curl -X POST "https://app.datadoghq.com/api/v1/monitor/${DD_MUTE_ID}/mute?api_key=${DD_API_KEY}&application_key=${DD_APP_KEY}" | |
fi | |
} | |
function dd_unmute() { | |
if [[ ${DD_MUTE_ID+x} ]]; then | |
echo "un-muting DD monitor id: ${DD_MUTE_ID}" | |
curl -X POST "https://app.datadoghq.com/api/v1/monitor/${DD_MUTE_ID}/unmute?api_key=${DD_API_KEY}&application_key=${DD_APP_KEY}" | |
fi | |
} | |
function notify() { | |
if [[ ${ROLLBAR_ACCESS_TOKEN+x} ]]; then | |
echo "notifying rollbar" | |
curl https://api.rollbar.com/api/1/deploy/ -F access_token=$ROLLBAR_ACCESS_TOKEN -F environment=$ENV -F revision=$CIRCLE_SHA1 -F local_username=$CIRCLE_USERNAME -F comment="$CIRCLE_BUILD_URL" | |
fi | |
} | |
dd_mute | |
eb deploy $* -v --timeout 15 | |
if [ $? -eq 0 ]; then | |
export SL_COLOR="good" | |
export SL_TEXT="Success: Deployed ${CIRCLE_BRANCH} (<${CIRCLE_COMPARE_URL}|${SHA1}>) by ${CIRCLE_USERNAME} !!" | |
export SL_ICON="https://s3.ap-northeast-1.amazonaws.com/www.hands-lab.com-458223574924/wp-content/uploads/2021/10/08155018/88f5ba5fbabcead2484d9cbcae728c07.png" | |
export EXIT=0 | |
notify | |
else | |
export SL_COLOR="danger" | |
export SL_TEXT="Failure: Deploying ${CIRCLE_BRANCH} (<${CIRCLE_COMPARE_URL}|${SHA1}>) by ${CIRCLE_USERNAME} !!" | |
export SL_ICON="https://s3.ap-northeast-1.amazonaws.com/www.hands-lab.com-458223574924/wp-content/uploads/2021/10/08155018/88f5ba5fbabcead2484d9cbcae728c07.png" | |
export EXIT=1 | |
fi | |
curl -X POST --data-urlencode 'payload={"username": "Elastic Beanstalk ('"$CIRCLE_PROJECT_REPONAME"')", "icon_url": "'"$SL_ICON"'", "channel": "'"${CHANNEL:-#test}"'", "attachments": [{ "color": "'"$SL_COLOR"'", "text": "'"$SL_TEXT"'", "mrkdwn_in": ["text"] }] }' https://hooks.slack.com/services/${SLACK_HOOK} | |
dd_unmute | |
exit $EXIT |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment