mirror of
https://github.com/kairos-io/kairos-sdk.git
synced 2025-04-27 19:15:23 +00:00
Allow the users to apply arbitrary images in framework-profile.yaml (#33)
so that they can force an older or newer release of one specific package Signed-off-by: Dimitris Karakasilis <dimitris@karakasilis.me>
This commit is contained in:
parent
03c6a9b8f5
commit
6d60329315
@ -15,6 +15,7 @@ type profileDataStruct struct {
|
||||
|
||||
type profileFileStruct struct {
|
||||
Common []string `yaml:"common"`
|
||||
Images []string `yaml:"images"`
|
||||
Flavors map[string][]string `yaml:"flavors"`
|
||||
}
|
||||
|
||||
@ -44,13 +45,11 @@ func BuildFlavor(flavor string, profileFile string, directory string) error {
|
||||
allPackages = append(allPackages, packages...)
|
||||
}
|
||||
|
||||
common, err := readCommonPackages(profileFile)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error while reading common packs: %w", err)
|
||||
if err := populateProfile(profileFile, directory, append(allPackages, prof.Common...)); err != nil {
|
||||
return fmt.Errorf("error while populating profile: %w", err)
|
||||
}
|
||||
allPackages = append(allPackages, common...)
|
||||
|
||||
return populateProfile(profileFile, directory, allPackages)
|
||||
return applyImages(directory, prof.Images)
|
||||
}
|
||||
|
||||
func readProfilePackages(profile string, profileFile string) ([]string, error) {
|
||||
@ -84,20 +83,19 @@ func readProfilePackages(profile string, profileFile string) ([]string, error) {
|
||||
return res, fmt.Errorf("profile '%s' not found", profile)
|
||||
}
|
||||
|
||||
func readCommonPackages(profileFile string) ([]string, error) {
|
||||
res := []string{}
|
||||
func readProfile(profileFile string) (*profileFileStruct, error) {
|
||||
dat, err := os.ReadFile(profileFile)
|
||||
if err != nil {
|
||||
return res, fmt.Errorf("error while reading profile: %w", err)
|
||||
return nil, fmt.Errorf("error while reading profile: %w", err)
|
||||
}
|
||||
|
||||
prof := &profileFileStruct{}
|
||||
|
||||
if err := yaml.Unmarshal(dat, &prof); err != nil {
|
||||
return res, fmt.Errorf("error while unmarshalling profile: %w", err)
|
||||
return nil, fmt.Errorf("error while unmarshalling profile: %w", err)
|
||||
}
|
||||
|
||||
return prof.Common, nil
|
||||
return prof, nil
|
||||
}
|
||||
|
||||
func populateProfile(config string, directory string, packages []string) error {
|
||||
@ -112,16 +110,33 @@ func populateProfile(config string, directory string, packages []string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func applyImages(directory string, images []string) error {
|
||||
for _, img := range images {
|
||||
cmd := fmt.Sprintf("luet util unpack %s %s", img, directory)
|
||||
fmt.Println("running:", cmd)
|
||||
out, err := utils.SH(cmd)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error while running luet: %w (%s)", err, out)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func Build(profile string, profileFile string, directory string) error {
|
||||
packages, err := readProfilePackages(profile, profileFile)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error while reading profile: %w", err)
|
||||
}
|
||||
|
||||
common, err := readCommonPackages(profileFile)
|
||||
prof, err := readProfile(profileFile)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error while reading profile: %w", err)
|
||||
}
|
||||
|
||||
return populateProfile(profileFile, directory, append(packages, common...))
|
||||
if err := populateProfile(profileFile, directory, append(packages, prof.Common...)); err != nil {
|
||||
return fmt.Errorf("error while populating profile: %w", err)
|
||||
}
|
||||
|
||||
return applyImages(directory, prof.Images)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user