Commit graph

155 commits

Author SHA1 Message Date
Achilleas Koutsou
9552ba0fc1 tools/osbuild-depsolve-dnf: return repositories in response
When generating package sources and rpm stage metadata for a manifest
from a list of packages, we need to associate repository configuration
options to each package [1].  Previously, a caller had all the
repository configurations because they were part of the request, so
packages could be associated with all the repository options by the
repository ID.  Now, osbuild-depsolve-dnf will use repositories loaded
from a directory that the caller shouldn't have to read, so returning
all repository configurations in the response makes it possible to
get all package metadata from the response.

This changes the whole structure of the response to a depsolve request.
Previously, we returned an array of packages.  Now we return an object
with two keys:
- packages: the array of packages as before
- repositories: an object mapping repository IDs to repository
  configurations.

Each package contains the repository ID it comes from (as before), under
`repo_id`.  This can be used to get repository configurations and
determine gpg keys and SSL certs for each package.

The new structure avoids duplicating values across all the (sometimes
hundreds) of packages.

[1] 92497c7b1f/pkg/dnfjson/dnfjson.go (L499-L507)
2024-04-10 16:22:13 -07:00
Achilleas Koutsou
38f5964205 tools/osbuild-depsolve-dnf: load repos from dir
Support loading repositories from a root tree instead of supplying them
with the request.  The repositories should be in the standard yum repo
format.  Both repository sources can be defined simultaneously, but at
least one is required.

The root_dir is expected to contain files necessary for depsolving in
the standard paths.

These files are:
- Repository (.repo) configurations in <root_dir>/etc/yum.repos.d/
- GPG key files in <root_dir>/etc/pki/rpm-gpg/
    - This will be used to resolve gpg key paths specified in the .repo
      files that are relative to the root_dir.
- (Optional) Custom dnf config variables in <root_dir>/etc/dnf/vars or
  <root_dir>/etc/yum/vars.
    - This is used by CentOS Stream to set the value of $stream.

Custom repository configurations in arbitrary (non-root) paths will have
to follow this directory structure.

A new variable is added to the request, `releasever`, which is mandatory
when using `root_dir`.  This variable is used in repository URLs and GPG
key paths.  In the default case, dnf reads this variable by inspecting
the rpm database.  We will override it in the Solver the same way we
override the arch and basearch for variable substitution.  In the
future, we will make this variable mandatory in all cases, which will
make the variable available for repo configs defined in the request as
well.

The root_dir is used in two ways:
- Set the base.conf.reposdir to <root_dir>/etc/yum.repos.d.
- Call update_from_etc() with root_dir to read custom variables in
  <root_dir>/etc/yum/vars and <root_dir>/etc/dnf/vars.
2024-04-10 16:22:13 -07:00
Achilleas Koutsou
06c8aca871 tools/osbuild-depsolve-dnf: type annotation
Silence the mypy linter.
2024-04-10 16:22:13 -07:00
Pierre-Yves Chibon
cccdf8b784 osbuild-mpp: Expend information in PkgInfo
This way we can extract these information later on.

Signed-off-by: Pierre-Yves Chibon <pingou@pingoured.fr>
2024-04-03 10:29:49 +02:00
Michael Vogt
f034bef127 tools: add example json-seq render based on tqdm
Add an example render to test/demo how the json-seq based progress
works. It needs the python `tqdm` package for the actual rendering.

See the output with:
```
$ sudo OSBUILD_TEST_STORE=/var/tmp/osbuild-test-store  \
    python3 -m osbuild --libdir=. --monitor=JSONSeqMonitor --export image \
      --output-dir=/tmp/output-dir ./test/data/manifests/fedora-boot.json | ./tools/osbuild-json-seq-progress-example-renderer
```
2024-03-12 16:44:12 +01:00
Simon de Vlieger
6536a45d0a lint: explicit check
Add an explicit check to the return value of subprocess.run.
2024-03-05 16:10:27 +01:00
Ondřej Budai
ec096f449b osbuild-mpp: disable zchunks
See the comment.
2024-03-04 14:06:33 +01:00
Michael Vogt
ba732b8532 workflow, osbuild-mpp: run with cache and use GH cache
Share cache between runs and also put into GH cache accross runs.
2024-03-04 14:06:33 +01:00
Michael Vogt
efcecd3867 tools: make osbuild-depsolve-dnf5 pylint clean 2024-02-20 14:52:23 -08:00
Michael Vogt
d4831a8924 tools: make osbuild-mpp pylint clean 2024-02-20 14:52:23 -08:00
Michael Vogt
a2bb687d54 tools: make gen-stage-test-diff pylint clean 2024-02-20 14:52:23 -08:00
Michael Vogt
2290aff94d check-snapshots: add log info when a download fails
When a requests.get() fails the exact nature of the error is
currently discarded. This commit adds a small print() to show
what exactly went wrong.
2024-02-20 14:52:23 -08:00
Michael Vogt
34cda2e1e3 check-snapshots: make exception for snapshot cache more targeted
The code in `check-snapshots` will print "No snapshots cache found
at ..." regardless of the error that happens when trying to open
the file. This can be misleading if e.g. the issue is permissions
to open the file or the file is corrupted. So make the exception
more targeted and only catch FileNotFound error and let python
how the full error for the other cases. Obviously this can be
done in many ways so I'm happy to tweak and e.g. keep catching
all exception but print the value etc.
2024-02-20 14:52:23 -08:00
Michael Vogt
2c86e90d05 tools: make check-snapshots pylint clean 2024-02-20 14:52:23 -08:00
Brian C. Lane
b131d3cf57 osbuild-depsolve-dnf5: Fix url substitutions
Substitutions should be set on Base, not per-repo. Discovered this
in lorax's dnf5 code so I am updating it here as well.
2024-02-20 09:42:01 +01:00
Brian C. Lane
4f83cdc434 osbuild-depsolve-dnf5: module_hotfixes wasn't really set
Typo in the previous change, wasn't setting `repo.module_hotfixes`
2024-02-20 09:32:43 +01:00
Brian C. Lane
291f5cc29e Revert "osbuild-depsolve-dnf: port weak dependencies"
This reverts commit e023fdec1b.

Ends up this was based on an older version of dnf-json, the correct
behavior is to use the "install_weak_deps" bool.
2024-02-13 00:17:16 +01:00
Brian C. Lane
8389c6302e osbuild-depsolve-dnf5: Add module_hotfixes support 2024-02-12 17:08:32 +01:00
Michael Vogt
7dede7746d osbuild-mpp: add bootc.install-to-filesystem to process_containers 2024-02-09 12:03:09 +01:00
Diaa Sami
e023fdec1b osbuild-depsolve-dnf: port weak dependencies
ported from d48da99a12
2024-02-08 00:12:32 +01:00
Diaa Sami
c673eab2b5 osbuild-depsolve-dnf: port module_hotfixes support over
from 61e6f75281
2024-02-08 00:03:59 +01:00
Nikita Dubrovskii
fc185dae8c support user-defined partition numbers for GPT disks
Partitions by default are indexed starting at 1, but in
some cases, such as CoreOS for IBM Z, it may be usefull
to set the 'partnum' for GPT disks explicitly, without
creating dummy partitions.

Now user can define an image:

```
    mpp-define-images:
      - id: image
        size: 10737418240
        table:
          uuid: 00000000-0000-4000-a000-000000000001
          label: gpt
          partitions:
            - name: boot
              type: 0FC63DAF-8483-4772-8E79-3D69D8477DE4
	      partnum: 3
              size: 786432
            - name: root
              type: 0FC63DAF-8483-4772-8E79-3D69D8477DE4
	      partnum: 4
              size: 4194304
```

So target disk would look like:

```
    Disklabel type: gpt
    Disk identifier: 00000000-0000-4000-A000-000000000001
    Device        Start     End Sectors  Size Type
    /dev/loop0p3   2048  788479  786432  384M Linux filesystem
    /dev/loop0p4 788480 4982783 4194304    2G Linux filesystem
```

This patch updates the osbuild-mpp tool and the sgdisk and sfdisk
stages to support this.

Co-authored-by: Dusty Mabe <dusty@dustymabe.com>
2024-02-06 17:44:31 +01:00
Brian C. Lane
18e5481ae8 osbuild-depsolve-dnf5: Add libdnf5 based depsolving for Fedora 40
dnf5-json will be used for building Fedora 40 and later.  RHEL and
Fedora < 40 will continue to use python3-libdnf via dnf-json.
2024-01-24 09:55:49 -08:00
Dusty Mabe
d50705249a osbuild-mpp: fix float correction
I mistakenly thought the .strip('.0') would strip off just '.0` but
in reality it strips off all instances of `.` or `0` on the end so
'4075520.0'.strip('.0') => '407552', which is clearly wrong.

This is a fixup for 5207e92.
2024-01-15 11:53:21 +01:00
Dusty Mabe
c62e555202 tools/osbuild-mpp: run _process_format() for mpp-embed dict
So we can use something like mpp-format-string inside of mpp-embed. An
example would be below where we want to substitute the ociarchive var
in using `mpp-format-string: 'file://{ociarchive}'`.

