|
19 | 19 | matrix: |
20 | 20 | description: "Image List" |
21 | 21 | value: ${{ jobs.get-image-list.outputs.matrix }} |
| 22 | + run_matrix: |
| 23 | + description: "Trivy Matrix composed of image name and Dockerfile path" |
| 24 | + value: ${{ jobs.get-image-list.outputs.run_matrix }} |
22 | 25 |
|
23 | 26 | jobs: |
24 | 27 | get-image-list: |
25 | 28 | runs-on: ubuntu-latest |
26 | 29 | outputs: |
27 | 30 | matrix: ${{ steps.get-matrix.outputs.matrix }} |
| 31 | + run_matrix: ${{ steps.get-matrix.outputs.run_matrix }} |
28 | 32 | steps: |
29 | 33 | - name: Checkout out Repo |
30 | 34 | uses: actions/checkout@v4 |
31 | 35 |
|
| 36 | + - name: Checkout GenAIComps Repository |
| 37 | + uses: actions/checkout@v4 |
| 38 | + with: |
| 39 | + repository: opea-project/GenAIComps |
| 40 | + path: GenAIComps |
| 41 | + |
32 | 42 | - name: Set Matrix |
33 | 43 | id: get-matrix |
34 | 44 | run: | |
35 | 45 | image_list=[] |
| 46 | + run_matrix="{\"include\":[" |
36 | 47 | if [[ ! -z "${{ inputs.examples }}" ]]; then |
37 | 48 | pip install yq |
38 | 49 | examples=($(echo ${{ inputs.examples }} | tr ',' ' ')) |
39 | 50 | for example in ${examples[@]} |
40 | 51 | do |
41 | 52 | images=$(cat ${{ github.workspace }}/${example}/docker_image_build/build.yaml | yq -r '.[]' | jq 'keys' | jq -c '.') |
| 53 | + dockerfiles=$(cat ${{ github.workspace }}/${example}/docker_image_build/build.yaml | yq -r '.[]' | jq -c --arg example "$example" 'to_entries[] | { image: .key, dockerfile: ( if (.value.build.context | test("\\.\\.")) then $example + "/docker_image_build/" + .value.build.context + "/" + .value.build.dockerfile else .value.build.context + "/" + .value.build.dockerfile end ) }') |
| 54 | + dockerfiles=$(echo ${dockerfiles} | tr ' ' ',') |
| 55 | + run_matrix="${run_matrix}${dockerfiles}," |
42 | 56 | image_list=$(echo ${image_list} | jq -s '.[0] + .[1] | unique' - <(echo ${images})) |
43 | 57 | done |
44 | 58 | fi |
45 | 59 |
|
46 | 60 | if [[ ! -z "${{ inputs.images }}" ]]; then |
47 | 61 | images=($(echo ${{ inputs.images }} | tr ',' ' ')) |
| 62 | + found=False |
| 63 | + for image in ${images[@]} |
| 64 | + do |
| 65 | + for compose_file in $(ls ${{ github.workspace }}/GenAIComps/.github/workflows/docker/compose/*-compose.yaml); do |
| 66 | + if grep -q "$image" "$compose_file"; then |
| 67 | + found=True |
| 68 | + docker_file="$compose_file" |
| 69 | + fi |
| 70 | + done |
| 71 | +
|
| 72 | + if [[ "${found}" == "False" ]]; then |
| 73 | + for build_file in $(ls ${{ github.workspace }}/*/docker_image_build/build.yaml); do |
| 74 | + if grep -q "$image" "$build_file"; then |
| 75 | + found=True |
| 76 | + docker_file="$build_file" |
| 77 | + fi |
| 78 | + done |
| 79 | + fi |
| 80 | +
|
| 81 | + if [[ "${found}" == "False" ]]; then |
| 82 | + echo "::error:: Image ${image} not found in any compose or build file." |
| 83 | + exit 1 |
| 84 | + fi |
| 85 | +
|
| 86 | + dockerfiles=$(yq -r ".services[\"$image\"] | {image: \"$image\", dockerfile: ( ( .build.context // \"\" ) + ( if .build.context and .build.dockerfile then \"/\" else \"\" end ) + ( .build.dockerfile // \"\" ) )}" "$docker_file" | jq -c . | tr -d ' ') |
| 87 | + run_matrix="${run_matrix}${dockerfiles}," |
| 88 | + done |
| 89 | +
|
48 | 90 | input_image_list=$(printf '%s\n' "${images[@]}" | sort -u | jq -R '.' | jq -sc '.') |
49 | 91 | image_list=$(echo ${image_list} | jq -s '.[0] + .[1] | unique' - <(echo ${input_image_list})) |
50 | 92 | fi |
|
53 | 95 | echo "$image_list" | jq . | jq -r '.[]' |
54 | 96 | echo "end of image list..." |
55 | 97 | echo "matrix=$(echo ${image_list} | jq -c '.')" >> $GITHUB_OUTPUT |
| 98 | + run_matrix="${run_matrix%,}" |
| 99 | + run_matrix="${run_matrix}]}" |
| 100 | +
|
| 101 | + echo "run_matrix=$(echo "${run_matrix}" | jq -c '{include: (.include | unique_by(.image))}')" |
| 102 | + echo "run_matrix=$(echo "${run_matrix}" | jq -c '{include: (.include | unique_by(.image))}')" >> $GITHUB_OUTPUT |
0 commit comments