Commit graph

120 commits

Author SHA1 Message Date
Simon de Vlieger
d60690ce46 tox: add tox
`tox` is a standard testing tool for Python projects, this allows you to
test locally with all your installed Python version with the following
command:

`tox -m test -p all`

To run the tests in parallel for all supported Python versions.

To run linters or type analysis:

```
tox -m lint -p all
tox -m type -p all
```

This commit *also* disables the `import-error` warning from `pylint`,
not all Python versions have the system-installed Python libraries
available and they can't be fetched from PyPI.

Some linters have been added and the general order linters run in has
been changed. This allows for quicker test failure when running
`tox -m lint`. As a consequence the `test_pylint` test has been removed
as it's role can now be fulfilled by `tox`.

Other assorted linter fixes due to newer versions:
- use a str.join method (`consider-using-join`)
- fix various (newer) mypy and pylint issues
- comments starting with `#` and no space due to `autopep8`

This also changes our CI to use the new `tox` setup and on top of that
pins the versions of linters used. This might move into separate
requirements.txt files later on to allow for easier updating of those
dependencies.
2023-08-01 15:01:13 +02:00
Simon de Vlieger
ea6085fae6 osbuild: run isort on all files 2022-09-12 13:32:51 +02:00
Simon de Vlieger
b07aca5d86 modules: explicit encodings for open() 2022-09-09 15:33:29 +02:00
Alexander Larsson
f4bfce05e3 org.osbuild.oci-archive: Support setting Entrypoint
This allows setting Entrypoint (as well as Cmd) in the oci image,
as per the spec:

  https://github.com/opencontainers/image-spec/blob/main/config.md

Note: These two are not equivalent, the Cmd part is replaced by the
argument on the `docker run` commandline, whereas the entrypoint is
kept from the config, so it is important to expose both of these.
2022-09-05 13:10:47 +02:00
Christian Kellner
f05078f66e global: fix PEP-8 formatting
This patch was generated by running `autopep8 --diff` on the
source tree and then applying the diff.
2022-08-05 09:41:05 +02:00
Simon de Vlieger
3fd864e5a9 osbuild: fix optional-types
Optional types were provided in places but were not always correct. Add
mypy checking and fix those that fail(ed).
2022-07-13 17:31:37 +02:00
Christian Kellner
b57376d160 pipeline: drop CAP_MAC_ADMIN by default
Drop `CAP_MAC_ADMIN` from the default capabilities which is needed
to write and read(!) unknown SELinux labels. Adjust the stages
that need to read or write SELinux labels accordingly.
2022-04-27 23:05:11 +01:00
Christian Kellner
0c8f5c7ef0 pipeline: drop CAP_{NET_ADMIN,SYS_PTRACE} caps
Drop CAP_{NET_ADMIN,SYS_PTRACE} from the default capabilities which
are only needed to run bwrap from inside a stage which is done by
the `ostree.commit` and `ostree.preptree` stages, so retain them
directly there.
2022-04-27 23:05:11 +01:00
Tomas Hozza
f41edba1fb Support VMDK subformat in qemu assembler 2022-04-07 15:51:44 +02:00
Roy Golan
ed82f33c8f Fix type orci-archive/oci-archive
Signed-off-by: Roy Golan <rgolan@redhat.com>
2022-02-14 14:15:19 +01:00
Christian Kellner
9a33fabd51 assembler/ostree.commit: fix copying of links
Commit 92cc269 fixed a bug where `/var` was copied into `/var`
resulting in `/var/var`. Sadly the fix broke copying links,
like `bin -> usr/bin`, where now the content of the link would
be copied but not the link itself. Use the `-t` command line
flag for `cp` which should ensure that we copy links as links
but also copy the contents for `/var` should the target dir,
i.e. `/var` already exist.
2021-07-16 10:32:12 +02:00
Christian Kellner
92cc26997f assemblers/ostree: fix copying of var
In the ostree assembler, `var`, `usr` and `boot` are copied from
the built tree to a newly initialized and ostree-conforming root
filesystem. The way in which `cp` was called resulted in the
source being created inside the target, if the latter existed.
This was the case for `var` resulting in `var/var`.
Use `cp ${source}/. {target}` to fix that.

