name: Compila e pubblica sul registro integrato
on: [push]

jobs:
  Build-Docker-Image:
    runs-on: linux_amd64
    container: gitea.laprogrammatriceverde.crabdance.com/verde/gitea-actions
    steps:
      - name: Login to Docker Registry
        run: echo "${{ secrets.REGISTRYTOKEN }}" | docker login "${{ vars.REGISTRY_URL }}" -u "${{ github.repository_owner }}" --password-stdin

      - name: Checkout Code
        uses: actions/checkout@v4
        
      - name: Set repository name lowercase
        run: echo "REPO_LOWERCASE=$(echo '${{ github.repository }}' | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV

      - name: Set up QEMU
        uses: docker/setup-qemu-action@v2

      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v2

      - name: Build and push
        id: docker_build
        uses: docker/build-push-action@v3
        with:
          context: .
          file: ./Dockerfile
          platforms: linux/amd64,linux/arm64
          push: true
          tags: ${{ env.REPO_LOWERCASE }}:latest

      #- name: Build Docker image
      #  run: |
      #    docker build -t $REPO_LOWERCASE:latest .          

      - name: Publish Docker image
        run: |
          docker tag "$REPO_LOWERCASE":latest "${{ vars.REGISTRY_URL }}"/"$REPO_LOWERCASE":latest
          docker push "${{ vars.REGISTRY_URL }}"/"$REPO_LOWERCASE:latest"          