debian-forge/README.md
Tom Gundersen 7c7fcecd47 ObjectStore: add an object store class
This also changes the structure of the object store, though the
basic idea is the same.

The object store contains a directory of objects, which are content
addressable filesystem trees. Currently we only ever use their
content-hash internally, but the idea for this is basically Lars
Karlitski and Kay Sievers' `treesum()`. We may exopse this in the
future.

Moreover, it contains a directory of refs, which are symlinks named
by the stage id they correspond to (as before), pointing to an object
generated from that stage-id.

The ObjectStore exposes three method:
`has_tree()`: This checks if the content store contains the given tree.
If so, we can rely on the tree remaining there.
`get_tree()`: This is meant to be used with a `with` block and yields
the path to a read-only instance of the tree with the given id. If the
tree_id is passed in as None, an empty directory is given instead.
`new_tree()`: This is meant to be used with a `with` block and yields
the path to a directory in which the tree by the given id should be
created. If a base_id is passed in, the tree is initialized with the
tree with the given id. Only when the block is exited successfully
is the tree written to the content store, referenced by the id in
question.

Use this in Pipeline.run() to avoid regenerating trees unneccessarily.
In order to trigger a regeneration, the content store must currently
be manually flushed.

Update the travis test to run the noop pipeline twice, verifying that
the stage is only run the first time.

Signed-off-by: Tom Gundersen <teg@jklm.no>
2019-08-01 22:39:52 +02:00

2.7 KiB

osbuild

A build system for operating system images, working towards an image build pipeline that's more comprehensible, reproducible, and extendable.

Pipelines

The build process for an image is described by a pipeline. Each stage in a pipeline is a program that, given some configuration, modifies a file system tree. Finally, an assembler takes a filesystem tree, and assembles it into an image. Pipelines are defined as JSON files like this one:

{
  "name": "Example Image",
  "stages": [
    {
      "name": "org.osbuild.dnf",
      "options": {
        "releasever": "30",
        "repos": {
          "fedora": {
            "name": "Fedora",
            "metalink": "https://mirrors.fedoraproject.org/metalink?repo=fedora-$releasever&arch=$basearch",
            "gpgkey": "file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-$releasever-$basearch"
          }
        },
        "packages": [ "@Core", "grub2-pc", "httpd" ]
        }
    },
    {
      "name": "org.osbuild.systemd",
      "options": {
        "enabled_services": [ "httpd" ]
      }
    },
    {
      "name": "org.osbuild.grub2",
      "options": {
        "root_fs_uuid": "76a22bf4-f153-4541-b6c7-0332c0dfaeac"
      }
    }
  ],
  "assembler": {
    "name": "io.weldr.qcow2",
    "options": {
      "filename": "example.qcow2",
      "root_fs_uuid": "76a22bf4-f153-4541-b6c7-0332c0dfaeac"
    }
  }
}

osbuild runs each of the stages in turn, isolating them from the host and from each other, with the exception that they all operate on the same filesystem-tree. The assembler is similarly isolated, and given the same tree, in read-only mode and assembles it into an image without altering its contents.

The filesystem tree produced by the final stage of a pipeline, is named and optionally saved to be reused as the base for future pipelines.

Each stage is passed the (appended) options object as JSON over stdin.

The above pipeline has no base and produces a qcow2 image.

Running

usage: python3 -m osbuild [-h] [--store DIRECTORY] [-l DIRECTORY] -o DIRECTORY
                   PIPELINE

Build operating system images

positional arguments:
  PIPELINE              json file containing the pipeline that should be built

optional arguments:
  -h, --help            show this help message and exit
  --store DIRECTORY   the directory where intermediary os trees are stored
  -l DIRECTORY, --libdir DIRECTORY
                        the directory containing stages, assemblers, and the
                        osbuild library

required named arguments:
  -o DIRECTORY, --output DIRECTORY
                        provide the empty DIRECTORY as output argument to the
                        last stage