name: Build and Deploy

on:
  workflow_dispatch: # Transformado em acionamento manual para não rodar duplicado

jobs:
  build-and-push:
    runs-on: ubuntu-latest
    permissions:
      contents: read
      packages: write

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

      # Adiciona suporte a QEMU para conseguir buildar ARM64 em runners AMD64
      - name: Set up QEMU
        uses: docker/setup-qemu-action@v3

      - 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 Manager
        uses: docker/build-push-action@v5
        with:
          context: ./manager
          push: true
          # Constrói para as duas arquiteturas
          platforms: linux/amd64,linux/arm64
          tags: ghcr.io/${{ github.repository }}/edumanager:latest

      - name: Build and push Portal
        uses: docker/build-push-action@v5
        with:
          context: ./portal
          push: true
          # Constrói para as duas arquiteturas
          platforms: linux/amd64,linux/arm64
          tags: ghcr.io/${{ github.repository }}/portalaluno:latest