Last active
July 30, 2020 07:39
-
-
Save takahirohonda/3d6479923048b0035533e1f33874cc2f to your computer and use it in GitHub Desktop.
static-asset-to-s3-buildspec.yaml
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
# Aws Doc: https://docs.aws.amazon.com/codebuild/latest/userguide/build-spec-ref.html | |
# Ref : https://github.com/backspace-academy/aws-nodejs-sample-codebuild/blob/master/buildspec.yml | |
# Do not change version. This is the version of aws buildspec, not the version of your buldspec file. | |
version: 0.2 | |
env: | |
exported-variables: | |
- env | |
- cfdistid #CloudFront Distribution ID to clear the cache | |
phases: | |
install: | |
runtime-versions: | |
nodejs: 12 | |
commands: | |
- echo Build is starting now... | |
- echo Installing source NPM dependencies... | |
- npm i | |
pre_build: | |
commands: | |
- echo Running unit tests... | |
- npm run test | |
build: | |
commands: | |
- echo Dev Build starting... | |
- npm run build:$env | |
- echo Checking build artifacts | |
- cd dist && ls -la | |
- cd .. | |
post_build: | |
commands: | |
- echo Checking Environment Variables | |
- echo environment - $env | |
- echo cfdistid - $cfdistid | |
# (1) Version control bundle | |
- echo "Getting Git Commit Sha for bundle version control" | |
- export bundleVersion=$(git rev-parse --short HEAD) | |
- cp dist/my-widget-$env.min.css dist/my-widget-$env-${bundleVersion}.min.css | |
- cp dist/my-widget-$env.min.js dist/my-widget-$env-${bundleVersion}.min.js | |
# (2) Clearing CloudFront Cache | |
- echo "Calling cloudfront create-invalidation" | |
- aws cloudfront create-invalidation --distribution-id $cfdistid --paths "/*" | |
- echo "Clear cache on cloudfront" | |
- echo "Job completed successfully! Wait for CloudFront Cache to be cleared for a few nimutes" | |
artifacts: | |
discard-paths: yes | |
# base-directory: 'dist' | |
files: | |
- dist/* |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment