Commit graph

55 commits

Author SHA1 Message Date
Tom Gundersen
96ea4e5698 BuildRoot: do not register with systemd-machined
This really only makes sense if we are running systemd as PID1
inside the container, but we are not booting a system, just using
it as a glorified chroot.

This means entering the namespaces from the outside will be a bit
more cumbersome, but that was not used much and was never reliable
to begin with.

Signed-off-by: Tom Gundersen <teg@jklm.no>
2019-07-19 01:27:17 +02:00
Tom Gundersen
670d51a746 BuildRoot: drop unused device permissions
We only need permissions for loop devices, not for loop-control
and not for partitions.

Signed-off-by: Tom Gundersen <teg@jklm.no>
2019-07-19 00:51:12 +02:00
Tom Gundersen
7274847711 Assembler: no longer mount devtmpfs in the container
Move the only assembler that relied on this to use LoopClient instead.

Signed-off-by: Tom Gundersen <teg@jklm.no>
2019-07-19 00:51:12 +02:00
Tom Gundersen
d855c6c35e Assembler: add the remoteloop API to the assembler build roots
Signed-off-by: Tom Gundersen <teg@jklm.no>
2019-07-19 00:51:12 +02:00
Tom Gundersen
c124ab264b loop: add helpers to use IPC to create loop devices
loop.py is a simple wrapper around the kernel loop API. remoteloop.py
uses this to create a server/clinet pair that communicates over an
AF_UNIX/SOCK_DGRAM socket to allow the server to create loop devices
for the client.

The client passes a fd that should be bound to the resulting loop
device, and a dir-fd where the loop device node should be created.
The server returns the name of the device node to the client.

The idea is that the client is run from whithin a container without
access to devtmpfs (and hence /dev/loop-control), and the server
runs on the host. The client would typically pass its (fake) /dev
as the output directory.

For the client this will be similar to `losetup -f foo.img --show`.

[@larskarlitski: pylint: ignore the new LoopInfo class, because it
only has dynamic attributes. Also disable attribute-defined-outside-init,
which (among other problems) is not ignored for that class.]

Signed-off-by: Tom Gundersen <teg@jklm.no>
2019-07-19 00:51:12 +02:00
Tom Gundersen
5d5766a98a BuildRoot: include the osbulid module in the containers
This way we have access to all our helper libraries from the stages
and assemblers.

Signed-off-by: Tom Gundersen <teg@jklm.no>
2019-07-19 00:51:12 +02:00
Tom Gundersen
e2dc0c5081 BuildRoot: add support for an API sockets dir
Add a directory to each BuildRoot potentially containing a set of
sockets. Also add a helper to create a named bound socket in a given
BuildRoot.

Signed-off-by: Tom Gundersen <teg@jklm.no>
2019-07-19 00:51:12 +02:00
Tom Gundersen
18ebce3016 Stage: don't bind-mount devtmpfs into the stage buildroot
We only use devices in Assemblers so this is not needed.

Signed-off-by: Tom Gundersen <teg@jklm.no>
2019-07-19 00:51:12 +02:00
Tom Gundersen
8994e7f803 libdir: allow osbulid to be built from the tree
This was a regression from when osbuild was made into a module.
Restore the old behavior.

Signed-off-by: Tom Gundersen <teg@jklm.no>
2019-07-19 00:51:12 +02:00
Martin Sehnoutka
b218430bfa add __main__ file for convenient CLI usage 2019-07-18 10:17:39 +02:00
Martin Sehnoutka
23680736bb create osbuild package 2019-07-18 10:17:39 +02:00
Lars Karlitski
781fc73176 osbuild.py: make StageFailed and AssemblerFailed consistent
This way they can both be used as ducks in an exception handler.
2019-07-17 10:36:13 +02:00
Lars Karlitski
baa5da6abe osbuild.py: clean up Pipeline API
Separate deserialization into a new `osbuid.load()` function.

Pass objects to `Pipeline.run()` instead of keeping it in an attribute
on the pipeline.
2019-07-17 10:36:13 +02:00
Martin Sehnoutka
a837cc5e82 make /run/osbuild in the pipeline class 2019-07-11 12:34:32 +02:00
Tom Gundersen
65151e22ff osbuild.py: assign ids to stages rather than to pipelines
Compute a hash based on the content of a stage, together with the
hash of its parent stage.

The output of a pipeline is saved by the id of the last stage.

This is largely equivalent to the current logic, where it is the
pipeline that contains the id, but this means that the ids are
indepedent of how pipelines are split, the only thing that matters
is the sequence of stages, not whether or not they are in one or
several interdependent pipelines.

Signed-off-by: Tom Gundersen <teg@jklm.no>
2019-07-09 12:41:26 +02:00
Tom Gundersen
cebed27cd9 osbuild: drop the concept of an input_dir
This removes the possibility of passing in arbitrary input data. We
now restrict ourselves to explicitly specified files/directories or
a base tree given by its pipeline id.

This drops the tar/tree stages/assemblers, as the tree/untree ones
are implicit in osbuild, and if we wish to also support compressed
trees, then we should add that to osbuild core as an option.

Signed-off-by: Tom Gundersen <teg@jklm.no>
2019-07-03 13:11:37 +02:00
Tom Gundersen
e607053c32 osbuild.py/pipeline: add the concept of a content store
Whenever an assembler is not specified, the output tree is instead
saved to the content store, in a directory named after the pipeline
id.

This should render the io.weldr.tree assembler redundant.

In order to build the samples as before, specify the content store
as the input directory to build any pipeline that uses the
io.weldr.untree stage.

Signed-off-by: Tom Gundersen <teg@jklm.no>
2019-07-03 13:11:37 +02:00
Tom Gundersen
f25cffa151 osbuild.py/pipeline: assign a unique id to every pipeline
This uniquely identifies a pipeline based on its content. Pipelines
are considered equal modulo whitespace and the order of object
elements.

The intention is that two runs of a pipeline with the same id
generates functionaly equivalent ids. It is up to the writers
of stages and pipelines to ensure this property holds.

Signed-off-by: Tom Gundersen <teg@jklm.no>
2019-07-03 13:11:37 +02:00
Tom Gundersen
1219f1dc55 osbuild.py: introduce a Pipeline class
This is not a functional change, it is just a wrapper class around the
pipeline state.

Signed-off-by: Tom Gundersen <teg@jklm.no>
2019-07-03 13:11:37 +02:00
Lars Karlitski
767b249b2d osbuild: move run() into osbuild.py
This allows for running a pipline from python and for non-interactive
mode, in which all output is captured.
2019-07-01 17:01:26 +02:00
Martin Sehnoutka
1d7f2461a0 make named parameters mandatory 2019-06-21 15:44:40 +02:00
Tom Gundersen
28fd21ba40 osbuild: allow empty output dir
We wanted to force an empty output dir to avoid assembly stages using
previous output when creating their new one, and hence creating
dependencies between osbuild runs. We may still do that, but for now
let's remove the restriction as it seems rather arbitrary to protect
people from themselves to this extent.

Signed-off-by: Tom Gundersen <teg@jklm.no>
2019-06-19 16:07:43 +02:00
Lars Karlitski
2d487fe685 osbuild.py: add systemResourcesFromEtc key
Some programs have resources in /etc (for example, /etc/pki or grub's
config scripts). Give stages a way to access these.
2019-06-14 20:29:14 +02:00
Lars Karlitski
bd87038210 osbuild.py: separate tree from build root
There's no reason to conflate the two. This allows us to build on
something other than a tmpfs.
2019-06-14 19:54:42 +02:00
Lars Karlitski
ce0b01e93d osbuild: remove --sit
It's not really useful because it's at the wrong place, after a stage
has torn down all mounts. It also makes the code more complex for too
little benefit.
2019-06-14 18:38:13 +02:00
Lars Karlitski
2dbd177b0f osbuild.py: add BuildRoot.run_assembler()
This is the canonical way to run an assembler.

Also improve error handling by introducing a StageFailed exception.
2019-06-13 21:07:23 +02:00
Lars Karlitski
b36c8135ae osbuild: split BuildRoot into a reusable module 2019-06-13 20:01:53 +02:00
Lars Karlitski
abca9d7b03 osbuild: mount build root and tree in /run/osbuild 2019-06-13 19:30:57 +02:00
Lars Karlitski
e7b8f757d4 osbuid: introduce libdir
Run stages and the runner from a libdir, which is either $prefix/lib or
the current directory.
2019-06-13 19:30:19 +02:00
Lars Karlitski
48f8a7fc2a osbuild: pass arguments to main() explicitly 2019-06-13 16:16:33 +02:00
Lars Karlitski
0178cce4ee osbuild: make --input and --output absolute paths 2019-06-13 16:04:42 +02:00
Lars Karlitski
9703b975c3 osbuild: be more quiet
Don't print systemd-nspawn's messages about starting and stopping
containers.

Also supress a ldconfig warning and only show output from
systemd-sysusers when it fails.
2019-06-13 13:35:45 +02:00
Lars Karlitski
170eadde04 osbuild: add "assembler"
An assembler is a stage that may have outputs. It is the only stage
that gets the output_dir argument passed (and not input_dir).
2019-06-13 10:04:46 +02:00
Lars Karlitski
88c1f7be3b osbuild: add BuildRoot.run_stage() 2019-06-12 20:53:38 +02:00
Lars Karlitski
3cca6ccb8a osbuild: factor running systemd-nspawn out of the main loop
Also rename BuildContainer to BuildRoot. It's not a container.
2019-06-12 20:33:00 +02:00
Lars Karlitski
da121beda1 osbuild: factor out BuildContainer
As start of a public API for osbuild.
2019-06-12 19:40:59 +02:00
Tom Gundersen
34de8e0274 osbuild: always pass an input_dir argument
All stages must be able to handle an input_dir argument, as we now
either pass it to all or none for agiven run. Simply set it to
'None' if it is not provided.

Signed-off-by: Tom Gundersen <teg@jklm.no>
2019-06-12 18:54:31 +02:00
Lars Karlitski
2462f0d6e1 osbuild: output stage stdout/stderr again 2019-06-12 18:24:41 +02:00
Lars Karlitski
6ad3a3b039 osbuild: work around systemd-nspawn "cleaning" the hostname 2019-06-12 18:15:02 +02:00
Lars Karlitski
72f10e184c osbuild: pass input directory to all stages 2019-06-12 17:12:30 +02:00
Tom Gundersen
40cf349f18 osbuild: replace --from and --save with --input and --output
The new arguments are passed to the first, respectively last, stage
and are both directories. --input is read only and can be used to
initialize the first stage. --output is r/w and is where the final
stage should place the produced image.

Signed-off-by: Tom Gundersen <teg@jklm.no>
2019-06-12 16:26:29 +02:00
Lars Karlitski
01aa00837f osbuild: drop state
Stages should be as stateless as possible. Don't provide an easy way out
of that.

Only the dnf stage used stage to save the dnf cache. That's only useful
during development and can be solved by pointing to a local repo mirror.
2019-06-12 15:23:45 +02:00
Lars Karlitski
7a866aa1c3 osbuild: don't show log output on the terminal
The output makes it hard to see which stage is currently processed and
how to enter the build container. Also, it doesn't include all relevant
logs.

Instead, stream log output into /tmp/output in the build container. Keep
outputting it to stdout, so that osbuild can collect it in the future.
2019-06-12 12:47:04 +02:00
Lars Karlitski
ba2a194d5d osbuild: add --sit
Passing --sit keeps the build environment up for inspection when a stage
failed.
2019-06-07 21:46:23 +02:00
Lars Karlitski
5e7a111120 osbuild: run further setup in build environment
Introduce `run-stage` script, which sets up the build environment before
running the stage. Run `ldconfig`, `systemd-sysusers`, and
`systemd-tmpfiles` in it.
2019-06-07 21:33:31 +02:00
Tom Gundersen
256bb718ee osbuild: print the nsenter command needed to get a shell in the container
This is useful for debugging, and would be as a very lightweight ssh
session, but one that only insepcts the environment without hooking
into anything.
2019-06-07 17:19:44 +02:00
Tom Gundersen
61f83b3f46 osbuild: run stages as PID2 instead of PID1
nspawn can provide a minimal PID1 implementation, avoiding stages to
themselves do things like reap zobies etc. Use that.
2019-06-07 17:00:24 +02:00
Lars Karlitski
5f59cc0cb4 osbuild: only use /usr from the host
Use systemd-nspawn's "volatile" mode, which creates a tmpfs for the root
directory. This ensures that we're not accidentally using configuration
from the host.

The only remaining hole is `/etc/pki`.

Anaconda cannot run without its configuation in `/etc`. Recreate the
defaults.
2019-06-07 13:14:21 +02:00
Tom Gundersen
13cb397eca osbuild: use systemd-nspawn
Rather than using unshare, we use nspawn as it gives us more isolation
for free. We are not sure if we will end up with this in the end, but
for the time being let's see how well it works for us.

We have to do a work-around as nspawn refuses to spawn with the current
root as the directory, even in read-only mode, so we bindmount it first
and use the bindmount, in order to trick nspawn.
2019-06-06 19:37:49 +02:00
Tom Gundersen
cdcfa1277e osbuild: make state handling generic
Rather than treating the dnf-cache specially, give each stage its
own state directory that they can reuse. This should obviously be
used with care by the stages in order to make the builds
reproducible.
2019-06-06 19:37:49 +02:00