Skip to content

Commit 5745939

Browse files
committed
bib: add support for ID_LIKE when finding the distro YAML
This commit adds a fallback check when no direct match for the distro ID from the bootc image is found. As long as the bootc container sets a correct `ID_LIKE` we should automatically have the same behavior as before when we used symlinks as aliases. If needed we might need to reintroduce an explicit mapping like: ```go // mapping of distro IDs that are compatible with var distroCompat = map[string]string{ "almalinux": "rhel", "aurora": "fedora", "aurora-helium": "rhel", "bazzite": "fedora", "bluefin": "fedora", "heliumos": "rhel", "rocky": "rhel", } ``` but lets hope we don't need this. Note that these tests use the "real" distros.yaml from the images library so make sure that if rhel-9 goes away the test is updated for rhel-XY (only the version needs to change)
1 parent 64c5dc5 commit 5745939

File tree

3 files changed

+76
-9
lines changed

3 files changed

+76
-9
lines changed

bib/cmd/bootc-image-builder/export_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ var (
55
GetDistroAndRunner = getDistroAndRunner
66
CreateRand = createRand
77
BuildCobraCmdline = buildCobraCmdline
8+
NewDistroYAMLFrom = newDistroYAMLFrom
89
)
910

1011
func MockOsGetuid(new func() int) (restore func()) {

bib/cmd/bootc-image-builder/legacy_iso.go

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -222,22 +222,37 @@ func labelForISO(os *osinfo.OSRelease, arch *arch.Arch) string {
222222
}
223223
}
224224

225+
// newDistroYAMLFrom() returns the distroYAML for the given sourceInfo,
226+
// if no direct match can be found it will it will use the ID_LIKE.
227+
// This should ensure we work on every bootc image that puts a correct
228+
// ID_LIKE= in /etc/os-release
229+
func newDistroYAMLFrom(sourceInfo *osinfo.Info) (*defs.DistroYAML, *distro.ID, error) {
230+
for _, distroID := range append([]string{sourceInfo.OSRelease.ID}, sourceInfo.OSRelease.IDLike...) {
231+
nameVer := fmt.Sprintf("%s-%s", distroID, sourceInfo.OSRelease.VersionID)
232+
id, err := distro.ParseID(nameVer)
233+
if err != nil {
234+
return nil, nil, err
235+
}
236+
distroYAML, err := defs.NewDistroYAML(nameVer)
237+
if err != nil {
238+
return nil, nil, err
239+
}
240+
if distroYAML != nil {
241+
return distroYAML, id, nil
242+
}
243+
}
244+
return nil, nil, fmt.Errorf("cannot load distro definitions for %s-%s or any of %v", sourceInfo.OSRelease.ID, sourceInfo.OSRelease.VersionID, sourceInfo.OSRelease.IDLike)
245+
}
246+
225247
func manifestForISO(c *ManifestConfig, rng *rand.Rand) (*manifest.Manifest, error) {
226248
if c.Imgref == "" {
227249
return nil, fmt.Errorf("pipeline: no base image defined")
228250
}
229-
230-
nameVer := fmt.Sprintf("%s-%s", c.SourceInfo.OSRelease.ID, c.SourceInfo.OSRelease.VersionID)
231-
id, err := distro.ParseID(nameVer)
232-
if err != nil {
233-
return nil, err
234-
}
235-
// XXX: ensure all aliases we have for bib are available in
236-
// images
237-
distroYAML, err := defs.NewDistroYAML(nameVer)
251+
distroYAML, id, err := newDistroYAMLFrom(c.SourceInfo)
238252
if err != nil {
239253
return nil, err
240254
}
255+
241256
// XXX: or "bootc-legacy-installer"?
242257
installerImgTypeName := "bootc-rpm-installer"
243258
imgType, ok := distroYAML.ImageTypes()[installerImgTypeName]
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package main_test
2+
3+
import (
4+
"testing"
5+
6+
"github.com/stretchr/testify/assert"
7+
8+
"github.com/osbuild/images/pkg/bib/osinfo"
9+
"github.com/osbuild/images/pkg/distro"
10+
11+
main "github.com/osbuild/bootc-image-builder/bib/cmd/bootc-image-builder"
12+
)
13+
14+
func TestNewDistroYAMLFromError(t *testing.T) {
15+
si := &osinfo.Info{
16+
OSRelease: osinfo.OSRelease{
17+
ID: "weirdos",
18+
VersionID: "2.71",
19+
IDLike: []string{"waffleos", "barky"},
20+
},
21+
}
22+
_, _, err := main.NewDistroYAMLFrom(si)
23+
assert.EqualError(t, err, "cannot load distro definitions for weirdos-2.71 or any of [waffleos barky]")
24+
}
25+
26+
func TestNewDistroYAMLFromDirect(t *testing.T) {
27+
si := &osinfo.Info{
28+
OSRelease: osinfo.OSRelease{
29+
ID: "centos",
30+
VersionID: "10",
31+
},
32+
}
33+
distroYAML, id, err := main.NewDistroYAMLFrom(si)
34+
assert.NoError(t, err)
35+
assert.Equal(t, &distro.ID{Name: "centos", MajorVersion: 10, MinorVersion: -1}, id)
36+
assert.Equal(t, "centos-10", distroYAML.Name)
37+
}
38+
39+
func TestNewDistroYAMLFromFallback(t *testing.T) {
40+
si := &osinfo.Info{
41+
OSRelease: osinfo.OSRelease{
42+
ID: "blmblinux",
43+
VersionID: "9.6",
44+
IDLike: []string{"non-existing", "rhel", "centos", "fedora"},
45+
},
46+
}
47+
distroYAML, id, err := main.NewDistroYAMLFrom(si)
48+
assert.NoError(t, err)
49+
assert.Equal(t, &distro.ID{Name: "rhel", MajorVersion: 9, MinorVersion: 6}, id)
50+
assert.Equal(t, "rhel-9.6", distroYAML.Name)
51+
}

0 commit comments

Comments
 (0)