From 2994772321d0aaffebaed068d971c47f2b0a8dac Mon Sep 17 00:00:00 2001
From: chensuyue <suyue.chen@intel.com>
Date: Thu, 15 Aug 2024 23:16:09 +0800
Subject: [PATCH 1/3] update image scan

Signed-off-by: chensuyue <suyue.chen@intel.com>
---
 .github/workflows/_example-workflow.yml                     | 6 +++---
 .../{manual-cd-workflow.yml => manual-example-workflow.yml} | 0
 2 files changed, 3 insertions(+), 3 deletions(-)
 rename .github/workflows/{manual-cd-workflow.yml => manual-example-workflow.yml} (100%)

diff --git a/.github/workflows/_example-workflow.yml b/.github/workflows/_example-workflow.yml
index c293a8b1ef..c99d01253a 100644
--- a/.github/workflows/_example-workflow.yml
+++ b/.github/workflows/_example-workflow.yml
@@ -97,7 +97,7 @@ jobs:
         id: scan-matrix
         run: |
           pip install yq
-          compose_path=${{ github.workspace }}/.github/workflows/docker/compose/${{ inputs.example }}-compose.yaml
+          compose_path=${{ github.workspace }}/${{ inputs.example }}/docker/docker_build_compose.yaml
           echo "matrix=$(cat ${compose_path} | yq -r '.[]' | jq 'keys' | jq -c '.')" >> $GITHUB_OUTPUT
 
   scan-images:
@@ -126,8 +126,8 @@ jobs:
 
       - uses: actions/upload-artifact@v4.3.4
         with:
-          name: ${{ inputs.example }}-${{ matrix.image }}-scan
-          path: ${{ inputs.example }}-${{ matrix.image }}-scan.txt
+          name: ${{ matrix.image }}-scan
+          path: ${{ matrix.image }}-scan.txt
           overwrite: true
 
 ####################################################################################################
diff --git a/.github/workflows/manual-cd-workflow.yml b/.github/workflows/manual-example-workflow.yml
similarity index 100%
rename from .github/workflows/manual-cd-workflow.yml
rename to .github/workflows/manual-example-workflow.yml

From a6bff45cd3de75cdbee1e471f8a976bbf6d70c01 Mon Sep 17 00:00:00 2001
From: chensuyue <suyue.chen@intel.com>
Date: Thu, 15 Aug 2024 23:48:31 +0800
Subject: [PATCH 2/3] add license scan workflow and docker publish workflow

Signed-off-by: chensuyue <suyue.chen@intel.com>
---
 .github/workflows/_example-workflow.yml       | 34 +--------
 .github/workflows/manual-bom-scan.yml         | 74 +++++++++++++++++++
 .github/workflows/manual-docker-publish.yml   | 68 +++++++++++++++++
 .github/workflows/manual-example-workflow.yml | 16 +---
 4 files changed, 148 insertions(+), 44 deletions(-)
 create mode 100644 .github/workflows/manual-bom-scan.yml
 create mode 100644 .github/workflows/manual-docker-publish.yml

diff --git a/.github/workflows/_example-workflow.yml b/.github/workflows/_example-workflow.yml
index c99d01253a..0cb984cc79 100644
--- a/.github/workflows/_example-workflow.yml
+++ b/.github/workflows/_example-workflow.yml
@@ -32,14 +32,6 @@ on:
         default: false
         required: false
         type: boolean
-      publish:
-        default: false
-        required: false
-        type: boolean
-      publish_tags:
-        default: "latest"
-        required: false
-        type: string
       GenAIComps_branch:
         default: "main"
         required: false
@@ -83,7 +75,7 @@ jobs:
 ####################################################################################################
 # Trivy Scan
 ####################################################################################################
-  image-list:
+  get-image-list:
     needs: [build-images]
     if: ${{ fromJSON(inputs.scan) && inputs.node == 'gaudi' }}
     runs-on: ubuntu-latest
@@ -101,12 +93,12 @@ jobs:
           echo "matrix=$(cat ${compose_path} | yq -r '.[]' | jq 'keys' | jq -c '.')" >> $GITHUB_OUTPUT
 
   scan-images:
-    needs: [image-list, build-images]
+    needs: [get-image-list, build-images]
     if: ${{ fromJSON(inputs.scan) && inputs.node == 'gaudi'}}
     runs-on: "docker-build-${{ inputs.node }}"
     strategy:
       matrix:
-        image: ${{ fromJSON(needs.image-list.outputs.matrix) }}
+        image: ${{ fromJSON(needs.get-image-list.outputs.matrix) }}
       fail-fast: false
     steps:
       - name: Pull Image
