Skip to content

Instantly share code, notes, and snippets.

@uriklar
Created June 20, 2018 13:56
Show Gist options
  • Save uriklar/c239cf52ce7f66b52a079f5df704046c to your computer and use it in GitHub Desktop.
Save uriklar/c239cf52ce7f66b52a079f5df704046c to your computer and use it in GitHub Desktop.
Phytech CircleCI config file example
defaults: &defaults
working_directory: ~/repo
docker:
- image: circleci/node:8.11
version: 2
jobs:
checkout_code:
<<: *defaults
steps:
- restore_cache:
keys:
- source-{{ .Branch }}-{{ .Revision }}
- source-{{ .Branch }}-
- source-
- checkout
- save_cache:
key: source-{{ .Branch }}-{{ .Revision }}
paths:
- "~/repo"
install:
<<: *defaults
steps:
- restore_cache:
key: source-{{ .Branch }}-{{ .Revision }}
- restore_cache:
key: dependency-cache-{{ checksum "package.json" }}
- run:
name: "Yarn install"
command: yarn install
- save_cache:
key: dependency-cache-{{ checksum "package.json" }}
paths:
- node_modules
test:
<<: *defaults
steps:
- restore_cache:
key: source-{{ .Branch }}-{{ .Revision }}
- restore_cache:
key: dependency-cache-{{ checksum "package.json" }}
- run:
name: "Test"
command: npm run test
build:
<<: *defaults
steps:
- restore_cache:
key: source-{{ .Branch }}-{{ .Revision }}
- restore_cache:
key: dependency-cache-{{ checksum "package.json" }}
- run:
name: "Build app"
command: npm run build
- persist_to_workspace:
root: ~/repo
paths:
- dist
- package.json
deploy:
<<: *defaults
environment:
- STAGING_BUCKET: YOUR_STAGING_BUCKET_NAME
- PRODUCTION_BUCKET: YOUR_PRODUCTION_BUCKET_NAME
- STAGING_DISTRIBUTION_ID: YOUR_STAGING_DISTRIBUTION_ID
- PRODUCTION_DISTRIBUTION_ID: YOUR_PRODUCTION_DISTRIBUTION_ID
steps:
- attach_workspace:
at: ~/repo
- run: sudo apt-get update && sudo apt-get install -y python-dev
- run: sudo curl -O https://bootstrap.pypa.io/get-pip.py
- run: sudo python get-pip.py
- run: sudo pip install awscli --upgrade
- run: aws --version
- run: aws s3 ls
- run:
name: "Deploy to S3"
command: |
if [ "${CIRCLE_BRANCH}" == "master" ]; then
aws s3 sync dist/ s3://${PRODUCTION_BUCKET} --delete
aws cloudfront create-invalidation --distribution-id "${PRODUCTION_DISTRIBUTION_ID}" --paths /index.html
elif [ "${CIRCLE_BRANCH}" == "develop" ]; then
aws s3 sync dist/ s3://${STAGING_BUCKET} --delete
aws cloudfront create-invalidation --distribution-id "${STAGING_DISTREBUTION_ID}" --paths /index.html
fi
workflows:
version: 2
build_and_test:
jobs:
- checkout_code
- install:
requires:
- checkout_code
- test:
requires:
- install
- build:
requires:
- install
- deploy:
requires:
- test
- build
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment