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 = """ SCHEMA_2 = """
"options": { "options": {
"additionalProperties": false, "additionalProperties": false,
"anyOf": [
{
"required": ["root-node"],
"not": {
"required": ["paths"]
}
},
{
"required": ["paths"],
"not": {
"required": ["root-node"]
}
},
{
"not": {
"required": ["paths", "root-node"]
}
}
],
"required": ["filename"], "required": ["filename"],
"properties": { "properties": {
"filename": { "filename": {
@ -54,8 +73,15 @@ SCHEMA_2 = """
"default": true "default": true
}, },
"root-node": { "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"] "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("/") filename = options["filename"].lstrip("/")
tarfmt = options.get("format", "gnu") tarfmt = options.get("format", "gnu")
root_node = options.get("root-node", "include") root_node = options.get("root-node", "include")
paths = options.get("paths", [])
extra_args = [] extra_args = []
# Set environment variables for the tar operation. # Set environment variables for the tar operation.
@ -106,13 +133,16 @@ def main(inputs, output_dir, options):
"-C", tree, "-C", tree,
] ]
# Should we include the root inode or not if len(paths) == 0:
# This will change the way files are listed: # Should we include the root inode or not
# `./file` (include) vs `file` (omit) # This will change the way files are listed:
if root_node == "include": # `./file` (include) vs `file` (omit)
tar_cmd += ["."] if root_node == "include":
tar_cmd += ["."]
else:
tar_cmd += os.listdir(tree)
else: else:
tar_cmd += os.listdir(tree) tar_cmd += paths
# Make a tarball of the tree. # Make a tarball of the tree.
subprocess.run( subprocess.run(