version: 2.1 executors: docker-publisher: environment: IMAGE_NAME: jeffyshewan/build-on-ci docker: - image: circleci/buildpack-deps:stretch workflows: std: jobs: - yarn - lint: requires: - yarn - test: requires: - yarn - e2e-test: requires: - yarn - build: requires: - lint - test - e2e-test - publish: requires: - build jobs: yarn: docker: - image: "circleci/node:12" steps: - checkout - restore_cache: key: npm-v2-dependencies-{{ checksum "yarn.lock" }} - run: yarn global add node-gyp && yarn install - save_cache: key: npm-v2-dependencies-{{ checksum "yarn.lock" }} paths: - ./node_modules lint: docker: - image: "circleci/node:12" steps: - checkout - restore_cache: key: npm-v2-dependencies-{{ checksum "yarn.lock" }} - run: yarn lint - run: yarn format:check test: docker: - image: "circleci/node:12" steps: - checkout - restore_cache: key: npm-v2-dependencies-{{ checksum "yarn.lock" }} - run: yarn test:ci e2e-test: docker: - image: "circleci/node:12" environment: DATABASE_URL: postgres://jeffyshewan:password@localhost:5432/testbdd JWT_SECRET: ARMA_eau_de_combat API_PORT: 3000 API_HOST: localhost API_PROTOCOL: http - image: "circleci/postgres:9.6.2-alpine" environment: POSTGRES_USER: jeffyshewan POSTGRES_DB: testbdd POSTGRES_PASSWORD: password steps: - checkout - restore_cache: key: npm-v2-dependencies-{{ checksum "yarn.lock" }} - run: name: connecting postgres command: dockerize -wait tcp://localhost:5432 -timeout 1m - run: name: start e2e test command: yarn test:e2e - save_cache: key: npm-v2-dependencies-{{ checksum "yarn.lock" }} paths: - ./node_modules build: executor: docker-publisher steps: - checkout - setup_remote_docker - run: name: Build and publish to DockerHub 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 publish: 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 DockerHub command: | echo "$DOCKERHUB_PASS" | docker login -u "$DOCKERHUB_USERNAME" --password-stdin docker push $IMAGE_NAME:latest