name: Docker Image CI

on:
  push:
    branches: [ main ]
jobs:

  build:

    runs-on: ubuntu-latest

    steps:
    - name: Docker meta
      id: meta
      uses: docker/metadata-action@v4
      with:
        images: ghcr.io/claperco/claper
        tags: |
          type=ref,event=branch
          type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'main') }}
          type=semver,pattern={{version}}
          type=semver,pattern={{major}}.{{minor}}
          type=semver,pattern={{major}}

    - uses: actions/checkout@v3
    - name: Set up QEMU
      id: qemu
      uses: docker/setup-qemu-action@v1
      with:
        image: tonistiigi/binfmt:latest
        platforms: all
    - name: Set up Docker Buildx
      uses: docker/setup-buildx-action@v1
      with:
        buildkitd-flags: --debug
        driver-opts: image=moby/buildkit:v0.9.1
    - name: Log in to registry
      # This is where you will update the PAT to GITHUB_TOKEN
      run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u $ --password-stdin
    - name: Build and push Docker images
      # You may pin to the exact commit or the version.
      # uses: docker/build-push-action@ac9327eae2b366085ac7f6a2d02df8aa8ead720a
      uses: docker/build-push-action@v2.10.0
      with:
        context: .
        push: true
        tags: ${{ steps.meta.outputs.tags }}
        labels: ${{ steps.meta.outputs.labels }}
        cache-from: type=gha
        cache-to: type=gha,mode=max


