diff --git a/tools/osbuilder/rootfs-builder/rootfs.sh b/tools/osbuilder/rootfs-builder/rootfs.sh index 92c2e5582..7a71ba902 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 238b6f702..978a89bc8 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 e7a39d889..e43f78143 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 +}