name: Build & publish Docker images
on:
  push:

env:
  REGISTRY: ghcr.io
  IMAGE_NAME: ${{ github.repository }}

jobs:
  build-and-push-image:
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        include:
          - context: ./mock-alto-bundler
            dockerfile: ./mock-alto-bundler/Dockerfile
            image: ghcr.io/pimlicolabs/mock-alto-bundler
          - context: ./mock-verifying-paymaster
            dockerfile: ./mock-verifying-paymaster/Dockerfile
            image: ghcr.io/pimlicolabs/mock-verifying-paymaster
    permissions:
      contents: read
      packages: write

    steps:
      - name: Checkout repository
        uses: actions/checkout@v2

      - name: Log in to the Container registry
        uses: docker/login-action@v3
        with:
          registry: ${{ env.REGISTRY }}
          username: ${{ github.actor }}
          password: ${{ secrets.DOCKER_PASSWORD }}

      - name: Extract metadata (tags, labels) for Docker
        id: meta
        uses: docker/metadata-action@v5
        with:
          images: ${{ matrix.image }}

      - name: Build and push Docker images
        uses: docker/build-push-action@v5
        with:
          context: ${{ matrix.context }}
          file: ${{ matrix.dockerfile }}
          push: true
          tags: ${{ steps.meta.outputs.tags }}
          labels: ${{ steps.meta.outputs.labels }}