version: 2.1 workflows: build_and_test: jobs: - build - test: requires: - build - build_docker: requires: - test filters: branches: only: - main - publish_image: requires: - build_docker filters: branches: only: - main - build_docs_artifact: requires: - test filters: branches: only: - main jobs: build: docker: - image: cimg/node:12.18.4 steps: - checkout - restore_cache: key: yarn-packages-v2{{ checksum "yarn.lock" }} - run: yarn global add node-gyp && yarn install - save_cache: key: yarn-packages-v2{{ checksum "yarn.lock" }} paths: - ./node_modules test: docker: - image: cimg/node:12.18.4 steps: - checkout - restore_cache: key: yarn-packages-v2{{ checksum "yarn.lock" }} - run : yarn test build_docker: environment: IMAGE_NAME: 698148/my-awesome-project docker: - image: circleci/buildpack-deps:stretch steps: - checkout - setup_remote_docker - run: docker image build --tag $IMAGE_NAME:app . - run: docker save -o image.tar $IMAGE_NAME - persist_to_workspace: root: . paths: - ./image.tar publish_image: environment: IMAGE_NAME: 698148/my-awesome-project docker: - image: circleci/buildpack-deps:stretch steps: - attach_workspace: at: /tmp/workspace - setup_remote_docker - run: docker load -i /tmp/workspace/image.tar - run: name: Login and Publish to Docker Hub command: | echo "$DOCKERHUB_PASS" | docker login --username 698148 --password-stdin docker tag $IMAGE_NAME:app $IMAGE_NAME:$CIRCLE_BUILD_NUM docker tag $IMAGE_NAME:app $IMAGE_NAME:latest docker push $IMAGE_NAME:$CIRCLE_BUILD_NUM docker push $IMAGE_NAME:latest deploy: docker: - image: cimg/node:12.18.4 steps: - checkout - attach_workspace: at: ./ - <<: *restore_cache - <<: *install_node_modules - run: name: Install netlify-cli command: sudo npm install -g --silent netlify-cli - run: name: Deploy to Netlify command: netlify deploy --dir=./public -p build_docs_artifact: docker: - image: cimg/node:12.18.4 steps: - checkout - restore_cache: key: yarn-packages-v2{{ checksum "yarn.lock" }} - run: ls - store_artifacts: path: doc-server destination: doc-server