Created
July 4, 2018 09:09
-
-
Save thedanielforum/374a94d24e4a93678afb842d9e3fd744 to your computer and use it in GitHub Desktop.
ReactJS, AWS, CircleCI 2.0 configuration file.
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
# ReactJS, AWS, CircleCI 2.0 configuration file. | |
version: 2 | |
jobs: | |
build-job: | |
docker: | |
# specify the version you desire here | |
- image: circleci/node:7.10 | |
working_directory: ~/repo | |
steps: | |
- checkout | |
# Download and cache dependencies | |
- restore_cache: | |
keys: | |
- v1-dependencies-{{ checksum "package.json" }} | |
# fallback to using the latest cache if no exact match is found | |
- v1-dependencies- | |
- run: yarn install | |
- save_cache: | |
paths: | |
- node_modules | |
key: v1-dependencies-{{ checksum "package.json" }} | |
# run tests! | |
- run: yarn run lint | |
- run: yarn test | |
deploy-job-prod: | |
docker: | |
- image: circleci/node:7.10 | |
working_directory: ~/repo | |
steps: | |
- checkout | |
# Download and cache dependencies | |
- restore_cache: | |
keys: | |
- v1-dependencies-{{ checksum "package.json" }} | |
# fallback to using the latest cache if no exact match is found | |
- v1-dependencies- | |
- run: yarn install | |
- run: sudo apt-get install awscli | |
- run: yarn build | |
- run: | |
name: Deploy to S3 if tests pass and branch is prod | |
command: aws s3 sync build/ s3://app.example.com --delete --region ap-southeast-1 | |
# TODO: Consider only invalidating index.html | |
- run: | |
name: Enable AWS CLI preview features | |
command: | | |
aws configure set preview.cloudfront true | |
aws configure set preview.create-invalidation true | |
- run: | |
name: Invalidate cloudfront content | |
command: | | |
timestamp=$(date +%s) | |
command=$(printf '{"Paths":{"Quantity":1,"Items":["/*"]},"CallerReference":"circleci-%s"}' $timestamp) | |
echo $command > invbatch.json | |
aws cloudfront create-invalidation --distribution-id XXXXYYYYZZZZ --invalidation-batch file://invbatch.json | |
workflows: | |
version: 2 | |
build-deploy: | |
jobs: | |
- build-job | |
- deploy-job-prod: | |
requires: | |
- build-job | |
filters: | |
branches: | |
only: prod |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment