name: Build Docker Images

on:
  workflow_dispatch:
    inputs:
      version:
        description: Version
        type: string
        required: true
      image:
        description: QEMU image
        type: string
        required: false
        default: tonistiigi/binfmt:latest
      os:
        description: OS
        type: string
        required: false
        default: ubuntu-24.04-arm

jobs:
  build:
    runs-on: ${{ inputs.os }}
    timeout-minutes: 20

    steps:
    - name: Checkout code
      uses: actions/checkout@v3
      with:
        submodules: recursive

    - name: Docker meta
      id: meta
      uses: docker/metadata-action@v4
      with:
        images: docuseal/docuseal
        tags: latest,${{ inputs.version }}

    - name: Set up QEMU
      uses: docker/setup-qemu-action@v3
      with:
        image: ${{ inputs.image }}

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

    - name: Create .version file
      run: echo ${{ inputs.version }} > .version

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

    - name: Build and push Docker image
      uses: docker/build-push-action@v6
      with:
        context: .
        push: true
        platforms: linux/amd64,linux/arm64
        tags: ${{ steps.meta.outputs.tags }}
