name: Build Release Docker Image

on:
  push:
    tags:
      - 'v[0-9]+.[0-9]+.[0-9]+'

jobs:
  docker:
    runs-on: ubuntu-latest
    permissions:
      packages: write
      contents: read
      attestations: write
      id-token: write
    steps:
      - name: Checkout
        uses: actions/checkout@v4
        with:
          submodules: 'true'
      - name: Install dotnet tool
        run: dotnet tool install -g dotnetCampus.TagToVersion
      - name: Set tag to version  
        run: dotnet TagToVersion -t ${{ github.ref }}
      - name: Sign in to Nuget
        run: dotnet nuget add source --username michael-j-green --password ${{ secrets.NUGETKEY }} --store-password-in-clear-text --name github "https://nuget.pkg.github.com/gaseous-project/index.json"
      - name: Set up QEMU
        uses: docker/setup-qemu-action@v3
      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v3
      - name: Login to Docker Hub
        uses: docker/login-action@v3
        with:
          username: ${{ secrets.DOCKERHUB_USERNAME }}
          password: ${{ secrets.DOCKERHUB_TOKEN }}
      - name: Login to GitHub Package Registry
        uses: docker/login-action@v3
        with:
          registry: ghcr.io
          username: ${{ github.actor }}
          password: ${{ secrets.GITHUB_TOKEN }}
      - name: Build and push standard image
        uses: docker/build-push-action@v6
        with:
          context: .
          file: ./build/Dockerfile
          platforms: linux/amd64,linux/arm64
          push: true
          tags: |
            gaseousgames/gaseousserver:latest
            gaseousgames/gaseousserver:${{ github.ref_name}}
            ghcr.io/gaseous-project/gaseousserver:latest
            ghcr.io/gaseous-project/gaseousserver:${{ github.ref_name}}
      - name: Build and push image with embedded mariadb
        uses: docker/build-push-action@v6
        with:
          context: .
          file: ./build/Dockerfile-EmbeddedDB
          platforms: linux/amd64,linux/arm64
          push: true
          tags: |
            gaseousgames/gaseousserver:latest-embeddeddb
            gaseousgames/gaseousserver:${{ github.ref_name}}-embeddeddb
            ghcr.io/gaseous-project/gaseousserver:latest-embeddeddb
            ghcr.io/gaseous-project/gaseousserver:${{ github.ref_name}}-embeddeddb
