Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
sysc dist/ to aws s3 and create invalidations in cloudfront with notifying at slack
#!/bin/sh
target_env=$1
profile=$2
SLACK_URL="xxxxxxxxslack_webhook_urlxxxxxxxx"
CHANNEL="#channel_name"
BOTNAME="deployer"
EMOJI=":masa:"
if [ $target_env != "prod" ] && [ $target_env != "staging" ]; then
echo "Specify stage. prod or staging"
exit 1
fi
if [ -z $2 ]; then
echo "Specity your aws-cli profile."
exit 1
fi
notify_slack() {
person=$(whoami)
SLACK_PAYLOAD_DATA=$(cat <<- EOF
{
"channel": "$CHANNEL",
"username": "$BOTNAME",
"icon_emoji": "$EMOJI",
"attachments": [
{
"fallback": "$1",
"text": "$2",
"color": "$3",
"fields": [
{
"title": "User",
"value": "$person",
"short": "true"
},
{
"title": "Stage",
"value": "$target_env",
"short": "true"
}
]
}
]
}
EOF
)
curl -X POST --data-urlencode "payload=$SLACK_PAYLOAD_DATA" $SLACK_URL
echo ""
}
case "$1" in
"prod")
dist_id="xxxxxxxxxxx"
bucket="example.com"
;;
"staging")
dist_id="xxxxxxxxxx"
bucket="staging.example.com"
;;
esac
text="Deploy starting... $bucket :slightly_smiling_face:"
notify_slack "start" "$text" "warning"
# Build for envs.
echo "BUILD for $target_env"
npm run build
# Deploy /builds.
echo "DEPLOY for $target_env"
# aws s3 sync dist/ s3://$bucket --profile $profile
# Remove cache.
echo "REMOVE CACHE..."
# aws cloudfront create-invalidation --distribution-id $dist_id --paths '/*' --profile $profile
text="Deploy succeeded! :tada:"
notify_slack "deployed" "$text" "good"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.