# Copyright (C) 2024 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

name: Services publish docker image on manual event
on:
  workflow_dispatch:
    inputs:
      services:
        default: ""
        description: "List of services to test [agent,asr,chathistory,dataprep,embeddings,feedback_management,finetuning,guardrails,intent_detection,knowledgegraphs,llms,lvms,nginx,prompt_registry,ragas,rerankings,retrievers,tts,vectorstores,web_retrievers]"
        required: false
        type: string
      images:
        default: ""
        description: "List of images to scan [dataprep-pgvector,dataprep-pinecone...]"
        required: false
        type: string
      tag:
        default: "rc"
        description: "Tag to publish"
        required: true
        type: string
      publish_tags:
        default: "latest,1.x"
        description: "Tag list apply to publish images"
        required: false
        type: string
      mode:
        default: "CD"
        description: "Whether the test range is CI, CD or CICD"
        required: false
        type: string

permissions: read-all
jobs:
  get-image-list:
    uses: ./.github/workflows/_get-image-list.yml
    with:
      services: ${{ inputs.services }}
      images: ${{ inputs.images }}
      mode: ${{ inputs.mode }}

  publish:
    needs: [get-image-list]
    strategy:
      matrix:
        image: ${{ fromJSON(needs.get-image-list.outputs.matrix) }}
    runs-on: "docker-build-gaudi"
    steps:
      - uses: docker/login-action@v3.2.0
        with:
          username: ${{ secrets.DOCKERHUB_USER }}
          password: ${{ secrets.DOCKERHUB_TOKEN }}

      - name: Image Publish
        uses: opea-project/validation/actions/image-publish@main
        with:
          local_image_ref: ${OPEA_IMAGE_REPO}opea/${{ matrix.image }}:${{ inputs.tag }}
          image_name: opea/${{ matrix.image }}
          publish_tags: ${{ inputs.publish_tags }}
