Skip to content

Multi-step builds using single top-level command (HMS-11466, HMS-11467) - #2803

Merged
supakeen merged 22 commits into
osbuild:mainfrom
achilleas-k:cmd/multi-step-builds
Nov 11, 2026
Merged

supakeen merged 22 commits into
osbuild:mainfrom
achilleas-k:cmd/multi-step-builds

Conversation

@achilleas-k

@achilleas-k achilleas-k commented Oct 28, 2026 •

Copy link
Copy Markdown
Member

This PR adds the image-builder task group of commands. See #2802 for discussion of ideas.

A task is a single build managed in multiple steps: init, prefetch (optional), and build-image. All the steps reuse the same working directory to read and write files. All build options are set on the init subcommand 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 called task.json in the working directory.

The following works:

› ./bin/image-builder task init --image-type qcow2 --arch x86_64 --with-buildlog --with-metrics --with-sbom --with-rpmlist --distro fedora-44 --output-name "{{ .Image.Type }}.taskdemo" ./demo

› ll demo
total 2.0M
-rw-r--r-- 1 achilleas achilleas  375K 2026-11-05 19:34 generic-qcow2.taskdemo.buildroot-build.spdx.json
-rw-r--r-- 1 achilleas achilleas 1008K 2026-11-05 19:34 generic-qcow2.taskdemo.image-os.spdx.json
-rw------- 1 achilleas achilleas  463K 2026-11-05 19:34 generic-qcow2.taskdemo.manifest.json
-rw-r--r-- 1 achilleas achilleas  103K 2026-11-05 19:34 generic-qcow2.taskdemo.rpmlist.json
-rw------- 1 achilleas achilleas   226 2026-11-05 19:34 task.json

› ./bin/image-builder task prefetch ./demo
[|] Downloading sources
[2 / 2] Pipeline source org.osbuild.librepo [-------------------------------------------------------->] 100.00%
Message: Finished pipeline org.osbuild.librepo

› ll demo
total 2.0M
drwxr-xr-x 1 achilleas achilleas   128 2026-11-05 19:34 cache/
-rw-r--r-- 1 achilleas achilleas  375K 2026-11-05 19:34 generic-qcow2.taskdemo.buildroot-build.spdx.json
-rw-r--r-- 1 achilleas achilleas 1008K 2026-11-05 19:34 generic-qcow2.taskdemo.image-os.spdx.json
-rw------- 1 achilleas achilleas  463K 2026-11-05 19:34 generic-qcow2.taskdemo.manifest.json
-rw-r--r-- 1 achilleas achilleas  103K 2026-11-05 19:34 generic-qcow2.taskdemo.rpmlist.json
-rw------- 1 achilleas achilleas   226 2026-11-05 19:34 task.json

› ll demo/cache
total 12K
drwxr-xr-x 1 achilleas achilleas   0 2026-11-05 19:34 objects/
drwxr-xr-x 1 achilleas achilleas  34 2026-11-05 19:34 sources/
drwxr-xr-x 1 achilleas achilleas   0 2026-11-05 19:34 stage/
drwxr-xr-x 1 achilleas achilleas   0 2026-11-05 19:34 tmp/
-rw-r--r-- 1 achilleas achilleas 130 2026-11-05 19:34 CACHEDIR.TAG
-rw-r--r-- 1 achilleas achilleas  43 2026-11-05 19:34 cache.info
-rw-r--r-- 1 achilleas achilleas   0 2026-11-05 19:34 cache.lock
-rw-r--r-- 1 achilleas achilleas   1 2026-11-05 19:34 cache.size

› sudo ./bin/image-builder task build-image ./demo
[sudo] password for achilleas@inigo:
[|] Image building step
[6 / 6] Pipeline qcow2 [---------------------------------------------------------------->] 100.00%
[2 / 2] Stage org.osbuild.qemu [-------------------------------------------------------->] 100.00%
Message: Finished pipeline qcow2
Metrics:
        os: Finished module org.osbuild.rpm: 1m9s
        build: Finished module org.osbuild.rpm: 12s
        qcow2: Finished module org.osbuild.qemu: 12s
        image: Finished module org.osbuild.copy: 5s

› ll demo/
total 950M
drwxr-xr-x 1 achilleas achilleas   128 2026-11-05 19:35 cache/
-rw-r--r-- 1 root      root       105K 2026-11-05 19:36 generic-qcow2.taskdemo.buildlog
-rw-r--r-- 1 achilleas achilleas  375K 2026-11-05 19:34 generic-qcow2.taskdemo.buildroot-build.spdx.json
-rw-r--r-- 1 achilleas achilleas 1008K 2026-11-05 19:34 generic-qcow2.taskdemo.image-os.spdx.json
-rw------- 1 achilleas achilleas  463K 2026-11-05 19:34 generic-qcow2.taskdemo.manifest.json
-rw-r--r-- 1 root      root       951M 2026-11-05 19:36 generic-qcow2.taskdemo.qcow2
-rw-r--r-- 1 achilleas achilleas  103K 2026-11-05 19:34 generic-qcow2.taskdemo.rpmlist.json
-rw------- 1 achilleas achilleas   226 2026-11-05 19:34 task.json

› cat demo/task.json
{"exports":{"qcow2":"generic-qcow2.taskdemo"},"basename":"generic-qcow2.taskdemo","buildlog":true,"metrics":true,"invm":false,"image_builder_version":"unknown","image_builder_commit":"3713858b77bb58b3e29a68e1cf874f113a59b98a"}

For follow-ups:

  • Documentation
  • image-builder task upload-image ./taskdir

@achilleas-k

Copy link
Copy Markdown
Member Author

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.

@achilleas-k
achilleas-k force-pushed the cmd/multi-step-builds branch from 26a122a to 81a1403 Compare October 28, 2026 18:04
@supakeen

Copy link
Copy Markdown
Member

I quite like it! Does the sidecar change between the various steps?

@achilleas-k

Copy link
Copy Markdown
Member Author

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

@thozza

thozza commented Oct 29, 2026

Copy link
Copy Markdown
Member

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?

@brlane-rht

Copy link
Copy Markdown
Contributor

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.

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.

@achilleas-k

Copy link
Copy Markdown
Member Author

the sidecar schema should be versioned

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 ("version": 1) to the sidecar data. Brian's idea of tying it to the IB binary version is a nice way to be even stricter with it, making it clear that everything should be done with the same version and suggesting that these tasks shouldn't be thought of as long-living things.

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.

@achilleas-k
achilleas-k force-pushed the cmd/multi-step-builds branch 2 times, most recently from 36ef588 to d18478a Compare November 4, 2026 18:12
@achilleas-k achilleas-k linked an issue Nov 4, 2026 that may be closed by this pull request
@lucasgarfield

Copy link
Copy Markdown

Looks great, this will make SBOMs in Konflux very easy to implement.

My only thought on the UX is that I think task init <image-type> [--workdir DIR] feels a little more natural since I'm used to build <image-type> but I also understand wanting to keep the shape of task init consistent across all subcommands, so I'll leave the final decision up to you.

@achilleas-k

Copy link
Copy Markdown
Member Author

keep the shape of task init consistent across all subcommands

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.

@achilleas-k
achilleas-k force-pushed the cmd/multi-step-builds branch from d18478a to 3713858 Compare November 5, 2026 18:28
@achilleas-k

Copy link
Copy Markdown
Member Author

Marking as ready. Added a test. I wanted to add some docs and also the upload-image command, but this is getting long so I'll break those out into follow-ups.

@achilleas-k
achilleas-k marked this pull request as ready for review November 5, 2026 18:29
@achilleas-k
achilleas-k requested a review from a team as a code owner November 5, 2026 18:29
@achilleas-k
achilleas-k force-pushed the cmd/multi-step-builds branch from 3713858 to cb80e2b Compare November 5, 2026 18:42
@supakeen

supakeen commented Nov 6, 2026 •

Copy link
Copy Markdown
Member

Looks great, this will make SBOMs in Konflux very easy to implement.

My only thought on the UX is that I think task init <image-type> [--workdir DIR] feels a little more natural since I'm used to build <image-type> but I also understand wanting to keep the shape of task init consistent across all subcommands, so I'll leave the final decision up to you.

Seconded, I'd prefer it to be as symmetric as possible to build, we can default the workdir somewhere; but not the image type :)

I wanted to add some docs and also the upload-image command, but this is getting long so I'll break those out into follow-ups.

If you do it probably makes sense to group them under usage and refer to them from the "build systems" section?

@achilleas-k

Copy link
Copy Markdown
Member Author

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.

@achilleas-k achilleas-k changed the title Multi-step builds using single top-level command Multi-step builds using single top-level command (HMS-11466, HMS-11467) Nov 6, 2026
Comment thread cmd/image-builder/task_test.go Resolved
@achilleas-k
achilleas-k force-pushed the cmd/multi-step-builds branch from cb80e2b to a779452 Compare November 6, 2026 15:06
@achilleas-k

Copy link
Copy Markdown
Member Author

Had claude do a review and found some minor issues. Working on them now and I'll push again soon.

Comment thread cmd/image-builder/main.go
}

func checkTaskVersion(task taskInfo) error {
ibVersion := readVersionInfo().ImageBuilder

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like that we shell out to osbuild for every subcommand here but I'll address that in a follow-up.

@achilleas-k
achilleas-k force-pushed the cmd/multi-step-builds branch 3 times, most recently from dec1bea to 82e6350 Compare November 6, 2026 18:23
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.
@achilleas-k
achilleas-k force-pushed the cmd/multi-step-builds branch from 82e6350 to 58d568d Compare November 10, 2026 11:30

@supakeen supakeen left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fine to go in and tinker, great work on all of this! ❤️

@supakeen
supakeen enabled auto-merge November 10, 2026 13:33
@supakeen
supakeen added this pull request to the merge queue Nov 11, 2026
Merged via the queue into osbuild:main with commit 0c4d9b8 Nov 11, 2026
55 checks passed
@achilleas-k
achilleas-k deleted the cmd/multi-step-builds branch November 11, 2026 12:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Multi-step builds

5 participants