Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add fedora repo support for eext #119

Merged
merged 3 commits into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cmd/testData/mrtparse-2/eext.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ package:
repo-bundle:
- name: el9
version: 9.1
priority: 2
50 changes: 49 additions & 1 deletion configfiles/dnfconfig.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
# yamllint disable rule:line-length
repo-bundle:
# --------------------------------------------------------------------------------------------

Check warning on line 4 in configfiles/dnfconfig.yaml

View workflow job for this annotation

GitHub Actions / Lint

4:1 [comments-indentation] comment not indented like content
# The defaults for this bundle points to the second most recent stable dot release 9.x.
# Upstream vaults/freezes the previous release repo once a new dot release is stable.
# The newest stable dot release keeps on receiving updates, so we use the previous one
Expand All @@ -23,7 +23,8 @@
enabled: false
version-labels:
default: 9.3
priority: 2
# --------------------------------------------------------------------------------------------

Check warning on line 27 in configfiles/dnfconfig.yaml

View workflow job for this annotation

GitHub Actions / Lint

27:1 [comments-indentation] comment not indented like content

# --------------------------------------------------------------------------------------------
epel9:
Expand All @@ -43,13 +44,14 @@
# The eext team is responsible for creating these snapshots.
# default points to the latest such snapshot.
default: v20240522-1
priority: 2
# --------------------------------------------------------------------------------------------

Check warning on line 48 in configfiles/dnfconfig.yaml

View workflow job for this annotation

GitHub Actions / Lint

48:1 [comments-indentation] comment not indented like content

# ********************************************************************************************
# DO NOT use any repo bundles below this unless you know what you're doing.
# ********************************************************************************************

#---------------------------------------------------------------------------------------------

Check warning on line 54 in configfiles/dnfconfig.yaml

View workflow job for this annotation

GitHub Actions / Lint

54:2 [comments] missing starting space in comment
el9-snapshot:
# DO NOT use el9-snapshot as a repo-bundle in your eext.yaml, unless recommended to you by the eext team.
# el9-snapshot is a snapshot of the repo cache of el9-unsafe.
Expand All @@ -57,7 +59,7 @@

gpgcheck: true
gpgkey: file:///usr/share/distribution-gpg-keys/alma/RPM-GPG-KEY-AlmaLinux-9
baseurl: '{{.Host}}/artifactory/eext-snapshots-local/el9/{{.Version}}/9/{{.RepoName}}/{{.Arch}}/os'
baseurl: "{{.Host}}/artifactory/eext-snapshots-local/el9/{{.Version}}/9/{{.RepoName}}/{{.Arch}}/os"
repo:
AppStream:
enabled: true
Expand All @@ -69,7 +71,27 @@
enabled: false
extras:
enabled: false
priority: 2
#---------------------------------------------------------------------------------------------

Check warning on line 75 in configfiles/dnfconfig.yaml

View workflow job for this annotation

GitHub Actions / Lint

75:2 [comments] missing starting space in comment

Check warning on line 75 in configfiles/dnfconfig.yaml

View workflow job for this annotation

GitHub Actions / Lint

75:1 [comments-indentation] comment not indented like content

#---------------------------------------------------------------------------------------------

Check warning on line 77 in configfiles/dnfconfig.yaml

View workflow job for this annotation

GitHub Actions / Lint

77:2 [comments] missing starting space in comment
fc40-snapshot:
# DO NOT use fc40-snapshot as a repo-bundle in your eext.yaml,
# unless recommended to you by the eext team.
# The eext team is responsible for creating these snapshots.

gpgcheck: true
gpgkey: file:///usr/share/distribution-gpg-keys/fedora/RPM-GPG-KEY-fedora-40-primary

# fc40 publishes i686 RPMS in x86_64 repo. This ensures that we point to the x86_64 repo
# when target is i686.
use-base-arch: true
baseurl: "{{.Host}}/artifactory/eext-snapshots-local/fc40/{{.Version}}/{{.RepoName}}/40/Everything/{{.Arch}}/os"
repo:
releases:
enabled: true
priority: 3
#---------------------------------------------------------------------------------------------

Check warning on line 94 in configfiles/dnfconfig.yaml

View workflow job for this annotation

GitHub Actions / Lint

94:2 [comments] missing starting space in comment

Check warning on line 94 in configfiles/dnfconfig.yaml

View workflow job for this annotation

GitHub Actions / Lint

94:1 [comments-indentation] comment not indented like content

# --------------------------------------------------------------------------------------------
el9-unsafe:
Expand Down Expand Up @@ -98,7 +120,8 @@
# default=9 always points to upstream latest dot release 9.x,
# which upstream updates regularly.
default: 9
priority: 2
# --------------------------------------------------------------------------------------------

Check warning on line 124 in configfiles/dnfconfig.yaml

View workflow job for this annotation

GitHub Actions / Lint

124:1 [comments-indentation] comment not indented like content

# --------------------------------------------------------------------------------------------
el9-beta-unsafe:
Expand Down Expand Up @@ -127,6 +150,7 @@
# default always points to upstream latest dot release 9.x's beta version,
# which upstream updates regularly.
default: 9.4-beta
priority: 2
# --------------------------------------------------------------------------------------------

# --------------------------------------------------------------------------------------------
Expand All @@ -151,6 +175,7 @@
version-labels:
# default always points to upstream stable repo which receives updates.
default: 9
priority: 2
# --------------------------------------------------------------------------------------------

# --------------------------------------------------------------------------------------------
Expand All @@ -174,4 +199,27 @@
version-labels:
# default always points to upstream next/beta repo which receives updates.
default: 9
priority: 2
# --------------------------------------------------------------------------------------------

#---------------------------------------------------------------------------------------------
fc40-unsafe:
# DO NOT use fc40-unsafe as a repo-bundle in your eext.yaml
# unless you know what you're doing. Use fc40-snapshot instead because this
# will ensure build reproducibility.
# fc40-unsafe is used by the eext team for experiments.

gpgcheck: true
gpgkey: file:///usr/share/distribution-gpg-keys/fedora/RPM-GPG-KEY-fedora-40-primary

# fc40 publishes i686 RPMS in x86_64 repo. This ensures that we point to the x86_64 repo
# when target is i686.
use-base-arch: true
baseurl: "{{.Host}}/artifactory/eext-fedora-linux/{{.RepoName}}/{{.Version}}/Everything/{{.Arch}}/os"
repo:
releases:
enabled: true
version-labels:
default: 40
priority: 3
#---------------------------------------------------------------------------------------------
32 changes: 32 additions & 0 deletions dnfconfig/defaultconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,38 @@ func TestDefaultDnfRepoConfig(t *testing.T) {
},
defaultVersion: "9",
},
"fc40-unsafe": ExpectedDefaultRepoBundle{
repoToURLFormatString: map[string]string{
"releases": "%s/artifactory/%s/releases/%s/Everything/%s/os",
},
archToArtifactoryRepo: map[string]string{
"i686": "eext-fedora-linux",
"x86_64": "eext-fedora-linux",
"aarch64": "eext-fedora-linux",
},
archToURLFormatArch: map[string]string{
"i686": "x86_64", // baseArch
"x86_64": "x86_64",
"aarch64": "aarch64",
},
defaultVersion: "40",
},
"fc40-snapshot": ExpectedDefaultRepoBundle{
repoToURLFormatString: map[string]string{
"releases": "%s/artifactory/%s/fc40/default/releases/%s/Everything/%s/os",
},
archToArtifactoryRepo: map[string]string{
"i686": "eext-snapshots-local",
"x86_64": "eext-snapshots-local",
"aarch64": "eext-snapshots-local",
},
archToURLFormatArch: map[string]string{
"i686": "x86_64", // baseArch
"x86_64": "x86_64",
"aarch64": "aarch64",
},
defaultVersion: "40",
},
}

