summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrtkapiper <andy.piper@arcticwolf.com>2023-07-11 17:39:03 +0000
committerLars Wirzenius <liw@liw.fi>2023-07-13 15:33:47 +0000
commit3b5842b1d4dad02ce3c4a145c694eaefb7a8b069 (patch)
treeeaabf1ecdc011241fdf1f0036a98b78c988174f6
parent748382a0384508fe6cee084f71e25ad450623285 (diff)
downloadvmdb2-3b5842b1d4dad02ce3c4a145c694eaefb7a8b069.tar.gz
cache_rootfs_plugin: allow forcing overwrite of existing rootfs tarball
The `force` key enables overwriting of an existing rootfs tarball by `vmdb2`, allowing the tarball to be used as both a build input and a build output. This can be useful in multi-stage build chains where a "common base OS" rootfs filesystem is populated and packaged as a rootfs tarball by `vmdb2`, and this tarball is consumed by multiple downstream `vmdb2` builds that extract the tarball into disk images that have different partition layouts and/or filesystems.
-rw-r--r--vmdb/plugins/cache_rootfs.mdwn11
-rw-r--r--vmdb/plugins/cache_rootfs_plugin.py4
2 files changed, 13 insertions, 2 deletions
diff --git a/vmdb/plugins/cache_rootfs.mdwn b/vmdb/plugins/cache_rootfs.mdwn
index c4270a7..2077de5 100644
--- a/vmdb/plugins/cache_rootfs.mdwn
+++ b/vmdb/plugins/cache_rootfs.mdwn
@@ -6,8 +6,19 @@ Create a tarball of the root filesystem in the image.
Step keys:
* `cache-rootfs` &mdash; REQUIRED; tag of root filesystem on image.
+* `force` &mdash; OPTIONAL; boolean that enables overwriting of an existing rootfs
+ tarball by `vmdb2`, allowing the tarball to be used as both a build input and a
+ build output. This can be useful in multi-stage build chains where a "common base
+ OS" rootfs filesystem is populated and packaged as a rootfs tarball by `vmdb2`, and
+ this tarball is consumed by multiple downstream `vmdb2` builds that extract the
+ tarball into disk images that have different partition layouts and/or filesystems.
Example (in the .vmdb file):
+ # typical use
- cache-rootfs: root
unless: rootfs_unpacked
+
+ # create a rootfs tarball output at the end of a build process
+ - cache-rootfs: root
+ force: true
diff --git a/vmdb/plugins/cache_rootfs_plugin.py b/vmdb/plugins/cache_rootfs_plugin.py
index c7ebb6d..cdbd3e6 100644
--- a/vmdb/plugins/cache_rootfs_plugin.py
+++ b/vmdb/plugins/cache_rootfs_plugin.py
@@ -28,7 +28,7 @@ class CacheRootFSPlugin(vmdb.Plugin):
class MakeCacheStepRunner(vmdb.StepRunnerInterface):
def get_key_spec(self):
- return {"cache-rootfs": str, "options": "--one-file-system"}
+ return {"cache-rootfs": str, "options": "--one-file-system", "force": False}
def run(self, values, settings, state):
fs_tag = values["cache-rootfs"]
@@ -49,7 +49,7 @@ class MakeCacheStepRunner(vmdb.StepRunnerInterface):
vmdb.progress("caching rootdir {}".format(rootdir))
vmdb.progress("caching relative {}".format(dirs))
- if not os.path.exists(tar_path):
+ if values["force"] or not os.path.exists(tar_path):
vmdb.runcmd(["tar"] + opts + ["-C", rootdir, "-caf", tar_path] + dirs)
def _find_cacheable_mount_points(self, tags, rootdir):