-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update the circle CI config with reusable commands
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.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -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: . | ||
|
@@ -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: | ||
|
@@ -129,6 +107,8 @@ workflows: | |
- hold: | ||
type: approval | ||
filters: | ||
tags: | ||
only: /^v.*/ | ||
branches: | ||
only: master | ||
requires: | ||
|