# Build rebacd for linux/amd64 and linux/arm64 and push ghcr.io/louvain-ai/rebacd:<version> and :latest on a `v*` tag.
name: image
on:
  push:
    tags: ["v*"]
permissions:
  contents: read

jobs:
  rebacd:
    runs-on: ubuntu-latest
    permissions:
      contents: read
      packages: write
    steps:
      - uses: actions/checkout@v4
      - name: Version from the tag
        run: echo "VERSION=${GITHUB_REF_NAME#v}" >> "$GITHUB_ENV"
      - uses: docker/setup-qemu-action@v3
      - uses: docker/setup-buildx-action@v3
      - uses: docker/login-action@v3
        with:
          registry: ghcr.io
          username: ${{ github.actor }}
          password: ${{ secrets.GITHUB_TOKEN }}
      - uses: docker/build-push-action@v6
        with:
          context: .
          platforms: linux/amd64,linux/arm64
          push: true
          tags: |
            ghcr.io/louvain-ai/rebacd:${{ env.VERSION }}
            ghcr.io/louvain-ai/rebacd:latest
          labels: |
            org.opencontainers.image.source=https://github.com/louvain-ai/pg_rebac
            org.opencontainers.image.licenses=Apache-2.0
            org.opencontainers.image.description=rebacd, the pg_rebac sync daemon: relays relationship writes to SpiceDB and keeps the projection in Postgres
            org.opencontainers.image.version=${{ env.VERSION }}
            org.opencontainers.image.revision=${{ github.sha }}
          cache-from: type=gha
          cache-to: type=gha,mode=max
