name: Build

on:
  push:
    tags:        
      - 'v*'

jobs:
  build:
    steps:
      - name: Checkout
        uses: actions/checkout@v2

      - name: Extract Version Tag
        id: extract-version
        run: echo "docker_tag=$(grep -oP '(?<=FROM nextcloud:)[0-9]+\.[0-9]+\.[0-9]+' Dockerfile)" >> $GITHUB_OUTPUT
        shell: bash
      
      - name: Install Docker
        run: |
          apt-get update
          apt-get install docker.io -y

      - name: Login to DockerHub
        uses: docker/login-action@v1
        with:
          username: ${{ secrets.DOCKERHUB_USERNAME }}
          password: ${{ secrets.DOCKERHUB_TOKEN }}

      - name: Set up QEMU
        uses: docker/setup-qemu-action@v2
      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v1
        with:
          driver-opts: network=host
          platforms: linux/amd64,linux/arm64

      - name: Build image
        uses: docker/build-push-action@v2
        with:
          push: true
          tags: jiriks74/nextcloud-extended:${{ steps.extract-version.outputs.docker_tag }},jiriks74/nextcloud-extended:latest
          platforms: linux/amd64,linux/arm64
          context: .
          file: ./Dockerfile

      # - name: Build image
      #   uses: docker/build-push-action@v2
      #   with:
      #     push: true
      #     tags:
      #       jiriks74/nextcloud-extended:latest
      #     platforms: linux/amd64,linux/arm64
      #     context: .
      #     file: ./Dockerfile

      # - name: Tag latest
      #   run: |
      #     docker image ls
          # docker tag nextcloud-extended:${{ steps.extract-version.outputs.docker_tag }} nextcloud-extended:latest
          # docker push nextcloud-extended:latest