From 7ffae5669cc230e6656fc42218bb142cc5c56626 Mon Sep 17 00:00:00 2001 From: Christian Kellner Date: Mon, 1 Feb 2021 18:43:18 +0000 Subject: [PATCH] osbuild: convert ostree stage to inputs Convert the `org.osbuild.ostree` stage to use inputs instead of sources. In the format (version 1) loading code, convert the stage to use an input based on the existing stage options. --- osbuild/formats/v1.py | 6 ++++++ stages/org.osbuild.ostree | 32 ++++++++++++++++++-------------- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/osbuild/formats/v1.py b/osbuild/formats/v1.py index b7bba23c..422f336c 100644 --- a/osbuild/formats/v1.py +++ b/osbuild/formats/v1.py @@ -96,6 +96,12 @@ def load_stage(description: Dict, index: Index, pipeline: Pipeline): options = {"metadata": {"rpm.check_gpg": gpg}} pkg = pkg["checksum"] ip.add_reference(pkg, options) + elif stage.name == "org.osbuild.ostree": + info = index.get_module_info("Input", "org.osbuild.ostree") + ip = stage.add_input("commits", info, "org.osbuild.source") + commit, ref = opts["commit"], opts.get("ref") + options = {"ref": ref} if ref else None + ip.add_reference(commit, options) def load_pipeline(description: Dict, index: Index, manifest: Manifest, n: int = 0) -> Pipeline: diff --git a/stages/org.osbuild.ostree b/stages/org.osbuild.ostree index bd6fb3a0..fe900553 100755 --- a/stages/org.osbuild.ostree +++ b/stages/org.osbuild.ostree @@ -27,7 +27,6 @@ import sys import subprocess import osbuild.api -import osbuild.sources from osbuild.util import selinux @@ -217,32 +216,37 @@ def populate_var(sysroot): raise RuntimeError(f"Failed to provision /var/{target}") +def parse_input(inputs): + commits = inputs["commits"] + data = commits["data"] + refs = data["refs"] + assert refs, "Need at least one commit" + return commits["path"], data["refs"] + + # pylint: disable=too-many-statements -def main(tree, sources, options): - commit = options["commit"] +def main(tree, inputs, options): + source_repo, commits = parse_input(inputs) osname = options["osname"] rootfs = options.get("rootfs") mounts = options.get("mounts", []) kopts = options.get("kernel_opts", []) - ref = options.get("ref", commit) remotes = options.get("remotes", []) pop_var = options.get("populate_var", False) ostree("admin", "init-fs", "--modern", tree, sysroot=tree) - print(f"Fetching ostree commit {commit}") - osbuild.sources.get("org.osbuild.ostree", [commit]) + ref, commit = None, None # keep pylint happy + for commit, data in commits.items(): + ref = data.get("ref", commit) - source_repo = f"{sources}/org.osbuild.ostree/repo" - - ostree("pull-local", source_repo, commit, - repo=f"{tree}/ostree/repo") - - if ref != commit: - ostree("refs", "--create", ref, commit, + ostree("pull-local", source_repo, ref, repo=f"{tree}/ostree/repo") + #NB: if there are multiple commits, we deploy only + # the latest one + ostree("admin", "os-init", osname, sysroot=tree) # this created a state root at `osname` stateroot = f"{tree}/ostree/deploy/{osname}" @@ -335,6 +339,6 @@ def main(tree, sources, options): if __name__ == '__main__': stage_args = osbuild.api.arguments() r = main(stage_args["tree"], - stage_args["sources"], + stage_args["inputs"], stage_args["options"]) sys.exit(r)