Commit graph

310 commits

Author SHA1 Message Date
Christian Kellner
9edc2b0362 remoteloop: port LoopServer to use BaseAPI
Now that `api.BaseAPI` provides the basic scaffolding for API
servers, use that base class and remove the code duplication.
2020-07-27 12:50:38 +01:00
Christian Kellner
3ae056bf0f sources: port to use api.BaseAPI
Now that `api.BaseAPI` provides the basic scaffolding for API
servers, use that base class and remove the code duplication.
2020-07-27 12:50:38 +01:00
Christian Kellner
1ce517e595 api: extract base class
Split out the part of `api.API` that is responsible for providing
the server infrastructure for the API; i.e. setting up the server
and the corresponding context manager and asynchronous event
handling. This leaves `API` itself which just the implementation
of the high level protocol and makes the API-server part re-usable.

NB: pylint, for some reason, confuses `API` and `BaseAPI`, like in
`test_monitor`. Annotate that accordingly.
2020-07-27 12:50:38 +01:00
Christian Kellner
38f282e3ce pipeline: proper path handling for sources cache
Use `os.path.join` to build the path for the source cache, instead
of string interpolation. This makes it possible to use other Path
representations, like `pathlib.Path`, transparently.
2020-07-22 09:37:30 +01:00
Christian Kellner
276019530c pipeline: support for trees being os.PathLike
Currently `objectstore.Object.{read, write}` directly return
strings but in the future they might return an Object that is
an `os.PathLike`, i.e. has a `__fspath__` method, instead.
Prepare for that by ensuring all `tree`s are converted to their
file system representation via `os.fspath` when needed, e.g.
when creating the bind-mount arguments for the `BuildRoot`.
2020-07-22 09:37:30 +01:00
Christian Kellner
6813fa4acc objectstore: proper path handling for ObjectStore
Instead of using string interpolation, use `os.path.join` in all
places. This should allow the use of `os.PathLike` objects as well
as bytes (i.e. `objectstore.PathLike` types) to be used and is
generally cleaner.
2020-07-22 09:37:30 +01:00
Christian Kellner
833a79ee6f objectstore: support os.PathLike in Object.export
Support `os.PathLike` arguments in `Object.export` by explicitly
converting the supplied argument via `os.fspath`. Additionally,
declare the support for those via the Python typing system with
a new Union type for general `PathLike` type, i.e. all valid
types for `os.fspath`, which are `str`, `bytes`, `os.PathLike`.
2020-07-22 09:37:30 +01:00
Christian Kellner
8250bd0b94 objectstore: re-use Object.export in Object.init
Instead of having a duplication of the invocation of `cp`, once in
`init`, once in `export`, re-use the latter in the former: the to
be copied object is accessed in the normal way via the store, and
then "exported" to the new location. This gets rid of the call to
resolve_ref as a nice side effect, which means less poking into
the internals of the store.
2020-07-22 09:37:30 +01:00
David Rheinsberg
d1b9304a56 buildroot: use bwrap to contain stages
This swaps the `systemd-nspawn` implementation for `bubblewrap` to
contain sub-processes. It also adjusts the `BuildRoot` implementation
to reduce the number of mounts required to keep locally.

This has the following advantages:

  * We know exactly how the build-root looks like. Only the bits and
    pieces we select will end up in the build-root. We can let RPM
    authors know what environment their post-install scripts need to
    run in, and we can reliably test this.

  * We no longer need any D-Bus access or access to other PID1
    facilities. Bubblewrap allows us to execute from any environment,
    including containers and sandboxes.

  * Bubblewrap setup is significantly faster than nspawn. This is a
    minor point though, since nspawn is still fast enough compared to
    the operations we perform in the container.

  * Bubblewrap does not require root.

At the same time, we have a bunch of downsides which might increase the
workload in the future:

  * We now control the build-root, which also means we have to make sure
    it works on all our supported architectures, all quirks are
    included, and all required resources are accessible from within the
    build-root.
    The good thing here is that we have lots of previous-art we can
    follow, and all the other ones just play whack-a-mole, so we can
    join that fun.

