Skip to content

Commit

Permalink
Update the circle CI config with reusable commands
Browse files Browse the repository at this point in the history
Use reusable commands with parameters to remove much of the copied
config for the jobs
  • Loading branch information
Julian Delerme committed Jun 3, 2019
1 parent 6d3fbbb commit dc57c3a
Showing 1 changed file with 46 additions and 66 deletions.
112 changes: 46 additions & 66 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,9 @@
version: 2.1
orbs:
aws-s3: circleci/[email protected]
jobs:
# generate bundles
build:
docker:
- image: circleci/node:7.10
working_directory: ~/answers
commands:
setup-workspace:
description: "Checks out the repo and installs node_modules with the cache"
steps:
- checkout
# Download and cache dependencies
Expand All @@ -21,6 +18,40 @@ jobs:
paths:
- node_modules
key: v1-dependencies-{{ checksum "package.json" }}
deploy-to-aws:
description: "Deploys the dist directory to a given subdirectory of the answers bucket"
parameters:
subdirectory:
type: string
default: ''
cache-control:
type: string
default: "no-cache"
steps:
- attach_workspace:
at: ~/answers
- run:
name: Configure AWS
command: |
mkdir ~/.aws
cp .circleci/aws_config ~/.aws/config
echo -e $AWS_PROD_PROFILE >> ~/.aws/config
- aws-s3/copy:
from: dist
to: '${AWS_DEPLOY_BUCKET}<< parameters.subdirectory >>'
arguments: |
--acl public-read \
--cache-control << parameters.cache-control >> \
--recursive \
--profile production \
jobs:
# generate bundles
build:
docker:
- image: circleci/node:7.10
working_directory: ~/answers
steps:
- setup-workspace
- run: npm run build
- persist_to_workspace:
root: .
Expand All @@ -33,85 +64,32 @@ jobs:
- image: circleci/node:7.10
working_directory: ~/answers
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: npm install
- save_cache:
paths:
- node_modules
key: v1-dependencies-{{ checksum "package.json" }}
- setup-workspace
- run: npm run test
# deploy to S3 in the root folder, overwriting the existing latest version
deploy_latest:
docker:
- image: circleci/python:2.7
working_directory: ~/answers
steps:
- attach_workspace:
at: ~/answers
- run:
name: Configure AWS
command: |
mkdir ~/.aws
cp .circleci/aws_config ~/.aws/config
echo -e $AWS_PROD_PROFILE >> ~/.aws/config
- aws-s3/copy:
from: dist
to: '${AWS_DEPLOY_BUCKET}'
arguments: |
--acl public-read \
--cache-control "no-cache" \
--recursive \
--profile production \
- deploy-to-aws
# deploys assets to an uncached folder in the S3 bucket named by branch
deploy_branch:
docker:
- image: circleci/python:2.7
working_directory: ~/answers
steps:
- attach_workspace:
at: ~/answers
- run:
name: Configure AWS
command: |
mkdir ~/.aws
cp .circleci/aws_config ~/.aws/config
echo -e $AWS_PROD_PROFILE >> ~/.aws/config
- aws-s3/copy:
from: dist
to: '${AWS_DEPLOY_BUCKET}/dev/${CIRCLE_BRANCH}'
arguments: |
--acl public-read \
--cache-control "no-cache" \
--recursive \
--profile production \
- deploy-to-aws:
subdirectory: '/dev/${CIRCLE_BRANCH}'
# deploys assets to a long-lived-cache folder in the S3 bucket named by release tag
deploy_version:
docker:
- image: circleci/python:2.7
working_directory: ~/answers
steps:
- attach_workspace:
at: ~/answers
- run:
name: Configure AWS
command: |
mkdir ~/.aws
cp .circleci/aws_config ~/.aws/config
echo -e $AWS_PROD_PROFILE >> ~/.aws/config
- aws-s3/copy:
from: dist
to: '${AWS_DEPLOY_BUCKET}/${CIRCLE_TAG}'
arguments: |
--acl public-read \
--cache-control "max-age=31536000" \
--recursive \
--profile production \
- deploy-to-aws:
subdirectory: '/${CIRCLE_TAG}'
cache-control: 'max-age=31536000'
workflows:
version: 2
build_and_deploy:
Expand All @@ -129,6 +107,8 @@ workflows:
- hold:
type: approval
filters:
tags:
only: /^v.*/
branches:
only: master
requires:
Expand Down

0 comments on commit dc57c3a

Please sign in to comment.