Skip to content

Commit 35672fe

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 0c49c2e commit 35672fe

File tree

1 file changed

+45
-9
lines changed

1 file changed

+45
-9
lines changed

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

Lines changed: 45 additions & 9 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}")
@@ -298,13 +303,50 @@ 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"
307336
337+
# Second pass: process the results now that all find_signatures calls are complete
338+
for component_info in "${component_data[@]}"; do
339+
IFS='|' read -r COMPONENTS_INDEX repository TAGS manifest_digests sourceContainerDigest \
340+
rh_registry_repo registry_access_repo <<< "$component_info"
341+
342+
# Sign rh-registry-repo references (always) and registry-access-repo references
343+
# (only if signatures for this registry are required)
344+
REGISTRY_REFERENCES=("${rh_registry_repo}")
345+
if grep -q "^${repository}$" "${SIGN_REGISTRY_ACCESS_FILE}"; then
346+
REGISTRY_REFERENCES+=("${registry_access_repo}")
347+
fi
348+
349+
for manifest_digest in $manifest_digests; do
308350
# Iterate over both rh-registry-repo and registry-access-repo
309351
for registry_reference in "${REGISTRY_REFERENCES[@]}"; do
310352
@@ -324,12 +366,6 @@ spec:
324366
done
325367
326368
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-
333369
for registry_reference in "${REGISTRY_REFERENCES[@]}"; do
334370
335371
for tag in ${TAGS}; do
@@ -343,8 +379,8 @@ spec:
343379
echo "- reference=${registry_reference}:${sourceTag}"
344380
echo "- manifest_digest=${sourceContainerDigest}"
345381
fi
382+
done
346383
done
347-
done
348384
fi
349385
done
350386

0 commit comments

Comments
 (0)