```
version: '2'
mpp-vars:
  ociarchive: /path/to/fedora-coreos-39.20240104.dev.2-ostree.x86_64.ociarchive
pipelines:
  - name: oci-archive
    stages:
      - type: org.osbuild.copy
        inputs:
          inlinefile:
            type: org.osbuild.files
            origin: org.osbuild.source
            mpp-embed:
              id: fcos.ociarchive
              url:
                mpp-format-string: 'file://{ociarchive}'
        options:
          paths:
            - from:
                mpp-format-string: input://inlinefile/{embedded['fcos.ociarchive']}
              to: tree:///fcos.ociarchive
```
2024-01-05 18:57:43 +01:00
Ondřej Budai
fdc5bf3b98 stages: org.osbuild.container-deploy 2024-01-03 11:25:48 -08:00
Dusty Mabe
c3b52ba240 osbuild-mpp: add partnum field to the partitions
Partitions are usually indexed starting a 1 so an index starting
at 0 is confusing (i.e. you never say mount the filesystem on
partition 0). Let's add a partnum field that can be used in
definitions instead.
2023-12-22 10:18:29 -05:00
Simon de Vlieger
b225d1cf04 osbuild-mpp: conditional losetup
`mpp-define-images` can create an image file, using `losetup` to deal
with non-standard sector sizes requires root. Not all users run
`osbuild-mpp` as root.

While I am not a fan of "suddenly sudo" based on the input manifest this
does alleviate builds breaking for manifests with default sector sizes
when non-root.
2023-11-30 14:16:57 +01:00
Dusty Mabe
e191dc1d0d tools/osbuild-mpp: set part ID from name if missing
For our Fedora CoreOS disk images we set the partition labels (name)
for the partitions. This is also supported using the primitives here
in OSBuild, but it wasn't obvious that I needed to set the name in
the mpp-define-images definition. Let's set the name there, but let's
also allow osbuild-mpp to set the `id`, which is what is used later
to access that partition from the `name` too if `id` isn't set.

This means we allow something like:

   - name: BIOS-BOOT
     type: 21686148-6449-6E6F-744E-656564454649
     bootable: true
     uuid: FAC7F1FB-3E8D-4137-A512-961DE09A5549
     size: 100

rather than requiring something like:

   - id: BIOS-BOOT
     name: BIOS-BOOT
     type: 21686148-6449-6E6F-744E-656564454649
     bootable: true
     uuid: FAC7F1FB-3E8D-4137-A512-961DE09A5549
     size: 100
2023-11-29 10:37:08 +01:00
Dusty Mabe
28c2772d42 tools/osbuild-mpp: add sector size support for image layouts
Now you can specify a sector_size in `mpp-define-images` to support
creating a 4k native disk image (sector_size=4096).

This does use a loopback device, which means osbuild-mpp also needs
to run as root, when previously that wasn't necessary.
2023-11-29 10:37:08 +01:00
Dusty Mabe
2e1f6e2553 tools/osbuild-mpp: support defining multiple image layouts
Right now you can only define a single image, lets add mpp-define-images
and accept a list.
2023-11-29 10:37:08 +01:00
Dusty Mabe
5207e92cab tools/osbuild-mpp: handle corner case in mpp-format-int
If you do math in mpp-format-int it could end up getting converted
to a float. Of course if you end up with a decimal value that isn't
`.0` that's a problem for an int, but if it is `.0` let's handle it
gracefully.

For example, math like this could end up with a value with `.0`:

  mpp-format-int: "{bios_boot_size_mb * 1024 * 1024 / sector_size_bytes}"
2023-11-29 10:37:08 +01:00
Alexander Larsson
677a874115 osbuild-mpp: Print better errors if eval fails
I'm trying to debug some failures, and having no feedback as to
what file we're parsing or what code is evaluated when something
fails makes it hard to debug manifests.

This adds some nice error messages that will help.
2023-11-28 18:03:05 +01:00
Michael Vogt
5c345fb3fa test,tools: use sys.executable instead of hardcoding python3
Thanks to Simon!
2023-11-14 20:34:50 +01:00
Michael Vogt
d801ef3958 tests: run osbuild as a python module in gen-stage-test-diff
Instead of running osbuild as a binary use `python3 -m osbuild`
(just like in `test/test.py:compile()`) so that it will use
osbuild fromgit and can be run from a checkout without the need
for an installed osbuild.
2023-11-14 20:34:50 +01:00
Michael Vogt
742291eac3 tools: fix cache-max-size defaults 2023-11-14 20:34:50 +01:00
Ondřej Budai
3bb5a00375 test/run/assemblers: convert to a v2 manifest
Instead of using the F34-based manifests, let's switch to F38. I tried my
best to import the vars into the new manifest, but I don't think that's
currently supported.
2023-11-14 10:45:44 -08:00
Michael Vogt
d52738d70c tools: add "tools" dir to LINTABLES and fix issues
The `./tools` dir was not part of the LINTABLES in the `tox.ini`
which meant that pep8/pylint etc checks were not run on the tools
there.

This commit adds it and fixes the issues that `make lint` found.
2023-11-13 10:10:12 +01:00
Brian C. Lane
73dc9fe50e tools: Add helper script to check Schutzfile and gitlab-ci.yml runners
This script reads the RUNNER entries from .gitlab-ci.yml and the
snapshot repo names from Schutzfile. It then prints which runners don't
have entries in Schutzfile and which Schutzfile entries don't have
runners.

This is slightly complicated by the fact that centos-stream reports
itself as centos. So when checking for missing entries they are
considered to be the same thing. eg. If centos is a RUNNER and
centos-stream is in Schutzfile it doesn't report anything missing.
2023-11-03 08:02:16 -07:00
Simon de Vlieger
1542813296 depsolve-dnf: helpful exception for repo 2023-10-26 15:53:47 +02:00
Simon de Vlieger
f371651d66 depsolve-dnf: enable weak deps selection
The import of `dnf-json` came from `osbuild-composer`, as we sadly
have/had multiple copies this wasn't the *right* version as it was
lacking previous work to disable weak dependencies.
2023-10-26 15:11:24 +02:00
Luke Yang
f9a039d068 stages: add ostree.deploy.container stage
This stage is similar to ostree.deploy, but deploys from a container
image rather than from an OSTree commit by using the `ostree container
image deploy` command. An example stage definition could look like:

```
  - type: org.osbuild.ostree.deploy.container
    options:
      osname: fedora-coreos
      target_imgref: ostree-remote-registry:fedora:quay.io/fedora/fedora-coreos:stable
      mounts:
	- /boot
	- /boot/efi
      kernel_opts:
	- rw
	- console=tty0
	- console=ttyS0
	- ignition.platform.id=qemu
	- '$ignition_firstboot'
    inputs:
      images:
	type: org.osbuild.containers
	origin: org.osbuild.source
	mpp-resolve-images:
	  images:
	    - source: quay.io/fedora/fedora-coreos
	      tag: stable
```

Co-authored-by: Dusty Mabe <dusty@dustymabe.com>
2023-10-24 13:46:10 -04:00
Dusty Mabe
b32ddc4136 tools/osbuild-mpp: include container tag in default name
In case the tag was something other than `:latest` let's include the
tag in the default name.
2023-10-18 19:55:26 +02:00
Alexander Larsson
745f86c94c tools/osbuild-mpp: Really fix empty ostree commit object in deploy stage
The fix in 980ca03685 ensured that
no empty commit object was changed, but it still created an (empty)
input object, which causes failures, like:
 https://gitlab.com/CentOS/automotive/sample-images/-/merge_requests/388

We need to move the check before the line that adds the empty default
input object.
2023-10-17 14:02:39 +02:00
Simon de Vlieger
7c35b945ee depsolve: import dnf-json
Import the `dnf-json` Python script that is included in the "images" and
"osbuild-composer" repository into "osbuild".

`dnf-json` provides dependency solving capabilities by taking in some
JSON and then outputting the package set that JSON resolves to. Since it
is a Python script it moves into a subpackage of `osbuild`.

The script is renamed to `osbuild-depsolve-dnf`.
2023-10-16 20:47:17 +02:00
Luke Yang
980ca03685 tools/osbuild-mpp: Fix empty ostree commit object in deploy stage
This adds an early return to the `_process_ostree_commits` function to
prevent an empty ostree commit object from being created in the deploy
stage which causes violations to the deploy stage input schema.
2023-10-16 20:26:10 +02:00
Dusty Mabe
ecc997a81a tools/osbuild-mpp: add mpp-resolve-ostree-commits helper
This will make it easier to resolve OSTree refs into commits similar
to how mpp-resolve-images works for container image references to
SHA256 digests.
2023-10-16 20:26:10 +02:00
Brian C. Lane
68f4c5bd5f tests: Add a check for valid snapshot urls
This pulls the list of snapshots from the rpmrepo API, greps the
codebase for all uses of rpmrepo.osbuild.org that look like a snapshot
name, and then checks to make sure they are still valid.

This is the same script as osbuild-composer, except that it also skips
checking ./test/data/stages/ which has rpm urls that look like snapshot
urls.
2023-08-16 10:40:05 +02:00
Brian C. Lane
44c28c8c16 autopep8: Update with changes to make autopep8 -a -a -a happy 2023-08-10 13:04:14 +02:00
Ondřej Budai
5045bde6b7 tools/tree-diff: make its output stable
I don't see a reason why not to make the default output from tree-diff always
stable.

The stage tests already do that before running the comparison.
2023-08-08 12:41:17 +02:00