name: Build docker image

on:
  release:
    types: [published]

jobs:
  multi:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v2
      - name: Set up QEMU
        id: qemu
        uses: docker/setup-qemu-action@v2
        with:
          platforms: linux/amd64,linux/arm64,linux/arm/v7
      - name: Available platforms
        run: echo ${{ steps.qemu.outputs.platforms }}
      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v2
      - name: Parse the git tag
        id: get_tag
        run: echo ::set-output name=TAG::$(echo $GITHUB_REF | cut -d / -f 3)
      - name: Login to DockerHub
        uses: docker/login-action@v2
        with:
          username: ${{ secrets.DOCKER_USERNAME }}
          password: ${{ secrets.DOCKER_TOKEN }}
      - name: Login to GitHub
        uses: docker/login-action@v1
        with:
          registry: ghcr.io
          username: ${{ github.actor }}
          password: ${{ secrets.GITHUB_TOKEN }}
      - name: Build and push
        uses: docker/build-push-action@v4
        with:
          context: .
          file: ./Dockerfile
          platforms: linux/amd64,linux/arm64,linux/arm/v7
          push: true
          # cache-from: type=local,src=/tmp/.buildx-cache
          # cache-to: type=local,dest=/tmp/.buildx-cache
          tags: |
            alfhou/hammond:latest
            alfhou/hammond:${{ steps.get_tag.outputs.TAG }}
            ghcr.io/alfhou/hammond:latest
            ghcr.io/alfhou/hammond:${{ steps.get_tag.outputs.TAG }}
