Commit graph

69 commits

Author SHA1 Message Date
Martin Sehnoutka
d3023ec7f7 move the resulting image into the output directory 2019-06-21 15:44:40 +02:00
Tom Gundersen
63a4f795dc stages/selinux: add an selinux stage
This stage labels the target tree based on an SELinux policy already
installed in the target.

Signed-off-by: Tom Gundersen <teg@jklm.no>
2019-06-21 13:36:49 +02:00
Tom Gundersen
73629185c0 samples: add a collection of samples
These are meant to test the various assembers and stages and to show how pipelines
can be created. However, they are not meant to necessarily be the best way to create
any given image.

Note that some of the pipelines are dependent on each other.
2019-06-19 19:49:53 +02:00
Tom Gundersen
e9363f96ed osbuild.py: give assemblers a full devtmpfs
This follows what is done for the stages. We intend to look into
making this unnecessary, but for now allow full access so we can
work on the individual assemblers.

Signed-off-by: Tom Gundersen <teg@jklm.no>
2019-06-19 19:49:53 +02:00
Tom Gundersen
a428ff05ad assemblers/qcow2: move from the old stage and make it work again
Minor ajustments needed after we changed the internal API.

Signed-off-by: Tom Gundersen <teg@jklm.no>
2019-06-19 19:49:53 +02:00
Tom Gundersen
4742ae1e72 stages/locale: fix typo
Add missing quotes around a string.

Signed-off-by: Tom Gundersen <teg@jklm.no>
2019-06-19 18:49:21 +02:00
Tom Gundersen
a2441bf112 stages/dnf: allow both operation and verbosity to be configurable
This is for the sake of debuggability, but I figure dnf is the most
complex of our tools, so instrumenting that a bit makes sense.

The defaults are "install" and "info", as before.

Signed-off-by: Tom Gundersen <teg@jklm.no>
2019-06-19 16:08:29 +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
Tom Gundersen
4b69d02dc8 stages/systemd: minor fixes
We cannot use the tool from within the tree unless we chroot
(library versions ay be wring etc). If possible we want to
always use tools from the build image, in order to avoid forcing
the contenst of the target tree, so do that instead.

Finally, add a missing include.

Signed-off-by: Tom Gundersen <teg@jklm.no>
2019-06-18 23:54:23 +02:00
Tom Gundersen
b38506a702 stages/dnf: allow other operations on the provided packages than 'install'
We would like to avoid 'upgrading', but let's allow it in the tools.

Signed-off-by: Tom Gundersen <teg@jklm.no>
2019-06-18 23:53:27 +02:00
Tom Gundersen
31a5eed4d9 stages: fix cp usage
We want to copy the contents of a directory to another, the correct
syntax for that is `cp -a src/. dst`. I was not aware of this beauty,
so the previous patch simulated the functionality in python code.

Signed-off-by: Tom Gundersen <teg@jklm.no>
2019-06-18 09:48:35 +02:00
Tom Gundersen
f246ccf11e stages/assemblers: add tree/untree assembler and stage
In the simplest case we don't need to make an image, a filesystem tree
will do. Also support using such a tree as input for further pipelines
through the untree stage.

Signed-off-by: Tom Gundersen <teg@jklm.no>
2019-06-17 17:44:04 +02:00
Tom Gundersen
6ae19579c1 stages/io.weldr.grub2: add a stage to generate grub2 configuration
The stage populates the tree with grub2 configuration. The API and
semantics is the way we want it, but internally this is a massive
hack.

GRUB2 is only able to run grub2-mkconfig on the image it wants to
configure. The reason is that it will inspect / and /boot to detect
the existing UUIDs and filesystems to use, despite this being
information we already know. In principle, the tool does support
passing this is, but due to several bugs that functionality does
not work.

We therefore create the image we want, copy over the tree, run
grub2-mkconfig in this image, then copy it back over the tree. The
end result is that the files /etc/defaults/grub,
/boot/grub2/grub.cfg and /boot/grub2/grubev are added to the tree.

The alternative would be to do what tools typically do, and just
run grub2-mkconfig on the final image at the time it is being
assembled. We want to avoid this in order to fully split filesystem
tree generation from image assembly. This way we can better control
and verify what ends up on the filesystem which should help with
reprobucibility and reuse of filesystem trees. Above all though,
we want to make sure that we can actually place some guarantees
on what each stage of the image building process actually does,
allowing us to argue about and change it without worrying about
arbitrary fallout.

Signed-off-by: Tom Gundersen <teg@jklm.no>
2019-06-17 14:55:42 +02:00
Tom Gundersen
0646b48bb3 osbulid.py/nspawn: bindmount /dev rather than use a synthetic one
We need dynamic device node creation when we create loop devices
and their partitions. It would be possible to mknod them, but
just using the host /dev seems more straight-forward. Access to
the various nodes still needs to be granted explictly as we are
in the devices CGroup.

Signed-off-by: Tom Gundersen <teg@jklm.no>
2019-06-17 14:49:53 +02:00
Tom Gundersen
566911cc27 osbuild.pi: grant access to loop device nodes
We are in the devices namespace, so we must explicitly grant
permission to devices and/or device classes if we are to use
them.

We rely on being able to create and access loop devices in
order to create partitions and filesystems.

/dev/loop-control allows us to create new loop devices backed by
files. The block-loop class allows access to the created block
devices to set up a partition table and the block-blkext class
allows access to the partitions to create and mount filesystems.

Signed-off-by: Tom Gundersen <teg@jklm.no>
2019-06-16 22:48:16 +02:00
Tom Gundersen
253ae27eca osbuild.py/tmpfs: mount with the right mode
Mount tmpfs by default as 0755. This only really makes a differente
when we copy the whole tree.

Signed-off-by: Tom Gundersen <teg@jklm.no>
2019-06-16 13:58:13 +02:00
Lars Karlitski
92f3af94f6 stage api: pass options in a separate key
This avoids name clashes between osbuild and stage options.
2019-06-16 12:07:27 +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
d43fe388a0 osbuild.py: clarify argument name 2019-06-14 19:46:37 +02:00
Lars Karlitski
c0769fc318 Add assemblers/ directory 2019-06-14 19:46:37 +02:00
Lars Karlitski
aea9dd1752 osbuild.py: don't use /tmp in the build root 2019-06-14 19:34:19 +02:00
Lars Karlitski
bc36adc1f1 osbuild.py: clean up bind mounts for stages
Allow input_dir for assemblers, but mount the tree read-only.
2019-06-14 19:32:05 +02:00
Lars Karlitski
e6dd428107 osbuild.py: rename run-stage to osbuild-run
Run all programs in the build root through osbuild-run. The things it
sets up are probbaly needed by everything.
2019-06-14 18:45:55 +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
7ee6571640 osbuild.py: use readonly bind mounts when possible 2019-06-13 21:12:51 +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
Tom Gundersen
fc72b5cd03 stages/untargz: add a stage to populate a tree from a tar.gz
Signed-off-by: Tom Gundersen <teg@jklm.no>
2019-06-12 19:46:39 +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
35917303c8 stages/targz: add a targz stage
This generates a tarball of the tree.

Signed-off-by: Tom Gundersen <teg@jklm.no>
2019-06-12 18:55:49 +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