summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniil Baturin <daniil@vyos.io>2024-09-19 18:45:42 +0100
committerDaniil Baturin <daniil@vyos.io>2024-09-20 16:07:00 +0100
commit25aeda5c4b9be04ae7e41cbf6423d280a6094c89 (patch)
treed0e6c9a0d9a9fc6fd3efc41b0b7c9882a21535c8
parent8274a418944c4cfc4c431951fc0018d72b15a0bf (diff)
downloadvyos-build-25aeda5c4b9be04ae7e41cbf6423d280a6094c89.tar.gz
vyos-build-25aeda5c4b9be04ae7e41cbf6423d280a6094c89.zip
build: T3664: add an option to specify artifact extensions
so that the manifest only contains files considered build artifacts, and those artifacts can be automatically picked up by CI jobs and the like
-rwxr-xr-xscripts/image-build/build-vyos-image27
1 files changed, 27 insertions, 0 deletions
diff --git a/scripts/image-build/build-vyos-image b/scripts/image-build/build-vyos-image
index 80b4d61d..c1711a5c 100755
--- a/scripts/image-build/build-vyos-image
+++ b/scripts/image-build/build-vyos-image
@@ -337,6 +337,17 @@ if __name__ == "__main__":
if type(build_config["image_format"]) != list:
build_config["image_format"] = [ build_config["image_format"] ]
+ ## If the user didn't explicitly specify what extensions build artifact should have,
+ ## assume that the list is the same as image formats.
+ ## One case when it's not the same is when a custom build hook is used
+ ## to build a format that our build script doesn't support natively.
+ if not has_nonempty_key(build_config, "artifact_format"):
+ build_config["artifact_format"] = build_config["image_format"]
+ else:
+ # If the option is there, also make it list if it's a scalar
+ if type(build_config["artifact_format"]) != list:
+ build_config["artifact_format"] = [ build_config["artifact_format"] ]
+
## Dump the complete config if the user enabled debug mode
if debug:
import json
@@ -631,6 +642,9 @@ Pin-Priority: 600
# Copy the image
shutil.copy("live-image-{0}.hybrid.iso".format(build_config["architecture"]), iso_file)
+ # Add the image to the manifest
+ manifest['artifacts'].append(iso_file)
+
# If the flavor has `image_format = "iso"`, then the work is done.
# If not, build additional flavors from the ISO.
if build_config["image_format"] != ["iso"]:
@@ -669,5 +683,18 @@ Pin-Priority: 600
{build_config['architecture']} {hook_opts}")
manifest['artifacts'].append(custom_image)
+ # Filter out unwanted files from the artifact list
+ # and leave only those the user specified
+ # in either `artifact_format` or `image_format`.
+ #
+ # For example, with `image_format = "raw"`,
+ # the ISO image is just an intermediate object, not an target artifact.
+
+ # os.path.splitext returns extensions with dots,
+ # so we need to remove the dots, hence [1:]
+ is_artifact = lambda f: os.path.splitext(f)[-1][1:] in build_config['artifact_format']
+
+ manifest['artifacts'] = list(filter(is_artifact, manifest['artifacts']))
+
with open('manifest.json', 'w') as f:
f.write(json.dumps(manifest))