From 13805d779c2abf3d39643e474b505025e6062d67 Mon Sep 17 00:00:00 2001 From: Somnath Chataraj Date: Mon, 29 Jul 2024 18:49:22 +0530 Subject: [PATCH] Add CI/CD pipeline --- .github/workflows/build.yaml | 44 +++++++++++++++++++++++++++++++++++ .github/workflows/deploy.yaml | 30 ++++++++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 .github/workflows/build.yaml create mode 100644 .github/workflows/deploy.yaml diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml new file mode 100644 index 0000000..503f182 --- /dev/null +++ b/.github/workflows/build.yaml @@ -0,0 +1,44 @@ +name: Build and Migrate + +on: + push: + branches: + - main + pull_request: + branches: + - main + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Set up Node.js + uses: actions/setup-node@v3 + with: + node-version: '20' + cache: 'npm' + + - name: Navigate to backend directory + run: cd backend + + - name: Install dependencies + run: npm install + working-directory: backend + + - name: Build code + run: npm run build + working-directory: backend + + - name: Set up Prisma + run: npx prisma generate + working-directory: backend + + - name: Run Prisma Migrate + env: + DATABASE_URL: ${{ secrets.DATABASE_URL }} + run: npx prisma migrate deploy + working-directory: backend diff --git a/.github/workflows/deploy.yaml b/.github/workflows/deploy.yaml new file mode 100644 index 0000000..d8bc79b --- /dev/null +++ b/.github/workflows/deploy.yaml @@ -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: ./backend/Dockerfile + push: true + tags: somnath910/statuscode1:latest # Replace with your Docker Hub username and repository + + - name: Verify Pushed Image + run: docker pull somnath910/statuscode1:latest # Replace with your Docker Hub username and repository