Skip to content

Update redhatrelease to detect Alma Linux and have osrelease ignore it #892

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

Closed
wants to merge 1 commit into from
Closed
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 ext/featurens/osrelease/osrelease.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
var (
// blocklistFilenames are files that should exclude this detector.
blocklistFilenames = []string{
"etc/almalinux-release",
"etc/alpine-release",
"etc/centos-release",
"etc/fedora-release",
Expand Down
12 changes: 11 additions & 1 deletion ext/featurens/redhatrelease/redhatrelease.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,15 @@ import (
)

var (
almaReleaseRegexp = regexp.MustCompile(`(?P<os>AlmaLinux) (release) (?P<version>[\d]+)`)
amazonReleaseRegexp = regexp.MustCompile(`(?P<os>Amazon) (Linux release|Linux AMI release) (?P<version>[\d]+\.[\d]+|[\d]+)`)
oracleReleaseRegexp = regexp.MustCompile(`(?P<os>Oracle) (Linux Server release) (?P<version>[\d]+)`)
centosReleaseRegexp = regexp.MustCompile(`(?P<os>[^\s]*) (Linux release|release) (?P<version>[\d]+)`)
redhatReleaseRegexp = regexp.MustCompile(`(?P<os>Red Hat Enterprise Linux) (Client release|Server release|Workstation release|release) (?P<version>[\d]+)`)
rockyReleaseRegexp = regexp.MustCompile(`(?P<os>Rocky) (Linux release) (?P<version>[\d]+)`)

// RequiredFilenames defines the names of the files required to identify the RHEL-based release.
RequiredFilenames = []string{"etc/oracle-release", "etc/centos-release", "etc/redhat-release", "etc/rocky-release", "etc/system-release"}
RequiredFilenames = []string{"etc/almalinux-release", "etc/oracle-release", "etc/centos-release", "etc/redhat-release", "etc/rocky-release", "etc/system-release"}
)

type detector struct{}
Expand All @@ -55,6 +56,15 @@ func (d detector) Detect(files analyzer.Files, opts *featurens.DetectorOptions)

var r []string

// Attempt to match Alma Linux.
r = almaReleaseRegexp.FindStringSubmatch(string(f.Contents))
if len(r) == 4 {
return &database.Namespace{
Name: "alma:" + r[3],
VersionFormat: rpm.ParserName,
}
}

// Attempt to match Amazon Linux.
r = amazonReleaseRegexp.FindStringSubmatch(string(f.Contents))
if len(r) == 4 {
Expand Down
12 changes: 12 additions & 0 deletions ext/featurens/redhatrelease/redhatrelease_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,18 @@ func TestDetector(t *testing.T) {
"etc/rocky-release": {Contents: []byte(`Rocky Linux release 9.0 (Blue Onyx)`)},
}),
},
{
ExpectedNamespace: &database.Namespace{Name: "alma:8", VersionFormat: rpm.ParserName},
Files: tarutil.CreateNewLayerFiles(map[string]analyzer.FileData{
"etc/almalinux-release": {Contents: []byte(`AlmaLinux release 8.6 (Sky Tiger)`)},
}),
},
{
ExpectedNamespace: &database.Namespace{Name: "alma:9", VersionFormat: rpm.ParserName},
Files: tarutil.CreateNewLayerFiles(map[string]analyzer.FileData{
"etc/almalinux-release": {Contents: []byte(`AlmaLinux release 9.0 (Emerald Puma)`)},
}),
},
{
ExpectedNamespace: nil,
Files: tarutil.CreateNewLayerFiles(nil),
Expand Down