-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
base OS sysexts: separate build script, inventory generation
This change refactors base OS sysext builds to use a separate build script `build_library/sysext_prod_builder`, which is called from `build_library/prod_image_util.sh` when `build_image` runs. This allows for better separation of cleanup traps: prod image sysext builds need its own trap / cleanup function for temporary build directories and loopback mounts. Prod sysext builds properly generate lincense and SBOM information, and provide detailed file listings and disk space usage stats. - SBOM / licenses JSON now include all packages of the final image, i.e. a combined list of base image and all base OS sysexts. - Packages lists, files list and detailed files list include the sysext squashfs files for the base image, and separate sections with files / packages lists for each sysext. - Disk usage contains both final disk image usage as well as usage of each individual sysext squashfs.
- Loading branch information
Showing
4 changed files
with
213 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
#!/bin/bash | ||
# Copyright (c) 2023 by the Flatcar Maintainers. | ||
# Use of this source code is governed by the Apache 2.0 license. | ||
|
||
# Helper script for building OS images w/ sysexts included. | ||
# Called by build_image -> prod_image_util.sh. | ||
# This is a separate script mainly so we can trap EXIT and clean up our mounts | ||
# without interfering with traps set by build_image. | ||
|
||
# We're in build_library/, script root is one up | ||
SCRIPT_ROOT="$(cd "$(dirname "$(readlink -f "$0")")/../"; pwd)" | ||
. "${SCRIPT_ROOT}/common.sh" || exit 1 | ||
|
||
# Script must run inside the chroot | ||
assert_inside_chroot | ||
switch_to_strict_mode | ||
|
||
. "${BUILD_LIBRARY_DIR}/build_image_util.sh" || exit 1 | ||
|
||
# Create a sysext from a package and install it to the OS image. | ||
# Conventions: | ||
# - For each <group>/<package>, <group>_<package>_pkginfo will be built. Can be used in subsequent calls | ||
# to build dependent sysexts. | ||
# - If ${BUILD_LIBRARY_DIR}/sysext_mangle_<group>_<package> exists it will be used as FS mangle script | ||
# when building the sysext. | ||
create_prod_sysext() { | ||
local BOARD="$1" | ||
local output_dir="$2" | ||
local workdir="$3" | ||
local base_sysext="$4" | ||
local install_root="$5" | ||
local grp_pkg="$6" | ||
local pkginfo="${7:-}" | ||
|
||
local name="${grp_pkg//\//_}" # some-group/some-package => some-group_some-package | ||
local pkginfo_opt="" | ||
local manglefs_opt="" | ||
|
||
local msg="Creating sysext '${grp_pkg}' ==> ${name}.raw" | ||
|
||
# Include previous sysexts' pkginfo if supplied | ||
if [[ -n "${pkginfo}" ]] ; then | ||
if [[ ! -f "${output_dir}/${pkginfo}" ]] ; then | ||
die "Sysext build '${grp_pkg}': unable to find package info at '${output_dir}/${pkginfo}'." | ||
fi | ||
msg="${msg} w/ package info '${pkginfo}'" | ||
pkginfo_opt="--base_pkginfo=${output_dir}/${pkginfo}" | ||
fi | ||
|
||
# Include FS mangle script if present | ||
if [[ -x "${BUILD_LIBRARY_DIR}/sysext_mangle_${name}" ]] ; then | ||
manglefs_opt="--manglefs_script=${BUILD_LIBRARY_DIR}/sysext_mangle_${name}" | ||
msg="${msg}, FS mangle script 'sysext_mangle_${name}'" | ||
fi | ||
|
||
info "${msg}." | ||
|
||
sudo "${SCRIPTS_DIR}/build_sysext" \ | ||
--board="${BOARD}" \ | ||
--image_builddir="${workdir}/sysext-build" \ | ||
--squashfs_base="${base_sysext}" \ | ||
--generate_pkginfo \ | ||
${manglefs_opt} ${pkginfo_opt} \ | ||
"${name}" "${grp_pkg}" | ||
|
||
sudo mv "${workdir}/sysext-build/${name}.raw" "${workdir}/sysext-build/${name}_pkginfo.raw" \ | ||
"${workdir}/sysext-build/${name}"_*.txt "${output_dir}" | ||
|
||
sudo mkdir -p "${install_root}"/usr/share/flatcar/sysext | ||
sudo install -m 0644 -D "${output_dir}/${name}.raw" "${install_root}"/usr/share/flatcar/sysext/ | ||
|
||
sudo mkdir -p "${install_root}"/etc/extensions/ | ||
sudo ln -sf "/usr/share/flatcar/sysext/${name}.raw" "${install_root}/etc/extensions/${name}.raw" | ||
} | ||
# -- | ||
|
||
BOARD="$1" | ||
BUILD_DIR="$2" | ||
root_fs_dir="$3" | ||
|
||
merged_rootfs_dir="$4" | ||
sysext_output_dir="$5" | ||
|
||
sysexts_list="$6" | ||
|
||
grp_pkg="" | ||
prev_pkginfo="" | ||
sysext_workdir="${BUILD_DIR}/prod-sysext-work" | ||
sysext_mountdir="${BUILD_DIR}/prod-sysext-work/mounts" | ||
sysext_base="${sysext_workdir}/base-os.squashfs" | ||
|
||
function cleanup() { | ||
sudo umount "${sysext_mountdir}"/* || true | ||
rm -rf "${sysext_workdir}" || true | ||
} | ||
# -- | ||
|
||
trap cleanup EXIT | ||
|
||
rm -rf "${sysext_workdir}" "${sysext_output_dir}" | ||
mkdir "${sysext_workdir}" "${sysext_output_dir}" | ||
|
||
info "creating temporary base OS squashfs" | ||
sudo mksquashfs "${root_fs_dir}" "${sysext_base}" -noappend | ||
|
||
# Build sysexts on top of root fs and mount sysexts' squashfs + pkginfo squashfs | ||
# for combined overlay later. | ||
prev_pkginfo="" | ||
sysext_lowerdirs="${sysext_mountdir}/rootfs-lower" | ||
for grp_pkg in ${sysexts_list//,/ }; do | ||
create_prod_sysext "${BOARD}" \ | ||
"${sysext_output_dir}" \ | ||
"${sysext_workdir}" \ | ||
"${sysext_base}" \ | ||
"${root_fs_dir}"\ | ||
"${grp_pkg}" \ | ||
"${prev_pkginfo}" | ||
name="${grp_pkg//\//_}" | ||
|
||
mkdir -p "${sysext_mountdir}/${name}" \ | ||
"${sysext_mountdir}/${name}_pkginfo" | ||
sudo mount -rt squashfs -o loop,nodev "${sysext_output_dir}/${name}.raw" \ | ||
"${sysext_mountdir}/${name}" | ||
sudo mount -rt squashfs -o loop,nodev "${sysext_output_dir}/${name}_pkginfo.raw" \ | ||
"${sysext_mountdir}/${name}_pkginfo" | ||
|
||
sysext_lowerdirs="${sysext_lowerdirs}:${sysext_mountdir}/${name}" | ||
sysext_lowerdirs="${sysext_lowerdirs}:${sysext_mountdir}/${name}_pkginfo" | ||
|
||
prev_pkginfo="${name}_pkginfo.raw" | ||
done | ||
|
||
# Mount the combined overlay (base OS, sysexts, and syset pkginfos) and copy a snapshot | ||
# into the designated output dir for upper layers to process. | ||
mkdir -p "${sysext_mountdir}/rootfs-lower" | ||
sudo mount -rt squashfs -o loop,nodev "${sysext_base}" "${sysext_mountdir}/rootfs-lower" | ||
|
||
# Mount overlay for report generation | ||
mkdir -p "${sysext_workdir}/.work" | ||
mkdir -p "${sysext_mountdir}/rootfs-upper" | ||
sudo mount -t overlay overlay \ | ||
-o lowerdir="${sysext_lowerdirs}",upperdir="${sysext_mountdir}/rootfs-upper",workdir="${sysext_workdir}/.work" \ | ||
"${sysext_mountdir}/rootfs-upper" | ||
|
||
|
||
sudo rm -rf "${merged_rootfs_dir}" | ||
sudo cp -a "${sysext_mountdir}/rootfs-upper" "${merged_rootfs_dir}" | ||
|
||
|
||
cleanup | ||
trap -- EXIT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters