From af65baa6fe38364f28c1b6630ea1303c221091c6 Mon Sep 17 00:00:00 2001 From: Tomas Hozza Date: Wed, 24 Aug 2022 14:35:49 +0200 Subject: [PATCH] worker/osbuild: use `os-release` to determine host OS When running an osbuild job, we read `/etc/redhat-release` to get the host OS name to attach as metadata to the job result. Only Fedora and RHEL ship this file, which makes the osbuild job always fail on other distributions. The main reason to report host OS back to the worker server is due to Koji composes and the koji-finalize job, which pushes it to Koji. The motivation is to have enough information to potentially re-instantiate / identify the original builder host OS. There are no specific requirements on the string. Modify the code to use `/etc/os-release` to determine the host OS. Fall back to using `linux` as the host OS, in case reading `os-release` fails, log the error and continue with the job. The `linux` fallback is suggested by the `os-release` spec [1] [1] https://www.freedesktop.org/software/systemd/man/os-release.html#ID= Co-authored-by: Achilleas Koutsou --- cmd/osbuild-worker/jobimpl-osbuild.go | 6 +++--- internal/common/distro.go | 16 ---------------- 2 files changed, 3 insertions(+), 19 deletions(-) diff --git a/cmd/osbuild-worker/jobimpl-osbuild.go b/cmd/osbuild-worker/jobimpl-osbuild.go index 2536a8b41..c3fcddaeb 100644 --- a/cmd/osbuild-worker/jobimpl-osbuild.go +++ b/cmd/osbuild-worker/jobimpl-osbuild.go @@ -246,10 +246,10 @@ func (impl *OSBuildJobImpl) Run(job worker.Job) error { Arch: common.CurrentArch(), } - hostOS, err := common.GetRedHatRelease() + hostOS, _, _, err := common.GetHostDistroName() if err != nil { - osbuildJobResult.JobError = clienterrors.WorkerClientError(clienterrors.ErrorBuildJob, err.Error(), nil) - return nil + logWithId.Warnf("Failed to get host distro name: %v", err) + hostOS = "linux" } osbuildJobResult.HostOS = hostOS diff --git a/internal/common/distro.go b/internal/common/distro.go index e4202c0ad..ade88be36 100644 --- a/internal/common/distro.go +++ b/internal/common/distro.go @@ -3,9 +3,7 @@ package common import ( "bufio" "errors" - "fmt" "io" - "io/ioutil" "os" "strings" ) @@ -31,20 +29,6 @@ func GetHostDistroName() (string, bool, bool, error) { return name, beta, isStream, nil } -// GetRedHatRelease returns the content of /etc/redhat-release -// without the trailing new-line. -func GetRedHatRelease() (string, error) { - raw, err := ioutil.ReadFile("/etc/redhat-release") - if err != nil { - return "", fmt.Errorf("cannot read /etc/redhat-release: %v", err) - } - - //Remove the trailing new-line. - redHatRelease := strings.TrimSpace(string(raw)) - - return redHatRelease, nil -} - func readOSRelease(r io.Reader) (map[string]string, error) { osrelease := make(map[string]string) scanner := bufio.NewScanner(r)