stages/oci-archive: support additional layers

In addition to the required base layer, provided via the the input
of the same name, the oci-archive stage now accepts up to nine
additional layers that get added on top of each other, sorted in
ascending order, i.e. `layer.1` to `layer.9`.

Adapt the `fedora-ostree-container` example manifest so that the
ostree commit is now in a separate layer, which makes it possible
to share the base layer between different commits container.
This commit is contained in:
Christian Kellner 2021-02-16 22:11:16 +01:00 committed by Tom Gundersen
parent 47c15e5b41
commit d4ebbb821a
3 changed files with 47 additions and 12 deletions

View file

@ -5,6 +5,10 @@ Assemble an OCI image archive
Assemble an Open Container Initiative[1] image[2] archive, i.e. a Assemble an Open Container Initiative[1] image[2] archive, i.e. a
tarball whose contents is in the OCI image layout. tarball whose contents is in the OCI image layout.
The content of the container will consist of the base layer provided
via the `base` layer. On top of that further inputs provided via the
`layer.X` inputs that are sorted in ascending order.
Currently the only required options are `filename` and `architecture`. Currently the only required options are `filename` and `architecture`.
The execution parameters for the image, which then should form the base The execution parameters for the image, which then should form the base
for the container, can be given via `config`. They have the same format for the container, can be given via `config`. They have the same format
@ -34,7 +38,7 @@ import osbuild.api
DEFAULT_PATH = "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" DEFAULT_PATH = "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
SCHEMA_2 = """ SCHEMA_2 = r"""
"options": { "options": {
"additionalProperties": false, "additionalProperties": false,
"required": ["architecture", "filename"], "required": ["architecture", "filename"],
@ -104,7 +108,13 @@ SCHEMA_2 = """
"type": "object", "type": "object",
"additionalProperties": true "additionalProperties": true
} }
} },
"patternProperties": {
"layer\\.[1-9]\\d*": {
"type": "object",
"additionalProperties": true
}
}
} }
""" """
@ -208,7 +218,7 @@ def config_from_options(options):
return config return config
def create_oci_dir(tree, output_dir, options): def create_oci_dir(inputs, output_dir, options):
architecture = options["architecture"] architecture = options["architecture"]
config = { config = {
@ -237,11 +247,12 @@ def create_oci_dir(tree, output_dir, options):
os.makedirs(blobs) os.makedirs(blobs)
## layers / rootfs ## layers / rootfs
for ip in sorted(inputs.keys()):
tree = inputs[ip]["path"]
digest, info = blobs_add_layer(blobs, tree)
digest, info = blobs_add_layer(blobs, tree) config["rootfs"]["diff_ids"] = [digest]
manifest["layers"].append(info)
config["rootfs"]["diff_ids"] = [digest]
manifest["layers"].append(info)
## write config ## write config
info = blobs_add_json(blobs, config, "config") info = blobs_add_json(blobs, config, "config")
@ -262,15 +273,13 @@ def create_oci_dir(tree, output_dir, options):
def main(inputs, output_dir, options): def main(inputs, output_dir, options):
base = inputs["base"]["path"]
filename = options["filename"] filename = options["filename"]
with tempfile.TemporaryDirectory(dir=output_dir) as tmpdir: with tempfile.TemporaryDirectory(dir=output_dir) as tmpdir:
workdir = os.path.join(tmpdir, "output") workdir = os.path.join(tmpdir, "output")
os.makedirs(workdir) os.makedirs(workdir)
create_oci_dir(base, workdir, options) create_oci_dir(inputs, workdir, options)
command = [ command = [
"tar", "tar",

View file

@ -893,7 +893,13 @@
"options": { "options": {
"language": "en_US" "language": "en_US"
} }
}, }
]
},
{
"name": "container-ostree",
"build": "name:build",
"stages": [
{ {
"type": "org.osbuild.ostree.init", "type": "org.osbuild.ostree.init",
"options": { "options": {
@ -932,6 +938,13 @@
"references": [ "references": [
"name:container-tree" "name:container-tree"
] ]
},
"layer.1": {
"type": "org.osbuild.tree",
"origin": "org.osbuild.pipeline",
"references": [
"name:container-ostree"
]
} }
}, },
"options": { "options": {

View file

@ -169,7 +169,13 @@
"options": { "options": {
"language": "en_US" "language": "en_US"
} }
}, }
]
},
{
"name": "container-ostree",
"build": "name:build",
"stages": [
{ {
"type": "org.osbuild.ostree.init", "type": "org.osbuild.ostree.init",
"options": { "options": {
@ -208,6 +214,13 @@
"references": [ "references": [
"name:container-tree" "name:container-tree"
] ]
},
"layer.1": {
"type": "org.osbuild.tree",
"origin": "org.osbuild.pipeline",
"references": [
"name:container-ostree"
]
} }
}, },
"options": { "options": {