From a4214738b92b7b57d4722d2fec1629eb73e1bf1e Mon Sep 17 00:00:00 2001 From: Marcel Apfelbaum Date: Wed, 25 Aug 2021 19:45:53 +0000 Subject: [PATCH 1/3] osbuilder: Fix Makefile Let the DISTRO variable to be set from outside, allowing "sudo -E DISTRO= make clean" to delete the correct files. Signed-off-by: Marcel Apfelbaum --- tools/osbuilder/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/osbuilder/Makefile b/tools/osbuilder/Makefile index b70ca7a20a..a35139c5a9 100644 --- a/tools/osbuilder/Makefile +++ b/tools/osbuilder/Makefile @@ -9,7 +9,7 @@ ROOTFS_BUILDER := $(MK_DIR)/rootfs-builder/rootfs.sh INITRD_BUILDER := $(MK_DIR)/initrd-builder/initrd_builder.sh IMAGE_BUILDER := $(MK_DIR)/image-builder/image_builder.sh -DISTRO := centos +DISTRO ?= centos BUILD_METHOD := distro BUILD_METHOD_LIST := distro dracut AGENT_INIT ?= no From 65a1e13195817cb84498153e4371924ee8faa66c Mon Sep 17 00:00:00 2001 From: Marcel Apfelbaum Date: Wed, 25 Aug 2021 19:49:14 +0000 Subject: [PATCH 2/3] osbuilder: Allow running the tool several times Once the ${ROOTFS_DIR} is created, the tool can't run the second time since the directory is populated and the debootstrap tool will fail. Fix by deleting the contents of ${ROOTFS_DIR} if the directory exists. Note that running make clean will also allow the re-run, it is only an optimization for some cases the build fails in the middle. Signed-off-by: Marcel Apfelbaum --- tools/osbuilder/rootfs-builder/rootfs.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tools/osbuilder/rootfs-builder/rootfs.sh b/tools/osbuilder/rootfs-builder/rootfs.sh index c058c257a1..b63567ad5d 100755 --- a/tools/osbuilder/rootfs-builder/rootfs.sh +++ b/tools/osbuilder/rootfs-builder/rootfs.sh @@ -326,7 +326,11 @@ build_rootfs_distro() trap error_handler ERR fi - mkdir -p ${ROOTFS_DIR} + if [ -d "${ROOTFS_DIR}" ] && [ "${ROOTFS_DIR}" != "/" ]; then + rm -rf "${ROOTFS_DIR}"/* + else + mkdir -p ${ROOTFS_DIR} + fi # need to detect rustc's version too? detect_rust_version || From 9de1129bf72f0db2a7d698f94aba4b6e3e126a9c Mon Sep 17 00:00:00 2001 From: Marcel Apfelbaum Date: Wed, 25 Aug 2021 19:53:21 +0000 Subject: [PATCH 3/3] osbuilder: Fix rootfs-builder when running in VMs The script runs apt sync at some point which scans all possible fds in order to close them. The operation is incredibly slow on VMs and may lead to build timeouts. Fix it by limiting the container runtime fds to a sane limit. Fixes: #2510 Signed-off-by: Marcel Apfelbaum --- tools/osbuilder/rootfs-builder/rootfs.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/osbuilder/rootfs-builder/rootfs.sh b/tools/osbuilder/rootfs-builder/rootfs.sh index b63567ad5d..44fdab42ea 100755 --- a/tools/osbuilder/rootfs-builder/rootfs.sh +++ b/tools/osbuilder/rootfs-builder/rootfs.sh @@ -373,6 +373,8 @@ build_rootfs_distro() docker_run_args="" docker_run_args+=" --rm" + # apt sync scans all possible fds in order to close them, incredibly slow on VMs + docker_run_args+=" --ulimit nofile=262144:262144" docker_run_args+=" --runtime ${DOCKER_RUNTIME}" if [ -z "${AGENT_SOURCE_BIN}" ] ; then