name: Postgres image
on:
  push:
    branches:
      - main
    tags:
      - "v*"

env:
  MINOR_VERSIONS: '{"15": "10","17": "2"}'

jobs:
  buildAndPush:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        postgres_major:
          - "15"
          - "17"
    steps:
      - uses: actions/checkout@v4

      - name: Login to container registry
        uses: docker/login-action@v3
        with:
          registry: code.icb4dc0.de
          username: prskr
          password: ${{ secrets.RELEASE_TOKEN }}

      - name: Build and push
        uses: docker/build-push-action@v6
        with:
          file: postgres/Dockerfile
          platforms: linux/amd64,linux/arm64
          push: true
          tags: code.icb4dc0.de/prskr/supabase-operator/postgres:${{ matrix.postgres_major }}.${{ fromJSON(env.MINOR_VERSIONS)[matrix.postgres_major] }}.${{ github.run_number }}
          build-args: |
            POSTGRES_MAJOR=${{ matrix.postgres_major }}
            POSTGRES_MINOR=${{ fromJSON(env.MINOR_VERSIONS)[matrix.postgres_major] }}