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.
This commit is contained in:
Lars Karlitski 2020-02-28 11:15:36 +01:00 committed by Tom Gundersen
parent c5b31ff2ac
commit a578a2b7e7
3 changed files with 28 additions and 20 deletions

2
.gitignore vendored
View file

@ -10,8 +10,6 @@ __pycache__
/test/.vagrant
/runners/org.osbuild.host
/.vscode
/.idea
/.gdb_history

View file

@ -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

View file

@ -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)