From 8e01a2c8f9f782a22686eecfed8916f16de7a4c5 Mon Sep 17 00:00:00 2001 From: Thilo Fromm Date: Fri, 6 Oct 2023 10:14:18 +0200 Subject: [PATCH] build_image: add sysext command line option This change refactors sysext builds during build_image and generalises the code (no hard-coded containerd and docker anymore). A command line option is added to build_image for sysexts to include in the OS image. It defaults to containerd and docker but may be set to arbitrary packages. The command line supports simple depenencies, i.e. the "docker" sysext will re-use package information from the "containerd" sysext and not include another containerd. Signed-off-by: Thilo Fromm --- build_image | 4 +- build_library/build_image_util.sh | 28 -------- build_library/prod_image_util.sh | 67 +++++++++++++++++++ .../sysext_mangle_app-containers_containerd | 0 .../sysext_mangle_app-containers_docker | 0 5 files changed, 70 insertions(+), 29 deletions(-) rename manglefs_containerd => build_library/sysext_mangle_app-containers_containerd (100%) rename manglefs_docker => build_library/sysext_mangle_app-containers_docker (100%) diff --git a/build_image b/build_image index c7bef33f10..a10a410f1d 100755 --- a/build_image +++ b/build_image @@ -33,6 +33,8 @@ DEFINE_string base_pkg "coreos-base/coreos" \ "The base portage package to base the build off of (only applies to prod images)" DEFINE_string base_dev_pkg "coreos-base/coreos-dev" \ "The base portage package to base the build off of (only applies to dev containers)" +DEFINE_string base_sysexts "app-containers/containerd,app-containers/docker" \ + "Comma-separated list of packages to build into sysexts and include with OS image and update payload. Must be in order of dependencies, base sysexts come first." DEFINE_string output_root "${DEFAULT_BUILD_ROOT}/images" \ "Directory in which to place image result directories (named by version)" DEFINE_string disk_layout "" \ @@ -165,7 +167,7 @@ fi if [[ "${PROD_IMAGE}" -eq 1 ]]; then IMAGE_BUILD_TYPE="prod" - create_prod_image ${FLATCAR_PRODUCTION_IMAGE_NAME} ${DISK_LAYOUT} ${FLAGS_group} ${FLAGS_base_pkg} + create_prod_image ${FLATCAR_PRODUCTION_IMAGE_NAME} ${DISK_LAYOUT} ${FLAGS_group} ${FLAGS_base_pkg} ${FLAGS_base_sysexts} if [[ ${FLAGS_generate_update} -eq ${FLAGS_TRUE} ]]; then generate_update "${FLATCAR_PRODUCTION_IMAGE_NAME}" ${DISK_LAYOUT} elif [[ ${FLAGS_extract_update} -eq ${FLAGS_TRUE} ]]; then diff --git a/build_library/build_image_util.sh b/build_library/build_image_util.sh index f2ba149a64..7073da75d3 100755 --- a/build_library/build_image_util.sh +++ b/build_library/build_image_util.sh @@ -635,34 +635,6 @@ finish_image() { local install_grub=0 local disk_img="${BUILD_DIR}/${image_name}" - info "Creating containerd and docker sysexts." - - sudo "${SCRIPTS_DIR}/build_sysext" \ - --board="${BOARD}" \ - --image_builddir="${BUILD_DIR}" \ - --squashfs_base="${BUILD_DIR}/${image_sysext_base}" \ - --manglefs_script="${SCRIPTS_DIR}/manglefs_containerd" \ - --generate_pkginfo \ - containerd app-containers/containerd - - sudo "${SCRIPTS_DIR}/build_sysext" \ - --board="${BOARD}" \ - --image_builddir=${BUILD_DIR} \ - --squashfs_base="${BUILD_DIR}/${image_sysext_base}" \ - --manglefs_script="${SCRIPTS_DIR}/manglefs_docker" \ - --base_pkginfo="${BUILD_DIR}/containerd_pkginfo.raw" \ - docker app-containers/docker - - sudo mkdir -p "${root_fs_dir}"/usr/share/flatcar/sysext - sudo install -m 0644 -D "${BUILD_DIR}/containerd.raw" "${root_fs_dir}"/usr/share/flatcar/sysext/ - sudo install -m 0644 -D "${BUILD_DIR}/docker.raw" "${root_fs_dir}"/usr/share/flatcar/sysext/ - - # Install symlinks into /etc/extensions - this will be picked up by the logic to populate - # /usr/share/flatcar/etc below, so it will end up below /usr in the final image. - sudo mkdir -p "${root_fs_dir}"/etc/extensions/ - sudo ln -sf /usr/share/flatcar/sysext/containerd.raw "${root_fs_dir}"/etc/extensions/containerd.raw - sudo ln -sf /usr/share/flatcar/sysext/docker.raw "${root_fs_dir}"/etc/extensions/docker.raw - # Only enable rootfs verification on prod builds. local disable_read_write="${FLAGS_FALSE}" if [[ "${IMAGE_BUILD_TYPE}" == "prod" ]]; then diff --git a/build_library/prod_image_util.sh b/build_library/prod_image_util.sh index 9aa86eae7e..6259f0dbdd 100755 --- a/build_library/prod_image_util.sh +++ b/build_library/prod_image_util.sh @@ -52,6 +52,58 @@ extract_prod_gcc() { package_provided "${gcc}" } +# Create a sysext from a package and install it to the OS image. +# Conventions: +# - For each /, __pkginfo will be built. Can be used in subsequent calls +# to build dependent sysexts. +# - If ${BUILD_LIBRARY_DIR}/sysext_mangle__ exists it will be used as FS mangle script +# when building the sysext. +# +create_prod_sysext() { + local install_root="$1" + local base_image="$2" + local grp_pkg="$3" + local pkginfo="${4:-}" + + 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 "${BUILD_DIR}/${pkginfo}" ]] ; then + die "Sysext build '${grp_pkg}': unable to find package info at '${BUILD_DIR}/${pkginfo}'." + fi + msg="${msg} w/ package info '${pkginfo}'" + pkginfo_opt="--base_pkginfo=${BUILD_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="${BUILD_DIR}" \ + --squashfs_base="${base_image}" \ + --generate_pkginfo \ + ${manglefs_opt} ${pkginfo_opt} \ + "${name}" "${grp_pkg}" + + sudo mkdir -p "${install_root}"/usr/share/flatcar/sysext + sudo install -m 0644 -D "${BUILD_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" +} +# -- + create_prod_image() { local image_name="$1" local disk_layout="$2" @@ -62,6 +114,8 @@ create_prod_image() { exit 1 fi + local base_sysexts="$5" + info "Building production image ${image_name}" local root_fs_dir="${BUILD_DIR}/rootfs" local image_contents="${image_name%.bin}_contents.txt" @@ -136,6 +190,19 @@ EOF # Remove source locale data, only need to ship the compiled archive. sudo rm -rf ${root_fs_dir}/usr/share/i18n/ + if [[ -n "${base_sysexts}" ]] ; then + local grp_pkg="" + local prev_pkginfo="" + for grp_pkg in ${base_sysexts//,/ }; do + create_prod_sysext "${root_fs_dir}"\ + "${BUILD_DIR}/${image_sysext_base}" \ + "${grp_pkg}" \ + "${prev_pkginfo}" + prev_pkginfo="${grp_pkg//\//_}_pkginfo.raw" + done + fi + + # Finish image will move files from /etc to /usr/share/flatcar/etc. finish_image \ "${image_name}" \ "${disk_layout}" \ diff --git a/manglefs_containerd b/build_library/sysext_mangle_app-containers_containerd similarity index 100% rename from manglefs_containerd rename to build_library/sysext_mangle_app-containers_containerd diff --git a/manglefs_docker b/build_library/sysext_mangle_app-containers_docker similarity index 100% rename from manglefs_docker rename to build_library/sysext_mangle_app-containers_docker