@@ -118,7 +110,7 @@ jobs:
         uses: opea-project/validation/actions/trivy-scan@main
         with:
           image-ref: ${{ env.OPEA_IMAGE_REPO }}opea/${{ matrix.image }}:${{ inputs.tag }}
-          output: ${{ inputs.example }}-${{ matrix.image }}-scan.txt
+          output: ${{ matrix.image }}-scan.txt
 
       - name: Cleanup
         if: always()
@@ -157,21 +149,3 @@ jobs:
       tag: ${{ inputs.tag }}
     secrets: inherit
 
-
-####################################################################################################
-# Publish
-####################################################################################################
-  publish:
-    needs: [image-list, build-images, scan-images, test-example-compose]
-    if: ${{ fromJSON(inputs.publish) && inputs.node == 'gaudi' }}
-    strategy:
-      matrix:
-        image: ${{ fromJSON(needs.image-list.outputs.matrix) }}
-    runs-on: "docker-build-gaudi"
-    steps:
-      - 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 }}
diff --git a/.github/workflows/manual-bom-scan.yml b/.github/workflows/manual-bom-scan.yml
new file mode 100644
index 0000000000..4be4600f48
--- /dev/null
+++ b/.github/workflows/manual-bom-scan.yml
@@ -0,0 +1,74 @@
+# Copyright (C) 2024 Intel Corporation
+# SPDX-License-Identifier: Apache-2.0
+
+name: Examples docker images BoM scan
+on:
+  workflow_dispatch:
+    inputs:
+      node:
+        default: "gaudi"
+        description: "Hardware to run test"
+        required: true
+        type: string
+      examples:
+        default: "ChatQnA"
+        description: 'List of examples to test [AudioQnA,ChatQnA,CodeGen,CodeTrans,DocSum,FaqGen,SearchQnA,Translation]'
+        required: true
+        type: string
+      tag:
+        default: "latest"
+        description: "Tag to apply to images"
+        required: true
+        type: string
+
+permissions: read-all
+jobs:
+  get-image-list:
+    runs-on: ubuntu-latest
+    outputs:
+      matrix: ${{ steps.scan-matrix.outputs.matrix }}
+    steps:
+      - name: Checkout out Repo
+        uses: actions/checkout@v4
+
+      - name: Set Matrix
+        id: scan-matrix
+        run: |
+          pip install yq
+          examples=($(echo ${{ inputs.examples }} | tr ',' ' '))
+          image_list=[]
+          for example in ${examples[@]}
+          do
+              images=$(cat ${{ github.workspace }}/${example}/docker/docker_build_compose.yaml | yq -r '.[]' | jq 'keys' | jq -c '.')
+              image_list=$(echo ${image_list} | jq -s '.[0] + .[1] | unique' - <(echo ${images}))
+          done
+          echo "matrix=$(echo ${image_list} | jq -c '.')" >> $GITHUB_OUTPUT
+
+  scan-license:
+    needs: get-image-list
+    runs-on: "docker-build-${{ inputs.node }}"
+    strategy:
+      matrix:
+        image: ${{ fromJson(needs.get-image-list.outputs.matrix) }}
+      fail-fast: false
+    steps:
+      - name: Pull Image
+        run: |
+          docker pull ${OPEA_IMAGE_REPO}opea/${{ matrix.image }}:${{ inputs.tag }}
+          echo "OPEA_IMAGE_REPO=${OPEA_IMAGE_REPO}" >> $GITHUB_ENV
+
+      - name: Scan Container
+        uses: opea-project/validation/actions/license-scan@main # TODO
+        with:
+          image-ref: ${{ env.OPEA_IMAGE_REPO }}opea/${{ matrix.image }}:${{ inputs.tag }}
+          output: ${{ matrix.image }}-scan.txt
+
+      - name: Cleanup
+        if: always()
+        run: docker rmi -f ${OPEA_IMAGE_REPO}opea/${{ matrix.image }}:${{ inputs.tag }}
+
+      - uses: actions/upload-artifact@v4.3.4
+        with:
+          name: ${{ matrix.image }}-scan
+          path: ${{ matrix.image }}-scan.txt
+          overwrite: true
diff --git a/.github/workflows/manual-docker-publish.yml b/.github/workflows/manual-docker-publish.yml
new file mode 100644
index 0000000000..44315a6df4
--- /dev/null
+++ b/.github/workflows/manual-docker-publish.yml
@@ -0,0 +1,68 @@
+# Copyright (C) 2024 Intel Corporation
+# SPDX-License-Identifier: Apache-2.0
+
+name: Examples CD workflow on manual event
+on:
+  workflow_dispatch:
+    inputs:
+      nodes:
+        default: "gaudi"
+        description: "Hardware to run test"
+        required: true
+        type: string
+      examples:
+        default: "ChatQnA"
+        description: 'List of examples to test [AudioQnA,ChatQnA,CodeGen,CodeTrans,DocSum,FaqGen,SearchQnA,Translation]'
+        required: true
+        type: string
+      tag:
+        default: "latest"
+        description: "Tag to apply to images"
+        required: true
+        type: string
+      publish:
+        default: false
+        description: 'Publish images to docker hub'
+        required: false
+        type: boolean
+      publish_tags:
+        default: "latest,v1.0"
+        description: 'Tag list apply to publish images'
+        required: false
+        type: string
+
+permissions: read-all
+jobs:
+  get-image-list:
+    runs-on: ${{ inputs.node }}
+    outputs:
+      matrix: ${{ steps.scan-matrix.outputs.matrix }}
+    steps:
+      - name: Checkout out Repo
+        uses: actions/checkout@v4
+
+      - name: Set Matrix
+        id: scan-matrix
+        run: |
+          examples=($(echo ${{ inputs.examples }} | tr ',' ' '))
+          image_list=[]
+          for example in ${examples[@]}
+          do
+              images=$(cat ${{ github.workspace }}/${example}/docker/docker_build_compose.yaml | yq -r '.[]' | jq 'keys' | jq -c '.')
+              image_list=$(echo ${image_list} | jq -s '.[0] + .[1] | unique' - <(echo ${images}))
+          done
+          echo "matrix=$(echo ${image_list} | jq -c '.')" >> $GITHUB_OUTPUT
+
+  publish:
+    needs: [get-image-list]
+    strategy:
+      matrix:
+        image: ${{ fromJSON(needs.get-image-list.outputs.matrix) }}
+    runs-on: "docker-build-${{ inputs.node }}"
+    steps:
+      - 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 }}
diff --git a/.github/workflows/manual-example-workflow.yml b/.github/workflows/manual-example-workflow.yml
index 7159ba6321..561183685c 100644
--- a/.github/workflows/manual-example-workflow.yml
+++ b/.github/workflows/manual-example-workflow.yml
@@ -40,16 +40,6 @@ on:
         description: 'Test examples with k8s'
         required: false
         type: boolean
-      publish:
-        default: false
-        description: 'Publish images to docker hub'
-        required: false
-        type: boolean
-      publish_tags:
-        default: "latest,v1.0"
-        description: 'Tag list apply to publish images'
-        required: false
-        type: string
       GenAIComps_branch:
         default: "main"
         description: 'GenAIComps branch for image build'
@@ -67,10 +57,10 @@ jobs:
     - name: Create Matrix
       id: get-matrix
       run: |
-        examples=($(echo ${{ github.event.inputs.examples }} | tr ',' ' '))
+        examples=($(echo ${{ inputs.examples }} | tr ',' ' '))
         examples_json=$(printf '%s\n' "${examples[@]}" | sort -u | jq -R '.' | jq -sc '.')
         echo "examples=$examples_json" >> $GITHUB_OUTPUT
-        nodes=($(echo ${{ github.event.inputs.nodes }} | tr ',' ' '))
+        nodes=($(echo ${{ inputs.nodes }} | tr ',' ' '))
         nodes_json=$(printf '%s\n' "${nodes[@]}" | sort -u | jq -R '.' | jq -sc '.')
         echo "nodes=$nodes_json" >> $GITHUB_OUTPUT
 
@@ -90,7 +80,5 @@ jobs:
       scan: ${{ fromJSON(inputs.scan) }}
       test_compose: ${{ fromJSON(inputs.test_compose) }}
       test_k8s: ${{ fromJSON(inputs.test_k8s) }}
-      publish: ${{ fromJSON(inputs.publish) }}
-      publish_tags: ${{ inputs.publish_tags }}
       GenAIComps_branch: ${{ inputs.GenAIComps_branch }}
     secrets: inherit

From b16c0a10baaceff7ba3162605024e44348106235 Mon Sep 17 00:00:00 2001
From: "pre-commit-ci[bot]"
 <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Date: Thu, 15 Aug 2024 15:53:29 +0000
Subject: [PATCH 3/3] [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci
---
 .github/workflows/_example-workflow.yml | 1 -
 1 file changed, 1 deletion(-)

diff --git a/.github/workflows/_example-workflow.yml b/.github/workflows/_example-workflow.yml
index 0cb984cc79..7e86ed288b 100644
--- a/.github/workflows/_example-workflow.yml
+++ b/.github/workflows/_example-workflow.yml
@@ -148,4 +148,3 @@ jobs:
       hardware: ${{ inputs.node }}
       tag: ${{ inputs.tag }}
     secrets: inherit
-
