name: Reusable Publish Docker Self Hosting Image Workflow

on:
  workflow_call:
    secrets:
      DOCKER_USERNAME:
        required: true
      DOCKER_PASSWORD:
        required: true
      AWS_ACCESS_KEY_ID:
        required: true
      AWS_SECRET_ACCESS_KEY:
        required: true

jobs:
  publish:
    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v3

    - name: Login to Docker Hub
      uses: docker/login-action@v2
      with:
        username: ${{ secrets.DOCKER_USERNAME }}
        password: ${{ secrets.DOCKER_PASSWORD }}

    - name: Set up QEMU
      uses: docker/setup-qemu-action@master
      with:
        platforms: all

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

    - name: Publish Docker image
      uses: docker/build-push-action@v3
      with:
        builder: ${{ steps.buildx.outputs.name }}
        context: .
        file: Dockerfile
        platforms: linux/amd64,linux/arm64
        push: true
        tags: |
          standardnotes/server:latest
          standardnotes/server:${{ github.sha }}
