name: Build and Publish
run-name: ${{ gitea.actor }} build 🚀
on: [push]

jobs:
  BuildAndDeployAmd64:
    runs-on: amd64
    steps:
      - uses: actions/checkout@v5
      - name: Build amd64 image
        run: |
          docker build \
            --progress=plain \
            -t registry.knatofs.se/go-cart-actor-amd64:latest \
            .
      - name: Push amd64 images
        run: |
          docker push registry.knatofs.se/go-cart-actor-amd64:latest
      - name: Apply deployment manifests
        run: kubectl apply -f deployment/deployment.yaml -n cart
      - name: Rollout amd64 backoffice deployment
        run: |
          kubectl rollout restart deployment/cart-backoffice-x86 -n cart

  BuildAndDeployArm64:
    runs-on: arm64
    steps:
      - uses: actions/checkout@v5
      - name: Build arm64 image
        run: |
          docker build \
            --progress=plain \
            -t registry.knatofs.se/go-cart-actor:latest \
            -t registry.knatofs.se/go-cart-actor:${{ needs.Metadata.outputs.version }} \
            .
      - name: Push arm64 images
        run: |
          docker push registry.knatofs.se/go-cart-actor:latest
      # - name: Rollout arm64 deployment (pin to version)
      #   run: |
      #     kubectl set image deployment/cart-actor-arm64 -n cart cart-actor-arm64=registry.knatofs.se/go-cart-actor:${{ needs.Metadata.outputs.version }}
      #     # kubectl rollout status deployment/cart-actor-arm64 -n cart
