|
7 | 7 | type: string |
8 | 8 | required: false |
9 | 9 | default: "" |
10 | | - description: Comma separated list of build keys. Leave empty to run for all. |
| 10 | + description: "Comma separated list of build keys. Leave empty to run for all." |
11 | 11 | push_to: |
12 | 12 | type: string |
13 | 13 | required: false |
14 | 14 | default: "" |
15 | | - description: Comma separated list of push keys. Leave empty to trigger for all. |
| 15 | + description: "Comma separated list of push keys. Leave empty to trigger for all." |
16 | 16 | branch: |
17 | 17 | type: string |
18 | 18 | required: false |
19 | 19 | skip_push: |
| 20 | + description: "Skip retagging and pushing the built images to customer registries" |
20 | 21 | type: boolean |
21 | 22 | required: false |
22 | 23 | default: false |
|
25 | 26 | required: false |
26 | 27 | default: true |
27 | 28 | scan_high_severity: |
28 | | - description: 'Include high severity' |
| 29 | + description: "Include high severity" |
29 | 30 | type: boolean |
30 | 31 | required: false |
31 | 32 | default: true |
|
60 | 61 | result: ${{ steps.get-flavors.outputs.result }} |
61 | 62 | # Do not run this on self-hosted, as it is faster and shouldn't be blocking anything |
62 | 63 | # runs-on: ${{ inputs.runs_on || 'ubuntu-22.04' }} |
63 | | - runs-on: 'ubuntu-22.04' |
| 64 | + runs-on: "ubuntu-22.04" |
64 | 65 | steps: |
65 | 66 | - name: Checkout repository |
66 | 67 | uses: actions/checkout@v5 |
@@ -124,6 +125,7 @@ jobs: |
124 | 125 | flavor_directory: `./deploy/build/${flavor.directory}`, |
125 | 126 | build_time: buildTime, |
126 | 127 | image_tag: imageTag, |
| 128 | + image_ref: `${{ vars.DV_AWS_ECR_REGISTRY }}/${component.ecr_repository}:${imageTag}`, |
127 | 129 | image_tag_branch_name: imageTagBranchName, |
128 | 130 | formatted_build_args: formattedBuildArgs, |
129 | 131 | }; |
@@ -240,7 +242,7 @@ jobs: |
240 | 242 | # TODO: As soon as we only have a single tag, we can push the same image to multiple repositories: https://docs.docker.com/build/ci/github-actions/push-multi-registries/ |
241 | 243 | # This will be useful for the images which don't change between flavors, e.g. the backend images |
242 | 244 | tags: | |
243 | | - ${{ vars.DV_AWS_ECR_REGISTRY }}/${{ matrix.component.ecr_repository }}:${{ matrix.component.image_tag }} |
| 245 | + ${{ matrix.component.image_ref }} |
244 | 246 | labels: | |
245 | 247 | name=${{ matrix.component.ecr_repository }} |
246 | 248 | version=${{ matrix.component.image_tag_branch_name }} |
@@ -269,36 +271,112 @@ jobs: |
269 | 271 | - name: Run Trivy vulnerability scanner |
270 | 272 | uses: aquasecurity/[email protected] |
271 | 273 | with: |
272 | | - image-ref: ${{ vars.DV_AWS_ECR_REGISTRY }}/${{ matrix.component.ecr_repository }}:${{ matrix.component.image_tag }} |
| 274 | + image-ref: ${{ matrix.component.image_ref }} |
273 | 275 | # Disable scanning the current directory (defaults to .) |
274 | | - scan-ref: '/dev/null' |
275 | | - format: 'table' |
276 | | - exit-code: '1' |
| 276 | + scan-ref: "/dev/null" |
| 277 | + format: "table" |
| 278 | + exit-code: "1" |
277 | 279 | ignore-unfixed: false |
278 | | - vuln-type: 'os,library' |
| 280 | + vuln-type: "os,library" |
279 | 281 | severity: ${{ steps.set_severity.outputs.severity }} |
280 | | - continue-on-error: false |
| 282 | + continue-on-error: false |
281 | 283 |
|
282 | 284 | - name: Push image |
283 | | - if: ${{ inputs.skip_push != true }} |
284 | 285 | # Instead of the docker/build-push-action@v6 which will rebuild the image, just push it directly |
285 | | - run: docker push ${{ vars.DV_AWS_ECR_REGISTRY }}/${{ matrix.component.ecr_repository }}:${{ matrix.component.image_tag }} |
| 286 | + run: docker push ${{ matrix.component.image_ref }} |
| 287 | + |
| 288 | + - name: Log out from Amazon ECR |
| 289 | + shell: bash |
| 290 | + run: docker logout ${{ steps.login-ecr.outputs.registry }} |
| 291 | + |
| 292 | + test-images: |
| 293 | + name: Test images of flavor ${{ matrix.flavor.id || 'default' }} |
| 294 | + needs: [get-flavors, build-flavors] |
| 295 | + strategy: |
| 296 | + fail-fast: false |
| 297 | + matrix: |
| 298 | + flavor: ${{ fromJson(needs.get-flavors.outputs.result).flavors }} |
| 299 | + runs-on: ${{ inputs.runs_on || 'ubuntu-22.04' }} |
| 300 | + steps: |
| 301 | + - name: Checkout repository |
| 302 | + uses: actions/checkout@v5 |
| 303 | + with: |
| 304 | + ref: ${{ inputs.branch || github.sha }} |
| 305 | + token: ${{ secrets.CHECKOUT_TOKEN || github.event.repository.private == true && secrets.DATAVISYN_BOT_REPO_TOKEN || github.token }} |
| 306 | + |
| 307 | + - name: Checkout github-workflows repository |
| 308 | + uses: actions/checkout@v5 |
| 309 | + with: |
| 310 | + repository: datavisyn/github-workflows |
| 311 | + ref: ${{ env.WORKFLOW_BRANCH }} |
| 312 | + path: ./tmp/github-workflows |
| 313 | + |
| 314 | + - name: Configure AWS Credentials |
| 315 | + uses: aws-actions/[email protected] |
| 316 | + with: |
| 317 | + role-to-assume: ${{ vars.DV_AWS_ECR_ROLE }} |
| 318 | + aws-region: ${{ vars.DV_AWS_REGION }} |
| 319 | + |
| 320 | + - name: Login to Amazon ECR |
| 321 | + id: login-ecr |
| 322 | + uses: aws-actions/[email protected] |
| 323 | + |
| 324 | + - name: Run test-images.sh hook |
| 325 | + shell: bash |
| 326 | + id: test-images |
| 327 | + run: | |
| 328 | + hooks_folder="$(realpath -m "./deploy/build/${{ matrix.flavor.directory }}/hooks")" |
| 329 | + test_images_hook="$hooks_folder/test-images.sh" |
| 330 | + test_images_report="$hooks_folder/test-images-report" |
| 331 | +
|
| 332 | + if [[ -f "$test_images_hook" ]]; then |
| 333 | + # Iterate through all components and store their image ref in an environment variable |
| 334 | + for component in $(jq -c '.components[]' <<< "$FLAVOR"); do |
| 335 | + name=$(jq -r '.ecr_repository' <<< "$component") |
| 336 | + image_ref=$(jq -r '.image_ref' <<< "$component") |
| 337 | + # Replace all non-alphanumeric characters with underscores and convert to uppercase |
| 338 | + name_upper=$(echo "${name//[^[:alnum:]]/_}" | tr '[:lower:]' '[:upper:]') |
| 339 | + echo "Setting environment variable IMAGE_${name_upper}=${image_ref}" |
| 340 | + export "IMAGE_${name_upper}=${image_ref}" |
| 341 | + done; |
| 342 | +
|
| 343 | + # Create report folder to avoid any downstream Docker volume issues |
| 344 | + # TODO: For some reason this doesn't work yet, i.e. if a docker-compose script mounts a volume here, nothing shows up... |
| 345 | + mkdir -p "$test_images_report" |
| 346 | + chmod 777 "$test_images_report" |
| 347 | + echo "test_images_report=${test_images_report}" >> "$GITHUB_OUTPUT" |
| 348 | +
|
| 349 | + echo "Run $test_images_hook" |
| 350 | + chmod +x "$test_images_hook" |
| 351 | + bash "$test_images_hook" |
| 352 | + else |
| 353 | + echo "No $test_images_hook found, skipping tests." |
| 354 | + fi |
| 355 | + env: |
| 356 | + FLAVOR: ${{ toJSON(matrix.flavor) }} |
| 357 | + |
| 358 | + - name: Upload test-images-report |
| 359 | + uses: actions/upload-artifact@v4 |
| 360 | + if: ${{ steps.test-images.outputs.test_images_report }} |
| 361 | + with: |
| 362 | + name: "test-images-report-${{ matrix.flavor.id || 'default' }}" |
| 363 | + path: ${{ steps.test-images.outputs.test_images_report }} |
286 | 364 |
|
287 | 365 | - name: Log out from Amazon ECR |
288 | 366 | shell: bash |
289 | 367 | run: docker logout ${{ steps.login-ecr.outputs.registry }} |
290 | 368 |
|
291 | 369 | retag-images: |
292 | 370 | name: Retag images of flavor ${{ matrix.flavor.id || 'default' }} |
293 | | - needs: [get-flavors, build-flavors] |
| 371 | + needs: [get-flavors, test-images] |
294 | 372 | if: ${{ inputs.skip_push != true }} |
295 | 373 | strategy: |
296 | 374 | fail-fast: false |
297 | 375 | matrix: |
298 | 376 | flavor: ${{ fromJson(needs.get-flavors.outputs.result).flavors }} |
299 | 377 | # Do not run this on self-hosted, as it is faster and shouldn't be blocking anything |
300 | 378 | # runs-on: ${{ inputs.runs_on || 'ubuntu-22.04' }} |
301 | | - runs-on: 'ubuntu-22.04' |
| 379 | + runs-on: "ubuntu-22.04" |
302 | 380 | steps: |
303 | 381 | - name: Checkout repository |
304 | 382 | uses: actions/checkout@v5 |
|
0 commit comments