Skip to content

Instantly share code, notes, and snippets.

@justindra
Created November 23, 2017 03:30
Show Gist options
  • Save justindra/ec2c904b2454036aacb38170dd11b9c5 to your computer and use it in GitHub Desktop.
Save justindra/ec2c904b2454036aacb38170dd11b9c5 to your computer and use it in GitHub Desktop.
CircleCI 2.0 Test and Deploy to S3
builder_image: &builder_image
docker:
- image: circleci/node:6.10.3-browsers
working_directory: ~/project
deploy_image: &deploy_image
docker:
- image: circleci/python:3.6.1
working_directory: ~/project
version: 2
jobs:
build:
<<: *builder_image
steps:
- checkout
- restore_cache:
keys:
- v1-dependencies-{{ checksum "package.json" }}
# fallback to using the latest cache if no exact match is found
- v1-dependencies-
- run: sudo yarn global add gulp
- run: yarn install
- save_cache:
paths:
- node_modules
key: v1-dependencies-{{ checksum "package.json" }}
- run: gulp test
- store_test_results:
path: ./coverage
- store_artifacts:
path: ./coverage
- persist_to_workspace:
# Must be an absolute path, or relative path from working_directory
root: .
# Must be relative path from root
paths:
- export
- scripts
deploy:
<<: *deploy_image
steps:
- attach_workspace:
at: workspace
- run: pip install awscli --upgrade --user
- run: echo 'export PATH=~/.local/bin:$PATH' >> $BASH_ENV
- run: ./workspace/scripts/deploy.sh
notify:
<<: *builder_image
steps:
- checkout
- run: ./scripts/notify.sh
workflows:
version: 2
build-deploy-notify:
jobs:
- build
- deploy:
requires:
- build
filters:
branches:
only:
- master
- prod
- notify:
requires:
- deploy
#!/bin/bash
# Initialize constants
BRANCH="$CIRCLE_BRANCH"
EXPORT_DIR='workspace/export'
S3_BUCKET_DIR_PROD="PUT S3_bucket here"
S3_BUCKET_DIR_STAGE="PUT S3_bucket here"
# Run the different deploy script depending on the BRANCH
if [[ $BRANCH == "prod" ]]
then
echo 'Production Deploy Starting'
aws s3 sync $EXPORT_DIR "$S3_BUCKET_DIR_PROD" --delete --acl public-read
elif [[ $BRANCH == "master" ]]
then
echo 'Staging Deploy Starting'
aws s3 sync $EXPORT_DIR "$S3_BUCKET_DIR_STAGE" --delete --acl public-read
fi
echo 'Deploy finished'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment