Commit graph

229 commits

Author SHA1 Message Date
Michael Vogt
655b6bbd0f progress: tweak progress error reporting
This commit adds catpure of os.Std{out,err} when running osbuild so
that we capture the error log and can display it as part of
an error from osbuild, e.g. when osbuild itself crashes.

This gives us more accurate error reporting if anything fails
during the osbuild building.
2025-03-31 19:42:59 +00:00
Michael Vogt
9ac654a7b1 progress: move from an internal package to external
This commit makes the previously internal `progress` package an
external API. The is the result of the discussion in images
PR#1150 where we decided that the progress module is not a great
fit for the "images" library.

We want to share this code between bootc-image-builder and
image-builder-cli now. In the future we will also want to
use it in the `worker-executor` in `osbuild-composer` to
parse the stream data from `osbuild`.

We plan to merge bootc-image-builder and image-builder-cli
medium term so importing code from bootc-image-buider in
image-builder cli is not that stange.

When we (longer-term) use this code the `worker-executor`
we will need to think about this again and maybe put it
back into images. However this commit unblocks us without
making anything worse.
2025-03-31 19:42:59 +00:00
Simon de Vlieger
6d0927c2f9 import: move bib files to correct path
Moves the files imported from `bootc-image-builder` to the appropriate
path under `pkg/` so they can be imported reverse. Also fix up the
import paths that are in these files to refer to their new locations.

Signed-off-by: Simon de Vlieger <supakeen@redhat.com>
2025-03-31 18:19:33 +00:00
Gianluca Zuccarelli
441d408aee bib: deprecate the --local flag
Pulling container images before building would break in the case of
authenticated images on podman machine, since the auth file lives on the
host and not podman machine and won't know about it.

This commit deprecates the `--local` flag and warns users when it is
passed to the CLI so that this won't break things for anyone who might
already be using the flag. This change means that the user will have to
ensure that the container is pulled to the local container store before
initiating the build.

Co-authored-by: Ondřej Budai <obudai@redhat.com>
2025-03-31 18:19:33 +00:00
bstrausser
c74c402d74 bib/internal/setup: use fake podman binary for testing
Create a mock podman executable script and add it at the top of PATH.
Use it to generate output for the container tag validation.
2025-03-31 18:19:33 +00:00
bstrausser
3cd7df7b13 bib: change octal literal prefix
Use `0o` instead of just `0` for better readability.
2025-03-31 18:19:33 +00:00
bstrausser
2a89cb6739 bib/internal/setup: validate container tags early
Check that the container has the expected bootc tags early and fail if
they are missing.
2025-03-31 18:19:33 +00:00
Michael Vogt
4fa4ad34a0 bib: detect missing qemu-user early
This commit checks early if cross architecture building support via
`qemu-user-static` (or similar tooling) is missing and errors in
a more user friendly way.

Note that there is no integration test right now because testing
this for real requires mutating the very global state of
`echo 0 > /proc/sys/fs/binfmt_misc/qemu-aarch64`
which would make the test non-parallelizable and even risks
failing other cross-arch tests running on the same host (because
binfmt-misc is not namespaced (yet)).
2025-03-31 18:19:33 +00:00
Michael Vogt
b3ef264353 bib: simplify getContainerSize()
The getContainerSize() was not using some of the modern go helpers.
So let's use `exec.Command().Output()` and introduce a new
`util.OutputErr()` helper that will be able to also show stderr to
the user if the Output() call returns an error.
2025-03-31 18:19:33 +00:00
Colin Walters
9b280f0ba3 setup: Simplify container-storage mounted check
I ran into the `--local` option not working at least in my
setup with the current container image (which for some reason
hasn't been updated, and predates the latest tip commit
which talks about btrfs)

On this current test system (MacOS + podman 5 + default podman-machine)
things do work with the tip commit.

However...I don't quite understand the need to *both* try to
run `systemd-detect-virt` *and* parse `/proc/self/mountinfo`.

(BTW, the logic for `insideContainer` was really confusing me because
 it only returned `true` if we were *not* in a container...I wonder
 if that was really intentional?)

Anyways, I think the goal here is just a friendly direct error
message if it doesn't look like the mount is there, which we can
do by just checking for the file path.  If it isn't mounted
from the host then nothing will be there.

Signed-off-by: Colin Walters <walters@verbum.org>
2025-03-31 18:19:33 +00:00
Michael Vogt
2f0d81288a setup: deal with btrfs subvolumes when checking mapped storage
When the container storage is checked it may come from a btrfs
subvolume. In /proc/self/mountinfo this looks like:
```
1364 1345 0:33 /root/var/lib/containers/storage /var/lib/containers/storage rw,relatime - btrfs /dev/mapper/luks-1356123c-c7b9-1bd7-a8bf-e13d4cbb5500 rw,seclabel,compress=zstd:1,ssd,discard=async,space_cache,subvolid=257,subvol=/root
```
as a quick fix just compare the suffix of the root instead of the
full path.

Thanks for Ondrej!
2025-03-31 18:19:33 +00:00
Michael Vogt
280f7626d5 bib: check /var/lib/containers/storage when using "--local"
Ensure to error early when the user is not passing the required
```
-v /var/lib/containers/storage:/var/lib/containers/storage
```
when doing a local build.
2025-03-31 18:19:33 +00:00
Michael Vogt
1bfb930266 test: add test that ensure disk space is doubled
Ensure that the disk size of a container is taken into account
when the image is generated. The current heuristic is that we
just double the container size.

The test will not build an image just generate a manifest and
check that the image file is generated with the expected size.
2025-03-31 18:19:33 +00:00
Colin Walters
2d95d34bb6 Ensure root_t label for /store
The way osbuild works is to synthesize a filesystem tree in the
store, then copy it to the disk.  This ensures the label for the
store is `root_t` which ends up being the labeling for
the "infrastructure" bits in the `/ostree` repository in the
target root.

This in turn is blocking a lot of things.

Closes: https://github.com/osbuild/bootc-image-builder/issues/149
2025-03-31 18:19:33 +00:00
Michael Vogt
1ea8e87fad bib: tweak EnsureEnvironment() based on the feedback from Colin 2025-03-31 18:19:33 +00:00
Michael Vogt
4fa198c18d bib: mount devtmpfs inside the container too
This ensures that the new `partscan` feature in osbuild works. By
default the containers only have a static snapshot of /dev on a
tmpfs. This means that anything later added by losetup will be
missing inside the container.

It also means that https://github.com/osbuild/osbuild/pull/1468
can be reverted.
2025-03-31 18:19:33 +00:00
Colin Walters
bff341cb0b Rename utils -> util
Per style.
2025-03-31 18:19:33 +00:00
Colin Walters
3c717fde11 Add and use a helper to run subprocess
In most cases e.g. we do want to show stdout/stderr, and
it's handy to have a debug log when we're running
a subprocess.

While we're here, switch to just forking `cp` in
the setup code.

Signed-off-by: Colin Walters <walters@verbum.org>
2025-03-31 18:19:33 +00:00
Colin Walters
214fcda30e Validate that we're in rootful podman
As this is a footgun that multiple people have run into.

Signed-off-by: Colin Walters <walters@verbum.org>
2025-03-31 18:19:33 +00:00
Colin Walters
402c3955b9 Move some helpers into modules
For functional clarity.

Signed-off-by: Colin Walters <walters@verbum.org>
2025-03-31 18:19:33 +00:00
Simon de Vlieger
02461ac2a3 main: allow seed setting
Allow users to define the seed that's used for manifest generation.
Regenerating an image with a given seed leads to the same manifest
(provided depsolving does the same).

The seed is normally mostly used to generate random filesystem UUIDs.

This will need a bunch of documentation in a follow up since the use
cases are meant to be advanced but it can really speed up multi-type and
rebuilds of the same image.

Signed-off-by: Simon de Vlieger <supakeen@redhat.com>
2025-03-31 17:31:12 +00:00
Simon de Vlieger
f25b5e325e Revert "blueprintload: enable strict checking for toml"
This reverts commit d41bd9aa5b.

