From 4d3be87472fa3d36c1e8044c9f162327ef6f30f4 Mon Sep 17 00:00:00 2001 From: SimonBurdy Date: Sat, 15 Jan 2022 16:26:06 +0100 Subject: [PATCH] dockerfile , circleci --- .circleci/config.yml | 134 +++++++++++++++++++++++++++++++++++++++++++ Dockerfile | 16 ++++++ Procfile | 1 + 3 files changed, 151 insertions(+) create mode 100644 .circleci/config.yml create mode 100644 Dockerfile create mode 100644 Procfile diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 0000000..a9c2094 --- /dev/null +++ b/.circleci/config.yml @@ -0,0 +1,134 @@ +# Use the latest 2.1 version of CircleCI pipeline process engine. +# See: https://circleci.com/docs/2.0/configuration-reference +version: 2.1 + +orbs: + # The Node.js orb contains a set of prepackaged CircleCI configuration you can utilize + # Orbs reduce the amount of configuration required for common tasks. + # See the orb documentation here: https://circleci.com/developer/orbs/orb/circleci/node + node: circleci/node@4.7 + +jobs: + build: &shared-config + docker: + - image: circleci/node:lts-fermium + working_directory: ~/repo + steps: + - checkout + - restore_cache: + keys: + - dependencies-{{ checksum "package.json" }}-v1 + - dependencies- + - run: yarn install + - save_cache: + paths: + - node_modules + key: dependencies-{{ checksum "package.json" }}-v1 + lint: + <<: *shared-config + steps: + - checkout + - restore_cache: + key: dependencies-{{ checksum "package.json" }}-v1 + - run: yarn lint + - run: yarn format:check + + + back-test-unit: + <<: *shared-config + steps: + - checkout + - restore_cache: + key: dependencies-{{ checksum "package.json" }}-v1 + - run: + command: yarn test + environment: + DATABASE_URL: postgres://psqluer:psqlpassword@localhost:5432/psqluer + + + + back-test-e2e: + docker: + - image: circleci/node:lts-fermium + - image: circleci/postgres:9.6.5 + environment: + POSTGRES_DB: psqluer + POSTGRES_USER: psqluer + POSTGRES_PASSWORD: psqlpassword + working_directory: ~/repo + steps: + - checkout + - restore_cache: + key: dependencies-{{ checksum "package.json" }}-v1 + - run: + command: yarn test:e2e + environment: + DATABASE_URL: postgres://psqluer:psqlpassword@localhost:5432/psqluer + + + docker-build-and-push: + working_directory: /dockerapp + docker: + - image: docker:17.05.0-ce-git + steps: + - checkout + - setup_remote_docker: + version: 19.03.13 + - run: + name: Build application Docker image + command: docker build -t app . + - deploy: + name: Publish application to docker hub + command: | + docker login -e $DOCKER_HUB_EMAIL -u $DOCKER_HUB_USER_ID -p $DOCKER_HUB_PWD + docker tag app $DOCKER_HUB_USER_ID/$DOCKER_HUB_NAME:$CIRCLE_BUILD_NUM + docker tag app $DOCKER_HUB_USER_ID/$DOCKER_HUB_NAME:latest + docker push $DOCKER_HUB_USER_ID/$DOCKER_HUB_NAME:$CIRCLE_BUILD_NUM + docker push $DOCKER_HUB_USER_ID/$DOCKER_HUB_NAME:latest + back-deploy-heroku: + docker: + - image: buildpack-deps:trusty + steps: + - checkout + - run: + name: Heroku Deploy + command: git push https://heroku:$HEROKU_KEY@git.heroku.com/$HEROKU_NAME.git HEAD:main + - run: + name: Smoke Test + command: | + HTTPCODE=`curl -s -o /dev/null -w "%{http_code}" https://$HEROKU_NAME.herokuapp.com/` + if [ "$HTTPCODE" -ne 200 ];then + echo "heroku app not responding, failing deploy" + exit 1 + fi +workflows: + build-test-and-lint: + jobs: + - build + - back-test-unit: + requires: + - build + - back-test-e2e: + requires: + - build + - lint: + requires: + - build + - docker-build-and-push: + requires: + - build + - lint + - back-test-e2e + - back-test-unit + filters: + branches: + only: main + - back-deploy-heroku: + requires: + - build + - lint + - back-test-e2e + - back-test-unit + filters: + branches: + only: main diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..36d3354 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,16 @@ +FROM node:lts-fermium +LABEL maintainer="TP FINAL DEVOPS" + +WORKDIR /repo + + +COPY . /repo + + +RUN yarn install + + +RUN yarn build + + +ENTRYPOINT [ "yarn", "start:prod" ] \ No newline at end of file diff --git a/Procfile b/Procfile new file mode 100644 index 0000000..723924b --- /dev/null +++ b/Procfile @@ -0,0 +1 @@ +web: yarn start:prod \ No newline at end of file