mirror of
https://github.com/flatcar/scripts.git
synced 2025-08-07 04:56:58 +02:00
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 <thilofromm@microsoft.com>
This commit is contained in:
parent
8f8f262f19
commit
8e01a2c8f9
@ -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
|
||||
|
@ -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
|
||||
|
@ -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 <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 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}" \
|
||||
|
Loading…
Reference in New Issue
Block a user