Skip to content

Instantly share code, notes, and snippets.

@lior-amsalem
Created August 24, 2019 20:14
Show Gist options
  • Save lior-amsalem/0a73cdf8eb80ee343b4b02fbb7766616 to your computer and use it in GitHub Desktop.
Save lior-amsalem/0a73cdf8eb80ee343b4b02fbb7766616 to your computer and use it in GitHub Desktop.
The process/jobs
# Check https://circleci.com/docs/2.0/language-javascript/ for more details
version: 2.1
orbs:
aws-s3: circleci/[email protected]
slack: circleci/[email protected]
jobs:
# Job #1
build:
docker:
- image: circleci/node:11.10
working_directory: ~/app
steps:
- checkout
# cache dependencies (to speed automation process)
- restore_cache:
keys:
- v1-dependencies-{{ checksum "package.json" }}
# fallback to using the latest cache if no exact match is found
- v1-dependencies-
- run:
name: Authenticate with registry
command: echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > ~/app/.npmrc
- run:
name: Install NPM dependencies - via yarn
command: yarn install
- run:
name: Install Jest Global
command: yarn global add jest
- run:
name: Build Production Assets
command: yarn run build
- persist_to_workspace:
# Must be an absolute path, or relative path from working_directory. This is a directory on the container which is
# taken to be the root directory of the workspace.
root: ~/app
# Must be relative path from root
paths:
- node_modules # contain dependencies
- dist # contain files we've build for distribution
- save_cache:
paths:
- node_modules
key: v1-dependencies-{{ checksum "package.json" }}
# Job #2
test:
docker:
- image: circleci/node:11.10
working_directory: ~/app
steps:
- checkout
- attach_workspace:
# Must be an absolute path or relative path from working_directory
at: ~/app
- run:
name: Test
command: yarn test
- run:
name: Generate code coverage
command: npm run test -- --coverage
# Job #3
deploy_dev_branches:
docker:
- image: circleci/node:11.10
working_directory: ~/app
steps:
- checkout
- attach_workspace:
# Must be an absolute path or relative path from working_directory
at: ~/app
- run:
name: apt-get update
command: sudo apt-get update
- run:
name: Install python-dev
command: sudo apt-get install python-dev
- run:
name: Install pip
command: sudo apt-get install python-pip
- run:
name: Install awscli
command: sudo pip install awscli
- run:
name: "What branch am I on?"
command: echo ${CIRCLE_BRANCH}
- run:
name: "What AWS region i am on now?"
command: echo $AWS_REGION
- aws-s3/sync:
from: ~/app/dist/my-project
to: 's3://bucket-assets/${CIRCLE_PROJECT_REPONAME}/${CIRCLE_BRANCH}/${CIRCLE_SHA1}'
arguments: |
--region $AWS_REGION \
--acl public-read
# Job #4
deploy_production_latest:
docker:
- image: circleci/node:11.10
working_directory: ~/app
steps:
- checkout
- attach_workspace:
# Must be an absolute path or relative path from working_directory
at: ~/app
- run:
name: apt-get update
command: sudo apt-get update
- run:
name: Install python-dev
command: sudo apt-get install python-dev
- run:
name: Install pip
command: sudo apt-get install python-pip
- run:
name: Install awscli
command: sudo pip install awscli
- run:
name: "What branch am I on?"
command: echo ${CIRCLE_BRANCH}
- run:
name: "What AWS region i am on now?"
command: echo $AWS_REGION
- aws-s3/sync: # first copy per commit hash (easier to locate files)
from: ~/app/dist/my-project
to: 's3://bucket-assets/${CIRCLE_PROJECT_REPONAME}/${CIRCLE_BRANCH}/${CIRCLE_SHA1}'
arguments: |
--region $AWS_REGION \
--acl public-read
- slack/status:
success_message: Hey @${CIRCLE_USERNAME}, job is done successfully! :)
failure_message: Hey @${CIRCLE_USERNAME}, job failed! :(
only_for_branches: master
workflows:
version: 2.1
build-test-and-deploy:
jobs:
- build: # job #1
context: dev
- test: # job #2
context: dev
requires:
- build
- deploy_dev_branches: # job #3
context: dev
requires:
- test
filters:
branches:
ignore: # We ignore master/latest here (this is branch deployment)
- master
- deploy_production_latest: # job #4
context: dev
requires:
- test
filters:
branches:
only: # We deploy latest only in master
- master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment