Skip to content

Commit 2228685

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 c1a4ca8 commit 2228685

File tree

1 file changed

+44
-9
lines changed

1 file changed

+44
-9
lines changed

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

Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,11 @@ spec:
250250
declare -a to_sign_references=()
251251
declare -a to_sign_digests=()
252252
253+
# Arrays to store information for parallel processing
254+
declare -a find_signatures_jobs=()
255+
declare -a component_data=()
256+
257+
# First pass: collect all find_signatures calls and start them in parallel
253258
for (( COMPONENTS_INDEX=0; COMPONENTS_INDEX<COMPONENTS_LENGTH; COMPONENTS_INDEX++ )); do
254259
255260
referenceContainerImage=$(jq -r ".components[${COMPONENTS_INDEX}].containerImage" "${SNAPSHOT_PATH}")
@@ -297,13 +302,49 @@ spec:
297302
REGISTRY_REFERENCES+=("${registry_access_repo}")
298303
fi
299304
300-
for manifest_digest in $manifest_digests; do
305+
# Store component data for later processing
306+
component_data+=("${COMPONENTS_INDEX}|${repository}|${TAGS}|${manifest_digests}|${sourceContainerDigest}|${rh_registry_repo}|${registry_access_repo}")
301307
308+
# Start find_signatures jobs in parallel for manifest digests
309+
for manifest_digest in $manifest_digests; do
310+
echo "Starting find_signatures job for manifest digest: ${manifest_digest}"
302311
find_signatures --pyxis-graphql-api "${PYXIS_GRAPHQL_URL}" \
303312
--manifest_digest "${manifest_digest}" \
304313
--repository "${repository}" \
305-
--output_file "/tmp/${manifest_digest}"
314+
--output_file "/tmp/${manifest_digest}" &
315+
find_signatures_jobs+=($!)
316+
done
317+
318+
# Start find_signatures job for source container digest if it exists
319+
if [ "${sourceContainerDigest}" != "" ] ; then
320+
echo "Starting find_signatures job for source container digest: ${sourceContainerDigest}"
321+
find_signatures --pyxis-graphql-api "${PYXIS_GRAPHQL_URL}" \
322+
--manifest_digest "${sourceContainerDigest}" \
323+
--repository "${repository}" \
324+
--output_file "/tmp/${sourceContainerDigest}" &
325+
find_signatures_jobs+=($!)
326+
fi
327+
done
328+
329+
# Wait for all find_signatures jobs to complete
330+
echo "Waiting for ${#find_signatures_jobs[@]} find_signatures jobs to complete..."
331+
for job in "${find_signatures_jobs[@]}"; do
332+
wait "$job"
333+
done
334+
echo "All find_signatures jobs completed"
306335
336+
# Second pass: process the results now that all find_signatures calls are complete
337+
for component_info in "${component_data[@]}"; do
338+
IFS='|' read -r COMPONENTS_INDEX repository TAGS manifest_digests sourceContainerDigest rh_registry_repo registry_access_repo <<< "$component_info"
339+
340+
# Sign rh-registry-repo references (always) and registry-access-repo references
341+
# (only if signatures for this registry are required)
342+
REGISTRY_REFERENCES=("${rh_registry_repo}")
343+
if grep -q "^${repository}$" "${SIGN_REGISTRY_ACCESS_FILE}"; then
344+
REGISTRY_REFERENCES+=("${registry_access_repo}")
345+
fi
346+
347+
for manifest_digest in $manifest_digests; do
307348
# Iterate over both rh-registry-repo and registry-access-repo
308349
for registry_reference in "${REGISTRY_REFERENCES[@]}"; do
309350
@@ -323,12 +364,6 @@ spec:
323364
done
324365
325366
if [ "${sourceContainerDigest}" != "" ] ; then
326-
327-
find_signatures --pyxis-graphql-api "${PYXIS_GRAPHQL_URL}" \
328-
--manifest_digest "${sourceContainerDigest}" \
329-
--repository "${repository}" \
330-
--output_file "/tmp/${sourceContainerDigest}"
331-
332367
for registry_reference in "${REGISTRY_REFERENCES[@]}"; do
333368
334369
for tag in ${TAGS}; do
@@ -342,8 +377,8 @@ spec:
342377
echo "- reference=${registry_reference}:${sourceTag}"
343378
echo "- manifest_digest=${sourceContainerDigest}"
344379
fi
380+
done
345381
done
346-
done
347382
fi
348383
done
349384

0 commit comments

Comments
 (0)