Skip to content

Commit 344e391

Browse files
committed
fix(RELEASE-1728): rh-sign-image optimization
- parallelize calls to find-signature in an effort to improve performance. Assisted-by: Cursor Signed-off-by: Scott Hebert <[email protected]>
1 parent b2e800f commit 344e391

File tree

1 file changed

+55
-10
lines changed

1 file changed

+55
-10
lines changed

tasks/managed/rh-sign-image/rh-sign-image.yaml

Lines changed: 55 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,11 @@ spec:
251251
declare -a to_sign_references=()
252252
declare -a to_sign_digests=()
253253
254+
# Arrays to store information for parallel processing
255+
declare -a find_signatures_jobs=()
256+
declare -a component_data=()
257+
258+
# First pass: collect all find_signatures calls and start them in parallel
254259
for (( COMPONENTS_INDEX=0; COMPONENTS_INDEX<COMPONENTS_LENGTH; COMPONENTS_INDEX++ )); do
255260
256261
referenceContainerImage=$(jq -r ".components[${COMPONENTS_INDEX}].containerImage" "${SNAPSHOT_PATH}")
@@ -268,7 +273,7 @@ spec:
268273
manifest_digests="${referenceContainerImage#*@}"
269274
# For multi arch, also sign all the manifests inside
270275
if [ "$(jq -r '.mediaType' <<< "$RAW_OUTPUT")" != "application/vnd.oci.image.manifest.v1+json" ] ; then
271-
nested_digests=$(jq -r '.manifests[].digest' <<< "$RAW_OUTPUT")
276+
nested_digests=$(jq -r '[.manifests[].digest] | join(" ")' <<< "$RAW_OUTPUT")
272277
manifest_digests="$manifest_digests $nested_digests"
273278
fi
274279
@@ -298,13 +303,59 @@ spec:
298303
REGISTRY_REFERENCES+=("${registry_access_repo}")
299304
fi
300305
301-
for manifest_digest in $manifest_digests; do
306+
# Store component data for later processing
307+
component_data+=("${COMPONENTS_INDEX}|${repository}|${TAGS}|${manifest_digests}|${sourceContainerDigest}|${rh_registry_repo}|${registry_access_repo}")
302308
309+
# Start find_signatures jobs in parallel for manifest digests
310+
for manifest_digest in $manifest_digests; do
311+
echo "Starting find_signatures job for manifest digest: ${manifest_digest}"
303312
find_signatures --pyxis-graphql-api "${PYXIS_GRAPHQL_URL}" \
304313
--manifest_digest "${manifest_digest}" \
305314
--repository "${repository}" \
306-
--output_file "/tmp/${manifest_digest}"
315+
--output_file "/tmp/${manifest_digest}" &
316+
find_signatures_jobs+=($!)
317+
done
318+
319+
# Start find_signatures job for source container digest if it exists
320+
if [ "${sourceContainerDigest}" != "" ] ; then
321+
echo "Starting find_signatures job for source container digest: ${sourceContainerDigest}"
322+
find_signatures --pyxis-graphql-api "${PYXIS_GRAPHQL_URL}" \
323+
--manifest_digest "${sourceContainerDigest}" \
324+
--repository "${repository}" \
325+
--output_file "/tmp/${sourceContainerDigest}" &
326+
find_signatures_jobs+=($!)
327+
fi
328+
done
329+
330+
# Wait for all find_signatures jobs to complete
331+
echo "Waiting for ${#find_signatures_jobs[@]} find_signatures jobs to complete..."
332+
for job in "${find_signatures_jobs[@]}"; do
333+
wait "$job"
334+
done
335+
echo "All find_signatures jobs completed"
336+
337+
# Second pass: process the results now that all find_signatures calls are complete
338+
for component_info in "${component_data[@]}"; do
339+
echo "Processing component_info: ${component_info}"
307340
341+
IFS='|' read -r COMPONENTS_INDEX repository TAGS manifest_digests sourceContainerDigest \
342+
rh_registry_repo registry_access_repo <<< "$component_info"
343+
344+
echo "repository: ${repository}"
345+
echo "TAGS: ${TAGS}"
346+
echo "manifest_digests: ${manifest_digests}"
347+
echo "sourceContainerDigest: ${sourceContainerDigest}"
348+
echo "rh_registry_repo: ${rh_registry_repo}"
349+
echo "registry_access_repo: ${registry_access_repo}"
350+
351+
# Sign rh-registry-repo references (always) and registry-access-repo references
352+
# (only if signatures for this registry are required)
353+
REGISTRY_REFERENCES=("${rh_registry_repo}")
354+
if grep -q "^${repository}$" "${SIGN_REGISTRY_ACCESS_FILE}"; then
355+
REGISTRY_REFERENCES+=("${registry_access_repo}")
356+
fi
357+
358+
for manifest_digest in $manifest_digests; do
308359
# Iterate over both rh-registry-repo and registry-access-repo
309360
for registry_reference in "${REGISTRY_REFERENCES[@]}"; do
310361
@@ -324,12 +375,6 @@ spec:
324375
done
325376
326377
if [ "${sourceContainerDigest}" != "" ] ; then
327-
328-
find_signatures --pyxis-graphql-api "${PYXIS_GRAPHQL_URL}" \
329-
--manifest_digest "${sourceContainerDigest}" \
330-
--repository "${repository}" \
331-
--output_file "/tmp/${sourceContainerDigest}"
332-
333378
for registry_reference in "${REGISTRY_REFERENCES[@]}"; do
334379
335380
for tag in ${TAGS}; do
@@ -343,8 +388,8 @@ spec:
343388
echo "- reference=${registry_reference}:${sourceTag}"
344389
echo "- manifest_digest=${sourceContainerDigest}"
345390
fi
391+
done
346392
done
347-
done
348393
fi
349394
done
350395

0 commit comments

Comments
 (0)