name: Build Docker Image
description: Builds a Docker image using Docker Buildx
inputs:
  dockerfile:
    description: Path to the Dockerfile
    required: true
  tags:
    description: Comma-separated list of tags for the Docker image
    required: true
  push:
    description: Whether to push the Docker image to the registry
    required: false
    default: "false"
  token:
    description: GitHub Token
    required: false
runs:
  using: composite
  steps:
    - name: Checkout Repository
      uses: actions/checkout@v4

    - name: Setup QEMU
      uses: docker/setup-qemu-action@v3

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

    - name: Login to GitHub Container Registry
      if: ${{ inputs.push == 'true' }}
      uses: docker/login-action@v3
      with:
        registry: ghcr.io
        username: ${{ github.actor }}
        password: ${{ inputs.token }}

    - name: Build Docker Image
      uses: docker/build-push-action@v5
      with:
        context: .
        file: ${{ inputs.dockerfile }}
        platforms: linux/amd64,linux/arm64
        push: ${{ inputs.push }}
        tags: ${{ inputs.tags }}
        cache-from: type=gha
        cache-to: type=gha,mode=max
