name: build-and-push

on:
  push:
    branches:
      - main
      - high-performance

jobs:
  build:
    runs-on: ubuntu-latest
    env:
      DOCKER_HOST: unix:///var/run/docker.sock
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Set up Docker Buildx
        run: |
          export DOCKER_HOST=unix:///var/run/docker.sock
          docker version
          docker buildx create --use || true
          docker buildx inspect --bootstrap

      - name: Login to Registry
        env:
          REGISTRY_HOSTPORT: ${{ secrets.REGISTRY_HOSTPORT }}
          REGISTRY_USERNAME: ${{ secrets.REGISTRY_USERNAME }}
          REGISTRY_PASSWORD: ${{ secrets.REGISTRY_PASSWORD }}
        run: |
          set -euo pipefail
          export DOCKER_HOST=unix:///var/run/docker.sock
          test -n "$REGISTRY_HOSTPORT"
          echo "$REGISTRY_PASSWORD" | docker login "$REGISTRY_HOSTPORT" -u "$REGISTRY_USERNAME" --password-stdin

      - name: Build and push
        env:
          REGISTRY_HOSTPORT: ${{ secrets.REGISTRY_HOSTPORT }}
        run: |
          set -euo pipefail
          export DOCKER_HOST=unix:///var/run/docker.sock
          docker buildx build --push \
            -f Dockerfile \
            -t "$REGISTRY_HOSTPORT/nxtgauge-frontend-solid:${{ gitea.sha }}" \
            -t "$REGISTRY_HOSTPORT/nxtgauge-frontend-solid:high-performance-latest" \
            .
