Skip to content

Instantly share code, notes, and snippets.

@feldmanz66
Created June 28, 2022 16:59
Show Gist options
  • Save feldmanz66/002f9d216d1213e3eb7b96560cfd2cac to your computer and use it in GitHub Desktop.
Save feldmanz66/002f9d216d1213e3eb7b96560cfd2cac to your computer and use it in GitHub Desktop.
Enigma Circle CI 2.1 example
version: 2.1
orbs:
node: circleci/node@4.1.0
slack: circleci/slack@3.4.2
jobs:
pr:
docker:
# Specify service dependencies here if necessary
# CircleCI maintains a library of pre-built images
# documented at https://circleci.com/docs/2.0/circleci-images/
- image: circleci/node:14.4.0
parallelism: 1
resource_class: large
working_directory: ~/project/
steps:
# Checkout the code from the branch into the working_directory
- checkout:
path: ~/project
# Log the current branch
- run:
name: Show current branch
command: echo ${CIRCLE_BRANCH}
# Restore local dependencies from cache
# - restore_cache:
# keys:
# - v1-dependencies-{{ checksum "package.json" }}
# # fallback to using the latest cache if no exact match is found
# - v1-dependencies-
# Install project dependencies
- run:
name: Install local dependencies
command: npm install
# Cache local dependencies if they don't exist
- save_cache:
key: v1-dependencies-{{ checksum "package.json" }}
paths:
- node_modules
Lint the source code
- run:
name: Linting
command: npm run lint
Test the source code
- run:
name: Testing
command: npm run test
# Build project with different configuration based on
# the current branch
- run:
name: Building
command: npm run build:nolint --loglevel verbose
# Cache the build folder for the deploy job
- save_cache:
key: v1-build-{{ .Environment.CIRCLE_BRANCH }}-{{ .Environment.CIRCLE_SHA1 }}
paths:
- build
# - slack/notify:
# color: "#42e2f4"
# mentions: "UM36E2SS3,"
# message: Circle CI results for branch ~ ${CIRCLE_BRANCH}
- slack/status:
fail_only: false
success_message: ':tada: The $CIRCLE_JOB job by $CIRCLE_USERNAME has succeeded! branch ~ $CIRCLE_BRANCH'
failure_message: ':red_circle: The $CIRCLE_JOB job by $CIRCLE_USERNAME has failed! branch ~ $CIRCLE_BRANCH'
# The deploy job
prod:
working_directory: ~/project/aws
docker:
- image: circleci/node:12-browsers
resource_class: large
steps:
# Checkout the code from the branch into the working_directory
- checkout:
path: ~/project
# Log the current branch
- run:
name: Show current branch
command: echo ${CIRCLE_BRANCH}
# Restore cache from the build job which contains the
# build folder that needs to be deployed
- restore_cache:
key: v1-build-{{ .Environment.CIRCLE_BRANCH }}-{{ .Environment.CIRCLE_SHA1 }}
# Install AWS cli
- run:
name: Update apt-get
command: sudo apt-get update
- run:
name: Install aws cli
command: sudo apt-get -y -qq install awscli
- run:
name: Install pip3
command: sudo apt-get -y install python3-pip
# Install SLS
# !!! @Alex youmay need to upgrade these serverless library versions to latest !!!
- run:
name: Install sls
command: npm install serverless serverless-appsync-plugin@1.4.0 serverless-step-functions@2.26.0 serverless-pseudo-parameters@2.5.0
# Set the signature version for the S3 auth
- run:
name: Setting Signature Version 4 for S3 Request Authentication
command: aws configure set default.s3.signature_version s3v4
# Deploy to the S3 bucket corresponding to the current branch
- run:
name: Deploy to S3
command: aws --region us-east-1 s3 sync ../dist s3://www.enigmaglass.com/ --delete
- run:
name: Build AWS prod resources
command: npm run build:lambdas:backend
- run:
name: Deploy AWS prod resources
command: |
npm run deploy:prod
- slack/status:
fail_only: false
success_message: ':tada: The $CIRCLE_JOB job by $CIRCLE_USERNAME has succeeded! branch ~ $CIRCLE_BRANCH'
failure_message: ':red_circle: The $CIRCLE_JOB job by $CIRCLE_USERNAME has failed! branch ~ $CIRCLE_BRANCH'
workflows:
version: 2.1
# The build and deploy workflow
enigma_workflow_pipeline:
jobs:
- pr
# The deploy job will only run on the filtered branches and
# require the build job to be successful before it starts
- prod:
requires:
- pr
filters:
branches:
only:
- master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment