Commit graph

2894 commits

Author SHA1 Message Date
Simon de Vlieger
a9f4024ded lint: fix up adjusted stages 2024-03-19 15:32:45 +01:00
Simon de Vlieger
bb58892571 stages: externalize schemas
Copy all schemas into the relevant `.meta.json` files instead of having
them contained inside the stages.
2024-03-19 15:32:45 +01:00
Simon de Vlieger
02b6d696ef stages: consistent docstrings
Make docstrings consistent across stages regarding whitespace and
summary line.
2024-03-19 15:32:45 +01:00
Michael Vogt
352bf5cd52 curl: rename "transform" to "amend_secrets"
The curl source is the only source left that uses "transform". And
here the name is very generic but in fact we only do a single thing:
we add secrets for subscriptions for for mtls to the download.

So rename to make it clear what this is all about.
2024-03-19 14:21:57 +01:00
Michael Vogt
1fc7ead2f4 sources: transform() is only used in the curl sources, remove from ABC 2024-03-19 14:21:57 +01:00
Michael Vogt
7431653882 test: add (trivial) test for ConditionPathIsDirectory 2024-03-19 10:19:26 +01:00
Sayan Paul
548d2a51ea stage/unit-create:new systemd unit config params
Added new systemd unit config : ConditionPathIsDirectory

Signed-off-by: Sayan Paul <paul.sayan@gmail.com>
2024-03-19 10:19:26 +01:00
Michael Vogt
155e24e4cb stage: user test that tests adduser is called the right way
The issue with mocking subprocess.call() is that we will not
catch if arguments are passed as eg. integers. So instead use
the `mock_command()` helper so that a real binary is called.
2024-03-18 20:37:21 +01:00
Michael Vogt
9393211b8a testutil: tweak mock_command to write a call_log
Instead of just mocking the binary also write a log of the way
it got called so that tests can use this to check if the right
options are passed.

Note that the API should be improved here, instead of returning
a "naked" path to the calllog file there should be a class wrapping
it. And of course there should be tests.
2024-03-18 20:37:21 +01:00
Michael Vogt
fd0167f130 test: return container_id in make_container
The current `make_container()` helper is a bit silly (which is
entirely my fault). It requires a container tag as input but all
tests end up creating a random number for this input. So instead
just remove the input and return the container_id from the podman
build in the contextmanager and use that.
2024-03-18 20:36:19 +01:00
Michael Vogt
df224fb32b stages: add support for kernel-options to bootc-install-to-fs
This commit adds support to use the `--kopt` arguments to
`bootc install to-filesystems`. It is not strictly needed right
now though.
2024-03-14 15:07:05 +01:00
Michael Vogt
626077ffc0 stages: add root ssh options to bootc.install-to-filesystem
To start using the `bootc.instal-to-filesystem` stage we need
to be able to test the generated images. This requires a login
on the disk. Traditionally we did that via the `users` stage.

But on a bootc system we do not want to modify the disk after
bootc did the install to avoid messing with things like the
selinux labels or (future) fsverity setups.

So for now we will use the `--root-ssh-authorized-keys` feature
to inject support for login.

So this commit adds a new option to the stage called
`root-ssh-authorized-keys`.
2024-03-14 15:07:05 +01:00
Michael Vogt
a7b4565445 meta: add tests for invalid python json/schema parsing
Based on the feedback from Tomáš in [0] this commit adds tests
that ensure consistent behavior between the python and the json
loader.

It's not 100% because the python is extremly leaniant and does
not even check if the required pieces of the json are there.
I.e. it will load a module without a SCHEMA or SCHEMA_2 variable
and the json loader code will warn about the issue but not
raise an error.

Fwiw, I have no strong opinion here but I do lean slightly towards
staying close to the original code (but both approaches of failing
with an exectption and continue with a warning have good arguments).

[0] https://github.com/osbuild/osbuild/pull/1618#discussion_r1521141148
2024-03-14 13:37:57 +01:00
Michael Vogt
9af7c9b279 meta: add .meta.json schema validation 2024-03-14 13:37:57 +01:00
Michael Vogt
3e11b57815 meta: rename -meta.json to .meta.json
With `.meta.json` it's two "real" file extension. The `-meta.json`
feels less clear.
2024-03-14 13:37:57 +01:00
Michael Vogt
16d30254c4 tox,osbuild: deal with stages that have external json data
Some existing code/test assumes that anything in `stages/` is
executable. This commit fixes this and excludes e.g. json from
lintables.
2024-03-14 13:37:57 +01:00
Michael Vogt
9b09ed9eb4 osbuild: allow json data to come from a {stage}-meta.json file
Instead of always parsing the python stage to load meta information
allow the user of a new `{stage}-meta.json` file. This is a first
step towards allowing modules to be written in a different language
than python. It also has some practical advantages:
- slightly faster as it avoids calling python to output the schemas
- easier to write schemas as this can be done in a real json editor
  now
- more extensible in a future where stages maybe binaries with
  shlib dependencies that are only satisfied in the buildroot
  but not on the host
2024-03-14 13:37:57 +01:00
Michael Vogt
3dd12931e4 tox.ini: update autopep8/pyocdestyle to support py3.12 2024-03-14 13:25:55 +01:00
schutzbot
c7c5a4d8e6 schutzfile: Update snapshots to 20240313 2024-03-14 11:25:09 +01:00
Michael Vogt
b29aa5e651 Revert "osbuild: ensure loop.Loop() has the required device node"
This reverts commit 158acaac78.

With https://github.com/osbuild/bootc-image-builder/pull/238 the
original reason to call mknod goes away so we can just revert
it. osbuild now requires not only the loop device but also uses
`losetup --partscan` quite a lot now so the mknod approach becomes
impractical and the consumers of osbuild in a container should
just setup devtmpfs.
2024-03-13 22:16:51 +02:00
Michael Vogt
a1eaf3da3a doc: document the new json-sequence monitor
Add basic documentation about the new json sequence progress support.
2024-03-13 17:27:39 +01:00
Michael Vogt
185d88e282 test: fix ruff lint error 2024-03-13 17:27:39 +01:00
schutzbot
435c6d3460 Post release version bump
[skip ci]
2024-03-13 08:16:16 +00:00
Michael Vogt
dd575465db monitor: make origin a setter 2024-03-12 16:44:12 +01:00
Michael Vogt
27ac6dd544 osbuild: use sort_keys=True when calculating the Context.id
Since we support python3.6 we cannot assume that dicts are ordered
in any way. To ensure the `id` is still always valid we pass
sort_keys=True to json.dump().

Thanks to Simon!
2024-03-12 16:44:12 +01:00
Michael Vogt
87015318d3 osbuild: tweak "origin=" values, thanks to Simon! 2024-03-12 16:44:12 +01:00
Michael Vogt
66468a3c58 osbuild: resolve TODOs
When an alternative monitor like JSONSeqMonitor is used there is
still non json output printed to stdout. This was a TODO but
this commit removes it because it's okay, there is the
"--monitor-fd" that should be used when using the json-seq monitor.
2024-03-12 16:44:12 +01:00
Michael Vogt
f214c69a98 osbuild: add workaround to integrate sources into progress reporting
This commit is somewhat poor, sorry for that. It mostly adds
workaround so that the osbuild sources can emit some progress
reporting as well. Without that the user experience is rather poor
and there is a long delay before any sort of progress can be
reported (even before the normal stages run).

With it the user experience is still not good but slightly better,
i.e. the progress monitor will report that the sources have
started downloading and curl will generated some log output. No
real progress unfortunately (sources subprogress will jump from
zero to 100%).
2024-03-12 16:44:12 +01:00
Michael Vogt
861f48a7e1 test,monitor: fix pep8/pylint issues 2024-03-12 16:44:12 +01: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
Michael Vogt
83e66839bc monitor: log start/stop of stages and pipelines too
Generate log messages with origin "org.osbuild.main" when
pipelines/stages start and finish. This way a higher level
frontend can display high level progress coming from this
origin and filter out e.g. stages based log messages (that
are usually quite technical as they are just stdout/stderr
from the stages).
2024-03-12 16:44:12 +01:00
Michael Vogt
fd61bcdcab monitor: introduce Context.with_origin()
The existing JSONSeqMonitor was saving/restoring the "origin"
when generating a new log-entry. This allows logging from
different origins (e.g. "org.osbuild.main") in a kind of
"out-of-band" fashion.

But this save/restore feels slightly inelegant because
JSONSeqMonitor feels like the wrong layer to deal with this.
This is why a new `with_origin()` helper is introduced that
will either reuse the existing context or create a new one
with the requested origin.
2024-03-12 16:44:12 +01:00
Michael Vogt
3fbd0b2a73 monitor: tweak/simplify Progress
Tweak the Progress class to be simpler. Given that progress does
not need to support arbitrary depth but only has a single level
the class now just exposes "sub_progress" to the caller.

When the main progress is advanced the sub_progress is now fully
deleted instead of just reset. The rational is that when the main
progress is done and advances a step it is very likely that a
new sub_progress is required and it's most likely an error if
the same sub_progress will get re-used.

This means that `reset()` can be removed as it's not used anymore
(and YAGNI). We can add it back when we have a use-case.

It also change the code so that "total" starts with 0 instead
of `None` (principle of least surprise). This means that now
`progress.incr()` is called in the JSONSeqMonitor() for
`finish()` and `result()` to indicate that the pipeline/stage
is finished.
2024-03-12 16:44:12 +01:00
Michael Vogt
de9ead53a2 montior: remove "unit" from Progress (YAGNI)
Removing "unit" from progress as it is currently unused and we
can always add it back when we have a real use-case.
2024-03-12 16:44:12 +01:00
Michael Vogt
f6125048c6 main: log success/failures via the monitor too 2024-03-12 16:44:12 +01:00
Michael Vogt
1fa0472a8c monitor: tweak Context() to auto recalculate id, rename methods
This commit tweaks Context a bit so that any write will automatically
reset the `_id`. This ensures that we do not forget to reset `_id`
when the code changes.

