name: Build and Push Docker Images

on:
  push:
    branches: [ roman ]

env:
  REGISTRY: git.nullptr.top

jobs:
  build:
    runs-on: ubuntu-latest
    strategy:
      max-parallel: 2
      matrix:
        service: [ gateway, worker ]
        include:
          - service: gateway
            dockerfile: src/LiquidCode.Tester.Gateway/Dockerfile
            image: git.nullptr.top/liquidcode/liquidcode-tester-gateway-roman
          - service: worker
            dockerfile: src/LiquidCode.Tester.Worker/Dockerfile
            image: git.nullptr.top/liquidcode/liquidcode-tester-worker-roman
    steps:
      - name: Checkout repository
        uses: actions/checkout@v4

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

      - name: Log in to Container Registry
        uses: docker/login-action@v3
        with:
          registry: ${{ env.REGISTRY }}
          username: liquidcode-ci-service 
          password: ${{ secrets.SERVICE_ACCOUNT_TOKEN }}

      - name: Build and Push ${{ matrix.service }} image
        uses: docker/build-push-action@v6
        with:
          context: .
          file: ${{ matrix.dockerfile }}
          push: true
          tags: ${{ matrix.image }}:latest,${{ matrix.image }}:${{ gitea.sha }}
          cache-from: type=registry,ref=${{ matrix.image }}:buildcache
          cache-to: type=registry,ref=${{ matrix.image }}:buildcache,mode=max