The `bubblewrap` project is used by podman and flatpak, it is packaged
for all major distributions, and looks like a stable dependency.
2020-07-21 14:20:32 +02:00
Christian Kellner
3e18d8118c api: introduce pipeline monitoring
Introduce the concept of pipeline monitoring: A new monitor class is
passed to the pipeline.run() function. The main idea is to separate
the monitoring from the code that builds pipeline. Through the build
process various methods will be called on that object, representing
the different steps and their targets during the build process. This
can be used to fully stream the output of the various stages or just
indicate the start and finish of the individual stages.

This replaces the 'interactive' argument throughout the pipeline
code. The old interactive behavior is replicated via the new
`LogMonitor` class that logs the beginning of stages/assembler,
but also streams all the output of them to stdout.
The non-interactive behavior of not reporting anything is done by
using the `NullMonitor` class, which in turn outputs nothing.
2020-07-21 13:25:04 +02:00
Christian Kellner
5d55bc9aca api: use io.StringIO as output data buffer
Instead of using plain python strings and appending to them, use
'io.StringIO' which is a data structure meant to be used for i/o.
This should increase performance compared to plain strings.
2020-07-21 13:25:04 +02:00
Christian Kellner
1e88ee62e3 api: use pipe for output
Instead of either using a text file, in non-interactive mode, or
directly stdout otherwise, create a pipe and always use that as
for stdout/stderr when preparing the output for 'setup_stdio'.
This streamlines the two cases (interactive, non-interactive) and
as a result 'API.output' will always contain the full output data.
2020-07-21 13:25:04 +02:00
Christian Kellner
4c6ca0b4a0 api: properly close the event loop
Close the event loop when the context is exited, which will clear
the internal queues and shut down the executor of the event loop.
Not doing this will create a warning when the object is garbage
collected.
2020-07-21 13:25:04 +02:00
Christian Kellner
e9c4075bb3 remoteloop: properly close the event loop
Close the event loop when the context is exited, which will clear
the internal queues and shut down the executor of the event loop.
Not doing this will create a warning when the object is garbage
collected.
2020-07-21 13:25:04 +02:00
Christian Kellner
291fadd0b2 pylint: increase max attributes to 10
In three places we have more than 7 instances attributes, but less
then 10; instead of disabling the warning for all these cases,
increase the limit to a reasonable size of 10 and re-enable the
warnings in all the places.
2020-07-21 13:25:04 +02:00
chloenayon
58bd7a204a osbuild: return if output-directory not specified
If the user does not specify an output directory or checkpoints
to osbuild, exit successfully without building.

