|
| 1 | +# Copyright (C) 2024 Intel Corporation |
| 2 | +# SPDX-License-Identifier: Apache-2.0 |
| 3 | + |
| 4 | +name: Example jobs |
| 5 | +permissions: read-all |
| 6 | +on: |
| 7 | + workflow_call: |
| 8 | + inputs: |
| 9 | + example: |
| 10 | + required: true |
| 11 | + type: string |
| 12 | + tag: |
| 13 | + default: "latest" |
| 14 | + required: false |
| 15 | + type: string |
| 16 | + build: |
| 17 | + default: true |
| 18 | + required: false |
| 19 | + type: boolean |
| 20 | + scan: |
| 21 | + default: true |
| 22 | + required: false |
| 23 | + type: boolean |
| 24 | + test_compose: |
| 25 | + default: false |
| 26 | + required: false |
| 27 | + type: boolean |
| 28 | + test_k8s: |
| 29 | + default: false |
| 30 | + required: false |
| 31 | + type: boolean |
| 32 | + publish: |
| 33 | + default: false |
| 34 | + required: false |
| 35 | + type: boolean |
| 36 | + publish_tags: |
| 37 | + default: "latest" |
| 38 | + required: false |
| 39 | + type: string |
| 40 | +jobs: |
| 41 | +#################################################################################################### |
| 42 | +# Image Build |
| 43 | +#################################################################################################### |
| 44 | + build-images: |
| 45 | + if: ${{ fromJSON(inputs.build) }} |
| 46 | + strategy: |
| 47 | + matrix: |
| 48 | + node: ["docker-build-xeon", "docker-build-gaudi"] |
| 49 | + runs-on: ${{ matrix.node }} |
| 50 | + continue-on-error: true |
| 51 | + steps: |
| 52 | + - name: Clean Up Working Directory |
| 53 | + run: | |
| 54 | + sudo rm -rf ${{github.workspace}}/* |
| 55 | +
|
| 56 | + - name: Checkout out Repo |
| 57 | + uses: actions/checkout@v4 |
| 58 | + |
| 59 | + - name: Build Image |
| 60 | + uses: opea-project/validation/actions/image-build@main |
| 61 | + with: |
| 62 | + work_dir: ${{ github.workspace }}/${{ inputs.example }} |
| 63 | + docker_compose_path: ${{ github.workspace }}/.github/workflows/docker/compose/${{ inputs.example }}-compose.yaml |
| 64 | + registry: ${OPEA_IMAGE_REPO}opea |
| 65 | + tag: ${{ inputs.tag }} |
| 66 | + |
| 67 | +#################################################################################################### |
| 68 | +# Trivy Scan |
| 69 | +#################################################################################################### |
| 70 | + image-list: |
| 71 | + needs: [ build-images ] |
| 72 | + if: ${{ fromJSON(inputs.scan) }} |
| 73 | + runs-on: ubuntu-latest |
| 74 | + outputs: |
| 75 | + matrix: ${{ steps.scan-matrix.outputs.matrix }} |
| 76 | + steps: |
| 77 | + - name: Harden Runner |
| 78 | + uses: step-security/harden-runner@v2.8.1 |
| 79 | + with: |
| 80 | + egress-policy: audit |
| 81 | + |
| 82 | + - name: Checkout out Repo |
| 83 | + uses: actions/checkout@v4 |
| 84 | + |
| 85 | + - name: Set Matrix |
| 86 | + id: scan-matrix |
| 87 | + run: | |
| 88 | + pip install yq |
| 89 | + compose_path=${{ github.workspace }}/.github/workflows/docker/compose/${{ inputs.example }}-compose.yaml |
| 90 | + echo "matrix=$(cat ${compose_path} | yq -r '.[]' | jq 'keys' | jq -c '.')" >> $GITHUB_OUTPUT |
| 91 | +
|
| 92 | + scan-images: |
| 93 | + needs: [image-list] |
| 94 | + if: ${{ fromJSON(inputs.scan) }} |
| 95 | + runs-on: "docker-build-gaudi" |
| 96 | + strategy: |
| 97 | + matrix: |
| 98 | + image: ${{ fromJSON(needs.image-list.outputs.matrix) }} |
| 99 | + fail-fast: false |
| 100 | + steps: |
| 101 | + - name: Harden Runner |
| 102 | + uses: step-security/harden-runner@v2.8.1 |
| 103 | + with: |
| 104 | + egress-policy: audit |
| 105 | + |
| 106 | + - name: Pull Image |
| 107 | + run: docker pull ${OPEA_IMAGE_REPO}opea/${{ matrix.image }}:${{ inputs.tag }} |
| 108 | + |
| 109 | + - name: Scan Container |
| 110 | + uses: opea-project/validation/actions/trivy-scan@main |
| 111 | + with: |
| 112 | + image-ref: ${OPEA_IMAGE_REPO}opea/${{ matrix.image }}:${{ inputs.tag }} |
| 113 | + output: ${{ inputs.example }}-${{ matrix.image }}-scan.txt |
| 114 | + |
| 115 | + - name: Cleanup |
| 116 | + if: always() |
| 117 | + run: docker rmi -f ${OPEA_IMAGE_REPO}opea/${{ matrix.image }}:${{ inputs.tag }} |
| 118 | + - uses: actions/upload-artifact@v4.3.4 |
| 119 | + with: |
| 120 | + name: ${{ inputs.example }}-scan |
| 121 | + path: ${{ inputs.example }}-${{ matrix.image }}-scan.txt |
| 122 | + overwrite: true |
| 123 | + |
| 124 | +#################################################################################################### |
| 125 | +# Docker Compose Test |
| 126 | +#################################################################################################### |
| 127 | + test-example-compose: |
| 128 | + needs: [build-images] |
| 129 | + if: ${{ fromJSON(inputs.test_compose) }} |
| 130 | + strategy: |
| 131 | + matrix: |
| 132 | + hardware: ["xeon", "gaudi"] |
| 133 | + fail-fast: false |
| 134 | + uses: ./.github/workflows/_run-docker-compose.yml |
| 135 | + with: |
| 136 | + tag: ${{ inputs.tag }} |
| 137 | + example: ${{ inputs.example }} |
| 138 | + hardware: ${{ matrix.hardware }} |
| 139 | + secrets: inherit |
| 140 | + |
| 141 | + |
| 142 | +#################################################################################################### |
| 143 | +# K8S Test |
| 144 | +#################################################################################################### |
| 145 | +# TODO |
| 146 | + |
| 147 | + |
| 148 | +#################################################################################################### |
| 149 | +# Publish |
| 150 | +#################################################################################################### |
| 151 | + publish: |
| 152 | + needs: [image-list, build-images, scan-images, test-example-compose] |
| 153 | + if: ${{ fromJSON(inputs.publish) }} |
| 154 | + strategy: |
| 155 | + matrix: |
| 156 | + image: ${{ fromJSON(needs.image-list.outputs.matrix) }} |
| 157 | + runs-on: "docker-build-gaudi" |
| 158 | + steps: |
| 159 | + - name: Image Publish |
| 160 | + uses: opea-project/validation/actions/image-publish@main |
| 161 | + with: |
| 162 | + local_image_ref: ${OPEA_IMAGE_REPO}opea/${{ matrix.image }}:${{ inputs.tag }} |
| 163 | + image_name: opea/${{ matrix.image }} |
| 164 | + publish_tags: ${{ inputs.publish_tags }} |
0 commit comments