From 601bb97f77372e235ecae03be33c0032ac02928c Mon Sep 17 00:00:00 2001 From: Manoj Date: Fri, 29 Nov 2024 22:14:27 +0530 Subject: [PATCH 01/12] Added workflow --- .github/workflows/build.yml | 6 ++---- .github/workflows/deploy.yml | 42 ------------------------------------ 2 files changed, 2 insertions(+), 46 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index c8b64f0e..0c3cc769 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -7,6 +7,7 @@ on: jobs: build: + name: Build the project runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 @@ -14,12 +15,9 @@ jobs: uses: actions/setup-node@v3 with: node-version: '20' - + - name: Install Dependencies run: npm install - - - name: Generate prisma client - run: npm run db:generate - name: Run Build run: npm run build diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index acbed6e5..e69de29b 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -1,42 +0,0 @@ -name: Build and Deploy to Docker Hub - -on: - push: - branches: - - master - -jobs: - build-and-push: - runs-on: ubuntu-latest - steps: - - name: Check Out Repo - uses: actions/checkout@v2 - - - name: Log in to Docker Hub - uses: docker/login-action@v1 - with: - username: ${{ secrets.DOCKER_USERNAME }} - password: ${{ secrets.DOCKER_PASSWORD }} - - - name: Build and Push Docker image - uses: docker/build-push-action@v2 - with: - context: . - file: ./docker/Dockerfile.user - push: true - tags: 100xdevs/week-18-class:latest # Replace with your Docker Hub username and repository - - - name: Verify Pushed Image - run: docker pull 100xdevs/week-18-class:latest # Replace with your Docker Hub username and repository - - - name: Deploy to EC2 - uses: appleboy/ssh-action@master - with: - host: ${{ secrets.SSH_HOST }} - username: ${{ secrets.SSH_USERNAME }} - key: ${{ secrets.SSH_KEY }} - script: | - sudo docker pull 100xdevs/week-18-class:latest - sudo docker stop web-app || true - sudo docker rm web-app || true - sudo docker run -d --name web-app -p 3005:3000 100xdevs/week-18-class:latest \ No newline at end of file From 31c4ca9c1a8dbb0aa14b3169a340f1276afe3962 Mon Sep 17 00:00:00 2001 From: Manoj Date: Fri, 29 Nov 2024 22:34:30 +0530 Subject: [PATCH 02/12] Space --- apps/bank-webhook/src/index.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/apps/bank-webhook/src/index.ts b/apps/bank-webhook/src/index.ts index bb92555d..e10a0cbb 100644 --- a/apps/bank-webhook/src/index.ts +++ b/apps/bank-webhook/src/index.ts @@ -1,3 +1,6 @@ + + + import express from "express"; import db from "@repo/db/client"; const app = express(); From 6c39dea5b264b32fedbdf8a3048d025bfaa29202 Mon Sep 17 00:00:00 2001 From: Manoj Date: Fri, 29 Nov 2024 22:46:11 +0530 Subject: [PATCH 03/12] added workflow --- .github/workflows/build.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 0c3cc769..65c27dfc 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -18,6 +18,8 @@ jobs: - name: Install Dependencies run: npm install - + + - name: Generate prisma Client + run: npm run db:generate - name: Run Build run: npm run build From 7cc8eb3887285ce9cb1bcd07be880e65c9344a68 Mon Sep 17 00:00:00 2001 From: Manoj Date: Fri, 29 Nov 2024 22:48:15 +0530 Subject: [PATCH 04/12] update index --- apps/bank-webhook/src/index.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/apps/bank-webhook/src/index.ts b/apps/bank-webhook/src/index.ts index e10a0cbb..0ff4f940 100644 --- a/apps/bank-webhook/src/index.ts +++ b/apps/bank-webhook/src/index.ts @@ -1,6 +1,9 @@ + + + import express from "express"; import db from "@repo/db/client"; const app = express(); From eaace0990fba741819bd91bb5ff34d55cd432b53 Mon Sep 17 00:00:00 2001 From: Manoj Date: Fri, 29 Nov 2024 23:03:35 +0530 Subject: [PATCH 05/12] update workflow --- apps/bank-webhook/src/index.ts | 6 ------ 1 file changed, 6 deletions(-) diff --git a/apps/bank-webhook/src/index.ts b/apps/bank-webhook/src/index.ts index 0ff4f940..bb92555d 100644 --- a/apps/bank-webhook/src/index.ts +++ b/apps/bank-webhook/src/index.ts @@ -1,9 +1,3 @@ - - - - - - import express from "express"; import db from "@repo/db/client"; const app = express(); From d8eb3cc5befaf89f49539b45703261fd3cdb3fa0 Mon Sep 17 00:00:00 2001 From: Manoj Date: Fri, 29 Nov 2024 23:05:29 +0530 Subject: [PATCH 06/12] update workflow --- apps/bank-webhook/src/index.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/apps/bank-webhook/src/index.ts b/apps/bank-webhook/src/index.ts index bb92555d..7ced06fb 100644 --- a/apps/bank-webhook/src/index.ts +++ b/apps/bank-webhook/src/index.ts @@ -5,8 +5,9 @@ const app = express(); app.use(express.json()) app.post("/hdfcWebhook", async (req, res) => { - //TODO: Add zod validation here? + //TODO: Add zod validation here //TODO: HDFC bank should ideally send us a secret so we know this is sent by them + //check already request is success const paymentInformation: { token: string; userId: string; From cbe3c1bfd95a77909c426e6bed40db37928b8b3e Mon Sep 17 00:00:00 2001 From: Manoj Date: Fri, 29 Nov 2024 23:11:43 +0530 Subject: [PATCH 07/12] changed workflow --- apps/bank-webhook/src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/bank-webhook/src/index.ts b/apps/bank-webhook/src/index.ts index 7ced06fb..9edb095f 100644 --- a/apps/bank-webhook/src/index.ts +++ b/apps/bank-webhook/src/index.ts @@ -7,7 +7,7 @@ app.use(express.json()) app.post("/hdfcWebhook", async (req, res) => { //TODO: Add zod validation here //TODO: HDFC bank should ideally send us a secret so we know this is sent by them - //check already request is success + //pr from feature-branch to master with CI const paymentInformation: { token: string; userId: string; From 42eed97fac7dce956815ea5d932e04680120cf9c Mon Sep 17 00:00:00 2001 From: Manoj Date: Fri, 29 Nov 2024 23:14:14 +0530 Subject: [PATCH 08/12] changed index.ts --- apps/bank-webhook/src/index.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/apps/bank-webhook/src/index.ts b/apps/bank-webhook/src/index.ts index 9edb095f..706b8d01 100644 --- a/apps/bank-webhook/src/index.ts +++ b/apps/bank-webhook/src/index.ts @@ -5,9 +5,7 @@ const app = express(); app.use(express.json()) app.post("/hdfcWebhook", async (req, res) => { - //TODO: Add zod validation here - //TODO: HDFC bank should ideally send us a secret so we know this is sent by them - //pr from feature-branch to master with CI + //TODO: const paymentInformation: { token: string; userId: string; From a15771abc44080dd096aa9e5b0b0ea08dc124d64 Mon Sep 17 00:00:00 2001 From: Manoj Date: Sat, 30 Nov 2024 11:01:00 +0530 Subject: [PATCH 09/12] new comment added --- apps/bank-webhook/src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/bank-webhook/src/index.ts b/apps/bank-webhook/src/index.ts index 706b8d01..288dc530 100644 --- a/apps/bank-webhook/src/index.ts +++ b/apps/bank-webhook/src/index.ts @@ -1,7 +1,7 @@ import express from "express"; import db from "@repo/db/client"; const app = express(); - +//commit to feature branch app.use(express.json()) app.post("/hdfcWebhook", async (req, res) => { From 87aba6fa2a7b8c61ebcbb091d68858e1f67fa702 Mon Sep 17 00:00:00 2001 From: Manoj Date: Sat, 30 Nov 2024 11:48:01 +0530 Subject: [PATCH 10/12] docker file --- docker/Dockerfile.user | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/docker/Dockerfile.user b/docker/Dockerfile.user index d8cde5b1..1a52bc2f 100644 --- a/docker/Dockerfile.user +++ b/docker/Dockerfile.user @@ -1,18 +1,16 @@ -FROM node:20.12.0-alpine3.19 +FROM node:20 -WORKDIR /usr/src/app +WORKDIR usr/src/app COPY package.json package-lock.json turbo.json tsconfig.json ./ COPY apps ./apps COPY packages ./packages -# Install dependencies RUN npm install -# Can you add a script to the global package.json that does this? + RUN npm run db:generate -# Can you filter the build down to just one app? RUN npm run build CMD ["npm", "run", "start-user-app"] \ No newline at end of file From 710e5c026cdef6387beec7bdbcf5a9f360f4d572 Mon Sep 17 00:00:00 2001 From: Manoj Date: Sat, 30 Nov 2024 11:51:21 +0530 Subject: [PATCH 11/12] docker file updated --- docker/Dockerfile.user | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docker/Dockerfile.user b/docker/Dockerfile.user index 1a52bc2f..41b9d1bb 100644 --- a/docker/Dockerfile.user +++ b/docker/Dockerfile.user @@ -4,6 +4,8 @@ WORKDIR usr/src/app COPY package.json package-lock.json turbo.json tsconfig.json ./ + + COPY apps ./apps COPY packages ./packages From 93f7b1927aeeebb58f53d299c97072f7ef022fea Mon Sep 17 00:00:00 2001 From: Manoj Date: Sat, 30 Nov 2024 22:18:03 +0530 Subject: [PATCH 12/12] new cd --- .github/workflows/deploy.yml | 30 ++++++++++++++++++++++++++++++ Dockerfile | 18 ++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 Dockerfile diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index e69de29b..a5c43cb5 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -0,0 +1,30 @@ +name: Build and Deploy to docker hub + +on: + push: + branches: + - master + +jobs: + build-and-push: + runs-on: ubuntu-latest + steps: + - name: Check out Repo + uses: actions/checkout@v2 + + - name: Log in to Docker Hub + uses: docker/login-action@v1 + with: + username: ${{secrets.DOCKER_USERNAME}} + password: ${{secrets.DOCKER_PASSWORD}} + + - name: Build and Push Docker image + uses: docker/build-push-action@v2 + with: + context: . + file: ./docker/Dockerfile.user + push: true + tags: man0jx/cd:latest + + - name: Verify pushed Image + run: docker pull man0jx/cd:latest \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..41b9d1bb --- /dev/null +++ b/Dockerfile @@ -0,0 +1,18 @@ +FROM node:20 + +WORKDIR usr/src/app + +COPY package.json package-lock.json turbo.json tsconfig.json ./ + + + +COPY apps ./apps +COPY packages ./packages + +RUN npm install + +RUN npm run db:generate + +RUN npm run build + +CMD ["npm", "run", "start-user-app"] \ No newline at end of file