From 5edec615220178a4170e40608f528dc895350416 Mon Sep 17 00:00:00 2001 From: Francois Lannoy Date: Wed, 4 Nov 2020 18:24:41 +0100 Subject: [PATCH] Update config.yml --- .circleci/config.yml | 184 +++++++++++++++++++++++++++---------------- 1 file changed, 117 insertions(+), 67 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 0e0f947..25e4134 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,68 +1,118 @@ version: 2.1 -workflows: - work: - jobs: - - build - - lint: - requires: - - build - - test: - requires: - - build - - e2e: - requires: - - build - -jobs: - build: - docker: - - image: cimg/node:12.18 - steps: - - checkout - - restore_cache: - key: yarn-packages-v1{{ checksum "yarn.lock" }} - - run: yarn global add node-gyp && yarn install - - save_cache: - key: yarn-packages-v2{{ checksum "yarn.lock" }} - paths: - - ./node_modules - lint: - docker: - - image: cimg/node:12.18 - steps: - - checkout - - restore_cache: - key: yarn-packages-v2{{ checksum "yarn.lock" }} - - run: yarn lint && yarn format:check - - test: - docker: - - image: cimg/node:12.18 - steps: - - checkout - - restore_cache: - key: yarn-packages-v2{{ checksum "yarn.lock" }} - - run: yarn test:ci - e2e: - docker: - - image: cimg/node:12.18 - environment: - DATABASE_URL: "postgres://e2e:test@localhost:5432/psdb" - API_PORT: 3000 - API_HOST: localhost - API_PROTOCOL: http - JWT_SECRET: yeet - - image: circleci/postgres:9.6.2-alpine - environment: - POSTGRES_USER: e2e - POSTGRES_DB: psdb - POSTGRES_PASSWORD: test - step: - - checkout - - restore_cache: - key: yarn-packages-v2{{ checksum "yarn.lock" }} - - run: dockerize -wait tcp://localhost:5432 -timeout 1m - - run: yarn test:e2e - - - \ No newline at end of file + workflows: + build_and_test: + jobs: + - build + - lint: + requires: + - build + - test: + requires: + - build + - e2e: + requires: + - build + - build_docker: + requires: + - e2e + - lint + - test + filters: + branches: + only: + - main + - publish_image: + context: + - DOCKER + requires: + - build_docker + filters: + branches: + only: + - main + jobs: + build: + docker: + - image: cimg/node:12.18 + 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 + lint: + docker: + - image: cimg/node:12.18 + steps: + - checkout + - restore_cache: + key: yarn-packages-v2{{ checksum "yarn.lock" }} + - run : yarn lint && yarn format:check + test: + docker: + - image: cimg/node:12.18 + steps: + - checkout + - restore_cache: + key: yarn-packages-v2{{ checksum "yarn.lock" }} + - run : yarn test:ci + e2e: + docker: + - image: cimg/node:12.18 + environment: + DATABASE_URL: "postgres://e2e:test@localhost:5432/psdb" + API_PORT: 3000 + API_HOST: localhost + API_PROTOCOL: http + JWT_SECRET: yeet + - image: circleci/postgres:9.6.2-alpine + environment: + POSTGRES_USER: e2e + POSTGRES_DB: psdb + POSTGRES_PASSWORD: test + + steps: + - checkout + - restore_cache: + key: yarn-packages-v2{{ checksum "yarn.lock" }} + - run: + name: Waiting for POSTGRES + command: dockerize -wait tcp://localhost:5432 -timeout 1m + - run: + name: Launching e2e test + command: yarn test:e2e + build_docker: + environment: + IMAGE_NAME: sgttabouret/my-awesome-ci-expr + 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: sgttabouret/my-awesome-ci-expr + 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 sgttabouret --password-stdin + docker tag $IMAGE_NAME:app $IMAGE_NAME:$CIRCLE_BUILD_NUM + docker tag $IMAGE_NAME:app $IMAGE_NAME:latest + docker push $IMAGE_NAME:latest + docker push $IMAGE_NAME:$CIRCLE_BUILD_NUM \ No newline at end of file