name: Publish Docker images

on:
  workflow_dispatch:
  push:
    paths:
      - tools/BUILD_CONTAINER_VERSION

jobs:
  docker:
    runs-on: ubuntu-latest
    steps:
      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v2

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

      - uses: actions/checkout@v4

      - name: Fetch versions in the repo
        id: fetch-versions
        run: |
          BUILD_CONTAINER_VERSION=$(cat tools/BUILD_CONTAINER_VERSION)
          echo "build_container_version=$BUILD_CONTAINER_VERSION" >> "$GITHUB_OUTPUT"

      - name: Build and push docker image
        uses: docker/build-push-action@v4
        with:
          context: .
          file: ./tools/Dockerfile
          platforms: linux/amd64
          push: true
          tags: dragonos/dragonos-dev:${{ steps.fetch-versions.outputs.build_container_version }}