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 - netlify_build: requires: - test filters: branches: only: - main - netlify_deploy: requires: - netlify_build 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 netlify_build: docker: - image: cimg/node:12.18.4 working_directory: ~/repo steps: - checkout - restore_cache: key: yarn-packages-v2{{ checksum "yarn.lock" }} - run: yarn build - run: name: Copy build to workspace command: | cp dist/ /tmp/dist -r - store_artifacts: path: /tmp/dist - persist_to_workspace: root: /tmp paths: - dist netlify_deploy: docker: - image: cimg/node:12.18.4 working_directory: ~/my-awesome-project steps: - attach_workspace: at: /tmp - run: name: Deploy app command: | ls -al /tmp sudo npm install -g --silent netlify-cli npx netlify deploy --prod --auth $NETLIFY_AUTH_TOKEN --dir=/tmp/dist --site $SITEID 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