name: Build STT Container

on:
  push:
    branches: [main]
    paths:
      - "stt-container/**"
      - ".gitea/workflows/build-stt.yml"
  pull_request:
    branches: [main]
    paths:
      - "stt-container/**"
      - ".gitea/workflows/build-stt.yml"

env:
  REGISTRY: repo.anhonesthost.net
  IMAGE_NAME: cybercovellc/triple-c/triple-c-stt

jobs:
  build-stt-container:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Set up QEMU
        uses: docker/setup-qemu-action@v3

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

      - name: Login to Gitea Container Registry
        uses: docker/login-action@v3
        with:
          registry: ${{ env.REGISTRY }}
          username: ${{ gitea.actor }}
          password: ${{ secrets.REGISTRY_TOKEN }}

      - name: Login to GitHub Container Registry
        uses: docker/login-action@v3
        with:
          registry: ghcr.io
          username: shadowdao
          password: ${{ secrets.GH_PAT }}

      - name: Build and push STT container image
        uses: docker/build-push-action@v5
        with:
          context: ./stt-container
          file: ./stt-container/Dockerfile
          platforms: linux/amd64,linux/arm64
          push: ${{ gitea.event_name == 'push' }}
          tags: |
            ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
            ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ gitea.sha }}
            ghcr.io/shadowdao/triple-c-stt:latest
            ghcr.io/shadowdao/triple-c-stt:${{ gitea.sha }}
          cache-from: type=gha
          cache-to: type=gha,mode=max
