build_image_util: generate package license list for each image

There isn't a sane way for users to know the licenses of individual
packages in CoreOS images in built images. The information is hidden
away back in the original ebuilds. This extends our existing package
list with a new file that also includes licenses:

```
app-admin/flannel-0.3.0-r3::coreos Apache-2.0
app-admin/fleet-0.9.1::coreos Apache-2.0
app-admin/locksmith-0.2.3::coreos Apache-2.0
app-admin/sdnotify-proxy-0.1.0::coreos Apache-2.0
app-admin/sudo-1.8.10_p2::portage-stable ISC BSD
app-admin/toolbox-0.0.0-r4::coreos Apache-2.0
app-arch/bzip2-1.0.6-r6::portage-stable BZIP2
app-arch/gzip-1.5::portage-stable GPL-3
app-arch/tar-1.27.1-r2::portage-stable GPL-3+
...
```
This commit is contained in:
Michael Marineau 2015-03-21 19:13:12 -07:00
parent e235fb5f9f
commit 3b8cf7d1fb
3 changed files with 32 additions and 6 deletions

View File

@ -142,16 +142,38 @@ write_contents() {
popd >/dev/null popd >/dev/null
} }
# Generate a list of packages installed in an image.
# Usage: image_packages /image/root
image_packages() {
local profile="${BUILD_DIR}/configroot/etc/portage/profile"
ROOT="$1" PORTAGE_CONFIGROOT="${BUILD_DIR}"/configroot \
equery --no-color list --format '$cpv::$repo' '*'
# In production images GCC libraries are extracted manually.
if [[ -f "${profile}/package.provided" ]]; then
xargs --arg-file="${profile}/package.provided" \
equery-${BOARD} --no-color list --format '$cpv::$repo'
fi
}
# Generate a list of installed packages in the format: # Generate a list of installed packages in the format:
# sys-apps/systemd-212-r8::coreos # sys-apps/systemd-212-r8::coreos
write_packages() { write_packages() {
local profile="${BUILD_DIR}/configroot/etc/portage/profile"
info "Writing ${2##*/}" info "Writing ${2##*/}"
ROOT="$1" PORTAGE_CONFIGROOT="${BUILD_DIR}"/configroot \ image_packages "$1" | sort > "$2"
equery --no-color list '*' --format '$cpv::$repo' > "$2" }
if [[ -f "${profile}/package.provided" ]]; then
cat "${profile}/package.provided" >> "$2" # Generate a list of packages w/ their licenses in the format:
fi # sys-apps/systemd-212-r8::coreos GPL-2 LGPL-2.1 MIT public-domain
write_licenses() {
info "Writing ${2##*/}"
local vdb=$(portageq-${BOARD} vdb_path)
local pkg lic
for pkg in $(image_packages "$1" | sort); do
lic="$vdb/${pkg%%:*}/LICENSE"
if [[ -f "$lic" ]]; then
echo "$pkg $(< "$lic")"
fi
done > "$2"
} }
extract_docs() { extract_docs() {

View File

@ -84,12 +84,14 @@ create_dev_image() {
local root_fs_dir="${BUILD_DIR}/rootfs" local root_fs_dir="${BUILD_DIR}/rootfs"
local image_contents="${image_name%.bin}_contents.txt" local image_contents="${image_name%.bin}_contents.txt"
local image_packages="${image_name%.bin}_packages.txt" local image_packages="${image_name%.bin}_packages.txt"
local image_licenses="${image_name%.bin}_licenses.txt"
start_image "${image_name}" "${disk_layout}" "${root_fs_dir}" "${update_group}" start_image "${image_name}" "${disk_layout}" "${root_fs_dir}" "${update_group}"
set_image_profile dev set_image_profile dev
emerge_to_image "${root_fs_dir}" @system coreos-base/coreos-dev emerge_to_image "${root_fs_dir}" @system coreos-base/coreos-dev
write_packages "${root_fs_dir}" "${BUILD_DIR}/${image_packages}" write_packages "${root_fs_dir}" "${BUILD_DIR}/${image_packages}"
write_licenses "${root_fs_dir}" "${BUILD_DIR}/${image_licenses}"
# Setup portage for emerge and gmerge # Setup portage for emerge and gmerge
configure_dev_portage "${root_fs_dir}" "${devserver}" configure_dev_portage "${root_fs_dir}" "${devserver}"

View File

@ -39,6 +39,7 @@ create_prod_image() {
local root_fs_dir="${BUILD_DIR}/rootfs" local root_fs_dir="${BUILD_DIR}/rootfs"
local image_contents="${image_name%.bin}_contents.txt" local image_contents="${image_name%.bin}_contents.txt"
local image_packages="${image_name%.bin}_packages.txt" local image_packages="${image_name%.bin}_packages.txt"
local image_licenses="${image_name%.bin}_licenses.txt"
start_image "${image_name}" "${disk_layout}" "${root_fs_dir}" "${update_group}" start_image "${image_name}" "${disk_layout}" "${root_fs_dir}" "${update_group}"
@ -47,6 +48,7 @@ create_prod_image() {
extract_prod_gcc "${root_fs_dir}" extract_prod_gcc "${root_fs_dir}"
emerge_to_image "${root_fs_dir}" "${base_pkg}" emerge_to_image "${root_fs_dir}" "${base_pkg}"
write_packages "${root_fs_dir}" "${BUILD_DIR}/${image_packages}" write_packages "${root_fs_dir}" "${BUILD_DIR}/${image_packages}"
write_licenses "${root_fs_dir}" "${BUILD_DIR}/${image_licenses}"
extract_docs "${root_fs_dir}" extract_docs "${root_fs_dir}"
# Assert that if this is supposed to be an official build that the # Assert that if this is supposed to be an official build that the