-
Notifications
You must be signed in to change notification settings - Fork 49
fix(function-autoscaler): build linux/arm64 images #533
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
4c339a9
fix(function-autoscaler): build linux/arm64 images
balajinvda cf418c4
ci: pin bazel-ci 0.14.0 for arm64 libssl
balajinvda 8de70b8
test(function-autoscaler): assert the image index carries both arches
balajinvda 0d5f432
test(function-autoscaler): handle both OCI index layouts in the platf…
balajinvda File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
src/control-plane-services/function-autoscaler/rules/oci/private/BUILD.bazel
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,24 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| load("@rules_shell//shell:sh_test.bzl", "sh_test") | ||
|
|
||
| package(default_visibility = ["//rules/oci:__subpackages__"]) | ||
|
|
||
| # Referenced by the platform-coverage test that create_oci_image generates for | ||
| # every image, so it must be visible wherever an image is defined, not just | ||
| # under //rules/oci. | ||
| exports_files( | ||
| ["image_index_platforms_test.sh"], | ||
| visibility = ["//visibility:public"], | ||
| ) | ||
|
|
||
| # Tests the guard itself against synthetic OCI layouts. The platform-coverage | ||
| # test only runs against a real image index, which is always well-formed when | ||
| # the build is healthy, so nothing there would notice the guard silently | ||
| # passing on a broken index. This asserts it actually fails. | ||
| sh_test( | ||
| name = "image_index_platforms_selftest", | ||
| srcs = ["test_image_index_platforms.sh"], | ||
| data = ["image_index_platforms_test.sh"], | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
159 changes: 159 additions & 0 deletions
159
...ontrol-plane-services/function-autoscaler/rules/oci/private/image_index_platforms_test.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,159 @@ | ||
| #!/usr/bin/env bash | ||
| # SPDX-FileCopyrightText: Copyright (c) NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # | ||
| # Assert that an OCI image index carries exactly the expected architectures. | ||
| # | ||
| # Why this exists: this service shipped an amd64-only image index for months and | ||
| # nothing noticed. The build stayed green the whole time because dropping a | ||
| # platform is a configuration edit, not a compile error -- DEFAULT_PLATFORMS lost | ||
| # an entry and every downstream target happily built the smaller index. The | ||
| # arm64 half was missing from the published manifest and only a human reading | ||
| # the registry would have caught it. | ||
| # | ||
| # The expected architectures are passed in as policy, deliberately NOT derived | ||
| # from DEFAULT_PLATFORMS. Deriving them would make this test restate whatever | ||
| # the build already decided: removing arm64 from DEFAULT_PLATFORMS would also | ||
| # remove it from the expectation and the test would pass, which is precisely the | ||
| # regression it is here to catch. | ||
| # | ||
| # Both directions are checked. A missing architecture is the known failure, and | ||
| # an unexpected extra one means the index gained a platform nobody declared. | ||
| # | ||
| # Parsed with grep and sed rather than jq so the test stays hermetic, matching | ||
| # java_image_contract_test.sh. | ||
| set -euo pipefail | ||
|
|
||
| if [[ "$#" -lt 2 ]]; then | ||
| echo "usage: $0 <oci layout dir> <arch> [<arch>...]" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| index_dir="$1" | ||
| shift | ||
| expected=("$@") | ||
|
|
||
| if [[ ! -f "${index_dir}/index.json" ]]; then | ||
| echo "not an OCI layout (no index.json): ${index_dir}" >&2 | ||
| ls -la "${index_dir}" >&2 || true | ||
| exit 1 | ||
| fi | ||
|
|
||
| blob_for() { # blob_for <digest as sha256:hex> | ||
| printf '%s/blobs/%s/%s' "${index_dir}" "${1%%:*}" "${1#*:}" | ||
| } | ||
|
|
||
| # Resolve the manifest list, tolerating either OCI layout shape. | ||
| # | ||
| # rules_oci currently writes index.json with a SINGLE descriptor pointing at a | ||
| # nested image-index blob: oci/private/image_index.sh.tpl sets | ||
| # .manifests = [{"mediaType": "application/vnd.oci.image.index.v1+json", ...}] | ||
| # so the platform descriptors live one level down. The OCI spec also permits | ||
| # them inline in index.json, and other tooling emits that flatter form. | ||
| # | ||
| # Detect rather than assume. Hardcoding the nested walk would make this guard | ||
| # quietly stop finding anything if the ruleset ever switched shapes: with no | ||
| # architectures found it would report a missing platform, or worse, a future | ||
| # edit "fixing" that could turn it into a pass. Presence of a platform | ||
| # architecture in index.json is what distinguishes the two. | ||
| index_flat="$(tr -d ' \n' < "${index_dir}/index.json")" | ||
|
|
||
| if printf '%s' "${index_flat}" | grep -q '"architecture":"'; then | ||
| list_flat="${index_flat}" | ||
| else | ||
| top_digest="$(printf '%s' "${index_flat}" \ | ||
| | grep -o '"digest":"sha256:[0-9a-f]*"' | head -1 | cut -d'"' -f4)" | ||
|
balajinvda marked this conversation as resolved.
|
||
| if [[ -z "${top_digest}" ]]; then | ||
| echo "index.json has neither inline platforms nor a manifest descriptor" >&2 | ||
| cat "${index_dir}/index.json" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| manifest_list="$(blob_for "${top_digest}")" | ||
| if [[ ! -f "${manifest_list}" ]]; then | ||
| echo "index.json points at a missing blob: ${top_digest}" >&2 | ||
| exit 1 | ||
| fi | ||
| list_flat="$(tr -d ' \n' < "${manifest_list}")" | ||
| fi | ||
|
|
||
| # Split the manifests array into one entry per line so an architecture is only | ||
| # ever read from the entry that declares it, and a digest is only ever read from | ||
| # the same entry as its architecture. | ||
| entries="$(printf '%s' "${list_flat}" | sed 's/}, *{/}\n{/g')" | ||
|
|
||
| found=() | ||
| while IFS= read -r arch; do | ||
| [[ -n "${arch}" ]] && found+=("${arch}") | ||
| done < <(printf '%s' "${entries}" \ | ||
| | grep -o '"architecture":"[a-z0-9]*"' | cut -d'"' -f4 | sort -u) | ||
|
|
||
| if [[ "${#found[@]}" -eq 0 ]]; then | ||
| echo "image index declares no architectures at all" >&2 | ||
| printf '%s\n' "${list_flat}" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| status=0 | ||
|
|
||
| for want in "${expected[@]}"; do | ||
| hit=false | ||
| for got in "${found[@]}"; do | ||
| [[ "${got}" == "${want}" ]] && hit=true && break | ||
| done | ||
| if [[ "${hit}" != "true" ]]; then | ||
| echo "image index is missing the ${want} manifest" >&2 | ||
| status=1 | ||
| continue | ||
| fi | ||
|
|
||
| # Present in the list is not enough. Follow the descriptor to the config | ||
| # blob and confirm the image itself declares that architecture: an entry | ||
| # can be filed under one platform while pointing at another image, which | ||
| # pushes without complaint and then runs the wrong binary on that host. | ||
| entry="$(printf '%s' "${entries}" | grep -F "\"architecture\":\"${want}\"" | head -1)" | ||
| man_digest="$(printf '%s' "${entry}" \ | ||
| | grep -o '"digest":"sha256:[0-9a-f]*"' | head -1 | cut -d'"' -f4)" | ||
| man_blob="$(blob_for "${man_digest}")" | ||
| if [[ ! -f "${man_blob}" ]]; then | ||
| echo "${want}: manifest blob is missing: ${man_digest}" >&2 | ||
| status=1 | ||
| continue | ||
| fi | ||
|
|
||
| cfg_digest="$(tr -d ' \n' < "${man_blob}" \ | ||
| | grep -o '"config":{[^}]*}' \ | ||
| | grep -o '"digest":"sha256:[0-9a-f]*"' | head -1 | cut -d'"' -f4)" | ||
| cfg_blob="$(blob_for "${cfg_digest}")" | ||
| if [[ ! -f "${cfg_blob}" ]]; then | ||
| echo "${want}: config blob is missing: ${cfg_digest}" >&2 | ||
| status=1 | ||
| continue | ||
| fi | ||
|
|
||
| if ! tr -d ' \n' < "${cfg_blob}" | grep -F "\"architecture\":\"${want}\"" >/dev/null; then | ||
| echo "${want}: entry points at a config declaring a different architecture" >&2 | ||
| tr -d ' \n' < "${cfg_blob}" | grep -o '"architecture":"[a-z0-9]*"' >&2 || true | ||
| status=1 | ||
| continue | ||
| fi | ||
|
|
||
| echo "ok: ${want} manifest present and self-consistent" | ||
| done | ||
|
|
||
| for got in "${found[@]}"; do | ||
| hit=false | ||
| for want in "${expected[@]}"; do | ||
| [[ "${got}" == "${want}" ]] && hit=true && break | ||
| done | ||
| if [[ "${hit}" != "true" ]]; then | ||
| echo "image index declares an unexpected architecture: ${got}" >&2 | ||
| status=1 | ||
| fi | ||
| done | ||
|
|
||
| if [[ "${status}" -ne 0 ]]; then | ||
| echo "expected architectures: ${expected[*]}" >&2 | ||
| echo "index declares: ${found[*]}" >&2 | ||
| exit 1 | ||
| fi | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.