Skip to content

Instantly share code, notes, and snippets.

@igolden
Created September 20, 2018 20:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save igolden/4c6f1fa6c0a53c1ac6b447d0c9015116 to your computer and use it in GitHub Desktop.
Save igolden/4c6f1fa6c0a53c1ac6b447d0c9015116 to your computer and use it in GitHub Desktop.
Deploy an s3 website easily
set -e;
# Options
#======================================
# Warnings cause build failures
# if CI=true.
export CI=false
PROFILE=default
BUCKET_NAME=example
#=======================================
# Color Setup
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m'
#=======================================
# display error if exit
handle_error() {
echo -e "${RED}DEPLOY FAILED - VIEW LOGS"
}
trap 'handle_error $LINENO' ERR
echo -e "${YELLOW}Running production build command..${NC}"
if [ "$1" == "-q" ]; then
yarn build &> /dev/null
else
yarn build
fi
echo -e "${GREEN}Done!${NC}"
cd build
echo -e "${YELLOW}Uploading to S3 Bucket '$BUCKET_NAME'...${NC}"
if [ "$1" == "-q" ]; then
aws s3 cp --recursive . s3://$BUCKET_NAME &> /dev/null
else
aws s3 cp --recursive . s3://$BUCKET_NAME
fi
cd ..
echo -e "${GREEN}Success!${NC} View the project at: \nhttp://$BUCKET_NAME.s3-website-$REGION.amazonaws.com"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment