version: 2.1 workflows: workflow1: jobs: - hello1 workflow2: jobs: - yarn1 - lint1: requires: - yarn1 - test1: requires: - yarn1 - database1: requires: - yarn1 - build: requires: - lint1 - test1 filters: branches: only: main - deploy: requires: - build variables: executors: docker-publisher: environment: IMAGE_NAME: johanngif/my-awesome-ci-expr docker: - image: circleci/buildpack-deps:stretch jobs: hello1: docker: - image: 'circleci/node:12' steps: - checkout - run: command: 'echo ok' name: 'Hello World' yarn1: docker: - image: 'circleci/node:12' steps: - checkout - restore_cache: key: yarn-v1-packages-{{ checksum "yarn.lock" }} - run: yarn global add node-gyp && yarn install - save_cache: key: yarn-v1-packages-{{ checksum "yarn.lock" }} paths: - ./node_modules lint1: docker: - image: 'circleci/node:12' steps: - checkout - restore_cache: key: yarn-v1-packages-{{ checksum "yarn.lock" }} - run: yarn lint && yarn format:check test1: docker: - image: 'circleci/node:12' steps: - checkout - restore_cache: key: yarn-v1-packages-{{ checksum "yarn.lock" }} - run: yarn test:ci database1: docker: - image: 'circleci/node:12' environment: DATABASE_URL: postgres://psqluer:psqlpassword@localhost:5432/psdb JWT_SECRET: some string you want API_PORT: 3000 API_HOST: localhost API_PROTOCOL: http - image: 'circleci/postgres:9.6.2-alpine' environment: POSTGRES_USER: psqluer POSTGRES_PASSWORD: psqlpassword POSTGRES_DB: psdb steps: - checkout - restore_cache: key: yarn-v1-packages-{{ checksum "yarn.lock" }} - run: yarn test:e2e build: executor: docker-publisher steps: - checkout - setup_remote_docker - run: name: Build Docker image command: | docker build -t $IMAGE_NAME:latest . - run: name: Archive Docker image command: docker save -o image.tar $IMAGE_NAME - persist_to_workspace: root: . paths: - ./image.tar deploy: executor: docker-publisher steps: - attach_workspace: at: /tmp/workspace - setup_remote_docker - run: name: Load archived Docker image command: docker load -i /tmp/workspace/image.tar - run: name: Publish Docker Image to Docker Hub command: | echo "$DOCKERHUB_PASSWORD" | docker login --username "$DOCKERHUB_USERNAME" --password-stdin #IMAGE_TAG=${CIRCLE_TAG/v/''} IMAGE_TAG=$CIRCLE_BUILD_NUM docker tag $IMAGE_NAME:latest $IMAGE_NAME:$IMAGE_TAG docker push $IMAGE_NAME:latest docker push $IMAGE_NAME:$IMAGE_TAG