Reported-by: Luca Bruno <luca.bruno@coreos.com>
2021-06-22 10:07:07 +02:00
Christian Kellner
98a82ff47e aarch64: use single qemu-img thread
Work around a bug on aarch64[1] where `qemu-img` would hang
about a third of the time when converting images. To be able 
to activate the work-around based on the environment, i.e.
only on certain distributions, introduce an environment
variable, `OSBUILD_QEMU_IMG_COROUTINES`, that is set in the
runner and then picked up in the assembler.

[1] https://bugs.launchpad.net/qemu/+bug/1805256
2021-06-09 11:57:26 +02:00
Christian Kellner
e7620feca4 assemblers/qemu: support for qcow2 compat version
Add a new option `qcow2_comapt` which can be used explicitly
select the compatibility level of the qcow2 file format. Qemu
version 1.1 introduced extensions to the format that became
the default with 1.7, which are not readable by qemu < 1.1.
Thus if the resulting qcow2 should be read by such older qemu
versions, the compatibility level needs to be set to 0.10.
2021-04-08 10:22:56 +02:00
Christian Kellner
72ffa50c45 assemblers: add org.osbuild.error
This is, like the stage with the same name, an assembler that
will exit with an error code (default 255, but can be specified
via the assembler options). It is mostly useful for testing.
2021-03-09 21:40:47 +00:00
Christian Kellner
3d27b301a2 stages/oci-archive: do not include selinux labels
Instead of including SELinux labels for the content layers via the
`--selinux` tar option, make sure selinux labels are not included by
using the `--no-selinux` option.
The inclusion of the labels was a mistake, since they should be
determined by the target system because selinux labels are not
namespaced. On RHEL/Fedora the SELinux label used is something like
`system_u:object_r:container_ro_file_t:s0` for all the files in the
container.
Including the label was leading to permission problems because
the files had a different label on the host and programs inside
the container get `EACCES`, i.e. Permission denied, errors when
accessing files with the different label.
Interestingly this does not happen on Fedora 33 but only on RHEL.
One possibility is that the overlayfs kernel driver in RHEL is
behaving differently on RHEL than on Fedora.
2021-03-02 17:37:45 +01:00
Christian Kellner
f11817a1fa assembler/oci-archive: fix layer media type
When media type (mime type) of the layer was missing the "+"
separator between the compression and then base type.
2021-02-12 15:55:43 +01:00
Christian Kellner
05e5a5596f assembers/tar: add acls, selinux, xattrs options
Add the ability to opt out of preserving the ACLs, SELinux
contexts and extended attributes. It is opt out instead of
opt in since the assembler by default tries to preserve as
much as possible.
2021-01-26 12:09:23 +01:00
Christian Kellner
94d40da5cb assemblers/tar: small description cleanup
Replace the short and redundant first line of the description with
the more detailed following header line.
2021-01-26 12:09:23 +01:00
Christian Kellner
920f46880b assemblers/tar: include selinux, acls and xattrs
All of these options, i.e. SELinux labels, ACLs and extended
attributes (xattrs), are opt-in and thus were currently ignored.
This lead to trees that had their selinux labels missing and
were thus incorrect.
2021-01-26 12:09:23 +01:00
Christian Kellner
8ccc73d1c3 pipeline assemblers are stages now
Instead of using the `Assemblers` class to represent assemblers,
use the `Stage` class: The `Pipeline.add_assembler` method will
now instantiate and `Stage` instead of an `Assembler`. The tree
that the pipeline built is converted to an Input (while loading
the manifest description in `format/v1.py`) and all existing
assemblers are converted to use that input as the tree input.

The assembler run test is removed as the Assembler class itself
is not used (i.e. run) anymore.
2021-01-18 17:44:46 +01:00
Christian Kellner
61966e3f4c assemblers/tar: use osbuild.api.arguments
Instead of reading the arguments from sys.stdin, which requires
that stdin is setup properly for that in the runner, use the new
api.arguments() method to directly fetch the arguments.

Also fix missing newlines between imports and methods to be more
PEP-8 complaint, where needed.
2020-08-31 15:06:36 +02:00
Christian Kellner
fc6e6285ca assemblers: use api.arguments
Instead of reading the arguments from sys.stdin, which requires
that stdin is setup properly for that in the runner, use the new
api.arguments() method to directly fetch the arguments.

Also fix missing newlines between imports and methods to be more
PEP-8 complaint, where needed.
2020-08-25 18:51:55 +02:00
Christian Kellner
174a802803 assemblers/ostree.commit: report compose metadata
Pass all the compose metadata, as given by rpm-ostree via the
compose.json, back to osbuild via the new api.metadata method.
2020-08-13 10:50:34 +02:00
Christian Kellner
1af4fc7f2a assemblers/ostree.commit: regroup code for clarity
Re-order the os_version metadata conditional to group all the
optional metadata together. This should make it clearer what
belongs together.
2020-08-13 10:50:34 +02:00
Christian Kellner
6e63baa0d4 assemblers/ostree.commit: whitespace fixes
Be more PEP-8 compliant.
2020-08-12 08:08:17 +02:00
Christian Kellner
b89ef5aa5e assemblers/ostree.commit: version metadata support
Add a new `os_version` option that will result in the `version`
metadata being set as commit metadata. This will then be shown
in the `rpm-ostree status` output.
2020-08-12 08:08:17 +02:00
Davide Cavalca
925530ac0a assemblers: add btrfs support to qemu and rawfs 2020-08-04 10:49:37 +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
Christian Kellner
b0bf9c9392 assemblers/ostree.commit: set inputhash metadata
Use the new `meta` information passed to the assembler and use
the id as the `rpmostree.inputhash` metadata that will get set
on the commit.
2020-06-10 15:08:49 +02:00
Christian Kellner
7a2ad6f0f8 osbuild: replace capture_output in subprocess.run
The `capture_output` argument for subprocess.run was added in 3.7,
but want to support 3.6 as well. Change all the usages of it with
`stdout=subprocess.PIPE` that will have the same effect, at least
for stdout.
2020-06-09 13:42:35 +02:00
Lars Karlitski
d7d1d9dbbf Take care not to put large content on /tmp
Most stages and assemblers already use `/var/tmp` to store large
files or trees. Do this in the qemu assembler and copy stage as well.
2020-06-09 09:12:05 +02:00
David Rheinsberg
faaa6c1a6b modules: fix format-strings without interpolation
Fix all occurrences of format-strings without any interpolation. pylint
warns about those (and for some reason did not do so for our modules).
A followup will fix the pylint tests, so make sure all the warnings are
resolved.
2020-05-29 11:07:44 +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
7c9b44ce88 assemblers: add new org.osbuild.oci-archive
Add a new assembler that takes a tree and creates a Open Container
Initiative[2] image according to the OCI image format[2]. The final
result is a tarball, aka a "orci-archive", that can be pulled into
podman with `podman pull oci-archive:<archive>`. Currently the only
required options are `filename` and `architecture`.

[1] https://www.opencontainers.org/
[2 ]https://github.com/opencontainers/image-spec/
2020-05-20 20:05:22 +02:00
Christian Kellner
192430bd30 assemblers/ostree.commit: support archiving
Introduce a new `tar` option, which when given together with the
required `tar.filename` option, will result in the output of the
assembler being a tarball that contains the repo and the compose
information (`compose.json`).
Requires the `tar` command to be present in the build root. Modify
the sample to use that option and include the tar for the build
pipeline.
2020-05-20 14:47:40 +02:00
Christian Kellner
01ce01b1c7 stages & assemblers: don't allow additional props
Change all the schemata to not allow additional properties. This
should help with misspelled properties as well as missing schema
information in the stage itself.

Done via a small python3 script:

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

import os
import sys

def list_stages(base):
    return [(base, f) for f in os.listdir(base) if f.startswith("org.osbuild")]

stages = list_stages("stages")
stages += list_stages("assemblers")

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

NOADD = '"additionalProperties": false'

for stage in stages:
    with open(f"{stage[0]}/{stage[1]}", "r") as f:
        print(f"{stage[0]}/{stage[1]}", file=sys.stderr)
        data = f.readlines()
        i = find_line(data, 'STAGE_OPTS = """')
        if i:
            data.insert(i+1, NOADD + ",\n")
        else:
            i = find_line(data, 'STAGE_OPTS = ""')
            if i:
                data[i] = f'STAGE_OPTS = """\n'
                data.insert(i+1, NOADD + "\n")
                data.insert(i+2, '"""\n')

    with open(f"{stage[0]}/{stage[1]}", "w") as f:
        f.writelines(data)
2020-05-06 15:42:23 +02:00
Christian Kellner
b7367c037e assemblers/qemu: add 'raw.xz' to format schema
It is a valid option and even used in the tests, but was missing
in the schema.
2020-05-06 15:42:23 +02:00
David Rheinsberg
4d2f15fb46 modules: drop osbuild symlink
Drop the `osbuild -> ../osbuild` symlink from all module directories.
We now properly initialize the PYTHONPATH to provide the imported
osbuild module from the host environment. Therefore, these links are no
longer needed.

The sources run from the host environment, so they should just pick them
up from the environment the same way osbuild itself does.
2020-05-04 12:32:25 +02:00
David Rheinsberg
4ad4da4658 osbuild: convert to jsoncomm
Convert the hard-coded DGRAM communication to util.jsoncomm. This
avoids hard-coding any IPC-details and simplifies the callers quite a
bit.
2020-04-21 13:47:38 +02:00
Major Hayden
8464e8d1dc 🐎 Use more CPUs for xz with qemu
Signed-off-by: Major Hayden <major@redhat.com>
2020-04-17 18:39:42 +02:00
Major Hayden
cab71e5b18 🐎 Allow xz to use all available CPUs
By default, xz only uses one CPU core even if multiple cores are
available. If xz compression is chosen, allow xz to use all of the
cores available.

Signed-off-by: Major Hayden <major@redhat.com>
2020-04-17 14:01:07 +00:00
Christian Kellner
e424e40aae assembler: add org.osbuild.ostree.commit
Add a new assembler that takes a file system tree that is already
conforming to the ostree system layout[1], creates a new repository
in archive mode and commits the file system tree to it. Afterwards,
a reference is created with the value supplied in `ref`.

The repository is located at the `/repo` directory and additional
metadata is /compose.json which contain the compose information.

Currently uses rpm-ostree to do the actual committing. In the future
this might change to plain ostree.

[1] https://ostree.readthedocs.io/en/stable/manual/adapting-existing/
2020-04-15 15:39:45 +02:00
Ondřej Budai
de7227965f assembler/qemu: add support for vhdx format
VHDX is the best format for uploading to AWS, thus this commit adds the
support for it. Pros over other formats supported by AWS:
- vmdk - doesn't work, qemu-img probably needs some special options
- vhd - the image size gets round up (I can get only a >=7GB volume from
  a 6GB image)
- ova - just a wrapper over vmdk/vhd/vhdx adding some metadata
- raw - no compression, the images are huge

Also, the format specification is open, therefore I can't see any issues
with it.
2020-04-14 21:56:30 +02:00
Christian Kellner
d906b26372 assembler/qemu: support for GPT partition UUIDs
The GUID Partition Table (GPT) layout supports assigning UUIDs for
individual partitions. Add support for specifying those in the
partition description.
2020-04-01 14:37:25 +02:00
Christian Kellner
beb24a38b0 assembler/qemu: schema: 'dos' option for 'pttype'
Reflect the actual code by allowing 'dos' as pttype, which is as an
alias for 'mbr'.
2020-01-29 18:03:24 +01:00
Christian Kellner
ed8b71da36 assembler/qemu: fix 'size' schema type
It is an integer not a string.
2020-01-29 18:03:24 +01:00
Christian Kellner
2a3e5107f4 assembler/rawfs: fix schema type for 'size'
It is supposed to be an integer not a string.
2020-01-29 18:03:24 +01:00
Christian Kellner
eb71e3d85c assembler/qemu: grub prefix relative to mountpoint
The grub prefix ("/boot/grub2") should be defined as relative to the
mountpoint of the filesystem containing it, i.e. /boot/grub2 if it is
on the root filesystem or /grub2 if boot is on a separate partition.
2020-01-19 23:01:36 +01:00
Christian Kellner
49e1b91d47 assembler/qemu: support for zipl bootloader
Support the s390x bootloader zipl (z Initial Program Loader). We
supply the parameters for the kernel+initrd as well es the target,
i.e. the boot partition where the bootmap is creating, the device,
here called 'targetbase', to install the bootloader on, including
parameters describing the device (type, blocksize) and also the
offset of the partition containing the target from the start of
device (in sectors).
The kernel and initrd are found via the bootloader entry, ignoring
the rescue kernel.
Since zipl needs the device as well as access to the boot partition
the image is bound to a loopback device. Also keep the filesystem
tree mounted during the execution of the zipl installation.
2020-01-13 20:05:10 +01:00