Repository navigation
Multi-step builds using single top-level command (HMS-11466, HMS-11467) - #2803
Conversation
|
I didn't finish the output file naming because I wanted to get this up in draft form before the end of the day for people to see. |
26a122a to
81a1403
Compare
|
I quite like it! Does the sidecar change between the various steps? |
|
It doesn't now but the idea is that if any step needs to store anything for a subsequent one, it'll write to it |
|
I like it as well. I'm wondering if any image-builder version enforcement between the commands is needed. My gut feeling is that at the minimum, the sidecar schema should be versioned. Other than that, the rest of the compatibility is basically on osbuild for downloading the sources and building the manifest, right? |
We probably don't need to be to elaborate -- just write the image-builder version used to create it and only run the other steps with a matching version. |
I've been thinking about this a bit and was considering adding a plain version umber ( I think I'll go with the IB version at first. Even if we move to versioning the schema separately, having the IB version in the sidecar as metadata will be useful for debugging/troubleshooting anyway. I'll make sure to document everything we're doing here. |
36ef588 to
d18478a
Compare
|
Looks great, this will make SBOMs in Konflux very easy to implement. My only thought on the UX is that I think |
That's the main thing, yeah. Another option would be to have two positional arguments, the image type and the directory, but when there's no natural order to positional args, I'd rather only have one. |
d18478a to
3713858
Compare
|
Marking as ready. Added a test. I wanted to add some docs and also the |
3713858 to
cb80e2b
Compare
Seconded, I'd prefer it to be as symmetric as possible to
If you do it probably makes sense to group them under usage and refer to them from the "build systems" section? |
I was thinking I'd add it to the long description for the command(s) so they become part of the manpages. I'd like to start putting more information in there (I really like when packages have long, detailed manpages) and use those as the primary documentation source for osbuild.org as well. |
cb80e2b to
a779452
Compare
|
Had claude do a review and found some minor issues. Working on them now and I'll push again soon. |
| } | ||
|
|
||
| func checkTaskVersion(task taskInfo) error { | ||
| ibVersion := readVersionInfo().ImageBuilder |
There was a problem hiding this comment.
I don't like that we shell out to osbuild for every subcommand here but I'll address that in a follow-up.
dec1bea to
82e6350
Compare
getImage() takes as arguments the cobra.Command and list of positional arguments to determine which exact image configuration to choose for the required action. The function takes the first positional argument to be the image type name because in both commands that use it, 'build' and 'manifest', it is the only positional argument. This commit changes the second argument in the function to be the image type name so that we can use the same function from other commands that don't have the image type as a positional argument.
The command works almost identically to the 'manifest' command, but instead of printing the manifest to stdout, it writes it to a file under the working directory.
This is a copy of cmdPrefetch() with argument and option handling adjusted. If a manifest is not found under the working directory, it directs users to the init command.
The command simply loads the manifest and calls the build function. The most important piece of information we're missing is the name of the pipeline to export. Other option also need to be handled, like user-defined output filenames and templating.
A sidecar file named task.json is added to the task directory to store metadata required by the build step that's only available from the init step.
Copy all options from the build command to the task init subcommand. The one exception is the 'with-manifest' option since the 'init' subcommand's main job is to write the manifest. The 'output-name' option is not written directly to the sidecar file (task.json). Instead, it's used to determine the name for each export and the mapping (export name -> file basename) is saved for the build step to read. The 'with-extra' option is resolved (i.e. globs are expanded and values are verified) and the extra pipelines to export are appended to the default export(s) for the image. The other new options are written to the sidecar file directly.
The build-image subcommand of the multi-step task uses the export filenames from the sidecar to rename the exported artifacts
Normally, when a user requests to build an image for an architecture that doesn't match the host, we add a bootstrap pipeline that sets up a buildroot for the target architecture. This is how we experimentally support cross-architecture builds. We don't want this for the multi-step builds however, so we disable it in the manifest generation that happens in the 'init' command. Keep the option explicitly disabled in code to make the decision obvious (along with the comment). See the note in the code for more information on the reasoning.
There's no reason for this to be a pointer. It's never nil and it carries minimal data. Every caller assumes it's not nil, which is true now, the function initialises all the fields, but keeping it as a pointer leaves open the possibility for nil derefs in the future.
Task subcommands (prefetch, build-image, and later, upload-image) will need to be run using the exact same version of image-builder that created (init) the task. We're being stricter than we need to be on purpose here. We're playing it safe, limiting the assumptions we need to make in the functions that process a task, so we don't need to worry about changes in functionality of the subcommands or the task info (sidecar) structure itself. In the future, we may rely on versioning the schema of the task instead.
Read the metrics and in-vm options from the task info and propagate them to the build function.
Both blocks were resolving the basename and output directory the same way. The callers of the writer functions add the 'sbom' and 'rpmlist' components to the filenames themselves, so the function initialisers only need the common basename and output directory.
The generateManifest() function requires the cobra.Command and args as arguments. Since the 'task init' options are slightly different (the output-dir is a positional argument), we need to manipulate the command like flags to make the function work for this use case too. All such cases should be refactored. Cobra data structures (cobra.Command and args lists) should not be relied on for functionality after some initial processing at the front-most layer of the CLI handling. We work around the current architecture for now. This change causes rpmlist and sbom to be written to the working directory (the task directory) when '--with-rpmlist' and '--with-sbom' are added to the 'image-builder task init' command.
When the 'build-log' option is used in the 'task init' subcommand, the option (boolean) gets written to the sidecar. Read it in the 'task build' step and initialise the build log writer to write the log to the file in the task directory.
All build outputs are now named consistently based on the image basename. The contents of a task directory at the end of a build with all options enabled, for a Fedora 44 x86_64 qcow2, looks like this: cache/ fedora-44-generic-qcow2-x86_64.buildlog fedora-44-generic-qcow2-x86_64.buildroot-build.spdx.json fedora-44-generic-qcow2-x86_64.image-os.spdx.json fedora-44-generic-qcow2-x86_64.manifest.json fedora-44-generic-qcow2-x86_64.qcow2 fedora-44-generic-qcow2-x86_64.rpmlist.json task.json Also rename the build progress to match.
The task commands call the version function to write it to the sidecar file or to compare version compatibility between the running version and the version that created the task. The version function always calls 'osbuild --version', so we need to support this in the mock osbuild script to test the functions.
The 'task prefetch' command calls osbuild without '--export' to download the sources to the cache. Support calling without export and create the cache (store) directory when it's set.
The test mocks osbuild and the depsolver, like we do in other tests across cmd/image-builder, and verifies the osbuild command line arguments as well as the files in the working directory at every step.
The prefetch top-level command was a prototype for the new task group of commands. It's obsolete now.
82e6350 to
58d568d
Compare
supakeen
left a comment
There was a problem hiding this comment.
Fine to go in and tinker, great work on all of this! ❤️
This PR adds the
image-builder taskgroup of commands. See #2802 for discussion of ideas.A
taskis a single build managed in multiple steps:init,prefetch(optional), andbuild-image. All the steps reuse the same working directory to read and write files. All build options are set on theinitsubcommand and for the rest the user only needs to provide the working directory. All information that needs to be shared between steps is stored in a sidecar file calledtask.jsonin the working directory.The following works:
For follow-ups:
image-builder task upload-image ./taskdir