name: Docker Image CI Ontime

on:
  release:
    types: [published]
  workflow_dispatch:

jobs:

  publish_docker:
    runs-on: ubuntu-latest
    env:
      CI: ''

    steps:
    - uses: actions/checkout@v4

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

    - name: Docker Setup Buildx
      uses: docker/setup-buildx-action@v2.5.0

    - name: Build and push stable release
      if: github.event.release.prerelease == false
      uses: docker/build-push-action@v4.0.0
      with:
        context: .
        file: ./Dockerfile
        platforms: linux/amd64,linux/arm64,linux/arm/v7
        # Push is a shorthand for --output=type=registry
        push: true
        tags: ${{ secrets.DOCKERHUB_USERNAME }}/ontime:${{ github.event.release.tag_name }} , ${{ secrets.DOCKERHUB_USERNAME }}/ontime:latest

    - name: Build and push pre-release
      if: github.event.release.prerelease == true
      uses: docker/build-push-action@v4.0.0
      with:
        context: .
        file: ./Dockerfile
        platforms: linux/amd64,linux/arm64,linux/arm/v7
        # Push is a shorthand for --output=type=registry
        push: true
        tags: ${{ secrets.DOCKERHUB_USERNAME }}/ontime:${{ github.event.release.tag_name }} , ${{ secrets.DOCKERHUB_USERNAME }}/ontime:nightly

