stages: add org.osbuild.zip

In CoreOS Assembler, some hyperv artifact we `zip` for compression. This
new stage is modeled after the `org.osbuild.tar` stage with necessary
modifications.
This commit is contained in:
Luke Yang 2024-02-21 11:56:40 -05:00 committed by Achilleas Koutsou
parent 7b004a297e
commit ac8a2a4f30
5 changed files with 1097 additions and 0 deletions

46
stages/org.osbuild.zip Executable file
View file

@ -0,0 +1,46 @@
#!/usr/bin/python3
import os
import subprocess
import sys
import osbuild.api
def main(inputs, output_dir, options):
tree = inputs["tree"]["path"]
filename = options["filename"].lstrip("/")
# The zip command itself uses 6 as default if no level is specified.
# We choose to specifiy 6 as default here to make it explicit.
level = options.get("level", 6)
include = options.get("include", [])
# Set up the zip command.
zip_cmd = [
"zip",
"-q",
"-r",
f"-{level}",
os.path.join(output_dir, filename),
"."
]
if include:
# traditionally "-i" must be at the end of the commandline
zip_cmd += ["-i"]
zip_cmd += include
# Unlike the tar command, zip does not allow an option to change working dir.
# Therefore, we change directory within the subprocess function.
subprocess.run(
zip_cmd,
check=True,
cwd=tree
)
return 0
if __name__ == '__main__':
args = osbuild.api.arguments()
r = main(args["inputs"], args["tree"], args["options"])
sys.exit(r)

View file

@ -0,0 +1,48 @@
{
"summary": "Assembles the tree into a zip archive named `filename`",
"description": [
"Buildhost commands used: `zip`"
],
"schema_2": {
"options": {
"additionalProperties": false,
"required": [
"filename"
],
"properties": {
"filename": {
"description": "Filename for zip archive",
"type": "string",
"minLength": 1
},
"include": {
"type": "array",
"items": {
"type": "string",
"description": "If specified, the archive will only contain the specified paths in the specified order. Expects glob style expressions that is passed directly to the `zip` command."
}
},
"level": {
"description": "Compression level",
"type": "integer",
"minimum": 0,
"maximum": 9,
"default": 6
}
}
},
"inputs": {
"type": "object",
"additionalProperties": false,
"required": [
"tree"
],
"properties": {
"tree": {
"type": "object",
"additionalProperties": true
}
}
}
}
}

0
stages/test/test_zip.py Normal file
View file