Last active
January 25, 2021 22:42
-
-
Save jeffsheets/8eb6821b04a532d0dbf23443d986d84e to your computer and use it in GitHub Desktop.
AWS S3 Deploy sync w/ Cloudfront Invalidation and Cache-Control headers for Create-React-App
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
//Config for s3 websync with cloudfront invalidation | |
// and Cache-Control headers for a Create-React-App application | |
//https://www.npmjs.com/package/websync | |
module.exports = { | |
source: "build/", | |
target: `s3://yourcompany-us-east-1-${process.env.CI_ENVIRONMENT_NAME}-createreactapp/`, | |
invalidateDeletes: true, | |
modifiers: { | |
"static/**": { CacheControl: "max-age=31536000" }, | |
"!static/**": { CacheControl: "no-cache" } | |
} | |
}; |
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
//...snippet | |
"devDependencies": { | |
"websync": "^0.0.13" | |
} |
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
#...snippet | |
#Requires AWS credentials setup in gitlab ci/cd config | |
#Reusable script definition | |
.deploy-script: | |
script: &deploy_script | |
- echo "Syncing content files to S3 and invalidating Cloudfront CDN" | |
- yarn websync --config ./websyncConfig.js | |
- echo "Done!" | |
#Deploys to development environment when PR is merged to develop branch | |
deploy-dev: | |
stage: deploy | |
only: | |
- main | |
environment: | |
name: development | |
url: https://createreactapp.development.yourcompany.com/ | |
script: *deploy_script |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment