From 3c36ce8139340d50176ee6770118918ae3755ef5 Mon Sep 17 00:00:00 2001 From: Julio Montes Date: Tue, 8 Dec 2020 09:55:56 -0600 Subject: [PATCH] rootfs-builder: add functions to run before and after the container Define `before_starting_container` and `after_stopping_container` functions, these functions run before and after the container that builds the rootfs respectively. Signed-off-by: Julio Montes --- tools/osbuilder/rootfs-builder/rootfs.sh | 3 +++ .../template/rootfs_lib_template.sh | 25 ++++++++++++++++--- tools/osbuilder/scripts/lib.sh | 8 ++++++ 3 files changed, 32 insertions(+), 4 deletions(-) diff --git a/tools/osbuilder/rootfs-builder/rootfs.sh b/tools/osbuilder/rootfs-builder/rootfs.sh index 92c2e55829..7a71ba902d 100755 --- a/tools/osbuilder/rootfs-builder/rootfs.sh +++ b/tools/osbuilder/rootfs-builder/rootfs.sh @@ -400,6 +400,9 @@ build_rootfs_distro() done fi + before_starting_container + trap after_stopping_container EXIT + #Make sure we use a compatible runtime to build rootfs # In case Clear Containers Runtime is installed we dont want to hit issue: #https://github.com/clearcontainers/runtime/issues/828 diff --git a/tools/osbuilder/rootfs-builder/template/rootfs_lib_template.sh b/tools/osbuilder/rootfs-builder/template/rootfs_lib_template.sh index 238b6f702d..978a89bc87 100644 --- a/tools/osbuilder/rootfs-builder/template/rootfs_lib_template.sh +++ b/tools/osbuilder/rootfs-builder/template/rootfs_lib_template.sh @@ -12,18 +12,19 @@ # # BIN_AGENT: Name of the Kata-Agent binary # -# REPO_URL: URL to distribution repository ( should be configured in +# REPO_URL: URL to distribution repository ( should be configured in # config.sh file) # -# Any other configuration variable for a specific distro must be added +# Any other configuration variable for a specific distro must be added # and documented on its own config.sh -# +# # - Expected result # # rootfs_dir populated with rootfs pkgs # It must provide a binary in /sbin/init # -# Note: For some distros, the build_rootfs() function provided in scripts/lib.sh +# Note: For some distros, the build_rootfs(), before_starting_container() +# and after_starting_container() functions provided in scripts/lib.sh # will suffice. If a new distro is introduced with a special requirement, # then, a rootfs_builder//rootfs_lib.sh file should be created # using this template. @@ -52,3 +53,19 @@ build_rootfs() { # Populate ROOTFS_DIR # Must provide /sbin/init and /bin/${BIN_AGENT} } + +before_starting_container() { + # Run the following tasks before starting the container that builds the rootfs. + # For example: + # * Create a container + # * Create a volume + return 0 +} + +after_stopping_container() { + # Run the following tasks after stoping the container that builds the rootfs. + # For example: + # * Delete a container + # * Delete a volume + return 0 +} diff --git a/tools/osbuilder/scripts/lib.sh b/tools/osbuilder/scripts/lib.sh index e7a39d889a..e43f78143e 100644 --- a/tools/osbuilder/scripts/lib.sh +++ b/tools/osbuilder/scripts/lib.sh @@ -421,3 +421,11 @@ detect_musl_version() [ "$?" == "0" ] && [ "$MUSL_VERSION" != "null" ] } + +before_starting_container() { + return 0 +} + +after_stopping_container() { + return 0 +}