name: RustDesk Web Api
on:
  workflow_dispatch:
    inputs:
      docker_username:
        description: 'docker user name'
        required: true
        default: ''
      docker_password:
        description: 'docker user password'
        required: true
        default: ''

jobs:
  alpine:
    runs-on: ubuntu-latest
    name: Build Docker Image (Alpine)
    steps:
      -
        name: Checkout
        uses: actions/checkout@v3

      -
        name: Release version
        id: release_version
        run: |
          app_version=$(cat version.py |sed -ne "s/APP_VERSION\s=\s'v\(.*\)'/\1/gp")
          echo "app_version=${app_version}" >> $GITHUB_ENV

      - name: Docker metadata
        id: meta
        uses: docker/metadata-action@v4
        with:
          images: |
            ${{ github.event.inputs.docker_username }}/rustdesk-api-server
          tags: |
            type=raw,value=${{ env.app_version }}
            type=raw,value=latest

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

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

      -
        name: Login DockerHub
        uses: docker/login-action@v2
        with:
          username: ${{ github.event.inputs.docker_username }}
          password: ${{ github.event.inputs.docker_password }}

      - 
        name: Build Image
        uses: docker/build-push-action@v4
        with:
          context: docker
          file: docker/Dockerfile
          platforms: |
            linux/amd64
            linux/arm64
          push: true
          tags: ${{ steps.meta.outputs.tags }}
          labels: ${{ steps.meta.outputs.labels }}

  debian:
    runs-on: ubuntu-latest
    name: Build Docker Image (Debian)
    steps:
      -
        name: Checkout
        uses: actions/checkout@v3

      -
        name: Release version
        id: release_version
        run: |
          app_version=$(cat version.py |sed -ne "s/APP_VERSION\s=\s'v\(.*\)'/\1/gp")
          echo "app_version=${app_version}-debian" >> $GITHUB_ENV

      - name: Docker metadata
        id: meta
        uses: docker/metadata-action@v4
        with:
          images: |
            ${{ github.event.inputs.docker_username }}/rustdesk-api-server
          tags: |
            type=raw,value=${{ env.app_version }}
            type=raw,value=debian

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

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

      -
        name: Login DockerHub
        uses: docker/login-action@v2
        with:
          username: ${{ github.event.inputs.docker_username }}
          password: ${{ github.event.inputs.docker_password }}

      - 
        name: Build Image
        uses: docker/build-push-action@v4
        with:
          context: docker
          file: docker/debian.Dockerfile
          platforms: |
            linux/amd64
            linux/arm64
          push: true
          tags: ${{ steps.meta.outputs.tags }}
          labels: ${{ steps.meta.outputs.labels }}