From f958bb2bfe8759b482bd2426bceedb0f8c984891 Mon Sep 17 00:00:00 2001 From: Daoud-Hussain Date: Fri, 15 Nov 2024 10:09:53 +0500 Subject: [PATCH] Commits from stagging branch --- .github/workflows/deploy.yml | 22 -------- .github/workflows/dev-cicd.yml | 72 +++++++++++++++++++++++++ .github/workflows/integration.yml | 88 +++++++++++++++---------------- 3 files changed, 116 insertions(+), 66 deletions(-) delete mode 100644 .github/workflows/deploy.yml create mode 100644 .github/workflows/dev-cicd.yml diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml deleted file mode 100644 index 72f035a..0000000 --- a/.github/workflows/deploy.yml +++ /dev/null @@ -1,22 +0,0 @@ -name: Deploy - -on: - push: - branches: [ "main" ] - -jobs: - deploy: - - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v4 - - - name: "Building docker image" - run: docker build -t daoudhussaindev/next-js-app . - - - name: "Login Docker" - run: echo "${{secrets.DOCKER_PASSWORD}}" | docker login -u ${{secrets.DOCKER_USERNAME}} --password-stdin - - - name: "Pushing Image to dockerhub" - run: docker push daoudhussaindev/next-js-app:latest \ No newline at end of file diff --git a/.github/workflows/dev-cicd.yml b/.github/workflows/dev-cicd.yml new file mode 100644 index 0000000..15779e3 --- /dev/null +++ b/.github/workflows/dev-cicd.yml @@ -0,0 +1,72 @@ +name: Dev CI/CD Pipeline + +on: + push: + branches: + - dev + pull_request: + branches: + - dev + +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/dev' + + steps: + - uses: actions/checkout@v4 + - name: Build Docker image for dev + run: docker build -t ${{ env.IMAGE_NAME }}:dev . + - 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 (dev) + run: docker push ${{ env.IMAGE_NAME }}:dev + - name: Deploy to Dev Server + run: | + ssh -o StrictHostKeyChecking=no ${{ secrets.DEV_SERVER_USER }}@${{ secrets.DEV_SERVER_IP }} << 'EOF' + docker pull ${{ env.IMAGE_NAME }}:dev + docker stop dev-container || true + docker rm dev-container || true + docker run -d --name dev-container -p 3000:3000 ${{ env.IMAGE_NAME }}:dev + EOF diff --git a/.github/workflows/integration.yml b/.github/workflows/integration.yml index d9be68c..a7a4034 100644 --- a/.github/workflows/integration.yml +++ b/.github/workflows/integration.yml @@ -1,53 +1,53 @@ -name: Integration - -on: - push: - branches: [ "main" ] - pull_request: - branches: [ "main" ] - -jobs: - build: - - runs-on: ubuntu-latest - - strategy: - matrix: - node-version: [18.x, 20.x, 22.x] - - steps: - - uses: actions/checkout@v4 - - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v3 - with: - node-version: ${{ matrix.node-version }} - cache: 'npm' +# name: Integration + +# on: +# push: +# branches: [ "main" ] +# pull_request: +# branches: [ "main" ] + +# jobs: +# build: + +# runs-on: ubuntu-latest + +# strategy: +# matrix: +# node-version: [18.x, 20.x, 22.x] + +# steps: +# - uses: actions/checkout@v4 +# - name: Use Node.js ${{ matrix.node-version }} +# uses: actions/setup-node@v3 +# with: +# node-version: ${{ matrix.node-version }} +# cache: 'npm' - - name: "Installing Dependencies" - run: npm i +# - name: "Installing Dependencies" +# run: npm i - - name: "Build command" - run: npm run build +# - name: "Build command" +# run: npm run build - unit-tests: +# unit-tests: - runs-on: ubuntu-latest +# runs-on: ubuntu-latest - strategy: - matrix: - node-version: [18.x, 20.x, 22.x] +# strategy: +# matrix: +# node-version: [18.x, 20.x, 22.x] - steps: - - uses: actions/checkout@v4 - - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v3 - with: - node-version: ${{ matrix.node-version }} - cache: 'npm' +# steps: +# - uses: actions/checkout@v4 +# - name: Use Node.js ${{ matrix.node-version }} +# uses: actions/setup-node@v3 +# with: +# node-version: ${{ matrix.node-version }} +# cache: 'npm' - - name: "Installing Dependencies" - run: npm i +# - name: "Installing Dependencies" +# run: npm i - - name: "Running test cases" - run: npm run test \ No newline at end of file +# - name: "Running test cases" +# run: npm run test \ No newline at end of file