Skip to content

Commit 7e0a918

Browse files
authored
Merge pull request bottlerocket-os#1996 from jpculp/app-inventory
generate bottlerocket rpm inventory file to share with host containers
2 parents 29da70b + 97530bc commit 7e0a918

File tree

8 files changed

+44
-0
lines changed

8 files changed

+44
-0
lines changed

packages/filesystem/filesystem.spec

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Version: 1.0
55
Release: 1%{?dist}
66
Summary: The basic directory layout
77
License: Apache-2.0 OR MIT
8+
URL: https://github.com/bottlerocket-os/bottlerocket
89
BuildArch: noarch
910

1011
%description

packages/host-ctr/host-ctr.spec

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Version: 0.0
66
Release: 0%{?dist}
77
Summary: Bottlerocket host container runner
88
License: Apache-2.0 OR MIT
9+
URL: https://github.com/bottlerocket-os/bottlerocket
910
BuildRequires: %{_cross_os}glibc-devel
1011
Requires: %{_cross_os}containerd
1112

packages/login/login.spec

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Version: 0.0.1
55
Release: 1%{?dist}
66
Summary: A login helper
77
License: Apache-2.0 OR MIT
8+
URL: https://github.com/bottlerocket-os/bottlerocket
89
Source0: login
910
BuildRequires: %{_cross_os}glibc-devel
1011
Requires: %{_cross_os}bash

packages/os/os.spec

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Version: 0.0
99
Release: 0%{?dist}
1010
Summary: Bottlerocket's first-party code
1111
License: Apache-2.0 OR MIT
12+
URL: https://github.com/bottlerocket-os/bottlerocket
1213

1314
# sources < 100: misc
1415
Source2: api-sysusers.conf

packages/release/release.spec

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Version: 0.0
55
Release: 0%{?dist}
66
Summary: Bottlerocket release
77
License: Apache-2.0 OR MIT
8+
URL: https://github.com/bottlerocket-os/bottlerocket
89

910
Source11: nsswitch.conf
1011
Source96: release-repart-local.conf

packages/selinux-policy/selinux-policy.spec

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Version: 0.0
66
Release: 0%{?dist}
77
Summary: SELinux policy
88
License: Apache-2.0 OR MIT
9+
URL: https://github.com/bottlerocket-os/bottlerocket
910

1011
# CIL policy files
1112
Source0: base.cil

sources/host-ctr/cmd/host-ctr/main.go

+6
Original file line numberDiff line numberDiff line change
@@ -700,6 +700,12 @@ func withDefaultMounts(containerID string, persistentDir string) oci.SpecOpts {
700700
Destination: fmt.Sprintf("/etc/bottlerocket-release"),
701701
Source: fmt.Sprintf("/etc/os-release"),
702702
},
703+
// Bottlerocket RPM inventory available to the container
704+
{
705+
Options: []string{"bind", "ro"},
706+
Destination: fmt.Sprintf("/var/lib/bottlerocket/inventory/application.json"),
707+
Source: fmt.Sprintf("/usr/share/bottlerocket/application-inventory.json"),
708+
},
703709
}
704710

705711
// The `current` dir was added for easier referencing in Dockerfiles and scripts.

tools/rpm2img

+32
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ shopt -qs failglob
88
. "${0%/*}/partyplanner"
99

1010
OUTPUT_FMT="raw"
11+
BUILDER_ARCH="$(uname -m)"
1112

1213
for opt in "$@"; do
1314
optarg="$(expr "${opt}" : '[^=]*=\(.*\)')"
@@ -135,7 +136,38 @@ if [ "${PARTITION_PLAN}" == "split" ] ; then
135136
--sort --print "${DATA_IMAGE}"
136137
fi
137138

139+
INSTALL_TIME="$(date -u +%Y-%m-%dT%H:%M:%SZ)"
138140
rpm -iv --root "${ROOT_MOUNT}" "${PACKAGE_DIR}"/*.rpm
141+
142+
# inventory installed packages
143+
INVENTORY_QUERY="\{\"Name\":\"%{NAME}\"\
144+
,\"Publisher\":\"Bottlerocket\"\
145+
,\"Version\":\"${VERSION_ID}\"\
146+
,\"Release\":\"${BUILD_ID}\"\
147+
,\"InstalledTime\":\"${INSTALL_TIME}\"\
148+
,\"ApplicationType\":\"%{GROUP}\"\
149+
,\"Architecture\":\"%{ARCH}\"\
150+
,\"Url\":\"%{URL}\"\
151+
,\"Summary\":\"%{Summary}\"\}\n"
152+
153+
mapfile -t installed_rpms <<< "$(rpm -qa --root "${ROOT_MOUNT}" \
154+
--queryformat "${INVENTORY_QUERY}")"
155+
156+
# wrap installed_rpms mapfile into json
157+
INVENTORY_DATA="$(jq --raw-output . <<< "${installed_rpms[@]}")"
158+
# replace the package architecture with the target architecture (for cross-compiled builds)
159+
if [[ "${BUILDER_ARCH}" != "${ARCH}" ]]; then
160+
INVENTORY_DATA="$(jq --arg BUILDER_ARCH "${BUILDER_ARCH}" --arg TARGET_ARCH "${ARCH}" \
161+
'(.Architecture) |= sub($BUILDER_ARCH; $TARGET_ARCH)' <<< "${INVENTORY_DATA}")"
162+
fi
163+
# remove the 'bottlerocket-<arch>-' prefix from package names
164+
INVENTORY_DATA="$(jq --arg PKG_PREFIX "bottlerocket-${ARCH}-" \
165+
'(.Name) |= sub($PKG_PREFIX; "")' <<< "${INVENTORY_DATA}")"
166+
# sort by package name and add 'Content' as top-level
167+
INVENTORY_DATA="$(jq --slurp 'sort_by(.Name)' <<< "${INVENTORY_DATA}" | jq '{"Content": .}')"
168+
printf "%s\n" "${INVENTORY_DATA}" > "${ROOT_MOUNT}/usr/share/bottlerocket/application-inventory.json"
169+
170+
# install licenses
139171
install -p -m 0644 /host/{COPYRIGHT,LICENSE-APACHE,LICENSE-MIT} "${ROOT_MOUNT}"/usr/share/licenses/
140172
mksquashfs \
141173
"${ROOT_MOUNT}"/usr/share/licenses \

0 commit comments

Comments
 (0)