From a578a2b7e714fffdc03bbe1101f7bdd6d6488d42 Mon Sep 17 00:00:00 2001 From: Lars Karlitski Date: Fri, 28 Feb 2020 11:15:36 +0100 Subject: [PATCH] pipeline: detect host instead of using org.osbuild.host Detect the host dynamically from os-release(5) instead of relying on the `org.osbuild.host` symlink. It is awkward to install a symlink that tells osbuild which distro is is running on, when there is a standard way to detect this. This makes it easier to run osbuild from sources and removes the need to include every host in the spec file. The latter became hard to do, because there's no obvious way to distinguish RHEL minor releases. --- .gitignore | 2 -- osbuild.spec | 17 ----------------- osbuild/pipeline.py | 29 ++++++++++++++++++++++++++++- 3 files changed, 28 insertions(+), 20 deletions(-) diff --git a/.gitignore b/.gitignore index a4d4ca6c..469eb009 100644 --- a/.gitignore +++ b/.gitignore @@ -10,8 +10,6 @@ __pycache__ /test/.vagrant -/runners/org.osbuild.host - /.vscode /.idea /.gdb_history diff --git a/osbuild.spec b/osbuild.spec index 23eb2be9..4f21f09c 100644 --- a/osbuild.spec +++ b/osbuild.spec @@ -70,23 +70,6 @@ install -p -m 0755 $(find sources -type f) %{buildroot}%{pkgdir}/sources mkdir -p %{buildroot}%{pkgdir}/stages/osbuild mkdir -p %{buildroot}%{pkgdir}/assemblers/osbuild -# install host runner -%if 0%{?fc30} -ln -s org.osbuild.fedora30 %{buildroot}%{pkgdir}/runners/org.osbuild.host -%endif -%if 0%{?fc31} -ln -s org.osbuild.fedora31 %{buildroot}%{pkgdir}/runners/org.osbuild.host -%endif -%if 0%{?fc32} -ln -s org.osbuild.fedora32 %{buildroot}%{pkgdir}/runners/org.osbuild.host -%endif -%if 0%{?fc33} -ln -s org.osbuild.fedora33 %{buildroot}%{pkgdir}/runners/org.osbuild.host -%endif -%if 0%{?el8} -ln -s org.osbuild.rhel82 %{buildroot}%{pkgdir}/runners/org.osbuild.host -%endif - %check exit 0 # We have some integration tests, but those require running a VM, so that would diff --git a/osbuild/pipeline.py b/osbuild/pipeline.py index a435141c..abf3ce40 100644 --- a/osbuild/pipeline.py +++ b/osbuild/pipeline.py @@ -314,6 +314,33 @@ class Pipeline: return results +def detect_os(*paths): + """Detect the os from an os-release file. + + The first file in 'paths' is used and interpreted like a os-release(5) + file. + + Returns ID + VERSION_ID (without dots), which is the same format that + runners are named as. + """ + path = next((p for p in paths if os.path.exists(p)), None) + if not path: + raise FileNotFoundError("none of the specified os-release files exist") + + with open(path) as f: + osrelease = {} + for line in f: + line = line.strip() + if not line: + continue + if line[0] == "#": + continue + key, value = line.split("=", 1) + osrelease[key] = value.strip('"') + + return osrelease["ID"] + osrelease["VERSION_ID"].replace(".", "") + + def load_build(description, sources_options): pipeline = description.get("pipeline") if pipeline: @@ -329,7 +356,7 @@ def load(description, sources_options): if build: build_pipeline, runner = load_build(build, sources_options) else: - build_pipeline, runner = None, "org.osbuild.host" + build_pipeline, runner = None, "org.osbuild." + detect_os("/etc/os-release", "/usr/lib/os-release") pipeline = Pipeline(runner, build_pipeline)