name: ghaymah_exam CI/CD

on:
  push:
    branches:
      - main

permissions:
  contents: read
  packages: write

jobs:
  build-and-push:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout repository
        uses: actions/checkout@v4

      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v3

      - name: Log in to GitHub Container Registry
        uses: docker/login-action@v3
        with:
          registry: ghcr.io
          username: ${{ github.actor }}
          password: ${{ secrets.GITHUB_TOKEN }}

      - name: Build and push Docker image
        uses: docker/build-push-action@v6
        with:
          context: ./q1-deploy-monitor
          file: ./q1-deploy-monitor/Dockerfile
          push: true
          tags: |
            ghcr.io/${{ github.repository_owner }}/ghaymah-exam-ahmednasser-sre:latest
            ghcr.io/${{ github.repository_owner }}/ghaymah-exam-ahmednasser-sre:${{ github.sha }}

  deploy-production:
    name: Deploy to Production
    needs: build-and-push
    runs-on: ubuntu-latest

    environment:
      name: production

    steps:
      - name: Deploy application
        run: |
          echo "Deploying image to production..."