Skip to content

Commit

Permalink
feat(KONFLUX-4892): supply layer size information to pyxis
Browse files Browse the repository at this point in the history
This is meant to be paired with a change in the step image:
konflux-ci/release-service-utils#284

If the layers of the image are found to be gzip compressed, then pull
them, decompress them, and include information about their decompressed
digests and sizes in the manifest provided to the pyxis script.

Signed-off-by: Ralph Bean <rbean@redhat.com>
  • Loading branch information
ralphbean committed Oct 22, 2024
1 parent a0d50ff commit 69c2a2a
Showing 1 changed file with 38 additions and 2 deletions.
40 changes: 38 additions & 2 deletions tasks/create-pyxis-image/create-pyxis-image.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -156,19 +156,55 @@ spec:
ORAS_ARGS+=("--platform $os/$arch")
fi
# Save the OCI manifest locally, to pass to a script to create the pyxis entry
MANIFEST_FILE="/tmp/oras-manifest-fetch.json"
oras manifest fetch \
--registry-config "$AUTH_FILE" \
"${ORAS_ARGS[@]}" \
"${PULLSPEC}" \
| tee /tmp/oras-manifest-fetch.json
| tee "${MANIFEST_FILE}"
# Augment that manifest with further information about the layers, decompressed
# This requires pulling the layers to decompress and then measure them
while IFS= read -r BLOB_DETAIL;
do
BLOB_TYPE=$(jq -r '.mediaType' <<< "$BLOB_DETAIL")
BLOB_DIGEST=$(jq -r '.digest' <<< "$BLOB_DETAIL")
if [[ "$BLOB_TYPE" =~ ^.*\.gzip$|^.*\+gzip$ ]]; then
BLOB_FILE="/tmp/oras-blob-fetch-${BLOB_DIGEST}"
BLOB_PULLSPEC="${PULLSPEC%%@*}@${BLOB_DIGEST}"
# Save the blob
oras blob fetch \
--registry-config "$AUTH_FILE" \
--output "${BLOB_FILE}.gz" \
"${BLOB_PULLSPEC}"
# Decompress it
gunzip "${BLOB_FILE}.gz"
# Measure it
EXPANDED_DIGEST=$(sha256sum "${BLOB_FILE}" | cut -d " " -f 1)
EXPANDED_SIZE=$(wc --bytes "${BLOB_FILE}" | awk '{print $1}' | tr -d '\n')
# Append this information to the parsed_data manifest
cat <<< $(jq \
'.uncompressed_layers += [{"digest": "'"$EXPANDED_DIGEST"'", "size": '"$EXPANDED_SIZE"'}]' \
"${MANIFEST_FILE}") > "${MANIFEST_FILE}"
# Clean up, in case we're dealing with large images
rm "/tmp/oras-blob-fetch-${BLOB_DIGEST}"
fi
done <<< $(jq -c '.layers[]' "${MANIFEST_FILE}")
PYXIS_CERT_PATH=/tmp/crt PYXIS_KEY_PATH=/tmp/key create_container_image \
--pyxis-url $PYXIS_URL \
--certified $(params.certified) \
--tags "$TAGS" \
--is-latest $(params.isLatest) \
--verbose \
--oras-manifest-fetch "/tmp/oras-manifest-fetch.json" \
--oras-manifest-fetch "${MANIFEST_FILE}" \
--name "$REPOSITORY" \
--media-type "$MEDIA_TYPE" \
--digest "$DIGEST" \
Expand Down

0 comments on commit 69c2a2a

Please sign in to comment.