87 lines
2.9 KiB
Diff
87 lines
2.9 KiB
Diff
From 7e7b9627e08cde36feafa92338bf28040d61d333 Mon Sep 17 00:00:00 2001
|
|
From: Josue David Hernandez Gutierrez <josue.d.hernandez@oracle.com>
|
|
Date: Thu, 31 Oct 2024 01:58:42 +0000
|
|
Subject: [PATCH 7/8] Support using repository definitions with OCI variables.
|
|
|
|
We can use repository definitions in a format, more similar to generic Oracle repositories
|
|
with DNF vars.
|
|
Essentially in osbuild-composer log when parsing repos, we at first parse variables, then process
|
|
original repo file in memory and replace vars with their values and write modified repo to buffer.
|
|
After that we use buffer to actually populate repository data.
|
|
|
|
If we have failed to read ocidomain, which is the key variable, we fallback to values to generic public repos.
|
|
|
|
Signed-off-by: Alex Burmashev <alexander.burmashev@oracle.com>
|
|
Signed-off-by: Josue David Hernandez Gutierrez <josue.d.hernandez@oracle.com>
|
|
---
|
|
.../osbuild/images/pkg/rpmmd/repository.go | 41 ++++++++++++++++++-
|
|
1 file changed, 40 insertions(+), 1 deletion(-)
|
|
|
|
diff --git a/vendor/github.com/osbuild/images/pkg/rpmmd/repository.go b/vendor/github.com/osbuild/images/pkg/rpmmd/repository.go
|
|
index fe1d5d3..c95640d 100644
|
|
--- a/vendor/github.com/osbuild/images/pkg/rpmmd/repository.go
|
|
+++ b/vendor/github.com/osbuild/images/pkg/rpmmd/repository.go
|
|
@@ -9,6 +9,8 @@ import (
|
|
"strings"
|
|
"time"
|
|
|
|
+ "bufio"
|
|
+ "bytes"
|
|
"github.com/gobwas/glob"
|
|
)
|
|
|
|
@@ -231,12 +233,49 @@ func LoadRepositoriesFromFile(filename string) (map[string][]RepoConfig, error)
|
|
return nil, err
|
|
}
|
|
defer f.Close()
|
|
+ var ocidomain, ociregion, region []byte
|
|
|
|
+ var OCIlines []string
|
|
+ ocidomain = []byte("oracle.com")
|
|
+ ociregion = []byte("")
|
|
+ region = []byte("")
|
|
+
|
|
+ ociregion, err = os.ReadFile("/etc/dnf/vars/ociregion")
|
|
+ if err != nil {
|
|
+ fmt.Println("Error while reading file: /etc/dnf/vars/ociregion")
|
|
+ }
|
|
+ region, err = os.ReadFile("/etc/dnf/vars/region")
|
|
+ if err != nil {
|
|
+ fmt.Println("Error while reading file: /etc/dnf/vars/region")
|
|
+ }
|
|
+ ocidomain, err = os.ReadFile("/etc/dnf/vars/ocidomain")
|
|
+ if err != nil {
|
|
+ fmt.Println("Error while reading file: /etc/dnf/vars/ocidomain")
|
|
+ }
|
|
+ if ocidomain == nil {
|
|
+ ocidomain = []byte("oracle.com")
|
|
+ ociregion = []byte("")
|
|
+ }
|
|
+ scanner := bufio.NewScanner(f)
|
|
+ OCIreplacer := strings.NewReplacer("$ocidomain", strings.TrimSuffix(string(ocidomain), "\n"), "$ociregion", strings.TrimSuffix(string(ociregion), "\n"), "$region", strings.TrimSuffix(string(region), "\n"))
|
|
+ for scanner.Scan() {
|
|
+ line := scanner.Text()
|
|
+ OCIline := OCIreplacer.Replace(line)
|
|
+ OCIlines = append(OCIlines, OCIline)
|
|
+ continue
|
|
+ }
|
|
+ if err := scanner.Err(); err != nil {
|
|
+ panic(err)
|
|
+ }
|
|
+ fOCI := strings.Join(OCIlines, "\n")
|
|
var reposMap map[string][]repository
|
|
repoConfigs := make(map[string][]RepoConfig)
|
|
|
|
- err = json.NewDecoder(f).Decode(&reposMap)
|
|
+ buf := new(bytes.Buffer)
|
|
+ fmt.Fprint(buf, fOCI)
|
|
+ err = json.NewDecoder(buf).Decode(&reposMap)
|
|
if err != nil {
|
|
+ fmt.Println("Error parsing the repo")
|
|
return nil, err
|
|
}
|
|
|
|
--
|
|
2.43.5
|
|
|