It also tweaks the naming a bit, before there was a "setter" for
origin and functions to set "pipeline" and "stage". They are all
functions now with a "set_" prefix for symetry mostly.
2024-03-12 16:44:12 +01:00
Michael Vogt
ac16590838 monitor: refactor class LogLine to log_entry()
The class LogLine() is purely used as a dataclass with no state
and the only function on it is `as_dict()`. This got refactored
into a new function `log_entry()` because there is no need for
this to be a class. The function that takes the same inputs.
2024-03-12 16:44:12 +01:00
Michael Vogt
16c1768780 osbuild: make jsonseq montior creation more uniform
This changes the way monitors are initialized to always include
a `manifest` and now they will always log a `start` message.

This makes creation of a monitor symetric accross all monitors
again and no special cases for JSONSeqMonitor are required.

It means one needs to run the json-seq monitor with:
```
$ python3 -m osbuild --monitor=JSONSeqMonitor
```

Fwiw, I'm not 100% confident this is a win but it feels slightly
more right then the special cases in `main_cli.py` that is
replaces.
2024-03-12 16:44:12 +01:00
Michael Vogt
9bb42459aa monitor: use "omitempty" helper to remove None/"" values from json-seq output 2024-03-12 16:44:12 +01:00
Michael Vogt
c6eaac278d monitor: convert to json-seq
Tweak the existing json progress to follow the `application/json-seq`
media type as outlined in rfc7464 [0],[1].

[0] https://datatracker.ietf.org/doc/html/rfc7464
[1] https://en.wikipedia.org/wiki/JSON_streaming#Record_separator-delimited_JSON:wqu
2024-03-12 16:44:12 +01:00
Achilleas Koutsou
83dc625fc3 buildroot: add origin to log messages
Create an origin string of the form 'stages/<stagename>' from the argv
argument and add it to the log prints for messages coming from the
stage.

Signed-off-by: Achilleas Koutsou <achilleas@koutsou.net>
2024-03-12 16:44:12 +01:00
Achilleas Koutsou
9c8aba048e main: add --json-mode argument
When specified with --json controls the mode of the json output:
- batch (default) is the old mode which prints the result
  of the entire build after it's finished (NullMonitor)
- progress is the new mode that prints one json line per message
  (JSONProgressMonitor)

Signed-off-by: Achilleas Koutsou <achilleas@koutsou.net>
2024-03-12 16:44:12 +01:00
Achilleas Koutsou
1a2dfb0070 test: add tests for new monitor and its components
Signed-off-by: Achilleas Koutsou <achilleas@koutsou.net>
2024-03-12 16:44:12 +01:00
Achilleas Koutsou
5510d0c42e monitor: add origin to log for all monitor classes
Adding the origin argument to the log() methods for all monitor classes.

Signed-off-by: Achilleas Koutsou <achilleas@koutsou.net>
2024-03-12 16:44:12 +01:00
Achilleas Koutsou
da4044bc7b monitor: JSONProgressMonitor class
New monitor type that emits a JSON object for each log message.

Unlike other monitors:
- The constructor takes a build manifest as argument to initialise the
  Pipeline and Stage counts for the Progress part of the report.
- It doesn't print a 'result' at the end of the build.
- The log() method that prints a log message supports specifying an
  origin to override the default that's set by the constructor.

Although the Logline supports reporting errors separately, this isn't
used yet.

Signed-off-by: Achilleas Koutsou <achilleas@koutsou.net>
2024-03-12 16:44:12 +01:00
Achilleas Koutsou
512933ddd4 monitor: classes for new progress monitor
Foundation for new monitor type that will emit a JSON object for each
log message. The following classes are defined:
- LogLine: The top-level object that can be serialised into a single
  object containing a message and associated metadata.
- Context: Contextual information for a log line message. Describes the
  origin of the message and the current pipeline and stage.
  Automatically deduplicates this information using a hash/ID: keeps a
  history of IDs and omits the context when the context is not new.
- Progress: Information on the progress of the build. The object is
  recursive: can contain a sub-progress for nested progress reporting
  (pipelines > stages > ...).

Signed-off-by: Achilleas Koutsou <achilleas@koutsou.net>
2024-03-12 16:44:12 +01:00
Michael Vogt
439f7f08c7 test: add minimal test for expiredate for user stage 2024-03-12 07:38:31 +01:00
Andre Marianiello
f6ae58151e stages/org.osbuild.users: add expire date
Add the expiredate field to the users option in the org.osbuild.users
stage. This option maps to the --expiredate option of useradd/usermod,
which can be useful when creating users whose password must be changed
upon first login.
2024-03-12 07:38:31 +01:00
Gianluca Zuccarelli
8b601d146b util/containers: remount containers store as rw 2024-03-11 18:15:24 +02:00
Gianluca Zuccarelli
9258bda89d util/mnt: add a remount paramater
This is just a temporary workaround to get the containers-storage
input working in `bootc-image-builder`
2024-03-11 18:15:24 +02:00