name: Build and Push Docker Image

on:
  push:
    branches: [main]
  workflow_dispatch:

jobs:
  build:
    # Run directly on the forgerunner host: the bundled Docker CLI and the
    # mounted /var/run/docker.sock are available, so no nested-container or
    # socket juggling is needed.
    runs-on: host
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Log in to Gitea Container Registry
        uses: docker/login-action@v3
        with:
          registry: registry.alwisp.com
          username: ${{ secrets.REGISTRY_USER }}
          password: ${{ secrets.REGISTRY_TOKEN }}

      - name: Build and Push
        run: |
          # gitea.repository is already "owner/repo" (e.g. jason/breedr).
          IMAGE="registry.alwisp.com/${{ gitea.repository }}"
          docker build -t "${IMAGE}:latest" -t "${IMAGE}:${{ gitea.sha }}" .
          docker push "${IMAGE}:latest"
          docker push "${IMAGE}:${{ gitea.sha }}"