Signed-off-by: Simon de Vlieger <supakeen@redhat.com>
2025-03-28 16:05:11 +00:00
Michael Vogt
0d668c112a go.mod: update to latest version of github.com/osbuild/blueprint
This commit pulls in the latest fixes from
https://github.com/osbuild/blueprint/pull/7
2025-03-28 10:53:46 +00:00
Michael Vogt
d00e76ced1 main: tweak handling of --output-name to avoid adding double extensions
This commit tweaks the handling of the `--output-name` option so
that is a name with the same extension as the image is passed that
is just silently ignored. Its a common issue that first time
users run:
```console
$ image-builder build --output-name foo.qcow2 qcow2
```
which currently leads to a foo.qcow2.qcow2. With this commit
the expected "foo.qcow2" will appear.
2025-03-27 14:03:11 +00:00
Michael Vogt
d4c31389a9 main: show output directory content after image build
This commit adds the content of the output directory when a
build is finished. This is a convenient feature to make it easier
for the users.

Thanks to Simon for suggesting this!
2025-03-27 13:21:43 +00:00
Michael Vogt
2895e71064 many: move to use the new github.com/osbuild/blueprint module
This commit moves ibcli over to use the new `osbuild/blueprint`
module for better compatibility with the composer and on-prem
blueprints.
2025-03-27 11:59:45 +00:00
Michael Vogt
fe713a0995 main: tweak how ibcli determines if bootstraping is needed
This simplifies the way that ibcli determines if the manifest
needs a bootstrap stage or not. The logic is simple:
- when doing `image-builder manifest` we never include one
- when doing `image-builder build --arch` we add one if the
  target arch and host arch differ

Instead of passing a callback this is now just a simple bool
option. Thanks to Achilleas for suggesting this.

Co-Authored-by: Achilleas Koutsou <achilleas@koutsou.net>
2025-03-27 08:42:49 +00:00
Michael Vogt
d41bd9aa5b blueprintload: enable strict checking for toml
Add strict checking for toml keys in blueprints. This allows us
to error early if there are unknown keys in a toml blueprint and
helps our users by spotting e.g. typos early.

This is similar to
https://github.com/osbuild/bootc-image-builder/pull/549
(thanks Ondrej!).
2025-03-25 19:13:33 +00:00
Michael Vogt
bcdfda9b95 go.mod: update toml lib to v1.5.0
This release includes a fix for the issue that custom unmarshaled
toml was marked in the metadata as "Undecoded()" [0].

With that we can enable strict checking for blueprint configuration.

[0] BurntSushi/toml#425
2025-03-25 19:13:33 +00:00
Michael Vogt
c0248a1c24 README: document that cross building works
Document how cross building works.
2025-03-25 14:27:31 +00:00
Michael Vogt
cd1b5bae64 test: add cross-build end-to-end test
This commit uses the new `build --arch=` support to perform
a cross arch build for aarch64, ppc64le, riscv64, s390x on
fedora. We could do also centos-9 each arch is already 20min.
2025-03-25 11:58:24 +00:00
Michael Vogt
8e6a6673f5 main: auto-cross build for foreign architectures 2025-03-25 11:58:24 +00:00
Michael Vogt
dd4547034b go.mod: update to latest version of image to get PR#1342
This will allow us to get boostrap buildroot support.
2025-03-25 11:58:24 +00:00
schutzbot
2c5f05e85b Post release version bump
[skip ci]
2025-03-14 14:53:28 +00:00
Simon de Vlieger
e7b9fbff1e ibcli: don't split outputfilename
A small test for a basename that includes dotted parts (as used by for
example Fedora's buildsystem).

Also some code changes to make this test pass, it seems that SBOM base
was determined based on some other filename which is now no longer
relevant?

Signed-off-by: Simon de Vlieger <supakeen@redhat.com>
2025-03-14 14:47:36 +00:00
Michael Vogt
b51d1f983a image-builder: use testutil.Chdir() in TestBuildIntegrationHappy 2025-03-14 14:47:36 +00:00
Michael Vogt
2f0caddf91 testutil: add testutil.Chdir() helper
A tiny helper to run a specific function inside a different dir,
useful in our testsuite.
2025-03-14 14:47:36 +00:00
Michael Vogt
ccb4269b62 ibcli: add new --output-name flag
This commit adds a new `--output-name` flag that will rename
the resulting artifact after it was build. All auxillary artifacts
like buildlog, sbom etc are also name based on the same basename.

See also https://github.com/osbuild/images/pull/1039 for how
this could be simpler (especially the fake osbuild).

Closes: https://github.com/osbuild/image-builder-cli/issues/43
2025-03-14 14:47:36 +00:00
Michael Vogt
8635a22ad9 main: skip arch checks onIMAGE_BUILDER_EXPERIMENTAL=bootstrap
This commit skips the arch checks if the experimental "bootstrap"
option is used. The main use-case of this option is to bootstrap
a foreign architecture so just assume that and skip arch checks
when set.

This allows to write:
```
$ IMAGE_BUILDER_EXPERIMENTAL=bootstrap=ghcr.io/mvo5/fedora-buildroot:41 \
   ./image-builder build --arch=riscv64 minimal-raw --distro=fedora-41
```
and do a riscv64 cross arch build.
2025-03-12 18:10:46 +00:00
Michael Vogt
06e73caec1 main: show "success" message with output dir when build finishes
This commit adds a "success" message that also contains the output
dir when the build finishes.

Thanks to SimonS for suggesting this!
2025-03-12 17:03:59 +00:00
Simon de Vlieger
3eecad6b30 doc: fix typo
Signed-off-by: Simon de Vlieger <supakeen@redhat.com>
2025-03-10 09:28:05 +00:00
Michael Vogt
c3ca146161 main: fix creating output dir for --with-buildlog
Trivial fix for the missing `mkdir()` call when `--with-buildlog`
is specified (and the matching test update).
2025-03-07 13:17:10 +00:00
Simon de Vlieger
3fd0373bc0 packit: enable epel-9 and epel-10
Let's ship our package in epel-9 and epel-10 as well as all the
supported Fedora branches. I've manually created, built, and created
updates for these branches already.

I'm not adding automation to the epel-10.0 branch in this PR as we need
to probably consider that more carefully. However, I *have* submitted
version 13 for epel-10.0 manually.

Signed-off-by: Simon de Vlieger <supakeen@redhat.com>
2025-03-07 11:56:32 +00:00
dependabot[bot]
1087fd7187 build(deps): bump github.com/cheggaaa/pb/v3 in the go-deps group
Bumps the go-deps group with 1 update: [github.com/cheggaaa/pb/v3](https://github.com/cheggaaa/pb).


Updates `github.com/cheggaaa/pb/v3` from 3.1.6 to 3.1.7
- [Commits](https://github.com/cheggaaa/pb/compare/v3.1.6...v3.1.7)

---
updated-dependencies:
- dependency-name: github.com/cheggaaa/pb/v3
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: go-deps
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-03-05 08:28:39 +00:00
schutzbot
e03922e299 Post release version bump
[skip ci]
2025-03-05 08:19:49 +00:00
Simon de Vlieger
dfa58fd6b5 chore: bump deps
Bump to latest `images` to make Fedora Minimal work with all the new
bits and bobs. Manual PR because the other one was being weird.

Signed-off-by: Simon de Vlieger <supakeen@redhat.com>
2025-03-04 21:15:50 +00:00
Simon de Vlieger
0cc171e1f9 doc: build command
Introduce the `build` command.

Signed-off-by: Simon de Vlieger <supakeen@redhat.com>
2025-03-04 09:13:51 +00:00
Simon de Vlieger
ca7ea33765 doc: rename output -> format
Signed-off-by: Simon de Vlieger <supakeen@redhat.com>
2025-03-04 09:13:51 +00:00
Simon de Vlieger
08f8c13c5c doc: list-images
Signed-off-by: Simon de Vlieger <supakeen@redhat.com>
2025-03-04 09:13:51 +00:00
Simon de Vlieger
887d3fee22 doc: sudo for build
Signed-off-by: Simon de Vlieger <supakeen@redhat.com>
2025-03-04 09:13:51 +00:00