Repository navigation
fix(export-dynamic): verify registry artifacts before skipping workspace (RHDHBUGS-3635) #160
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
Open
gashcrumb
wants to merge
5
commits into
redhat-developer:main
Choose a base branch
from
gashcrumb:fix/RHDHBUGS-3635-verify-registry-artifacts
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+330
−1
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
bbc3682
fix(export-dynamic): verify registry artifacts before skipping worksp…
gashcrumb 164415b
fix: flatten conditional and use double brackets for conditional test
gashcrumb 6e2b5d8
fix(export-dynamic): address review feedback on registry-artifact ver…
gashcrumb 6fafcc4
fix(export-dynamic): support image indexes and add artifact verificat…
gashcrumb 00c2bcc
fix(export-dynamic): merge nested conditional in verify_registry_arti…
gashcrumb 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
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,38 @@ | ||
| #!/usr/bin/env bash | ||
| # Verifies that a container image exists in the registry and contains valid, | ||
| # non-empty dynamic package metadata (io.backstage.dynamic-packages). | ||
| # | ||
| # Supports both single-architecture OCI manifests (e.g. GHCR) and multi-architecture | ||
| # image indexes / manifest lists (e.g. Quay/Konflux) by dereferencing child manifests. | ||
|
|
||
| verify_registry_artifact() { | ||
| local repo_prefix="$1" | ||
| local plugin_name="$2" | ||
| local version="$3" | ||
| local transport="${4:-docker}" | ||
|
|
||
| local target="${transport}://${repo_prefix}/${plugin_name}:${version}" | ||
| if [[ "$transport" == "dir" ]]; then | ||
| target="dir:${repo_prefix}/${plugin_name}" | ||
| fi | ||
|
|
||
| local raw_manifest | ||
| raw_manifest=$(skopeo inspect --raw "${target}" 2>/dev/null) || raw_manifest="" | ||
| # If the image is an index/manifest list without direct annotations, resolve the first child manifest | ||
| if [[ -n "$raw_manifest" ]] && ! echo "$raw_manifest" | jq -e '.annotations["io.backstage.dynamic-packages"]' >/dev/null 2>&1 && echo "$raw_manifest" | jq -e '.manifests != null' >/dev/null 2>&1; then | ||
| local child_digest | ||
| child_digest=$(echo "$raw_manifest" | jq -r '.manifests[0].digest // empty') | ||
| if [[ -n "$child_digest" ]]; then | ||
| local child_target="${transport}://${repo_prefix}/${plugin_name}@${child_digest}" | ||
| if [[ "$transport" == "dir" ]]; then | ||
| child_target="dir:${repo_prefix}/${plugin_name}_child" | ||
| fi | ||
| raw_manifest=$(skopeo inspect --raw "${child_target}" 2>/dev/null) || raw_manifest="" | ||
| fi | ||
| fi | ||
|
|
||
| if [[ -z "$raw_manifest" ]] || ! echo "$raw_manifest" | jq -e '.annotations["io.backstage.dynamic-packages"] | @base64d | fromjson | length > 0' >/dev/null 2>&1; then | ||
| return 1 | ||
| fi | ||
| return 0 | ||
| } |
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,213 @@ | ||
| #!/usr/bin/env bash | ||
| set -euo pipefail | ||
|
|
||
| SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" | ||
| # shellcheck source=export-dynamic/verify-registry-artifacts.sh | ||
| source "${SCRIPT_DIR}/verify-registry-artifacts.sh" | ||
|
|
||
| assert_eq() { | ||
| local description="$1" | ||
| local expected="$2" | ||
| local actual="$3" | ||
| if [[ "$expected" == "$actual" ]]; then | ||
| echo "PASS: ${description}" | ||
| else | ||
| echo "FAIL: ${description} (expected '${expected}', got '${actual}')" >&2 | ||
| exit 1 | ||
| fi | ||
| } | ||
|
|
||
| WORKDIR=$(mktemp -d /tmp/verify-artifacts-test-XXXXXX) | ||
| trap 'rm -rf "$WORKDIR"' EXIT | ||
|
|
||
| # --- Offline tests using dir: transport --- | ||
|
|
||
| # 1. Valid single OCI manifest with dynamic-packages annotation | ||
| mkdir -p "${WORKDIR}/valid-pkg" | ||
| cat << 'JSON' > "${WORKDIR}/valid-pkg/manifest.json" | ||
| { | ||
| "schemaVersion": 2, | ||
| "mediaType": "application/vnd.oci.image.manifest.v1+json", | ||
| "config": { | ||
| "mediaType": "application/vnd.oci.image.config.v1+json", | ||
| "digest": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", | ||
| "size": 2 | ||
| }, | ||
| "layers": [], | ||
| "annotations": { | ||
| "io.backstage.dynamic-packages": "W3sidGVzdC1wbHVnaW4iOnsidmVyc2lvbiI6IjEuMC4wIn19XQ==" | ||
| } | ||
| } | ||
| JSON | ||
|
|
||
| res=0 | ||
| verify_registry_artifact "${WORKDIR}" "valid-pkg" "1.0.0" "dir" || res=$? | ||
| assert_eq "offline: valid manifest accepted" "0" "$res" | ||
|
|
||
| # 2. Manifest with empty annotation | ||
| mkdir -p "${WORKDIR}/empty-pkg" | ||
| cat << 'JSON' > "${WORKDIR}/empty-pkg/manifest.json" | ||
| { | ||
| "schemaVersion": 2, | ||
| "mediaType": "application/vnd.oci.image.manifest.v1+json", | ||
| "config": { | ||
| "mediaType": "application/vnd.oci.image.config.v1+json", | ||
| "digest": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", | ||
| "size": 2 | ||
| }, | ||
| "layers": [], | ||
| "annotations": { | ||
| "io.backstage.dynamic-packages": "" | ||
| } | ||
| } | ||
| JSON | ||
|
|
||
| res=0 | ||
| verify_registry_artifact "${WORKDIR}" "empty-pkg" "1.0.0" "dir" || res=$? | ||
| assert_eq "offline: empty annotation rejected" "1" "$res" | ||
|
|
||
| # 3. Manifest missing dynamic-packages annotation entirely | ||
| mkdir -p "${WORKDIR}/missing-pkg" | ||
| cat << 'JSON' > "${WORKDIR}/missing-pkg/manifest.json" | ||
| { | ||
| "schemaVersion": 2, | ||
| "mediaType": "application/vnd.oci.image.manifest.v1+json", | ||
| "config": { | ||
| "mediaType": "application/vnd.oci.image.config.v1+json", | ||
| "digest": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", | ||
| "size": 2 | ||
| }, | ||
| "layers": [], | ||
| "annotations": {} | ||
| } | ||
| JSON | ||
|
|
||
| res=0 | ||
| verify_registry_artifact "${WORKDIR}" "missing-pkg" "1.0.0" "dir" || res=$? | ||
| assert_eq "offline: missing annotation rejected" "1" "$res" | ||
|
|
||
| # 4. Manifest with empty array annotation (W10= is base64 of "[]") | ||
| mkdir -p "${WORKDIR}/empty-arr-pkg" | ||
| cat << 'JSON' > "${WORKDIR}/empty-arr-pkg/manifest.json" | ||
| { | ||
| "schemaVersion": 2, | ||
| "mediaType": "application/vnd.oci.image.manifest.v1+json", | ||
| "config": { | ||
| "mediaType": "application/vnd.oci.image.config.v1+json", | ||
| "digest": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", | ||
| "size": 2 | ||
| }, | ||
| "layers": [], | ||
| "annotations": { | ||
| "io.backstage.dynamic-packages": "W10=" | ||
| } | ||
| } | ||
| JSON | ||
|
|
||
| res=0 | ||
| verify_registry_artifact "${WORKDIR}" "empty-arr-pkg" "1.0.0" "dir" || res=$? | ||
| assert_eq "offline: empty array annotation rejected" "1" "$res" | ||
|
|
||
| # 5. Non-existent image/directory | ||
| res=0 | ||
| verify_registry_artifact "${WORKDIR}" "non-existent" "1.0.0" "dir" || res=$? | ||
| assert_eq "offline: non-existent target rejected" "1" "$res" | ||
|
|
||
| # 6. Image index dereferencing valid child manifest | ||
| mkdir -p "${WORKDIR}/index-valid-pkg" "${WORKDIR}/index-valid-pkg_child" | ||
| cat << 'JSON' > "${WORKDIR}/index-valid-pkg/manifest.json" | ||
| { | ||
| "schemaVersion": 2, | ||
| "mediaType": "application/vnd.oci.image.index.v1+json", | ||
| "manifests": [ | ||
| { | ||
| "mediaType": "application/vnd.oci.image.manifest.v1+json", | ||
| "digest": "sha256:childvalid", | ||
| "size": 100 | ||
| } | ||
| ] | ||
| } | ||
| JSON | ||
| cat << 'JSON' > "${WORKDIR}/index-valid-pkg_child/manifest.json" | ||
| { | ||
| "schemaVersion": 2, | ||
| "mediaType": "application/vnd.oci.image.manifest.v1+json", | ||
| "config": { | ||
| "mediaType": "application/vnd.oci.image.config.v1+json", | ||
| "digest": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", | ||
| "size": 2 | ||
| }, | ||
| "layers": [], | ||
| "annotations": { | ||
| "io.backstage.dynamic-packages": "W3sidGVzdC1wbHVnaW4iOnsidmVyc2lvbiI6IjEuMC4wIn19XQ==" | ||
| } | ||
| } | ||
| JSON | ||
|
|
||
| res=0 | ||
| verify_registry_artifact "${WORKDIR}" "index-valid-pkg" "1.0.0" "dir" || res=$? | ||
| assert_eq "offline: image index with valid child accepted" "0" "$res" | ||
|
|
||
| # 7. Image index dereferencing child manifest with empty annotation | ||
| mkdir -p "${WORKDIR}/index-empty-pkg" "${WORKDIR}/index-empty-pkg_child" | ||
| cat << 'JSON' > "${WORKDIR}/index-empty-pkg/manifest.json" | ||
| { | ||
| "schemaVersion": 2, | ||
| "mediaType": "application/vnd.oci.image.index.v1+json", | ||
| "manifests": [ | ||
| { | ||
| "mediaType": "application/vnd.oci.image.manifest.v1+json", | ||
| "digest": "sha256:childempty", | ||
| "size": 100 | ||
| } | ||
| ] | ||
| } | ||
| JSON | ||
| cat << 'JSON' > "${WORKDIR}/index-empty-pkg_child/manifest.json" | ||
| { | ||
| "schemaVersion": 2, | ||
| "mediaType": "application/vnd.oci.image.manifest.v1+json", | ||
| "config": { | ||
| "mediaType": "application/vnd.oci.image.config.v1+json", | ||
| "digest": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", | ||
| "size": 2 | ||
| }, | ||
| "layers": [], | ||
| "annotations": { | ||
| "io.backstage.dynamic-packages": "" | ||
| } | ||
| } | ||
| JSON | ||
|
|
||
| res=0 | ||
| verify_registry_artifact "${WORKDIR}" "index-empty-pkg" "1.0.0" "dir" || res=$? | ||
| assert_eq "offline: image index with empty child annotation rejected" "1" "$res" | ||
|
|
||
| # --- Online live tests against real registries (if reachable) --- | ||
| if skopeo inspect --raw docker://quay.io/rhdh/red-hat-developer-hub-backstage-plugin-scorecard-backend-module-dependabot:2.0.0--1.1.2 >/dev/null 2>&1; then | ||
| echo "Running online live registry tests..." | ||
|
|
||
| # Broken Quay scorecard image (empty annotation on child manifest, from RHDHBUGS-3834) | ||
| res=0 | ||
| verify_registry_artifact "quay.io/rhdh" "red-hat-developer-hub-backstage-plugin-scorecard-backend-module-dependabot" "2.0.0--1.1.1" || res=$? | ||
| assert_eq "online: broken scorecard image on Quay rejected" "1" "$res" | ||
|
|
||
| # Fixed Quay scorecard image (valid annotation on child manifest) | ||
| res=0 | ||
| verify_registry_artifact "quay.io/rhdh" "red-hat-developer-hub-backstage-plugin-scorecard-backend-module-dependabot" "2.0.0--1.1.2" || res=$? | ||
| assert_eq "online: fixed scorecard image on Quay accepted" "0" "$res" | ||
|
|
||
| # Valid GHCR image (single OCI manifest) | ||
| res=0 | ||
| verify_registry_artifact "ghcr.io/redhat-developer/rhdh-plugin-export-overlays" "backstage-community-plugin-github-actions" "bs_1.54.9__1.4.0" || res=$? | ||
| assert_eq "online: valid GHCR image accepted" "0" "$res" | ||
|
|
||
| # Non-existent image tag | ||
| res=0 | ||
| verify_registry_artifact "ghcr.io/redhat-developer/rhdh-plugin-export-overlays" "backstage-community-plugin-github-actions" "bs_1.54.9__99.99.99" || res=$? | ||
| assert_eq "online: non-existent tag rejected" "1" "$res" | ||
| else | ||
| echo "Skipping online tests (registry unreachable or network offline)" | ||
| fi | ||
|
|
||
| echo "All verify-registry-artifacts tests passed." |
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.