name: Release Build
on:
  push:
    tags:
      - builder-*

jobs:
  create-builder-docker-image:
    runs-on: ubuntu-latest
    container:
      image: docker:28.3.2-dind
    steps:
      - name: Checkout repository
        run: |
          # Install git
          apk add --no-cache git
          
          echo "=== GitHub Variables ==="
          echo "github.ref = ${{ github.ref }}"
          echo "github.ref_name = ${{ github.ref_name }}"
          echo "github.sha = ${{ github.sha }}"
          echo "github.repository = ${{ github.repository }}"
          echo "========================"
          git clone https://oauth2:${{ secrets.GITEATOKEN }}@direct-dev.ru/gitea/GiteaAdmin/hello_gitea.git hello_gitea
          cd hello_gitea
          git checkout ${{ github.ref }}

      - name: Setup Docker Buildx
        run: |
          # Docker is already installed in docker:dind image
          docker --version
          # Setup Docker Buildx for multi-platform builds
          docker buildx create --use
          docker buildx inspect --bootstrap

      - name: Login to Docker Hub
        run: |
          echo ${{ secrets.DOCKERHUB_TOKEN }} | docker login -u ${{ secrets.DOCKERHUB_USERNAME }} --password-stdin

      - name: Build multi-platform Docker images
        run: |
          cd hello_gitea
          # Build multi-platform images using buildx
          docker buildx build \
            --platform linux/amd64,linux/arm64 \
            --tag ${{ secrets.DOCKERHUB_USERNAME }}/my-build-golang-runner:${{ github.ref_name }} \
            --tag ${{ secrets.DOCKERHUB_USERNAME }}/my-build-golang-runner:latest \
            --push \
            .

