From d4ebbb821a285edf8d8cd954e5de19d20f682ea9 Mon Sep 17 00:00:00 2001 From: Christian Kellner Date: Tue, 16 Feb 2021 22:11:16 +0100 Subject: [PATCH] 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. --- stages/org.osbuild.oci-archive | 29 ++++++++++++------- .../manifests/fedora-ostree-container.json | 15 +++++++++- .../fedora-ostree-container.mpp.json | 15 +++++++++- 3 files changed, 47 insertions(+), 12 deletions(-) diff --git a/stages/org.osbuild.oci-archive b/stages/org.osbuild.oci-archive index 945ec518..55df3038 100755 --- a/stages/org.osbuild.oci-archive +++ b/stages/org.osbuild.oci-archive @@ -5,6 +5,10 @@ Assemble an OCI image archive Assemble an Open Container Initiative[1] image[2] archive, i.e. a 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`. 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 @@ -34,7 +38,7 @@ import osbuild.api DEFAULT_PATH = "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" -SCHEMA_2 = """ +SCHEMA_2 = r""" "options": { "additionalProperties": false, "required": ["architecture", "filename"], @@ -104,7 +108,13 @@ SCHEMA_2 = """ "type": "object", "additionalProperties": true } - } + }, + "patternProperties": { + "layer\\.[1-9]\\d*": { + "type": "object", + "additionalProperties": true + } + } } """ @@ -208,7 +218,7 @@ def config_from_options(options): return config -def create_oci_dir(tree, output_dir, options): +def create_oci_dir(inputs, output_dir, options): architecture = options["architecture"] config = { @@ -237,11 +247,12 @@ def create_oci_dir(tree, output_dir, options): os.makedirs(blobs) ## 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 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): - base = inputs["base"]["path"] - filename = options["filename"] with tempfile.TemporaryDirectory(dir=output_dir) as tmpdir: workdir = os.path.join(tmpdir, "output") os.makedirs(workdir) - create_oci_dir(base, workdir, options) + create_oci_dir(inputs, workdir, options) command = [ "tar", diff --git a/test/data/manifests/fedora-ostree-container.json b/test/data/manifests/fedora-ostree-container.json index 82f9fa56..283820d9 100644 --- a/test/data/manifests/fedora-ostree-container.json +++ b/test/data/manifests/fedora-ostree-container.json @@ -893,7 +893,13 @@ "options": { "language": "en_US" } - }, + } + ] + }, + { + "name": "container-ostree", + "build": "name:build", + "stages": [ { "type": "org.osbuild.ostree.init", "options": { @@ -932,6 +938,13 @@ "references": [ "name:container-tree" ] + }, + "layer.1": { + "type": "org.osbuild.tree", + "origin": "org.osbuild.pipeline", + "references": [ + "name:container-ostree" + ] } }, "options": { diff --git a/test/data/manifests/fedora-ostree-container.mpp.json b/test/data/manifests/fedora-ostree-container.mpp.json index 8e848076..4f655972 100644 --- a/test/data/manifests/fedora-ostree-container.mpp.json +++ b/test/data/manifests/fedora-ostree-container.mpp.json @@ -169,7 +169,13 @@ "options": { "language": "en_US" } - }, + } + ] + }, + { + "name": "container-ostree", + "build": "name:build", + "stages": [ { "type": "org.osbuild.ostree.init", "options": { @@ -208,6 +214,13 @@ "references": [ "name:container-tree" ] + }, + "layer.1": { + "type": "org.osbuild.tree", + "origin": "org.osbuild.pipeline", + "references": [ + "name:container-ostree" + ] } }, "options": {