Skip to content

Merge pull request #11 from Daoud-Hussain/main #4

Merge pull request #11 from Daoud-Hussain/main

Merge pull request #11 from Daoud-Hussain/main #4

Workflow file for this run

name: Production CI/CD Pipeline
on:
push:
branches:
- stagging
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