Skip to content

Instantly share code, notes, and snippets.

@petrogad
Created September 21, 2018 14:15
Show Gist options
  • Save petrogad/e08e0a875815dd3796df9f90c2bee795 to your computer and use it in GitHub Desktop.
Save petrogad/e08e0a875815dd3796df9f90c2bee795 to your computer and use it in GitHub Desktop.
CircleCI Configuration with AWS S3 Deploy and Cloudfront Invalidation.
# Quick CircleCI configuration that builds your JS, runs tests, and prepares to deploy to a bucket.
# With your manual approval, you can then deploy to your S3 bucket AND invalidate your cloudfront cache.
#
version: 2
jobs:
build:
docker:
# specify the version you desire here
- image: circleci/node:latest
working_directory: ~/myDirectory
steps:
- checkout
- attach_workspace:
at: ~/myDirectory
# 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 test
- run: yarn build
- persist_to_workspace:
root: .
paths: dist
deploy:
docker:
# specify the version you desire here
- image: cibuilds/aws:latest
working_directory: ~/myDirectory
steps:
- attach_workspace:
at: ~/myDirectory
- deploy:
name: Deploy to S3 if tests pass and branch is Master
command: |
aws s3 sync dist s3://${CloudFrontID} --region ${YOUR_REGION} --acl public-read && aws cloudfront create-invalidation --distribution-id ${CloudFrontID} --paths ${YOURPATHS}
workflows:
version: 2
build_and_deploy:
jobs:
- build
- hold:
filters:
branches:
only: master
type: approval
requires:
- build
- deploy:
requires:
- hold
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment