|
103 | 103 | required: false |
104 | 104 | type: string |
105 | 105 | default: "false" |
| 106 | + build-amd64-image: |
| 107 | + description: "Enable amd64 Docker image build. Set to 'false' to disable jobs which only |
| 108 | + build arm64 images." |
| 109 | + required: false |
| 110 | + type: string |
| 111 | + default: "true" |
106 | 112 | build-arm64-image: |
107 | | - description: "Enable arm64 Docker image build. Set to 'false' to disable which only |
108 | | - builds amd64 images." |
| 113 | + description: "Enable arm64 Docker image build. Set to 'false' to disable jobs which only |
| 114 | + build amd64 images." |
109 | 115 | required: false |
110 | 116 | type: string |
111 | 117 | default: "true" |
@@ -383,12 +389,19 @@ jobs: |
383 | 389 | env: |
384 | 390 | GITHUB_EVENT_NAME: ${{ inputs.github-event-name }} |
385 | 391 | GITHUB_REF_NAME: ${{ inputs.github-ref-name }} |
| 392 | + BUILD_AMD64_IMAGE: ${{ inputs.build-amd64-image }} |
| 393 | + BUILD_ARM64_IMAGE: ${{ inputs.build-arm64-image }} |
386 | 394 | run: | |
387 | 395 | echo "Validating event and ref inputs..." |
388 | 396 | if [[ "${GITHUB_EVENT_NAME:-}" == "pull_request" && ! "${GITHUB_REF_NAME:-}" =~ ^[0-9]+/merge$ ]]; then |
389 | 397 | echo "::error::GITHUB_EVENT_NAME is pull_request but GITHUB_REF_NAME does not match expected format of: <pr_number>/merge." |
390 | 398 | exit 1 |
391 | 399 | fi |
| 400 | +
|
| 401 | + if [[ "${BUILD_AMD64_IMAGE}" != "true" && "${BUILD_ARM64_IMAGE}" != "true" ]]; then |
| 402 | + echo "::error::At least one of build-amd64-image or build-arm64-image must be set to true." |
| 403 | + exit 1 |
| 404 | + fi |
392 | 405 | - name: Set extra outputs |
393 | 406 | id: set-extra-outputs |
394 | 407 | env: |
@@ -467,13 +480,21 @@ jobs: |
467 | 480 | env: |
468 | 481 | GITHUB_RUNNER_AMD64: ${{ inputs.github-runner-amd64 }} |
469 | 482 | GITHUB_RUNNER_ARM64: ${{ inputs.github-runner-arm64 }} |
| 483 | + BUILD_AMD64_IMAGE: ${{ inputs.build-amd64-image }} |
470 | 484 | BUILD_ARM64_IMAGE: ${{ inputs.build-arm64-image }} |
471 | 485 | run: | |
472 | | - matrix="[{\"runner\":\"${GITHUB_RUNNER_AMD64}\",\"arch\":\"amd64\"}" |
| 486 | + matrix="[]" |
| 487 | +
|
| 488 | + if [[ "${BUILD_AMD64_IMAGE}" == "true" ]]; then |
| 489 | + matrix=$(jq -c --arg runner "$GITHUB_RUNNER_AMD64" \ |
| 490 | + '. += [{"runner": $runner, "arch": "amd64"}]' <<< "$matrix") |
| 491 | + fi |
| 492 | +
|
473 | 493 | if [[ "${BUILD_ARM64_IMAGE}" == "true" ]]; then |
474 | | - matrix+=",{\"runner\":\"${GITHUB_RUNNER_ARM64}\",\"arch\":\"arm64\"}" |
| 494 | + matrix=$(jq -c --arg runner "$GITHUB_RUNNER_ARM64" \ |
| 495 | + '. += [{"runner": $runner, "arch": "arm64"}]' <<< "$matrix") |
475 | 496 | fi |
476 | | - matrix+="]" |
| 497 | +
|
477 | 498 | echo "matrix=$matrix" | tee -a "$GITHUB_OUTPUT" |
478 | 499 |
|
479 | 500 | build-publish: |
@@ -660,26 +681,25 @@ jobs: |
660 | 681 | env: |
661 | 682 | DOCKER_IMAGE_SHA_DIGEST_AMD64: ${{ needs.build-publish.outputs.docker-image-sha-digest-amd64 }} |
662 | 683 | DOCKER_IMAGE_SHA_DIGEST_ARM64: ${{ needs.build-publish.outputs.docker-image-sha-digest-arm64 }} |
| 684 | + BUILD_AMD64_IMAGE: ${{ inputs.build-amd64-image }} |
663 | 685 | BUILD_ARM64_IMAGE: ${{ inputs.build-arm64-image }} |
664 | 686 | run: | |
665 | | - # Set default empty arm64 digest |
| 687 | + echo "amd64_digest=" >> "$GITHUB_OUTPUT" |
666 | 688 | echo "arm64_digest=" >> "$GITHUB_OUTPUT" |
667 | 689 |
|
668 | | - # Always include the AMD64 build |
669 | | - amd64_digest="${DOCKER_IMAGE_SHA_DIGEST_AMD64}" |
670 | | - echo "amd64_digest=$amd64_digest" | tee -a "$GITHUB_OUTPUT" |
| 690 | + digests=() |
671 | 691 |
|
672 | | - image_digests="$amd64_digest" |
| 692 | + if [[ "${BUILD_AMD64_IMAGE}" == "true" && -n "${DOCKER_IMAGE_SHA_DIGEST_AMD64}" ]]; then |
| 693 | + echo "amd64_digest=${DOCKER_IMAGE_SHA_DIGEST_AMD64}" | tee -a "$GITHUB_OUTPUT" |
| 694 | + digests+=("${DOCKER_IMAGE_SHA_DIGEST_AMD64}") |
| 695 | + fi |
673 | 696 |
|
674 | | - # Only include ARM64 if enabled and build succeeded |
675 | | - if [[ "${BUILD_ARM64_IMAGE}" == "true" ]]; then |
676 | | - arm64_digest="${DOCKER_IMAGE_SHA_DIGEST_ARM64}" |
677 | | - if [[ -n "$arm64_digest" ]]; then |
678 | | - image_digests="$image_digests,$arm64_digest" |
679 | | - echo "arm64_digest=$arm64_digest" | tee -a "$GITHUB_OUTPUT" |
680 | | - fi |
| 697 | + if [[ "${BUILD_ARM64_IMAGE}" == "true" && -n "${DOCKER_IMAGE_SHA_DIGEST_ARM64}" ]]; then |
| 698 | + echo "arm64_digest=${DOCKER_IMAGE_SHA_DIGEST_ARM64}" | tee -a "$GITHUB_OUTPUT" |
| 699 | + digests+=("${DOCKER_IMAGE_SHA_DIGEST_ARM64}") |
681 | 700 | fi |
682 | 701 |
|
| 702 | + image_digests="$(IFS=,; echo "${digests[*]}")" |
683 | 703 | echo "image_digests=$image_digests" | tee -a "$GITHUB_OUTPUT" |
684 | 704 |
|
685 | 705 | - name: Generate manifest annotations |
|
0 commit comments