From d726447043dfbe136854515dd83a65536f3fef6f Mon Sep 17 00:00:00 2001 From: khushalbhardwaj-0111 Date: Fri, 8 Oct 2021 21:23:39 +0530 Subject: [PATCH 01/14] specified node engine --- package.json | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 15547e9..ca48568 100644 --- a/package.json +++ b/package.json @@ -77,6 +77,9 @@ "**/*.(t|j)s" ], "coverageDirectory": "../coverage", - "testEnvironment": "node" + "testEnvironment": "node", + "engines": { + "node": "14.x" + } } } From f933267b50f507e25a9066604d4c1b1a6f72cc39 Mon Sep 17 00:00:00 2001 From: khushalbhardwaj-0111 Date: Sat, 9 Oct 2021 20:18:42 +0530 Subject: [PATCH 02/14] chore: dockerized app --- .dockerignore | 3 +++ .prettierignore | 1 + Dockerfile | 29 +++++++++++++++++++++++++++++ docker-compose.yml | 11 +++++++++++ package.json | 2 ++ src/main.ts | 16 ++++++++-------- 6 files changed, 54 insertions(+), 8 deletions(-) create mode 100644 .dockerignore create mode 100644 .prettierignore create mode 100644 Dockerfile create mode 100644 docker-compose.yml diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..801e184 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,3 @@ +node_modules +npm-debug.log +coverage diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 0000000..1120be9 --- /dev/null +++ b/.prettierignore @@ -0,0 +1 @@ +docker-compose.yml diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..3242844 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,29 @@ +# # pulling the suitable version of node +FROM node:14.16 as build + +# specifying the container app directory +WORKDIR /khushal/src/app + +# copy package.json and everything in the directory +COPY package.json ./ + +RUN npm install + +# first dot - the working directory +# second dot - the docker app directory +COPY . . + +# build the project +RUN npm run build + +# ----------------------------- + +# Production container + +FROM node:14.16 +WORKDIR /user/src/app +COPY package.json . +RUN npm install --only=production +COPY --from=build /khushal/src/app/dist ./dist +COPY --from=build /khushal/src/app/.env ./ +CMD npm run start:prod diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..30fe509 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,11 @@ +version: "3.8" +services: + api: + # image: khushalbhardwaj-0111/notary + build: + dockerfile: Dockerfile + context: ./ + environment: + NODE_ENV: production + ports: + - "8080:80" diff --git a/package.json b/package.json index ca48568..ecaf75d 100644 --- a/package.json +++ b/package.json @@ -13,6 +13,8 @@ "start:dev": "nest build --webpack --webpackPath webpack.config.js --watch", "start:debug": "nest start --debug --watch", "start:prod": "node dist/main", + "up": "docker-compose up", + "down": "docker-compose down", "lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix", "test": "jest", "test:watch": "jest --watch", diff --git a/src/main.ts b/src/main.ts index dee8066..dea9a54 100644 --- a/src/main.ts +++ b/src/main.ts @@ -8,14 +8,14 @@ dotenv.config(); declare const module: any; (async function bootstrap() { - const app = await NestFactory.create(AppModule); - app.enableCors(); - app.use(helmet()); + const app = await NestFactory.create(AppModule); + app.enableCors(); + app.use(helmet()); - if (module.hot) { - module.hot.accept(); - module.hot.dispose(() => app.close()); - } + if (module.hot) { + module.hot.accept(); + module.hot.dispose(() => app.close()); + } - await app.listen(process.env.PORT || 8080); + await app.listen(process.env.PORT || 80); })(); From 8ff050782622aa000cfc13effa94ae8d3f9c138e Mon Sep 17 00:00:00 2001 From: khushalbhardwaj-0111 Date: Sat, 9 Oct 2021 21:38:31 +0530 Subject: [PATCH 03/14] ignored files --- .prettierignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.prettierignore b/.prettierignore index 1120be9..57a3c51 100644 --- a/.prettierignore +++ b/.prettierignore @@ -1 +1,4 @@ docker-compose.yml +node_modules +dist +coverage From 126ed985488b167454ba41b6fcc1652aa31da22a Mon Sep 17 00:00:00 2001 From: khushalbhardwaj-0111 Date: Sat, 9 Oct 2021 21:38:48 +0530 Subject: [PATCH 04/14] added deploy container to heroku action --- .github/workflows/deploy.yml | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 .github/workflows/deploy.yml diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 0000000..ee4df0d --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,17 @@ +name: Deploy + +on: + push: + branches: [master] + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: akhileshns/heroku-deploy@v3.12.12 + with: + heroku_api_key: ${{secrets.HEROKU_API_KEY}} + heroku_app_name: ${{secrets.HEROKU_APP_NAME}} + heroku_email: ${{secrets.HEROKU_ACCOUNT_EMAIL}} + usedocker: true From 0303719993a3a8014546b40610c69e23e80085d6 Mon Sep 17 00:00:00 2001 From: khushalbhardwaj-0111 Date: Sat, 9 Oct 2021 21:42:12 +0530 Subject: [PATCH 05/14] removed tabs from yml file --- .github/workflows/deploy.yml | 24 ++++++++++++------------ .prettierignore | 1 + 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index ee4df0d..db7e650 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -1,17 +1,17 @@ name: Deploy on: - push: - branches: [master] + push: + branches: [master] jobs: - build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - uses: akhileshns/heroku-deploy@v3.12.12 - with: - heroku_api_key: ${{secrets.HEROKU_API_KEY}} - heroku_app_name: ${{secrets.HEROKU_APP_NAME}} - heroku_email: ${{secrets.HEROKU_ACCOUNT_EMAIL}} - usedocker: true + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: akhileshns/heroku-deploy@v3.12.12 + with: + heroku_api_key: ${{secrets.HEROKU_API_KEY}} + heroku_app_name: ${{secrets.HEROKU_APP_NAME}} + heroku_email: ${{secrets.HEROKU_ACCOUNT_EMAIL}} + usedocker: true diff --git a/.prettierignore b/.prettierignore index 57a3c51..a836911 100644 --- a/.prettierignore +++ b/.prettierignore @@ -1,3 +1,4 @@ +.github/ docker-compose.yml node_modules dist From 3caffe02dc4a2962e807e8b0a44860abef654add Mon Sep 17 00:00:00 2001 From: khushalbhardwaj-0111 Date: Sat, 9 Oct 2021 21:43:27 +0530 Subject: [PATCH 06/14] added test deploy branch --- .github/workflows/deploy.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index db7e650..f0e43dc 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -2,7 +2,7 @@ name: Deploy on: push: - branches: [master] + branches: [dockerized] jobs: build: From a9096c2aa02a37da76c020c5b24e2fbacf3bfd95 Mon Sep 17 00:00:00 2001 From: khushalbhardwaj-0111 Date: Sat, 9 Oct 2021 21:49:32 +0530 Subject: [PATCH 07/14] updated docker file for deployment --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 3242844..3a2d0d6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -25,5 +25,5 @@ WORKDIR /user/src/app COPY package.json . RUN npm install --only=production COPY --from=build /khushal/src/app/dist ./dist -COPY --from=build /khushal/src/app/.env ./ +# COPY --from=build /khushal/src/app/.env ./ CMD npm run start:prod From 4260552741118450175f3fd989a1b1f84e71ba3c Mon Sep 17 00:00:00 2001 From: khushalbhardwaj-0111 Date: Sat, 9 Oct 2021 22:00:24 +0530 Subject: [PATCH 08/14] added app healthcheck --- .github/workflows/deploy.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index f0e43dc..faf6646 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -15,3 +15,11 @@ jobs: heroku_app_name: ${{secrets.HEROKU_APP_NAME}} heroku_email: ${{secrets.HEROKU_ACCOUNT_EMAIL}} usedocker: true + stack: "container" + healthcheck: | + "https://" + ${{secrets.HEROKU_APP_NAME}} + ".herokuapp.com/health" + checkstring: "ok" + delay: 5 + rollbackonhealthcheckfailed: true From 2436e81297393c5cac77f181f8247be1420740b0 Mon Sep 17 00:00:00 2001 From: khushalbhardwaj-0111 Date: Sat, 9 Oct 2021 22:06:48 +0530 Subject: [PATCH 09/14] increased delay and renamed job --- .github/workflows/deploy.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index faf6646..f725720 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -5,7 +5,7 @@ on: branches: [dockerized] jobs: - build: + deploy: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 @@ -21,5 +21,5 @@ jobs: ${{secrets.HEROKU_APP_NAME}} ".herokuapp.com/health" checkstring: "ok" - delay: 5 + delay: 3600 rollbackonhealthcheckfailed: true From 74a03b6e5cde542cf770336e3692a6e2e86ad1fe Mon Sep 17 00:00:00 2001 From: khushalbhardwaj-0111 Date: Sat, 9 Oct 2021 22:10:35 +0530 Subject: [PATCH 10/14] reduced workflow to 1min --- .github/workflows/deploy.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index f725720..108ece4 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -21,5 +21,5 @@ jobs: ${{secrets.HEROKU_APP_NAME}} ".herokuapp.com/health" checkstring: "ok" - delay: 3600 + delay: 60 rollbackonhealthcheckfailed: true From a5758e1d1934f7a3de9da678917cdde8ed1b599d Mon Sep 17 00:00:00 2001 From: khushalbhardwaj-0111 Date: Sat, 9 Oct 2021 22:11:12 +0530 Subject: [PATCH 11/14] removed test deploy --- .github/workflows/deploy.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 108ece4..e2df7ba 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -2,7 +2,7 @@ name: Deploy on: push: - branches: [dockerized] + branches: [master] jobs: deploy: From 7b5ce5f92801c6d4b3727d5a35125b1440e5fd2f Mon Sep 17 00:00:00 2001 From: khushalbhardwaj-0111 Date: Sat, 9 Oct 2021 22:14:28 +0530 Subject: [PATCH 12/14] updated for dev staging --- .github/workflows/deploy.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index e2df7ba..ea77ca6 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -2,7 +2,7 @@ name: Deploy on: push: - branches: [master] + branches: [master, dev] jobs: deploy: From 4b42097f70c1c36564c5cd44d2cb2682f4389734 Mon Sep 17 00:00:00 2001 From: khushalbhardwaj-0111 Date: Sat, 9 Oct 2021 22:15:18 +0530 Subject: [PATCH 13/14] create a patch version for docker --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index ecaf75d..b0e9b5b 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "notary-api", "private": true, - "version": "1.0.0", + "version": "1.0.1", "description": "Notary API", "license": "MIT", "scripts": { From fcb05b1568a2a1957ab70f00ff7d399c71de201c Mon Sep 17 00:00:00 2001 From: khushalbhardwaj-0111 Date: Sat, 9 Oct 2021 22:28:28 +0530 Subject: [PATCH 14/14] seprated prod and stage deployments --- .github/workflows/deploy-staging.yml | 25 +++++++++++++++++++++++++ .github/workflows/deploy.yml | 4 ++-- 2 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/deploy-staging.yml diff --git a/.github/workflows/deploy-staging.yml b/.github/workflows/deploy-staging.yml new file mode 100644 index 0000000..52975ad --- /dev/null +++ b/.github/workflows/deploy-staging.yml @@ -0,0 +1,25 @@ +name: Deploy + +on: + push: + branches: [dev] + +jobs: + deploy-stage: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: akhileshns/heroku-deploy@v3.12.12 + with: + heroku_api_key: ${{secrets.HEROKU_API_KEY}} + heroku_app_name: ${{secrets.HEROKU_APP_NAME}} + heroku_email: ${{secrets.HEROKU_ACCOUNT_EMAIL}} + usedocker: true + stack: "container" + healthcheck: | + "https://" + ${{secrets.HEROKU_STAGING_APP_NAME}} + ".herokuapp.com/health" + checkstring: "ok" + delay: 60 + rollbackonhealthcheckfailed: true diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index ea77ca6..03f6869 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -2,10 +2,10 @@ name: Deploy on: push: - branches: [master, dev] + branches: [master] jobs: - deploy: + deploy-prod: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2