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 <achilleas@koutsou.net>
This commit is contained in:
parent
f378209bf3
commit
af65baa6fe
2 changed files with 3 additions and 19 deletions
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue