diff --git a/.circleci/config.yml b/.circleci/config.yml index 8035d7980..e3701b139 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -2,12 +2,9 @@ version: 2.1 orbs: aws-s3: circleci/aws-s3@1.0.9 -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,18 +64,7 @@ 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: @@ -52,66 +72,24 @@ jobs: - 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: