stages(tar): add paths option

This adds an optional `paths` option to the tar stage. If specified, the
paths will be included in the tarball in order.

The OVA image needs to have its contents in a specific order in the
archive.
This commit is contained in:
Sanne Raymaekers 2024-01-30 16:06:31 +01:00 committed by Michael Vogt
parent 0b33adcec1
commit df663ada8a

View file

@ -26,6 +26,25 @@ CAPABILITIES = ["CAP_MAC_ADMIN"]
SCHEMA_2 = """
"options": {
"additionalProperties": false,
"anyOf": [
{
"required": ["root-node"],
"not": {
"required": ["paths"]
}
},
{
"required": ["paths"],
"not": {
"required": ["root-node"]
}
},
{
"not": {
"required": ["paths", "root-node"]
}
}
],
"required": ["filename"],
"properties": {
"filename": {
@ -54,8 +73,15 @@ SCHEMA_2 = """
"default": true
},
"root-node": {
"description": "How to handle the root node: include or omit",
"description": "How to handle the root node: include or omit, mutually exclusive with paths",
"enum": ["include", "omit"]
},
"paths": {
"type": "array",
"items": {
"type": "string",
"description": "If specified, the archive will only contain the specified paths, in the specified order"
}
}
}
},
@ -78,6 +104,7 @@ def main(inputs, output_dir, options):
filename = options["filename"].lstrip("/")
tarfmt = options.get("format", "gnu")
root_node = options.get("root-node", "include")
paths = options.get("paths", [])
extra_args = []
# Set environment variables for the tar operation.
@ -106,13 +133,16 @@ def main(inputs, output_dir, options):
"-C", tree,
]
# Should we include the root inode or not
# This will change the way files are listed:
# `./file` (include) vs `file` (omit)
if root_node == "include":
tar_cmd += ["."]
if len(paths) == 0:
# Should we include the root inode or not
# This will change the way files are listed:
# `./file` (include) vs `file` (omit)
if root_node == "include":
tar_cmd += ["."]
else:
tar_cmd += os.listdir(tree)
else:
tar_cmd += os.listdir(tree)
tar_cmd += paths
# Make a tarball of the tree.
subprocess.run(