Skip to content

Commit

Permalink
bib: support multiple distro versions in a distrodef
Browse files Browse the repository at this point in the history
This commit adds support to support multiple versions of a distro in
a distrodef. This is required so that centos-10 can used as it has a
different packageset compared to centos-9.
  • Loading branch information
mvo5 authored and achilleas-k committed Aug 8, 2024
1 parent 1baf9f3 commit a283df4
Show file tree
Hide file tree
Showing 9 changed files with 16 additions and 15 deletions.
2 changes: 1 addition & 1 deletion bib/cmd/bootc-image-builder/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ func manifestForISO(c *ManifestConfig, rng *rand.Rand) (*manifest.Manifest, erro
return nil, fmt.Errorf("pipeline: no base image defined")
}

imageDef, err := distrodef.LoadImageDef(c.DistroDefPaths, c.SourceInfo.OSRelease.ID, "anaconda-iso")
imageDef, err := distrodef.LoadImageDef(c.DistroDefPaths, c.SourceInfo.OSRelease.ID, c.SourceInfo.OSRelease.VersionID, "anaconda-iso")
if err != nil {
return nil, err
}
Expand Down
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions bib/data/defs/fedora-41.yaml
1 change: 1 addition & 0 deletions bib/data/defs/rhel-9.yaml
1 change: 0 additions & 1 deletion bib/data/defs/rhel.yaml

This file was deleted.

16 changes: 7 additions & 9 deletions bib/internal/distrodef/distrodef.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package distrodef
import (
"fmt"
"os"
"path"
"path/filepath"
"strings"

"golang.org/x/exp/maps"
Expand All @@ -17,28 +17,26 @@ type ImageDef struct {
Packages []string `yaml:"packages"`
}

func loadFile(defDirs []string, distro string) ([]byte, error) {
func loadFile(defDirs []string, distro, ver string) ([]byte, error) {
for _, loc := range defDirs {
p := path.Join(loc, distro+".yaml")
p := filepath.Join(loc, fmt.Sprintf("%s-%s.yaml", distro, ver))
content, err := os.ReadFile(p)
if os.IsNotExist(err) {
continue
}
if err != nil {
return nil, fmt.Errorf("could not read def file %s for distro %s: %v", p, distro, err)
return nil, fmt.Errorf("could not read def file %s for distro %s-%s: %v", p, distro, ver, err)
}

return content, nil
}

return nil, fmt.Errorf("could not find def file for distro %s", distro)
return nil, fmt.Errorf("could not find def file for distro %s-%s", distro, ver)
}

// Loads a definition file for a given distro and image type
//
// TODO: We should probably support multiple distro versions as well in the future.
func LoadImageDef(defDirs []string, distro, it string) (*ImageDef, error) {
data, err := loadFile(defDirs, distro)
func LoadImageDef(defDirs []string, distro, ver, it string) (*ImageDef, error) {
data, err := loadFile(defDirs, distro, ver)
if err != nil {
return nil, err
}
Expand Down
10 changes: 6 additions & 4 deletions bib/internal/distrodef/distrodef_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,18 @@ import (
const testDefLocation = "test_defs"

func TestLoad(t *testing.T) {
def, err := LoadImageDef([]string{testDefLocation}, "fedoratest", "anaconda-iso")
def, err := LoadImageDef([]string{testDefLocation}, "fedoratest", "41", "anaconda-iso")
require.NoError(t, err)

assert.NotEmpty(t, def.Packages)
}

func TestLoadUnhappy(t *testing.T) {
_, err := LoadImageDef([]string{testDefLocation}, "lizard", "anaconda-iso")
assert.ErrorContains(t, err, "could not find def file for distro lizard")
_, err := LoadImageDef([]string{testDefLocation}, "lizard", "42", "anaconda-iso")
assert.ErrorContains(t, err, "could not find def file for distro lizard-42")
_, err = LoadImageDef([]string{testDefLocation}, "fedoratest", "0", "anaconda-iso")
assert.ErrorContains(t, err, "could not find def file for distro fedoratest-0")

_, err = LoadImageDef([]string{testDefLocation}, "fedoratest", "anaconda-disk")
_, err = LoadImageDef([]string{testDefLocation}, "fedoratest", "41", "anaconda-disk")
assert.ErrorContains(t, err, "could not find def for distro fedoratest and image type anaconda-disk")
}

0 comments on commit a283df4

Please sign in to comment.