From eb7aaa51d55ebdcca9b10799cb80596e78aed52e Mon Sep 17 00:00:00 2001 From: mizanmahi Date: Fri, 27 Sep 2024 00:32:51 +0600 Subject: [PATCH 1/6] add: dev branch --- .github/workflows/deploy.yml | 3 ++- .gitignore | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index be83915..f5027d3 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -3,7 +3,8 @@ name: Build, Push, and Deploy Docker Image to EC2 on: push: branches: - - main # Trigger the workflow on push to the main branch + - main + - dev # Trigger the workflow on push to the dev branch jobs: build_and_deploy: diff --git a/.gitignore b/.gitignore index aaf2b40..1ddce6c 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ node_modules .vercel +dist \ No newline at end of file From 2623794393bb809a28ebfe6dcba5b263d052e255 Mon Sep 17 00:00:00 2001 From: mizanmahi Date: Fri, 27 Sep 2024 00:33:55 +0600 Subject: [PATCH 2/6] add: dev branch --- .github/workflows/deploy.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index f5027d3..330692e 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -25,12 +25,12 @@ jobs: # Step 3: Build the Docker image - name: Build Docker image run: | - docker build -t ${{ secrets.DOCKERHUB_USER_NAME }}/nextblog:3.0 . + docker build -t ${{ secrets.DOCKERHUB_USER_NAME }}/nextblog:5.0 . # Step 4: Push Docker image to DockerHub - name: Push Docker image run: | - docker push ${{ secrets.DOCKERHUB_USER_NAME }}/nextblog:3.0 + docker push ${{ secrets.DOCKERHUB_USER_NAME }}/nextblog:5.0 # Step 5: SSH to EC2 and deploy the Docker container - name: Deploy to EC2 @@ -42,7 +42,7 @@ jobs: port: 22 script: | # Pull the latest image - sudo docker pull ${{ secrets.DOCKERHUB_USER_NAME }}/nextblog:3.0 + sudo docker pull ${{ secrets.DOCKERHUB_USER_NAME }}/nextblog:5.0 # Check if the container is running and stop/remove it if it exists if [ "$(sudo docker ps -a -q -f name=nextblog)" ]; then @@ -58,4 +58,4 @@ jobs: # Run the container echo "Starting a new container..." - sudo docker run -d --name nextblog --env-file .env -p 9000:5000 ${{ secrets.DOCKERHUB_USER_NAME }}/nextblog:3.0 + sudo docker run -d --name nextblog --env-file .env -p 9000:5000 ${{ secrets.DOCKERHUB_USER_NAME }}/nextblog:5.0 From b936e2c850e595cb244034c803d9084e6a778147 Mon Sep 17 00:00:00 2001 From: mizanmahi Date: Mon, 7 Oct 2024 20:19:27 +0600 Subject: [PATCH 3/6] add: postgres from neon --- .env.example | 1 + src/app/middlewares/globalErrorHandler.ts | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/.env.example b/.env.example index cc10373..87585ec 100644 --- a/.env.example +++ b/.env.example @@ -2,6 +2,7 @@ NODE_ENV="development" PORT=5000 # DATABASE_URL="postgresql://postgres:123456@localhost:5432/mydb?blogdb=public" +# DATABASE_URL=postgresql://postgres:nextblogrds@db-nextblog.c72qycyeiylo.ap-southeast-1.rds.amazonaws.com:5432/nextblog -> aws rds DATABASE_URL="your database url" diff --git a/src/app/middlewares/globalErrorHandler.ts b/src/app/middlewares/globalErrorHandler.ts index dbfce85..fbd3125 100644 --- a/src/app/middlewares/globalErrorHandler.ts +++ b/src/app/middlewares/globalErrorHandler.ts @@ -17,3 +17,8 @@ const globalErrorHandler = ( }; export default globalErrorHandler; + + + + + From 4d650703753981591dc9922aad36eb88083663ae Mon Sep 17 00:00:00 2001 From: mizanmahi Date: Mon, 7 Oct 2024 21:32:07 +0600 Subject: [PATCH 4/6] updated workflow --- .github/workflows/deploy.yml | 8 ++++---- Dockerfile | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 330692e..8bf2fb8 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -25,12 +25,12 @@ jobs: # Step 3: Build the Docker image - name: Build Docker image run: | - docker build -t ${{ secrets.DOCKERHUB_USER_NAME }}/nextblog:5.0 . + docker build -t ${{ secrets.DOCKERHUB_USER_NAME }}/nextblog:7.0 . # Step 4: Push Docker image to DockerHub - name: Push Docker image run: | - docker push ${{ secrets.DOCKERHUB_USER_NAME }}/nextblog:5.0 + docker push ${{ secrets.DOCKERHUB_USER_NAME }}/nextblog:7.0 # Step 5: SSH to EC2 and deploy the Docker container - name: Deploy to EC2 @@ -42,7 +42,7 @@ jobs: port: 22 script: | # Pull the latest image - sudo docker pull ${{ secrets.DOCKERHUB_USER_NAME }}/nextblog:5.0 + sudo docker pull ${{ secrets.DOCKERHUB_USER_NAME }}/nextblog:7.0 # Check if the container is running and stop/remove it if it exists if [ "$(sudo docker ps -a -q -f name=nextblog)" ]; then @@ -58,4 +58,4 @@ jobs: # Run the container echo "Starting a new container..." - sudo docker run -d --name nextblog --env-file .env -p 9000:5000 ${{ secrets.DOCKERHUB_USER_NAME }}/nextblog:5.0 + sudo docker run -d --name nextblog --env-file .env -p 9000:5000 ${{ secrets.DOCKERHUB_USER_NAME }}/nextblog:7.0 diff --git a/Dockerfile b/Dockerfile index 5eac88a..d25b658 100644 --- a/Dockerfile +++ b/Dockerfile @@ -17,4 +17,4 @@ COPY . . EXPOSE 5000 # Define the command to run your application. -CMD ["sh", "-c", "npx prisma generate && npx prisma migrate deploy && yarn build && yarn start"] +CMD ["sh", "-c", "yarn migrate && yarn build && yarn start"] From 90998a35975e9fe722115d21635ac449b1c8a1b1 Mon Sep 17 00:00:00 2001 From: mizanmahi Date: Mon, 7 Oct 2024 21:58:08 +0600 Subject: [PATCH 5/6] updated workflow --- src/app/modules/Admin/admin.service.ts | 2 +- src/app/modules/{User => userssss}/user.constant.ts | 0 src/app/modules/{User => userssss}/user.controller.ts | 0 src/app/modules/{User => userssss}/user.interface.ts | 0 src/app/modules/{User => userssss}/user.routes.ts | 0 src/app/modules/{User => userssss}/user.service.ts | 0 src/app/modules/{User => userssss}/user.validationSchema.ts | 0 src/app/routes/index.ts | 2 +- 8 files changed, 2 insertions(+), 2 deletions(-) rename src/app/modules/{User => userssss}/user.constant.ts (100%) rename src/app/modules/{User => userssss}/user.controller.ts (100%) rename src/app/modules/{User => userssss}/user.interface.ts (100%) rename src/app/modules/{User => userssss}/user.routes.ts (100%) rename src/app/modules/{User => userssss}/user.service.ts (100%) rename src/app/modules/{User => userssss}/user.validationSchema.ts (100%) diff --git a/src/app/modules/Admin/admin.service.ts b/src/app/modules/Admin/admin.service.ts index 7726ee5..0f4ae3c 100644 --- a/src/app/modules/Admin/admin.service.ts +++ b/src/app/modules/Admin/admin.service.ts @@ -4,7 +4,7 @@ import { IPaginationParams, ISortingParams, } from '../../interfaces/paginationSorting'; -import { IUserFilterParams } from '../user/user.interface'; +import { IUserFilterParams } from '../userssss/user.interface'; import { generatePaginateAndSortOptions } from '../../../helpers/paginationHelpers'; import { searchableFields } from './admin.constants'; diff --git a/src/app/modules/User/user.constant.ts b/src/app/modules/userssss/user.constant.ts similarity index 100% rename from src/app/modules/User/user.constant.ts rename to src/app/modules/userssss/user.constant.ts diff --git a/src/app/modules/User/user.controller.ts b/src/app/modules/userssss/user.controller.ts similarity index 100% rename from src/app/modules/User/user.controller.ts rename to src/app/modules/userssss/user.controller.ts diff --git a/src/app/modules/User/user.interface.ts b/src/app/modules/userssss/user.interface.ts similarity index 100% rename from src/app/modules/User/user.interface.ts rename to src/app/modules/userssss/user.interface.ts diff --git a/src/app/modules/User/user.routes.ts b/src/app/modules/userssss/user.routes.ts similarity index 100% rename from src/app/modules/User/user.routes.ts rename to src/app/modules/userssss/user.routes.ts diff --git a/src/app/modules/User/user.service.ts b/src/app/modules/userssss/user.service.ts similarity index 100% rename from src/app/modules/User/user.service.ts rename to src/app/modules/userssss/user.service.ts diff --git a/src/app/modules/User/user.validationSchema.ts b/src/app/modules/userssss/user.validationSchema.ts similarity index 100% rename from src/app/modules/User/user.validationSchema.ts rename to src/app/modules/userssss/user.validationSchema.ts diff --git a/src/app/routes/index.ts b/src/app/routes/index.ts index 6752eb1..4cbc751 100644 --- a/src/app/routes/index.ts +++ b/src/app/routes/index.ts @@ -1,5 +1,5 @@ import express from 'express'; -import { userRoutes } from '../modules/user/user.routes'; +import { userRoutes } from '../modules/userssss/user.routes'; import { AdminRoutes } from '../modules/admin/admin.routes'; import { authRoutes } from '../modules/auth/auth.routes'; From 869e2867b3bbadc24e835ab22e288da5af7a6783 Mon Sep 17 00:00:00 2001 From: mizanmahi Date: Mon, 7 Oct 2024 21:58:42 +0600 Subject: [PATCH 6/6] updated workflow --- src/app/modules/Admin/admin.service.ts | 2 +- src/app/modules/{userssss => user}/user.constant.ts | 0 src/app/modules/{userssss => user}/user.controller.ts | 0 src/app/modules/{userssss => user}/user.interface.ts | 0 src/app/modules/{userssss => user}/user.routes.ts | 0 src/app/modules/{userssss => user}/user.service.ts | 0 src/app/modules/{userssss => user}/user.validationSchema.ts | 0 src/app/routes/index.ts | 2 +- 8 files changed, 2 insertions(+), 2 deletions(-) rename src/app/modules/{userssss => user}/user.constant.ts (100%) rename src/app/modules/{userssss => user}/user.controller.ts (100%) rename src/app/modules/{userssss => user}/user.interface.ts (100%) rename src/app/modules/{userssss => user}/user.routes.ts (100%) rename src/app/modules/{userssss => user}/user.service.ts (100%) rename src/app/modules/{userssss => user}/user.validationSchema.ts (100%) diff --git a/src/app/modules/Admin/admin.service.ts b/src/app/modules/Admin/admin.service.ts index 0f4ae3c..7726ee5 100644 --- a/src/app/modules/Admin/admin.service.ts +++ b/src/app/modules/Admin/admin.service.ts @@ -4,7 +4,7 @@ import { IPaginationParams, ISortingParams, } from '../../interfaces/paginationSorting'; -import { IUserFilterParams } from '../userssss/user.interface'; +import { IUserFilterParams } from '../user/user.interface'; import { generatePaginateAndSortOptions } from '../../../helpers/paginationHelpers'; import { searchableFields } from './admin.constants'; diff --git a/src/app/modules/userssss/user.constant.ts b/src/app/modules/user/user.constant.ts similarity index 100% rename from src/app/modules/userssss/user.constant.ts rename to src/app/modules/user/user.constant.ts diff --git a/src/app/modules/userssss/user.controller.ts b/src/app/modules/user/user.controller.ts similarity index 100% rename from src/app/modules/userssss/user.controller.ts rename to src/app/modules/user/user.controller.ts diff --git a/src/app/modules/userssss/user.interface.ts b/src/app/modules/user/user.interface.ts similarity index 100% rename from src/app/modules/userssss/user.interface.ts rename to src/app/modules/user/user.interface.ts diff --git a/src/app/modules/userssss/user.routes.ts b/src/app/modules/user/user.routes.ts similarity index 100% rename from src/app/modules/userssss/user.routes.ts rename to src/app/modules/user/user.routes.ts diff --git a/src/app/modules/userssss/user.service.ts b/src/app/modules/user/user.service.ts similarity index 100% rename from src/app/modules/userssss/user.service.ts rename to src/app/modules/user/user.service.ts diff --git a/src/app/modules/userssss/user.validationSchema.ts b/src/app/modules/user/user.validationSchema.ts similarity index 100% rename from src/app/modules/userssss/user.validationSchema.ts rename to src/app/modules/user/user.validationSchema.ts diff --git a/src/app/routes/index.ts b/src/app/routes/index.ts index 4cbc751..6752eb1 100644 --- a/src/app/routes/index.ts +++ b/src/app/routes/index.ts @@ -1,5 +1,5 @@ import express from 'express'; -import { userRoutes } from '../modules/userssss/user.routes'; +import { userRoutes } from '../modules/user/user.routes'; import { AdminRoutes } from '../modules/admin/admin.routes'; import { authRoutes } from '../modules/auth/auth.routes';