|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +ENV=$1 |
| 4 | +echo $ENV |
| 5 | +#AWS_REGION=$(eval "echo \$${ENV}_AWS_REGION") |
| 6 | +AWS_ACCESS_KEY_ID=$(eval "echo \$${ENV}_AWS_ACCESS_KEY_ID") |
| 7 | +AWS_SECRET_ACCESS_KEY=$(eval "echo \$${ENV}_AWS_SECRET_ACCESS_KEY") |
| 8 | +AWS_S3_BUCKET=$(eval "echo \$${ENV}_S3_BUCKET") |
| 9 | + |
| 10 | +configure_aws_cli() { |
| 11 | + aws --version |
| 12 | + aws configure set aws_access_key_id $AWS_ACCESS_KEY_ID |
| 13 | + aws configure set aws_secret_access_key $AWS_SECRET_ACCESS_KEY |
| 14 | + #aws configure set default.region $AWS_REGION |
| 15 | + aws configure set default.output json |
| 16 | + echo "Configured AWS CLI." |
| 17 | +} |
| 18 | + |
| 19 | +deploy_s3bucket() { |
| 20 | + #chmod -R 775 ${HOME}/${CIRCLE_PROJECT_REPONAME}/dist |
| 21 | + cat dist/app.2e9868372e0e2992d5d2.css |
| 22 | + #aws s3 sync --dryrun ${HOME}/${CIRCLE_PROJECT_REPONAME}/dist s3://${AWS_S3_BUCKET} --cache-control private,no-store,no-cache,must-revalidate,max-age=0 |
| 23 | + #result=`aws s3 sync ${HOME}/${CIRCLE_PROJECT_REPONAME}/dist s3://${AWS_S3_BUCKET} --cache-control private,no-store,no-cache,must-revalidate,max-age=0` |
| 24 | + aws s3 sync --dryrun ${HOME}/${CIRCLE_PROJECT_REPONAME}/dist s3://${AWS_S3_BUCKET} --cache-control max-age=0,s-maxage=86400 --exclude "*.txt" --exclude "*.js" --exclude "*.map" --exclude "*.css" |
| 25 | + result=`aws s3 sync ${HOME}/${CIRCLE_PROJECT_REPONAME}/dist s3://${AWS_S3_BUCKET} --cache-control max-age=0,s-maxage=86400 --exclude "*.txt" --exclude "*.js" --exclude "*.map" --exclude "*.css"` |
| 26 | + if [ $? -eq 0 ]; then |
| 27 | + #echo $result |
| 28 | + echo "All html, font, image and media files are Deployed without gzip encoding!" |
| 29 | + else |
| 30 | + echo "Deployment Failed - $result" |
| 31 | + exit 1 |
| 32 | + fi |
| 33 | + #result=`aws s3 sync ${HOME}/${CIRCLE_PROJECT_REPONAME}/dist s3://${AWS_S3_BUCKET} --cache-control private,no-store,no-cache,must-revalidate,max-age=0` |
| 34 | + aws s3 sync --dryrun ${HOME}/${CIRCLE_PROJECT_REPONAME}/dist s3://${AWS_S3_BUCKET} --cache-control max-age=0,s-maxage=86400 --exclude "*" --include "*.txt" --include "*.js" --include "*.map" --include "*.css" --content-encoding gzip |
| 35 | + result=`aws s3 sync ${HOME}/${CIRCLE_PROJECT_REPONAME}/dist s3://${AWS_S3_BUCKET} --cache-control max-age=0,s-maxage=86400 --exclude "*" --include "*.txt" --include "*.js" --include "*.map" --include "*.css" --content-encoding gzip` |
| 36 | + if [ $? -eq 0 ]; then |
| 37 | + #echo $result |
| 38 | + echo "All css, js, and map files are Deployed! with gzip" |
| 39 | + else |
| 40 | + echo "Deployment Failed - $result" |
| 41 | + exit 1 |
| 42 | + fi |
| 43 | + |
| 44 | +} |
| 45 | + |
| 46 | +#sed -i 's/^application\/x-font-woff.*/application\/font-woff\t\t\t\twoff/' /etc/mime.types |
| 47 | +echo -e "application/font-woff\t\t\t\twoff2" >> /etc/mime.types |
| 48 | +echo -e "application/font-sfnt\t\t\t\tttf" >> /etc/mime.types |
| 49 | +echo -e "application/json\t\t\t\tmap" >> /etc/mime.types |
| 50 | +#sed -i 's/^image\/vnd.microsoft.icon.*/image\/vnd.microsoft.icon/' /etc/mime.types |
| 51 | +#sed -i 's/^image\/x-icon.*/image\/x-icon\t\t\t\tico/' /etc/mime.types |
| 52 | +cat /etc/mime.types | grep -i woff |
| 53 | +cat /etc/mime.types | grep -i ico |
| 54 | +cat /etc/mime.types | grep -i map |
| 55 | +cat /etc/mime.types | grep -i ttf |
| 56 | + |
| 57 | +configure_aws_cli |
| 58 | +deploy_s3bucket |
0 commit comments