Skip to content

Commit

Permalink
Allow the users to apply arbitrary images in framework-profile.yaml (#33
Browse files Browse the repository at this point in the history
)

so that they can force an older or newer release of one specific package

Signed-off-by: Dimitris Karakasilis <[email protected]>
  • Loading branch information
jimmykarily authored Jun 23, 2023
1 parent 03c6a9b commit 6d60329
Showing 1 changed file with 27 additions and 12 deletions.
39 changes: 27 additions & 12 deletions profile/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type profileDataStruct struct {

type profileFileStruct struct {
Common []string `yaml:"common"`
Images []string `yaml:"images"`
Flavors map[string][]string `yaml:"flavors"`
}

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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 {
Expand All @@ -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)
}

0 comments on commit 6d60329

Please sign in to comment.