Commit graph

2872 commits

Author SHA1 Message Date
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
Gianluca Zuccarelli
36d1187c35 util/containers: update storage location
Change the contianers store from `/containers/storage` to
`/var/tmp/containers/storage` since technically `/containers/storage`
isn't ostree compatible.
2024-03-11 18:15:24 +02:00
Michael Vogt
945209a80c test: use del os.environ[] instead of os.unsetenv (thanks Simon)
Simon discovered that `os.unsetenv()` will not remove the env
from os.environ so this commit fixes this.

Thanks for figuring this out!
2024-03-11 14:20:27 +01:00
Michael Vogt
2efe2de09c workflow: run all unit tests in parallel
There were special cases in the workflow for only running specific
tests in parallel. However how that the test_assemblers parallel
runs are fixed [0] there is really no need for special cases anymore
and we can just run them all in parallel.

[0] https://github.com/osbuild/osbuild/pull/1641
2024-03-11 13:48:47 +01:00
Michael Vogt
2f0ed8c755 osbuild: ensure a usable /var/tmp is available inside the buildroot
Colin asked for this in
https://github.com/osbuild/bootc-image-builder/issues/223 and
it's easy enough.
2024-03-11 13:09:28 +01:00
Simon de Vlieger
a895aa177c stages/kickstart: add noswap to autopart
Allow passing the `noswap` option to `autopart`.
2024-03-11 11:50:34 +01:00
Sanne Raymaekers
29159189f1 sources/curl: add org.osbuild.mtls secrets support
If `org.osbuild.mtls` is passed as a secret name, look for the mtls data
in the environment.
2024-03-11 11:09:37 +01:00
Michael Vogt
c990c07f79 osbuild: reuse loop_for_fd() in LoopServer
The LoopServer._create_device() duplicates the code from
`Loop.loop_for_fd()` right now. Given that this is relatively
subtle code it's better to not duplicate it and instead just
reuse the loop_for_fd() implementation in LoopServer.
2024-03-11 10:56:49 +01:00
Michael Vogt
d43194c0b3 test: add unit-{type,path} test coverage 2024-03-08 16:20:48 -08:00
Gianluca Zuccarelli
6c0973238d utils/mnt: fix mount permissions
This is a follow up to #1550 where we enabled a `rw` permissions mode,
which is not ideal since it would theoretically be possible to set both
`ro` and `rw` modes at the same time. This commit fixes the issue by only
allowing one option at a time.

Fixes #1588
2024-03-07 13:01:47 +00:00
Sayan Paul
2d2cdd8097 stage/systemd-unit-create:paremeterize file location
User can now customize the systemd unit load path.
User can select between etc or usr , defaults to 'usr'.
Also user can customize the scope of the service between global
or system, defaults to system.

Signed-off-by: Sayan Paul <paul.sayan@gmail.com>
2024-03-07 14:04:00 +02:00
Simon Steinbeiss
144b0563d6 tests/manifest: Don't retain image-info artifacts
Nothing else seems to rely on the image-info generated by the manifest
tests, so let's not retain those artifacts. This currently makes the
`finish` stage take 6 minutes for no good reason.
2024-03-06 13:06:10 +01:00
Michael Vogt
1278e5d217 test: fix test_assembler to support parallel runs and run in parallel
The `test_assembler.py` hardcods some filesystem and partition
UUIDs. This leads to hard to diagnose test failures when the
test is run in parallel. The btrfs and xfs filesystem drivers
will see the same uuid for multi created images and error sometimes with
someting like:
```
Mar 06 10:22:54 top kernel: BTRFS error: device /dev/loop104 belongs to fsid aff010e9-df95-4f81-be6b-e22317251033, and the fs is already mounted, scanned by mount (123856)
```
Its a race that only happens when two images are checked at the
same time.

This commit fixes the issue by just using a randomized UUID in
the test_assemblers.py. It also re-enables running the test in
parallel (which make it run a lot faster, from 34min to 14min).
2024-03-06 12:28:10 +01:00
Michael Vogt
87636878da Revert "workflow: run assembler tests in parallel"
This reverts commit ea36e25b09.
2024-03-06 10:43:21 +01:00
Simon Steinbeiss
37d5a23a64 tests: Cancel in-progress tests on PR updates
Before this commit GitHub Action runs that were triggered by a PR were
not canceled when updates were made to the same PR. This lead to even
more clogging of our pipelines and not enough runners being available.

This changes the behavior in a way that whenever a PR gets updated all
still-in-progress runs get canceled and new runs get spawned.
2024-03-05 16:40:34 +01:00
schutzbot
b8b81280ff schutzfile: Update snapshots to 20240301 2024-03-05 17:10:53 +02:00
Simon de Vlieger
ef612d592c lint: add lint-quick target
This runs `ruff` locally, outside a special created environment which
makes it super quick but requires `ruff` to be installed.
2024-03-05 16:10:27 +01:00
Simon de Vlieger
82218c91a1 tox: remove isort
The role of the `isort` check is now performed by `ruff` instead of
`isort`.
2024-03-05 16:10:27 +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
Simon de Vlieger
c9739dbd2a lint: sort import(s) 2024-03-05 16:10:27 +01:00
Simon de Vlieger
a779d3268d ruff: configure
Newer versions of ruff support more linters and autoformatting, let's
configure those to do the same as our current linter selection.
2024-03-05 16:10:27 +01:00
Simon de Vlieger
7fc06acffc tox: update ruff dependency
Renames a property that should now live under `lint` to silence a
warning in newer `ruff`.
2024-03-05 16:10:27 +01:00
Achilleas Koutsou
a0f5262701 gitlab: don't update GitHub status from individual jobs
Never update the GitHub status at the end of a job.  Instead, when
everything is done, the 'fail' job will run in the 'finish' stage and
update the status accordingly.
2024-03-05 16:04:20 +01:00