koji: use the host name from /etc/redhat-release in CGImport metadata

As suggested by Brew maintainers Tomáš Kopeček and Lubomír Sedlář.
This commit is contained in:
Ondřej Budai 2020-10-22 13:05:53 +02:00 committed by Tom Gundersen
parent 3480fe3093
commit c64d46416e
2 changed files with 23 additions and 1 deletions

View file

@ -19,6 +19,7 @@ import (
"github.com/google/uuid"
"github.com/osbuild/osbuild-composer/internal/common"
"github.com/osbuild/osbuild-composer/internal/distro"
"github.com/osbuild/osbuild-composer/internal/osbuild"
"github.com/osbuild/osbuild-composer/internal/target"
"github.com/osbuild/osbuild-composer/internal/upload/awsupload"
@ -236,6 +237,12 @@ func RunJob(job worker.Job, store string, kojiServers map[string]koji.GSSAPICred
continue
}
hostOS, err := distro.GetRedHatRelease()
if err != nil {
r = append(r, err)
continue
}
build := koji.ImageBuild{
BuildID: options.BuildID,
TaskID: options.TaskID,
@ -249,7 +256,7 @@ func RunJob(job worker.Job, store string, kojiServers map[string]koji.GSSAPICred
{
ID: 1,
Host: koji.Host{
Os: "RHEL8",
Os: hostOS,
Arch: "noarch",
},
ContentGenerator: koji.ContentGenerator{

View file

@ -6,6 +6,7 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"os"
"sort"
"strings"
@ -193,6 +194,20 @@ func GetHostDistroName() (string, bool, error) {
return name, beta, 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)