name: Docker Build and Push

on:
  release:
    types: [published]
  workflow_dispatch: # 手动构建
    inputs:
      tag_name:
        description: 'Tag Name (leave empty for default latest)'
        required: false
        default: 'latest'
jobs:
  build-and-push:
    runs-on: ubuntu-latest
    steps:
    - name: Check out the repository
      uses: actions/checkout@v3

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

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

    - name: Build and push Docker image
      uses: docker/build-push-action@v3
      with:
        context: .
        file: ./Dockerfile
        push: true
        platforms: linux/amd64,linux/arm64
        tags: |
          chaoszhu/easynode:${{ github.event.release.tag_name || inputs.tag_name }}
          chaoszhu/easynode:latest

    # - name: Clean up post-build
    #   run: docker system prune -af