Previously, if a user did not include an output directory or
checkpoints, it would build the manifest and throw out the result.
Returning early will be clearer to the user and avoid wasting work.
2020-07-20 19:17:30 +02:00
Christian Kellner
53f6c41917 osbuild: use osbuild_cli directly as main entry
Instead of having a another indirection via `main_cli`, directly
use `osbuild_cli` in as main function in `__main__.py`. Also use
that in as the entry point for the generated `osbuild` executable.
Change `osbuild_cli` to be self-contained, i.e. it directly uses
`sys.argv` and `sys.exit`.
2020-07-17 16:30:46 +01:00
Christian Kellner
e3eccbe491 osbuild: remove ability to pass in secrets
The way secrets work has been changed via commit 372b117: instead
of passing them in via the command line, the information how to
obtain secrets are encoded along the sources themselves.
The only stage that still has support for the old style way is the
deprecated org.osbuild.dnf stage, which might be removed in the
near future.
2020-07-10 11:44:15 +02:00
Christian Kellner
9fd28c8c21 pipeline: remove extra empty line
More PEP-8. No semantic change.
2020-07-10 11:44:15 +02:00
Christian Kellner
0cf581a9a4 util/selinux: add gefilecon helper
Add a simple helper that gets the security context for a given
path as a plain string.
2020-06-15 20:36:48 +02:00
Christian Kellner
72e00f3f2b pipeline: pass meta data to stages & assemblers
Pass a new `meta` object to the stages and assemblers that for now
only contains the `id` of the corresponding stage or assembler.
2020-06-10 15:08:49 +02:00
Christian Kellner
a419ee9038 buildroot: grant CAP_MAC_ADMIN for labeling
When applying labels inside the container that are unknown to the
host, the process needs to have the CAP_MAC_ADMIN capability in order
to do so, otherwise the kernel will prevent setting those unknown
labels. See the previous commit for more details.
2020-06-10 01:35:05 +02:00
Christian Kellner
696219dab9 util/ostree: accept typing.List for List[str]
In python 3.6 the value of `__origin__` for typing.List[str] is
typing.List. This then changed to the actual `list` type in later
versions. Accept both versions.
2020-06-09 13:42:35 +02:00
Christian Kellner
52f33d56b7 ostree: add 'initramfs-args' option to Treefile
Add the initramfs-args Treefile option that can be used to pass
arguments to drauct via rpm-ostree. NB: the ostree module will
always be automatically be included by rpm-ostree.
2020-06-04 10:25:39 +02:00
Christian Kellner
5891beab4e meta: also validate the schema for sources
When validating the manifest, now also validate the schema for
the supplied sources.
2020-06-02 09:50:14 +02:00
Christian Kellner
bdae02a6b5 meta: ModuleInfo support for Sources
Add support for querying information about sources: add the mapping
from name to directory and accept "Source" as a module name. Adapt
the ModuleInfo schema property to handle the different styles for
stage-like schemata as well as sources now.
2020-06-02 09:50:14 +02:00
David Rheinsberg
fe6e58aa12 pipeline: drop redundant default arg value
Drop the default argument value for `output_directory`, but use
type-annotations to make clear it can be optional.
2020-05-29 11:07:29 +02:00
David Rheinsberg
13c0dec8ee util/jsoncomm: simplify condition
This reduces `if fds && len(fds) > 0:` to `if fds:`. In python, empty
collections are considered false, so the additional check is not needed.
2020-05-29 11:07:29 +02:00
Christian Kellner
2a9cdde5ec osbuild: refactor stage information
For all currently supported modules, i.e. stages and assemblers,
convert the STAGE_DESC and STAGE_INFO into a proper doc-string.
Rename the STAGE_OPTS into SCHEMA.
Refactor meta.ModuleInfo loading accordingly.

The script to be used for the conversion is:

  --- 8< --- 8< --- 8< --- 8< --- 8< --- 8< --- 8< --- 8< ---

import os
import sys

import osbuild
import osbuild.meta

from osbuild.meta import ModuleInfo

def find_line(lines, start):
    for i, l in enumerate(lines):
        if l.startswith(start):
            return i
    return None

def del_block(lines, prefix):
    start = find_line(lines, prefix)
    end = find_line(lines[start:], '"""')
    print(start, end)
    del lines[start:start+end+1]

def main():
    index = osbuild.meta.Index(os.curdir)

    modules = []
    for klass in ("Stage", "Assembler"):
        mods = index.list_modules_for_class(klass)
        modules += [(klass, module) for module in mods]

    for m in modules:
        print(m)
        klass, name = m
        info = ModuleInfo.load(os.curdir, klass, name)

        module_path = ModuleInfo.module_class_to_directory(klass)
        path = os.path.join(os.curdir, module_path, name)
        with open(path, "r") as f:
            data = list(f.readlines())

            i = find_line(data, "STAGE_DESC")
            print(i)
            del data[i]

            del_block(data, "STAGE_INFO")

            i = find_line(data, "STAGE_OPTS")
            data[i] = 'SCHEMA = """\n'

        docstr = '"""\n' + info.desc + "\n" + info.info + '"""\n'
        doclst = docstr.split("\n")
        doclst = [l + "\n" for l in doclst]
        data = [data[0]] + doclst + data[1:]

        with open(path, "w") as f:
            f.writelines(data)

