name: Docker Release

on:
  release:
    types: [published]
  workflow_dispatch:
    inputs:
      release:
        description: "Release (e.g., v1.9.0)"
        required: true

permissions:
  contents: read

jobs:
  docker-release:
    runs-on: ubuntu-latest
    env:
      RELEASE: ${{ github.event.inputs.release || github.event.release.tag_name }}
    steps:
      - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0  # v7.0.0
        with:
          persist-credentials: false
      - name: Build Docker Images
        run: make VERSION=${RELEASE:1} DOCKER=coredns -f Makefile.docker release
      - name: Show Docker Images
        run: docker images
      - name: Docker login
        uses: docker/login-action@650006c6eb7dba73a995cc03b0b2d7f5ca915bee  # v4.2.0
        with:
          username: ${{ secrets.DOCKERHUB_USERNAME }}
          password: ${{ secrets.DOCKERHUB_PASSWORD }}
      - name: Publish Docker Images
        run: make VERSION=${RELEASE:1} DOCKER=coredns -f Makefile.docker docker-push
        env:
          DOCKER_LOGIN: ${{ secrets.DOCKERHUB_USERNAME }}
          DOCKER_PASSWORD: ${{ secrets.DOCKERHUB_PASSWORD }}