t.Log("Testing expected defaults")
Expand Down
44 changes: 36 additions & 8 deletions dnfconfig/dnfconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package dnfconfig
import (
"bytes"
"fmt"
"io/ioutil"
"os"
"text/template"

Expand All @@ -17,8 +16,7 @@ import (
)

const (
RepoHighPriority int = 1
RepoStandardPriority = 2
RepoHighPriority int = 1
)

// DnfRepoConfig holds baseURL format template(/string)
Expand All @@ -35,6 +33,7 @@ type DnfRepoBundleConfig struct {
UseBaseArch bool `yaml:"use-base-arch"`
DnfRepoConfig map[string]*DnfRepoConfig `yaml:"repo"`
VersionLabels map[string]string `yaml:"version-labels"`
Priority int `yaml:"priority"`
baseURLFormatTemplate *template.Template
}

Expand All @@ -54,8 +53,9 @@ type DnfRepoURLData struct {
// RepoParamsOverride spec
// this is used to override default parameters for repos in the bundle.
type DnfRepoParamsOverride struct {
Enabled bool `yaml:"enabled"`
Exclude string `yaml:"exclude"`
Enabled bool `yaml:"enabled"`
Exclude string `yaml:"exclude"`
Priority int `yaml:"priority"`
}

// RepoData holds dnf repo name and baseurl for mock.cfg generation
Expand Down Expand Up @@ -149,14 +149,31 @@ func (b *DnfRepoBundleConfig) GetDnfRepoParams(
return nil, err
}

repoBundlePriority := b.Priority

var enabled bool
var exclude string
var priority int
repoOverride, isOverride := repoOverrides[repoName]
if isOverride {
enabled = repoOverride.Enabled
exclude = repoOverride.Exclude
priorityOverride := repoOverride.Priority
if priorityOverride == 0 {
// If repo priority not set, use repo-bundle priority
priority = repoBundlePriority
} else {
if priorityOverride > 1 {
priority = priorityOverride
} else if priorityOverride == 1 {
return nil, fmt.Errorf("%sRepo %s priority cannot be 1. Provide a priority > 1", errPrefix, repoName)
} else {
return nil, fmt.Errorf("%sInvaid repo priority %d. Provide a priority > 1", errPrefix, priorityOverride)
}
}
} else {
enabled = repoConfig.Enabled
priority = repoBundlePriority
}

return &DnfRepoParams{
Expand All @@ -166,7 +183,7 @@ func (b *DnfRepoBundleConfig) GetDnfRepoParams(
Exclude: exclude,
GpgCheck: b.GpgCheck,
GpgKey: b.GpgKey,
Priority: RepoStandardPriority,
Priority: priority,
}, nil
}

Expand All @@ -185,9 +202,9 @@ func LoadDnfConfig() (*DnfConfig, error) {
cfgPath, statErr)
}

yamlContents, readErr := ioutil.ReadFile(cfgPath)
yamlContents, readErr := os.ReadFile(cfgPath)
if readErr != nil {
return nil, fmt.Errorf("dnfconfig.LoadDnfConfig: ioutil.ReadFile on %s returned %s",
return nil, fmt.Errorf("dnfconfig.LoadDnfConfig: os.ReadFile on %s returned %s",
cfgPath, readErr)
}

Expand All @@ -206,6 +223,17 @@ func LoadDnfConfig() (*DnfConfig, error) {
repoBundleConfig.BaseURLFormat, bundleName)
}
repoBundleConfig.baseURLFormatTemplate = t

priority := repoBundleConfig.Priority
if priority == 0 {
return nil, fmt.Errorf("dnfconfig.LoadDnfConfig: Priority not set. Please provide a valid priority > 1")
} else if priority == 1 {
return nil, fmt.Errorf(
"dnfconfig.LoadDnfConfig: Priority 1 is reserved for local deps, please provide a priority > 1")
} else if priority < 0 {
return nil, fmt.Errorf(
"dnfconfig.LoadDnfConfig: Wrong priority %d provided Please provide a valid priority > 1", priority)
}
}
return &config, nil
}
2 changes: 2 additions & 0 deletions dnfconfig/testData/sample-dnfconfig.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ repo-bundle:
version-labels:
latest: 999
default: 1
priority: 2
bundle2:
baseurl: "{{.Host}}/bundle2-{{.Version}}/{{.RepoName}}/{{.Arch}}/"
use-base-arch: true
Expand All @@ -23,3 +24,4 @@ repo-bundle:
version-labels:
latest: 999
default: 1
priority: 3
3 changes: 3 additions & 0 deletions impl/testData/dnfconfig.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ repo-bundle:
enabled: true
version-labels:
default: v1
priority: 2
bundle-boo2:
baseurl: "{{.Host}}/boo2-{{.Version}}/{{.RepoName}}/{{.Arch}}/"
use-base-arch: true
Expand All @@ -24,6 +25,7 @@ repo-bundle:
version-labels:
default: v1
latest: v3
priority: 2
bundle-boo3:
baseurl: "{{.Host}}/boo3-{{.Version}}/{{.RepoName}}/{{.Arch}}/"
repo:
Expand All @@ -32,3 +34,4 @@ repo-bundle:
version-labels:
default: v1
latest: v3
priority: 3
2 changes: 1 addition & 1 deletion impl/testData/expected-mock.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ baseurl = https://foo.org/boo1-v1/repo-roo12/x86_64/
enabled = 0
gpgcheck = 1
gpgkey = file:///keyfile
priority = 2
priority = 3

[repo-roo13]
name = repo-roo13
Expand Down
1 change: 1 addition & 0 deletions impl/testData/manifest-with-deps.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ package:
exclude: "roo1-rpm.rpm"
repo-roo12:
enabled: false
priority: 3
- name: bundle-boo2
version: v2
- name: bundle-boo2
Expand Down
1 change: 1 addition & 0 deletions impl/testData/manifest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ package:
exclude: "roo1-rpm.rpm"
repo-roo12:
enabled: false
priority: 3
- name: bundle-boo2
version: v2
- name: bundle-boo2
Expand Down
1 change: 1 addition & 0 deletions manifest/testData/sampleManifest1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ package:
rfoo:
enabled: true
exclude: "rfoo.rpm"
priority: 4
- name: bar
- name: tcpdump
upstream-sources:
Expand Down
Loading