if __name__ == "__main__":
    main()
2020-05-29 08:37:47 +02:00
Christian Kellner
dd00c4f478 meta: add method to list modules of a given class
New Index.list_modules_for_class method that will list the names
of all the modules of a certain class, like 'Stage' or 'Assembler'.
2020-05-29 08:37:47 +02:00
Christian Kellner
2d5ec8edad meta: extract module class to dir mapping
Make the mapping of module class to the corresponding directory
a method of the ModuleInfo class. This is so it can be re-used
by others in the future.
2020-05-29 08:37:47 +02:00
Christian Kellner
80858a492b meta: rename StageInfo → ModuleInfo
The are converging on a nomenclature where the sum of Stages,
Assemblers, Sources (and future entities like those) together
are called 'Modules'.
Thus rename StageInfo to ModuleInfo and the corresponding
variables and methods.
2020-05-29 08:37:47 +02:00
David Rheinsberg
867adc1596 pipeline: checkpoint assemblers just like stages
Change the assembler-commit to be conditional on checkpoints, just like
we already do for stages. This means, assembler output is not
automatically committed, but only if you requested so via a checkpoint.

With this in place we can start sharing caches in osbuild-composer. The
only thing in the cache will be sources as well as checkpointed stages.
We can start checkpointing known pipelines and thus make use of the
cache. Furthermore, we can cache sources, as long as we do not fetch an
unbound set of RPMs. However, our RPM set is currently static, so this
should not be an issue. Nevertheless, it is up to Composer to decide
when to enable the cache.
2020-05-28 14:55:00 +02:00
David Rheinsberg
9c982dc147 pipeline: fix pylint-warning triggered by rebase
Fix osbuild/pipeline.py unused import. We now trigger pylint warnings
alongside pylint errors, and a PR rebase did not consider this.
2020-05-28 12:29:53 +02:00
David Rheinsberg
4c0b169881 pipeline: drop tree_id from osbuild results
We no longer need the `tree_id` in the osbuild output. All callers have
been converted to use other means. Drop the ID from the output and
avoid exposing our internals.
2020-05-28 11:16:15 +02:00
David Rheinsberg
43ddcf895d pipeline: drop output_id and pull in output-directory
Now that no caller requires the "output_id" anymore, drop it from our
results-dictionary. Instead, pass the output-directory through and copy
outputs where we produce / fetch them.

This still uses `objectstore.resolve_ref()`, since we do not have the
outputs pinned at the places where we want to copy. This needs a little
bit more rework, but we might just delay that until we have the cache
rework landed.

This already simplifies the output-directory path and drops the slight
hack which checked very late for produced outputs.

Note that we must be careful not to copy things too early, because we
do not want remnants in the output-directory if we return failure.
Hence, keep the copy-operation close to the commit-operation on the
store.
2020-05-28 11:16:15 +02:00
David Rheinsberg
18b16acd3f pipeline: drop redundant shortcut
All callsites of `Pipeline.assemble()` already check early whether the
output-object exists in the store and then return it. Checking again in
`assemble()` will never catch anything (unless another stage would
happen to produce the same ID as the assembler as a side-effect).

It does seem useful to keep the shortcuts in `assemble()`, so other
callers would get the shortcut as well. However, this does not really
work well right now, since you want to skip the stage-compilation as
well, and `assemble()` is really just the last step of the job. Hence,
it really is the job of the pipeline-executor to check early.

With that in mind, lets drop this fast-path which has no effect in the
current setup.
2020-05-28 11:16:15 +02:00
David Rheinsberg
46526cf205 osbuild: avoid [] as default value
Using `[]` as default value for arguments makes `pylint` complain. The
reason is that it creates an array statically at the time the function
is parsed, rather than dynamically on invocation of the function. This
means, when you append to this array, you change the global instance and
every further invocation of that function works on this modified array.

While our use-cases are safe, this is indeed a common pitfall. Lets
avoid using this and resort to `None` instead.

This silences a lot of warnings from pylint about "dangerous use of []".
2020-05-28 11:06:05 +02:00
David Rheinsberg
14ada360bd meta: avoid static assertion
Avoid raising a static assertion, but use `raise AssertionError()`
instead. This silences a complaint from pylint about static parameters
to `assert`.
2020-05-28 11:06:05 +02:00
David Rheinsberg
dfec7aca9d buildroot: convert unused format-string
Convert the `f""` into a `""`, since no format identifier is used. This
makes pylint happier!
2020-05-28 11:06:05 +02:00
Christian Kellner
869973dc68 pipeline: drop {tree, output}_id from --inspect js
We want to get rid of `tree_id` and `output_id` because the they
are now considered internals of the store and clients should not
use them directly. NB: they are still there indirectly as the id
of the last stage and the assembler.
Also, the `output_id` was never correct here, because it was the
`tree_id` as well. Ups.
2020-05-20 18:54:56 +02:00
David Rheinsberg
9dfa0e8a61 pipeline: only copy output if there is any
Make sure to verify that the pipeline actually produced any output
before attempting to copy it out. This fixes osbuild running with
`--output-directory` but without assembler.
2020-05-20 14:44:43 +02:00
Christian Kellner
1896047bae sources: pass the library dir to the sources
The idea is that source can themselves spawn other modules, esp.
new secrets modules. For this they need to know the library dir,
aka 'libdir' throughout the osbuild source. Therefore change the
SourceServer to directly get the library directory instead of
just the sub-directory to the sources. Then pass the library
directory to via the JSON API to the source.
Adjust all usage of the SourceServer, including the tests.
2020-05-20 14:43:33 +02:00
David Rheinsberg
d4f40362ec buildroot: drop kwargs from buildroot.run()
Drop the `kwargs` forwarding from buildroot.run() to subprocess.run().
We do not use it other than for `stdin=subprocess.DEVNULL`. Set that
option directly instead.

Doing the kwargs forwarding mixes the argument namespaces and is very
hard to read. It is not clear from the call-site which argument goes to
buildroot.run() and which to subprocess.run().

Lastly, it requires us to manually fetch `check` just to make pylint
happy. Lets just drop this dance and make the API explicit.
2020-05-13 14:17:30 +02:00
Christian Kellner
016d520dda meta: use draft 4 of jsonschema to validate
We currently don't seem to use anything that requires us to use
the draft 7 of the specification. The minimum version that we
need is draft 4, which is also supported by the python-jsonschema
version in RHEL 8.2 (which is 2.6.0).
2020-05-12 22:00:38 +02:00
David Rheinsberg
bc437520cd tmpfs: drop unused module
The osbuild/tmpfs.py module is unused. Drop it.
2020-05-12 11:14:16 +02:00
David Rheinsberg
8a195d7502 util/ctx: extract suppress_oserror()
Extract the `suppress_oserror()` function from the ObjectManager and
make it available as utility for other code as well.

This also adds a bunch of tests that verify it works as expected.
2020-05-11 18:05:12 +02:00
David Rheinsberg
19c74c3e8d cli: drop --build-env argument
Drop the --build-env command-line argument. It is not used by anything.
Furthermore, our manifests now allow embedding build-environments, so
there is little reason to continue supporting this.
2020-05-07 19:52:33 +02:00
Christian Kellner
9fce523f76 main_cli: pass proper libdir to meta.Index
In case `--libdir` is not specified on the command line, and thus
`args.libdir` is `None`, pass the standard `/usr/lib/osbuild` path
to the meta.Index constructor. Otherwise no schema information can
be found.
2020-05-06 20:18:15 +02:00
Christian Kellner
1fa3b88ab1 meta: truth value of Schema includes schema check
The truthiness of the `Schema` object itself now contains the
schema validation as well, i.e. schema is only valid if schema
information is present and said information passes validation.
2020-05-06 15:42:23 +02:00