Yield generated for 4156d3f3-fcd0-4573-aa22-18d62c9887f0
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

207 lines
4.7 KiB

version: 2.1
globals:
credentials:
dockerhub_username: &dockerhub_username anthonyjhoiro
docker-config:
- &docker-config
image: cimg/node:16.10.0
auth:
username: *dockerhub_username
password: $DOCKERHUB_PASSWORD
commands:
init:
description: Setup the environment
steps:
- checkout
- restore_cache:
keys:
- npm-v1-dependencies-{{ checksum "yarn.lock" }}
pushdockerhub:
description: Push tag image to Docker Hub
parameters:
baseimage:
type: string
default: app
destination:
type: string
default: ""
steps:
- run: docker tag << parameters.baseimage >> << parameters.destination >>
- run: docker push << parameters.destination >>
jobs:
# Install the node dependencies
install:
docker:
- *docker-config
steps:
- init
- run:
name: Install deps using Yarn
command: yarn install
- save_cache:
name: Save Yarn Package Cache
key: npm-v1-dependencies-{{ checksum "yarn.lock" }}
paths:
- node_modules
# Lint the code
lint:
docker:
- *docker-config
steps:
- init
- run:
name: Check files format
command: yarn format:check
- run:
name: Lint files
command: yarn lint
# Run CI tests
test-ci:
docker:
- *docker-config
steps:
- init
- run:
name: Unit Tests
command: yarn test
# Run e2e tests
test-e2e:
docker:
- *docker-config
- image: circleci/postgres:9.6-alpine
auth:
username: *dockerhub_username
password: $DOCKERHUB_PASSWORD
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: psdb
steps:
- init
- run:
name: Run e2e tests
environment:
DATABASE_URL: postgres://postgres:postgres@localhost:5432/psdb
command: yarn test:e2e
# Generate the documentation
gendoc:
docker:
- *docker-config
steps:
- init
- run:
name: Generate doc
command: yarn doc:build
- store_artifacts:
path: docs
# Build and push the docker image
builddocker:
docker:
- *docker-config
environment:
DOCKERHUB_LOGIN: *dockerhub_username
DOCKERHUB_REPOSITORY: my-awesome-ci-expr
steps:
- init
- setup_remote_docker # Can not cache docker in images in free tier
- run:
name: Build and Push docker image
command: docker build -t app .
- run:
name: Login to docker hub
command: echo $DOCKERHUB_PASSWORD | docker login -u $DOCKERHUB_LOGIN --password-stdin
# Push build number and latest for main branch
- when:
condition:
equal:
- main
- << pipeline.git.branch >>
steps:
- pushdockerhub:
destination: $DOCKERHUB_LOGIN/$DOCKERHUB_REPOSITORY:${CIRCLE_BUILD_NUM}
- pushdockerhub:
destination: $DOCKERHUB_LOGIN/$DOCKERHUB_REPOSITORY:latest
# Push dev images for develop branch
- when:
condition:
equal:
- << pipeline.git.branch >>
- develop
steps:
- pushdockerhub:
destination: $DOCKERHUB_LOGIN/$DOCKERHUB_REPOSITORY:${CIRCLE_BUILD_NUM}-dev
# Push prep images for hotfix & release branches
- when:
condition:
or:
- matches:
value: << pipeline.git.branch >>
pattern: /^hotfix\/.*/
- matches:
value: << pipeline.git.branch >>
pattern: /^release\/.*/
steps:
- pushdockerhub:
destination: $DOCKERHUB_LOGIN/$DOCKERHUB_REPOSITORY:${CIRCLE_BUILD_NUM}-prep
workflows:
build-workflow:
jobs:
- install
- lint:
requires:
- install
- test-ci:
requires:
- install
- test-e2e:
requires:
- install
- gendoc:
requires:
- lint
- test-ci
- test-e2e
- builddocker:
filters:
branches:
# Run only on main, develop, release/.* and hotfix/.* branches
only:
- main
- develop
- /^hotfix\/.*/
- /^release\/.*/
requires:
- lint
- test-ci
- test-e2e