Created
June 27, 2018 12:49
-
-
Save heesienooi/f5bb7cd4c0f1d3fa9ba9192852984f50 to your computer and use it in GitHub Desktop.
aws elasticbeanstalk deployment script
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
#!/usr/bin/env bash | |
# Environment variables | |
# EB_ENV="website-qa" | |
# S3_BUCKET="qa-selfmade-assets" | |
# CLOUDFRONT_ID="E1B4KQ9M175W9L" | |
if [ -z "$EB_ENV" ] || [ -z "$S3_BUCKET" ] || [ -z "$CLOUDFRONT_ID"]; | |
then | |
echo "" | |
echo "Missing environment variables. Example:" | |
echo "EB_ENV=website-qa S3_BUCKET=qa-selfmade-assets CLOUDFRONT_ID=E1B4KQ9M175W9L $0" | |
exit 1 | |
fi | |
# Deployment commands. Should be running sequantially | |
CMDS=( | |
"npm run build" | |
"eb deploy $EB_ENV" | |
"aws --profile selfmade s3 sync static/ s3://$S3_BUCKET/static/" | |
"aws --profile selfmade cloudfront create-invalidation --distribution-id $CLOUDFRONT_ID --paths '/*'" | |
) | |
# loop all command and execute them sequantially | |
for i in "${CMDS[@]}" | |
do | |
# execute command | |
eval $i | |
# command exit code | |
RESULT_CODE=$? | |
# if exit code is not equal to 0 then command has failed | |
if [ $RESULT_CODE -ne 0 ]; | |
then | |
# terminate script and stop executing other commands | |
exit $RESULT_CODE | |
fi | |
done | |
echo "($0): Deployment success! Please wait 5 mins for CloudFront to invalidate cache." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment