From 1a6fdcab67e8e64fc8e397977b8a118d75ac2c68 Mon Sep 17 00:00:00 2001 From: Daoud-Hussain Date: Fri, 15 Nov 2024 11:03:42 +0500 Subject: [PATCH 1/3] Test change triggered from dev branch --- .github/workflows/dev-cicd.yml | 2 +- .github/workflows/prod-cicd.yml | 72 +++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+), 1 deletion(-) diff --git a/.github/workflows/dev-cicd.yml b/.github/workflows/dev-cicd.yml index 8f99cb0..e8fb90a 100644 --- a/.github/workflows/dev-cicd.yml +++ b/.github/workflows/dev-cicd.yml @@ -1,4 +1,4 @@ -name: Dev - CI/CD Pipeline +name: Dev CI/CD Pipeline on: push: diff --git a/.github/workflows/prod-cicd.yml b/.github/workflows/prod-cicd.yml index e69de29..955ec51 100644 --- a/.github/workflows/prod-cicd.yml +++ b/.github/workflows/prod-cicd.yml @@ -0,0 +1,72 @@ +name: Production CI/CD Pipeline + +on: + push: + branches: + - main + pull_request: + branches: + - staging + +env: + IMAGE_NAME: daoudhussaindev/next-js-app + +jobs: + build: + runs-on: ubuntu-latest + strategy: + matrix: + node-version: [18.x] + + steps: + - uses: actions/checkout@v4 + - name: Set up Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v3 + with: + node-version: ${{ matrix.node-version }} + cache: 'npm' + - name: Install dependencies + run: npm ci + - name: Build Next.js application + run: npm run build + + test: + runs-on: ubuntu-latest + needs: build + strategy: + matrix: + node-version: [18.x] + + steps: + - uses: actions/checkout@v4 + - name: Set up Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v3 + with: + node-version: ${{ matrix.node-version }} + cache: 'npm' + - name: Install dependencies + run: npm ci + - name: Run tests + run: npm run test + + deploy: + runs-on: ubuntu-latest + needs: [test] + if: github.ref == 'refs/heads/main' + + steps: + - uses: actions/checkout@v4 + - name: Build Docker image for production + run: docker build -t ${{ env.IMAGE_NAME }}:latest . + - name: Login to Docker Hub + run: echo "${{ secrets.DOCKER_PASSWORD_DEV }}" | docker login -u "${{ secrets.DOCKER_USERNAME_DEV }}" --password-stdin + - name: Push Docker image to Docker Hub (latest) + run: docker push ${{ env.IMAGE_NAME }}:latest + # - name: Deploy to Production Server + # run: | + # ssh -o StrictHostKeyChecking=no ${{ secrets.PROD_SERVER_USER }}@${{ secrets.PROD_SERVER_IP }} << 'EOF' + # docker pull ${{ env.IMAGE_NAME }}:latest + # docker stop prod-container || true + # docker rm prod-container || true + # docker run -d --name prod-container -p 80:3000 ${{ env.IMAGE_NAME }}:latest + # EOF From 5472f02776e84dbd5ab60597835d3b0342b66587 Mon Sep 17 00:00:00 2001 From: Daoud-Hussain Date: Fri, 15 Nov 2024 11:32:39 +0500 Subject: [PATCH 2/3] final changes --- .github/workflows/prod-cicd.yml | 2 +- .github/workflows/stagging-cicd.yml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/prod-cicd.yml b/.github/workflows/prod-cicd.yml index 955ec51..489b5f9 100644 --- a/.github/workflows/prod-cicd.yml +++ b/.github/workflows/prod-cicd.yml @@ -3,7 +3,7 @@ name: Production CI/CD Pipeline on: push: branches: - - main + - stagging pull_request: branches: - staging diff --git a/.github/workflows/stagging-cicd.yml b/.github/workflows/stagging-cicd.yml index b29946e..ccc0ab0 100644 --- a/.github/workflows/stagging-cicd.yml +++ b/.github/workflows/stagging-cicd.yml @@ -3,10 +3,10 @@ name: Staging CI/CD Pipeline on: push: branches: - - staging + - dev pull_request: branches: - - dev + - stagging env: IMAGE_NAME: daoudhussaindev/next-js-app From 2e96d87143aaf29ec69cf5140759d3866325bc23 Mon Sep 17 00:00:00 2001 From: Daoud-Hussain Date: Fri, 15 Nov 2024 11:39:24 +0500 Subject: [PATCH 3/3] Test dev commits --- .github/workflows/prod-cicd.yml | 2 +- .github/workflows/stagging-cicd.yml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/prod-cicd.yml b/.github/workflows/prod-cicd.yml index 489b5f9..955ec51 100644 --- a/.github/workflows/prod-cicd.yml +++ b/.github/workflows/prod-cicd.yml @@ -3,7 +3,7 @@ name: Production CI/CD Pipeline on: push: branches: - - stagging + - main pull_request: branches: - staging diff --git a/.github/workflows/stagging-cicd.yml b/.github/workflows/stagging-cicd.yml index ccc0ab0..0228286 100644 --- a/.github/workflows/stagging-cicd.yml +++ b/.github/workflows/stagging-cicd.yml @@ -3,10 +3,10 @@ name: Staging CI/CD Pipeline on: push: branches: - - dev + - stagging pull_request: branches: - - stagging + - dev env: IMAGE_NAME: daoudhussaindev/next-js-app