Skip to content

Instantly share code, notes, and snippets.

@d3vAdv3ntur3s
Created July 31, 2021 15:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save d3vAdv3ntur3s/4f81c6e3e8e4aa8ceab0bb232a498873 to your computer and use it in GitHub Desktop.
Save d3vAdv3ntur3s/4f81c6e3e8e4aa8ceab0bb232a498873 to your computer and use it in GitHub Desktop.
CircleCI Mono Repo Setup
version: 2.1
# Use CircleCI's dynamic configuration feature
setup: true
# Orbs are built in helpers made by CircleCI & the community
orbs:
# Path iltering is the magic behind checking for file changes and leverages continuation orb to proceed with workflows
path-filtering: circleci/path-filtering@0.0.2
# Executors are used for jobs, options to what docker image is used for each
executors:
alpine-git:
docker:
- image: alpine/git:v2.30.2
# Jobs to be wired into a workflow, each job can have many steps
jobs:
update-mirror-repository:
executor: alpine-git
steps:
- checkout
- add_ssh_keys:
fingerprints:
- "ADD SSH KEY FINGERPRINT OF MIRROR REMOTE REPO" #https://circleci.com/docs/2.0/add-ssh-key/
- run:
name: Update Mirrored Repository
command: |
git remote add d3vadv3ntur3s-mirror git@github.com:d3vadv3ntur3s/d3vadv3ntur3s-mirror-project.git
git push --mirror d3vadv3ntur3s-mirror
workflows:
# Runs the two following jobs everytime
setup-workflow:
jobs:
- update-mirror-repository
- path-filtering/filter:
mapping: |
backend/.* run-backend true
frontend/.* run-frontend true
# Compares differences to main branch
base-revision: main
config-path: .circleci/workflows.yml
version: 2.1
# the default pipeline parameters, which will be updated according to the results of the path-filtering orb
parameters:
run-backend:
type: boolean
default: false
run-frontend:
type: boolean
default: false
executors:
node:
docker:
- image: cimg/node:16.5.0
dind:
docker:
- image: cimg/base:2021.07
jobs:
backend-unit-test:
executor: node
working_directory: ~/monorepo/backend
steps:
- checkout:
path: ~/monorepo
- restore_cache:
key: backend-dependency-cache-{{ checksum "package-lock.json" }}
- run:
name: Install Dependencies
command: npm ci
- save_cache:
key: backend-dependency-cache-{{ checksum "package-lock.json" }}
paths:
- node_modules
- run:
name: Run Linter
command: npm run lint
- run:
name: Backend Unit Test
command: npm test
backend-build:
executor: dind
working_directory: ~/monorepo/backend
steps:
- checkout:
path: ~/monorepo
- setup_remote_docker:
version: 20.10.6
- run: |
source ./aws_credentials
DOCKER_BUILDKIT=1 docker build --secret id=npmrc,src=.npmrc -t monorepo/backend:$CIRCLE_SHA1 .
docker tag monorepo/backend:$CIRCLE_SHA1 AWS_ACCOUNT_ID_HERE.dkr.ecr.eu-west-1.amazonaws.com/monorepo/backend:$CIRCLE_SHA1
aws ecr get-login-password --region eu-west-1 | docker login --username AWS --password-stdin "AWS_ACCOUNT_ID_HERE.dkr.ecr.eu-west-1.amazonaws.com"
docker push "AWS_ACCOUNT_ID_HERE.dkr.ecr.eu-west-1.amazonaws.com/monorepo/backend:$CIRCLE_SHA1"
# OMMITED Other steps for sake of brevity, i.e. not included frontend jobs, creds, deployment
# Workflow is decided based on the parameters, triggered from the config.yml based on file changes to frontend or backend
workflows:
backend:
when: << pipeline.parameters.run-backend >>
jobs:
- backend-unit-test:
name: unit-tests
- backend-build:
filters:
branches:
only: main
frontend:
when: << pipeline.parameters.run-frontend >>
jobs:
- frontend-unit-test:
name: unit-tests
- frontend-build:
filters:
branches:
only: main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment