Skip to content

Conversation

@mvo5
Copy link
Contributor

@mvo5 mvo5 commented Nov 19, 2025

[this is now used in https://github.com/osbuild/bootc-image-builder/pull/1157 and green there]

This PR move the bootc-image-builder code into
cmd/image-builder and changes main() so that image-builder
becomes a multi-call binary. When image-builder is called with
argv[0] as bootc-image-builder it will use the cobra commandline
and code from bootc-image-builder.

There is still a bit of duplication in the manifest generation
and building between bib_main.go and main.go but that is hard
to avoid if we want the "new" bib to be as close as possible
to the existing one (e.g. we do things like "canChownInPath()"
in bib which we do not need in ibcli).

One important difference between the two is how anaconda-iso
image types for bootc handle the repositories. The bib personality
stays the same as the orignal, i.e. it will use the container
repositories for depsolving. This require some complicated mTLS
handling that does not map well into ibcli. Here we do not do
that and instead use our own repos for the detected distro. I.e.
if the detected distro is fedora we build the (rpm) installer from
out fedora repos. We can strive to unify this and add (not so nice)
code into ibcli to support this or we just warn in ibcli if
bootc with anaconda-iso is used that this behaves differently
from bib and that people should use bib if they need the old
behavior (I would prefer that). I hope then we can phase out
this rpm based bootc anaconda-iso in favor of the container
based bootc-installer type.

This is osbuild/bootc-image-builder#1131
but directly in ibcli instead of doing the bib intermediate step.
The advantage is that we can "freeze" the bib repo and if we
run into issues with the transition have the last known good
bib code. Once we are happy we just delete all go files in the
bib repo and it just becomes a repo that builds the container
for bib.

It has many commits because it imports the full history of bib/cmd/bootc-image-builder.

/jira-epic HMS-8839

JIRA: HMS-9808

@mvo5 mvo5 force-pushed the merge-bib-multicall branch from 6ba4502 to d84ece8 Compare November 19, 2025 14:45
@achilleas-k achilleas-k self-requested a review November 19, 2025 16:16
mvo5 added a commit to mvo5/images that referenced this pull request Nov 21, 2025
The existing code was checking if dnf could be run with --version
to detect if dnf is installed at all. That is wrong, dnf can
fail when it is just run with --version, e.g.:
```
Failed to open log file: /var/log/hawkey.log
4.14.0
```
But errors like this should be surfaced to the user (which
the next call to dnf will do). So instead of running dnf
just run:
```
sh -c "command -v dnf"
```
to check if its available. This will fix the test failures
in osbuild/image-builder-cli#374

Note that the detection is covered by an existing test so
no new test needs adding.
supakeen pushed a commit to mvo5/images that referenced this pull request Nov 22, 2025
The existing code was checking if dnf could be run with --version
to detect if dnf is installed at all. That is wrong, dnf can
fail when it is just run with --version, e.g.:
```
Failed to open log file: /var/log/hawkey.log
4.14.0
```
But errors like this should be surfaced to the user (which
the next call to dnf will do). So instead of running dnf
just run:
```
sh -c "command -v dnf"
```
to check if its available. This will fix the test failures
in osbuild/image-builder-cli#374

Note that the detection is covered by an existing test so
no new test needs adding.
@mvo5 mvo5 force-pushed the merge-bib-multicall branch from d84ece8 to 8d4a5cb Compare November 24, 2025 08:22
@lzap
Copy link
Contributor

lzap commented Nov 24, 2025

So like with +1,630 −236 we get all features of bib? That is not too bad at all.

Once we are happy we just delete all go files in the
bib repo and it just becomes a repo that builds the container
for bib.

Do you mean there is a Containerfile that builds its binary from this repo?

Nice.

@mvo5
Copy link
Contributor Author

mvo5 commented Nov 24, 2025

So like with +1,630 −236 we get all features of bib? That is not too bad at all.

That is correct. Its is more lines than I would like but a lot is cobra setup which
we cannot get rid of. There is still a bit of duplication in the manifest creation/build
because of the mTLS handling. My quest is to see how to minimize this further (and maybe eliminate it, idk). But I don't think we can get rid of the cobra from bib without risking (subtle) incompatibilities.

Once we are happy we just delete all go files in the
bib repo and it just becomes a repo that builds the container
for bib.

Do you mean there is a Containerfile that builds its binary from this repo?

Nice.

Yeah, the goal would be that the bib containerfile essentially just does a GOBIN=/usr/bin/ go install github.com/osbuild/image-builder-cli/cmd/image-builder && mv /usr/bin/image-builder /usr/bin/bootc-image-bulder (c.f. https://github.com/osbuild/bootc-image-builder/pull/1157/files#diff-4d2a8eefdf2a9783512a35da4dc7676a66404b6f3826a8af9aad038722da6823R12)

@lzap
Copy link
Contributor

lzap commented Nov 24, 2025

the goal would be that the bib containerfile essentially

Maybe we do not need a symlink but just a variable to specify the target, because we only distribute bib in a container, do we? But this is fine, symlink is sort of expected in these scenarios.

github-merge-queue bot pushed a commit to osbuild/images that referenced this pull request Nov 24, 2025
The existing code was checking if dnf could be run with --version
to detect if dnf is installed at all. That is wrong, dnf can
fail when it is just run with --version, e.g.:
```
Failed to open log file: /var/log/hawkey.log
4.14.0
```
But errors like this should be surfaced to the user (which
the next call to dnf will do). So instead of running dnf
just run:
```
sh -c "command -v dnf"
```
to check if its available. This will fix the test failures
in osbuild/image-builder-cli#374

Note that the detection is covered by an existing test so
no new test needs adding.
Makefile Outdated
.PHONY: build
build: $(BUILDDIR)/bin/ ## build the binary from source
go build -ldflags="-X main.version=${VERSION}" -o $<image-builder ./cmd/image-builder/
(cd ./cmd/image-builder && ln -sf image-builder bootc-image-builder)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@lzap you mean this symlink here in your comment in #374 (comment) ? If so the idea behind this one was that it would be nice to provide the bib binary everywhere where we have ibcli so that its easier for users to switch - but thinking about this again maybe its not such a good ideas as we want people to move to bib and by making it too easy to just stick with bib we defeat this goal. Idk, happy to remove this again and reconsider.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, I meant this link.

Don't we only support bib via its container? Then introducing this link is actually a step back if we distribute it with CLI RPM and we might accidentally acquire more users of bib who were previously not exposed. That is why I thought just building differently named binary would be enough. In fact, if bib is only consumed via podman, then we could just introduce an environment variable because the name of the binary does not matter as it is never directly used it is docker or podman what is typed in.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I think this link here should go away for the reasons you outline.

@mvo5 mvo5 force-pushed the merge-bib-multicall branch 3 times, most recently from f8c277c to 14d57d8 Compare November 25, 2025 17:29
@mvo5 mvo5 marked this pull request as ready for review November 25, 2025 18:49
@mvo5 mvo5 requested a review from a team as a code owner November 25, 2025 18:49
@mvo5 mvo5 requested review from croissanne and lzap and removed request for a team November 25, 2025 18:49
Copy link
Contributor

@avitova avitova left a comment

Choose a reason for hiding this comment

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

I swear I had a different issue I found, so I started reviewing, but then I understood how this works and found out it is not an issue. So here I submit a review with a typo I found.

@schutzbot schutzbot changed the title cmd: make bootc-image-builder a multi-call binary of ibcli cmd: make bootc-image-builder a multi-call binary of ibcli (HMS-9808) Nov 27, 2025
@schutzbot schutzbot added the 🌟 best practice This pull request follows our best practices! label Nov 27, 2025
@mvo5 mvo5 force-pushed the merge-bib-multicall branch from 14d57d8 to 7d151ef Compare November 27, 2025 11:08
@supakeen supakeen self-requested a review December 1, 2025 15:08
@mvo5 mvo5 requested review from ondrejbudai and removed request for supakeen December 1, 2025 15:08
@supakeen supakeen self-requested a review December 1, 2025 15:08
mvo5 and others added 17 commits December 3, 2025 17:24
When adding new image types like `vhd` or the coming `gcp` I
noticed that we currently need to modify two different places.

This package consolidates all knowledge about image types, their
exports and if they are ISO or disk into a single package. This
should make it easier to expand the supported image types.
This commit uses the new `imagetypes` package and replaces the
use of `BuildType` with the new `ImageTypes` to determine what
is available, valid, what to export and if it's an ISO.
This commit adds a new image type `gce` that contains a tar
file with the raw image inside. This can then be imported
into GCE.
We want to move into a world where we build the anaconda image from
bootc containers instead of our current RPM based construction [0]
so lets mark the rpm based installer ISO image types as legacy.

This should make it easy to support a potential new `bootc-iso`
or `bootc-installer` image type [0] while still supporting the
legacy mode for a while.
This commit exposes the new `ova` image type and adds a
basic smoke test.
This commit adds support for the new `bootc-installer` image
type that will take a bootc container and create an ISO out
of it. It also adds a new `--installer-payload-ref` option
so that the user can specify a different payload container
to install.

See osbuild/images#1906 for details.

This is the equivalent of
osbuild#341
for bootc-image-builder and allows us to build these kinds
of images with bib now too.
Just use os.WriteFile() intead of reimplementing it.
Drop legacy_iso.go and use the images library to build the
image.
This commit move the cmd/bootc-image-builder code into
cmd/image-builder and changes `main()` so that bootc-image-builder
becomes a multi-call binary. When image-builder is called with
argv[0] as bootc-image-builder it will use the cobra commandline
and code from bootc-image-builder.

There is still a bit of duplication in the manifest generation
and building between bib_main.go and main.go but that is hard
to avoid if we want the "new" bib to be as close as possible
to the existing one (e.g. we do things like "canChownInPath()"
in bib which we do not need in ibcli).

One important difference between the two is how `anaconda-iso`
image types for bootc handle the repositories. The `bib` personality
stays the same as the orignal, i.e. it will use the container
repositories for depsolving. This require some complicated mTLS
handling that does not map well into ibcli. Here we do not do
that and instead use our own repos for the detected distro. I.e.
if the detected distro is fedora we build the (rpm) installer from
out fedora repos. We can strive to unify this and add (not so nice)
code into ibcli to support this *or* we just warn in ibcli if
bootc with anaconda-iso is used that this behaves differently
from bib and that people should use bib if they need the old
behavior (I would prefer that). I hope then we can phase out
this rpm based bootc anaconda-iso in favor of the container
based bootc-installer type.
@mvo5 mvo5 force-pushed the merge-bib-multicall branch from 93a09a9 to 54834ad Compare December 3, 2025 16:25
@mvo5
Copy link
Contributor Author

mvo5 commented Dec 3, 2025

This branch cannot be rebased due to conflicts

(though it's not showing any conflicts)

Its strange, rebasing also did not show a conflict - oh well! I rebased and hopefully its happy again.

@supakeen supakeen added this pull request to the merge queue Dec 3, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to a conflict with the base branch Dec 3, 2025
@achilleas-k
Copy link
Member

Happened again. Is it probably related to the way the original history was pulled in and rebased? It should be fine though 🤔

@supakeen
Copy link
Member

supakeen commented Dec 4, 2025

Ok, so how are we going to merge this? Does it require an admin merge and would that be safe to do?

Copy link
Member

@thozza thozza left a comment

Choose a reason for hiding this comment

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

I know that I'm late to the party and this PR would have been merged already if there weren't issues with the merge queue, but here I am 😅

I like this idea a lot. I have just one nitpick inline comment.

// ErrUploadTypeUnsupported is returned when the upload type is not supported
var ErrUploadTypeUnsupported = errors.New("unsupported type")

var awscloudNewUploader = awscloud.NewUploader
Copy link
Member

Choose a reason for hiding this comment

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

I must say that it is weird to see this moving from upload.go to bib_main.go, while uploaderForCmdAWS() in this file uses the variable.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great catch and silly me, I will fix this (probably in a followup, not sure what we should do about the (not)merge conflict in the meantime :( Silly GH!

@supakeen supakeen merged commit 37d5f29 into osbuild:main Dec 4, 2025
39 checks passed
mvo5 added a commit to mvo5/image-builder-cli that referenced this pull request Dec 8, 2025
During the merge of the bootc-image-builder code into bib
(PR#374) a function accidentially moved from `upload.go`
into `bib_main.go`. This was a mistake and this commit
moves it back into the right place.

Thanks to Thozza for finding this [0]

[0] osbuild#374 (comment)
github-merge-queue bot pushed a commit that referenced this pull request Dec 10, 2025
During the merge of the bootc-image-builder code into bib
(PR#374) a function accidentially moved from `upload.go`
into `bib_main.go`. This was a mistake and this commit
moves it back into the right place.

Thanks to Thozza for finding this [0]

[0] #374 (comment)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🌟 best practice This pull request follows our best practices!

Projects

None yet

Development

Successfully merging this pull request may close these issues.