Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 28 additions & 3 deletions twoliter/embedded/rpm2img
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,8 @@ INVENTORY_QUERY="\{\"Name\":\"%{NAME}\"\
,\"ApplicationType\":\"%{GROUP}\"\
,\"Architecture\":\"%{ARCH}\"\
,\"Url\":\"%{URL}\"\
,\"Summary\":\"%{Summary}\"\}\n"
,\"Summary\":\"%{Summary}\"\
,\"Alias\":\"[%{Obsoletes},]\"\}\n"

# shellcheck disable=SC2312 # Array is validated elsewhere.
mapfile -t installed_rpms <<<"$(rpm -qa --root "${ROOT_MOUNT}" \
Expand All @@ -186,6 +187,30 @@ INVENTORY_DATA="$(jq --raw-output . <<<"${installed_rpms[@]}")"
# Sort by package name and add 'Content' as top-level.
INVENTORY_DATA="$(jq --slurp 'sort_by(.Name)' <<<"${INVENTORY_DATA}" | jq '{"Content": .}')"

# Add alias entries from Obsoletes field.
# Alias is formatted as "[pkg1,pkg2,]" - we split and create an entry for each.
# We strip the bottlerocket- prefix because these Alias packages are not available in KIT_PKGS variable.
ORIG_COUNT=$(jq '.Content | length' <<<"${INVENTORY_DATA}")

INVENTORY_DATA=$(jq '
.Content |= (
. + [
.[] |
select(.Alias != null and .Alias != "(none)" and .Alias != "[]") |
. as $orig |
# We trim the opening and closing bracket and the ending comma from Alias to arrive at pkg1,pkg2 ...
(.Alias | ltrimstr("[") | rtrimstr("]") | rtrimstr(",") | split(",")[] | select(. != "")) |
sub("^bottlerocket-";"") |
($orig + {Name: .})
] |
unique_by(.Name) |
map(del(.Alias)) |
sort_by(.Name)
)
' <<<"${INVENTORY_DATA}")

ALIAS_COUNT=$(($(jq '.Content | length' <<<"${INVENTORY_DATA}") - ORIG_COUNT))

# Iterate through all kits used to build this variant.
EXTERNAL_KIT_METADATA_PATH="${EXTERNAL_KITS_PATH}/external-kit-metadata.json"
mapfile -t kits < <(jq -r ".kit[].name" "${EXTERNAL_KIT_METADATA_PATH}")
Expand Down Expand Up @@ -239,8 +264,8 @@ done
# Verify we successfully inventoried some RPMs.
INVENTORY_COUNT="$(jq '.Content | length' <<<"${INVENTORY_DATA}")"
RPM_COUNT="$(find "${PACKAGE_DIR}" -maxdepth 1 -type f -name '*.rpm' | wc -l)"
if [[ "${INVENTORY_COUNT}" -ne "${RPM_COUNT}" ]]; then
echo "Inventory of RPMs does not match what was expected: '${INVENTORY_COUNT}/${RPM_COUNT}'" >&2
if [[ "${INVENTORY_COUNT}" -ne "$((RPM_COUNT + ALIAS_COUNT))" ]]; then
echo "Inventory of RPMs does not match what was expected: '${INVENTORY_COUNT}/$((RPM_COUNT + ALIAS_COUNT))'" >&2
exit 1
fi
if grep -q "bottlerocket-release" <<<"${INVENTORY_DATA}"; then
Expand Down
Loading