Created
November 25, 2020 17:42
-
-
Save cameronmoreau/d1c577c8fbc217a50559e3a0d63f2540 to your computer and use it in GitHub Desktop.
Deploy React app to s3/cloudfront
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
#!/bin/bash | |
if [ "$1" == "staging" ]; then | |
NODE_ENV="staging" | |
ENV="staging" | |
S3_URL="s3://your-staging-bucket" | |
CLOUDFRONT_ID="XXX-STAGING-ID" | |
echo "[🔨 Deploy] Building project" | |
npm run build:staging | |
elif [ "$1" == "production" ]; then | |
NODE_ENV="production" | |
ENV="production" | |
S3_URL="s3://your-prod-bucket" | |
CLOUDFRONT_ID="XXX-PROD-ID" | |
echo "[🔨 Deploy] Building project" | |
npm run build | |
else | |
echo "Usage ./bin/deploy {staging|production}" && exit 1; | |
fi | |
echo "[☁️ Deploy] Deploying to s3" | |
aws s3 sync build $S3_URL | |
echo "[🌎 Deploy] Clearing app cache" | |
aws cloudfront create-invalidation --distribution-id $CLOUDFRONT_ID --paths "/*" > /dev/null | |
echo "[🚀 Deploy] Successfully deployed" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment