Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion fboss-image/distro_cli/lib/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,20 @@ def _build_base_image(self):
logger.info(f"Running build script: {build_script}")

# Run the build script
cmd = [str(build_script)]
if "pxe" in dist_formats or "usb" in dist_formats:
cmd.append("--build-pxe-usb")
if "onie" in dist_formats:
cmd.append("--build-onie")
try:
subprocess.run([str(build_script), "-b"], check=True)
subprocess.run(cmd, check=True)
except subprocess.CalledProcessError as e:
logger.error(f"Build script failed with exit code {e.returncode}")
sys.exit(1)

self._mv_distro_file(image_builder_dir, "usb", "iso")
self._mv_distro_file(image_builder_dir, "pxe", "tar")
self._mv_distro_file(image_builder_dir, "onie", "bin")

logger.info("Finished base OS image build")

Expand Down
3 changes: 2 additions & 1 deletion fboss-image/from_source.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"distribution_formats": {
"usb": "fboss-distro-image_usb.iso",
"pxe": "fboss-distro-image_pxe.tar"
"pxe": "fboss-distro-image_pxe.tar",
"onie": "fboss-distro-image_onie.bin"
},
"kernel": {
},
Expand Down
31 changes: 24 additions & 7 deletions fboss-image/image_builder/bin/build_image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ DOCKER_INSTANCE_NAME="${USER}-fboss-image-builder"
DOCKER_IMAGE_NAME="${USER}-fboss-image-builder"
BUILD_DOCKER_IMAGE="no"
DELETE_DOCKER_IMAGE="no"
BUILD_PXEUSB="no"
BUILD_ONIE="no"

print_help() {
echo "Usage: $0 [options] [--] [options for child scripts]"
Expand All @@ -33,7 +35,8 @@ print_help() {
echo ""
echo " --docker-image-name <name> Name of docker image to use (default: ${DOCKER_IMAGE_NAME})"
echo " --docker-instance-name <name> Name of docker instance to use (default: ${DOCKER_INSTANCE_NAME})"
echo " -b|--build-fboss-images Generate FBOSS images - USB ISO and PXE bootable"
echo " -p|--build-pxe-usb Build PXE and USB bootable image"
echo " -o|--build-onie Build ONIE installer image"
echo " -e|--enter-shell Enter shell in the docker container (for debugging)"
echo " -- All arguments after this are passed to child scripts"
echo ""
Expand All @@ -42,8 +45,8 @@ print_help() {
echo " $(basename "$0") -D Delete docker image"
echo " $(basename "$0") -e Enter shell in docker container"
echo " $(basename "$0") -B -b Build FBOSS images"
echo " $(basename "$0") -b -- -k <kernelrpmdir> Build FBOSS images using kernel from specified directory"
echo " $(basename "$0") -b -- -f <fboss.tar> Overlay image with specified tar file"
echo " $(basename "$0") -p -- -k <kernelrpmdir> Build FBOSS images using kernel from specified directory"
echo " $(basename "$0") -p -- -f <fboss.tar> Overlay image with specified tar file"
echo ""
}

Expand Down Expand Up @@ -72,8 +75,15 @@ while [[ $# -gt 0 ]]; do
shift 1
;;

-b | --build-fboss-images)
BUILD_FBOSS_IMAGES=yes
-p | --build-pxe-usb)
BUILD_FBOSS_IMAGES="yes"
BUILD_PXEUSB="yes"
shift 1
;;

-o | --build-onie)
BUILD_FBOSS_IMAGES="yes"
BUILD_ONIE="yes"
shift 1
;;

Expand Down Expand Up @@ -181,10 +191,17 @@ if [ "${ENTER_SHELL}" = "yes" ]; then
else
if [ "${BUILD_FBOSS_IMAGES}" = "yes" ]; then
dprint "Starting image build, launching in docker: /${IMAGE_BUILDER_DIR}/bin/build_image_in_container.sh ${CHILD_SCRIPT_ARGS[*]}"
image_args=""
if [ "${BUILD_PXEUSB}" = "yes" ]; then
image_args="${image_args} --build-pxe-usb"
fi
if [ "${BUILD_ONIE}" = "yes" ]; then
image_args="${image_args} --build-onie"
fi
#shellcheck disable=SC2086
docker run --rm ${DOCKER_ARGS} "${DOCKER_IMAGE_NAME}" /"${IMAGE_BUILDER_DIR}"/bin/build_image_in_container.sh "${CHILD_SCRIPT_ARGS[@]}" >>"${LOG_FILE}" 2>&1
docker run --rm ${DOCKER_ARGS} "${DOCKER_IMAGE_NAME}" /"${IMAGE_BUILDER_DIR}"/bin/build_image_in_container.sh ${image_args} "${CHILD_SCRIPT_ARGS[@]}" |& tee -a ${LOG_FILE}
RC=$?
handle_error "${RC}" "docker run /${IMAGE_BUILDER_DIR}/bin/build_image.sh ${CHILD_SCRIPT_ARGS[*]}"
handle_error "${RC}" "docker run /${IMAGE_BUILDER_DIR}/bin/build_image.sh ${image_args} ${CHILD_SCRIPT_ARGS[*]}"
fi
fi
dprint "$0 execution complete, exit code: ${RC}"
Expand Down
162 changes: 149 additions & 13 deletions fboss-image/image_builder/bin/build_image_in_container.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ ORIGINAL_ARGS=("$0" "$@")
# Default values
DESCRIPTION_DIR="${WSROOT}/templates/centos-09.0"
TARGET_DIR="${WSROOT}/output"
BUILD_PXE=""
BUILD_ONIE=""

# User configurable variables (fboss tarfile and kernel rpm directory)
FBOSS_TARFILE=""
Expand All @@ -34,6 +36,8 @@ help() {
echo ""
echo " -f|--fboss-tarfile Location of compressed FBOSS tar file to add to image"
echo " -k|--kernel-rpm-dir Directory containing kernel rpms to install (default: download LTS 6.12)"
echo " -p|--build-pxe-usb Build PXE and USB installers image (default: no)"
echo " -o|--build-onie Build ONIE installer image (default: no)"
echo ""
echo " -h|--help Print this help message"
echo ""
Expand All @@ -52,7 +56,77 @@ update_docker() {
dracut-kiwi-oem-dump \
kiwi-systemdeps-image-validation \
syslinux \
btrfs-progs
btrfs-progs \
glibc-static
}

build_zstd() {
if [ ! -d ${TARGET_DIR}/zstd ]; then
dprint "Building static zstd..."
git clone https://github.com/facebook/zstd.git ${TARGET_DIR}/zstd
pushd ${TARGET_DIR}/zstd >/dev/null
git checkout release
make -C programs zstd-frugal LDFLAGS="-static"
strip programs/zstd-frugal
popd >/dev/null
fi
}

build_onie_installer() {
build_zstd

dprint "Creating ONIE installer..."
out_bin=${TARGET_DIR}/onie/FBOSS-Distro-Image.x86_64-1.0.install.bin
rootfs=${TARGET_DIR}/onie/FBOSS-Distro-Image.x86_64-1.0.tar.zst

pushd ${TARGET_DIR}/onie >/dev/null

mkdir -p onie_installer
templates_dir="${WSROOT}/templates/onie"

cp ${templates_dir}/distro-setup.sh.tmpl onie_installer/distro-setup.sh
chmod a+x onie_installer/distro-setup.sh

cp ${templates_dir}/default_platform.conf onie_installer/default_platform.conf
chmod a+x onie_installer/default_platform.conf

cp ${templates_dir}/install.sh.tmpl onie_installer/install.sh
chmod a+x onie_installer/install.sh

cp ${TARGET_DIR}/zstd/programs/zstd-frugal onie_installer/zstd
chmod a+x onie_installer/zstd

dprint " Finding kernel and initrd..."
kernel=$(
set +o pipefail
tar -tf $rootfs | awk -F / '/^boot\/vmlinuz/ {print $2; exit 0}' || exit 1
)
initrd=$(
set +o pipefail
tar -tf $rootfs | awk -F / '/^boot\/initramfs/ {print $2; exit 0}' || exit 1
)

sed -i -e "s/%%KERNEL_FILENAME%%/$kernel/g" \
-e "s/%%INITRD_FILENAME%%/$initrd/g" \
onie_installer/install.sh

mv $rootfs onie_installer/rootfs.tar.zst

dprint " Packaging installer..."
tar -cf installer.tar onie_installer

sha1=$(cat installer.tar | sha1sum | awk '{print $1}')

cp ${templates_dir}/sharch_body.sh ${out_bin}
sed -i -e "s/%%IMAGE_SHA1%%/$sha1/" \
-e "s/%%PAYLOAD_IMAGE_SIZE%%/$(stat -c %s installer.tar)/" \
${out_bin}

cat installer.tar >>${out_bin}

rm -rf installer.tar onie_installer

popd >/dev/null
}

# Parse command line arguments
Expand All @@ -69,6 +143,16 @@ while [[ $# -gt 0 ]]; do
shift 2
;;

-p | --build-pxe-usb)
BUILD_PXE="yes"
shift 1
;;

-o | --build-onie)
BUILD_ONIE="yes"
shift 1
;;

-h | --help)
help
exit 0
Expand Down Expand Up @@ -105,9 +189,6 @@ fi
dprint "Updating docker image..."
update_docker >>"${LOG_FILE}" 2>&1

dprint "Deleting target directory: ${TARGET_DIR}"
rm -rf "${TARGET_DIR}"

# Create the output directory (in case it doesn't exist)
mkdir -p "${TARGET_DIR}"
chmod 777 "${TARGET_DIR}"
Expand Down Expand Up @@ -157,16 +238,71 @@ cp /etc/resolv.conf "${DESCRIPTION_DIR}/root/etc/"
echo "Built on: $(date -u)" >"$DESCRIPTION_DIR/root/etc/build-info"

# Generate the images
dprint "Generating PXE and USB bootable image, this will take few minutes..."
kiwi-ng-3 \
--profile FBOSS \
--type oem \
system build \
--description "${DESCRIPTION_DIR}" \
--target-dir "${TARGET_DIR}" \
>>"${LOG_FILE}" 2>&1
PXE_RC=0
ONIE_RC=0

if [ -n "${BUILD_PXE}" ]; then
dprint "Generating PXE and USB installer, this will take few minutes..."
rm -rf ${TARGET_DIR}/btrfs
(
set -e -o pipefail
kiwi-ng-3 \
--profile FBOSS \
--type oem \
system build \
--description ${DESCRIPTION_DIR} \
--target-dir ${TARGET_DIR}/btrfs |&
tee -a ${LOG_FILE} | awk '{print "PXE/USB Installer| " $0}'
mv ${TARGET_DIR}/btrfs/FBOSS-Distro-Image.x86_64-1.0.install.* ${TARGET_DIR}
) &
PXE_PID=$!
fi

RC=$?
if [ -n "${BUILD_ONIE}" ]; then
dprint "Generating ONIE installer, this will take few minutes..."
rm -rf ${TARGET_DIR}/onie
(
set -e -o pipefail
kiwi-ng-3 \
--profile FBOSS \
--type tbz \
system build \
--description ${DESCRIPTION_DIR} \
--target-dir ${TARGET_DIR}/onie |&
tee -a ${LOG_FILE} | awk '{print "ONIE installer| " $0}'
# Repack the rootfs so really long filenames are not truncated under Busybox
dprint "Repacking rootfs with zstd..."
mkdir ${TARGET_DIR}/onie/rootfs
pushd ${TARGET_DIR}/onie/rootfs >/dev/null
xzcat --threads=0 ${TARGET_DIR}/onie/FBOSS-Distro-Image.x86_64-1.0.tar.xz | tar -x
rm ${TARGET_DIR}/onie/FBOSS-Distro-Image.x86_64-1.0.tar.xz
tar --format=gnu -cf ${TARGET_DIR}/onie/FBOSS-Distro-Image.x86_64-1.0.tar *
zstd --threads=0 -19 ${TARGET_DIR}/onie/FBOSS-Distro-Image.x86_64-1.0.tar
popd >/dev/null

build_onie_installer | awk '{print "ONIE installer| " $0}'
mv ${TARGET_DIR}/onie/FBOSS-Distro-Image.x86_64-1.0.install.* ${TARGET_DIR}
) &
ONIE_PID=$!
fi

if [ -n "${BUILD_PXE}" ]; then
wait ${PXE_PID}
PXE_RC=$?
fi

if [ -n "${BUILD_ONIE}" ]; then
wait ${ONIE_PID}
ONIE_RC=$?
fi

if [ ${PXE_RC} -ne 0 ]; then
dprint "ERROR: PXE/USB image build failed"
fi
if [ ${ONIE_RC} -ne 0 ]; then
dprint "ERROR: ONIE installer build failed"
fi

RC=$((PXE_RC + ONIE_RC))
dprint "Image generation completed with exit code ${RC}"
exit "${RC}"
16 changes: 16 additions & 0 deletions fboss-image/image_builder/templates/centos-09.0/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
<oem-skip-verify>true</oem-skip-verify>
</oemconfig>
</type>
<type image="tbz">
</type>
</preferences>
<users>
<user name="root" password="$1$wYJUgpM5$YNklayYndL8.nnIpR/Fze0" groups="root" home="/root"/>
Expand Down Expand Up @@ -114,6 +116,19 @@
<package name="vim"/>
<package name="vi"/>
<package name="btrfs-progs"/>
<package name="re2"/>
<package name="libsodium"/>
<package name="double-conversion"/>
<package name="libdwarf"/>
<package name="libunwind"/>
<package name="xxhash-libs"/>
<package name="libgpiod"/>
<package name="glog"/>
<package name="python3-pip"/>
<package name="lz4"/>
<package name="zstd"/>
<package name="libusbx"/>
<package name="dmidecode"/>
</packages>

<packages type="bootstrap">
Expand All @@ -125,6 +140,7 @@
<package name="dracut-live"/>
<package name="dracut-kiwi-live"/>
<package name="dracut-kiwi-lib"/>
<package name="dracut-config-generic"/>
<package name="dracut-kiwi-oem-dump"/>
</packages>
</image>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Compress in parallel
xz:
- options: '--threads=0'
Loading
Loading