Skip to content

Commit 3afccee

Browse files
authored
⭐ Detect Bottlerocket (#6015)
1 parent 368a66f commit 3afccee

File tree

3 files changed

+88
-1
lines changed

3 files changed

+88
-1
lines changed

providers/os/detector/detector_all.go

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,47 @@ var amazonlinux = &PlatformResolver{
403403
},
404404
}
405405

406+
var bottlerocket = &PlatformResolver{
407+
Name: "bottlerocket",
408+
IsFamily: false,
409+
Detect: func(r *PlatformResolver, pf *inventory.Platform, conn shared.Connection) (bool, error) {
410+
f, err := conn.FileSystem().Open("/etc/bottlerocket-release")
411+
if err != nil {
412+
return false, nil
413+
}
414+
defer f.Close()
415+
416+
c, err := io.ReadAll(f)
417+
if err != nil || len(c) == 0 {
418+
log.Debug().Err(err)
419+
return false, nil
420+
}
421+
422+
content := strings.TrimSpace(string(c))
423+
osr, err := ParseOsRelease(content)
424+
if err != nil || osr["ID"] != "bottlerocket" {
425+
return false, nil
426+
}
427+
428+
if len(osr["ID"]) > 0 {
429+
pf.Name = osr["ID"]
430+
}
431+
432+
if len(osr["PRETTY_NAME"]) > 0 {
433+
pf.Title = osr["PRETTY_NAME"]
434+
}
435+
if len(osr["VERSION_ID"]) > 0 {
436+
pf.Version = osr["VERSION_ID"]
437+
}
438+
439+
if len(osr["BUILD_ID"]) > 0 {
440+
pf.Build = osr["BUILD_ID"]
441+
}
442+
443+
return false, nil
444+
},
445+
}
446+
406447
var windriver = &PlatformResolver{
407448
Name: "wrlinux",
408449
IsFamily: false,
@@ -936,7 +977,7 @@ var eulerFamily = &PlatformResolver{
936977
var linuxFamily = &PlatformResolver{
937978
Name: inventory.FAMILY_LINUX,
938979
IsFamily: true,
939-
Children: []*PlatformResolver{archFamily, redhatFamily, debianFamily, suseFamily, eulerFamily, amazonlinux, alpine, gentoo, busybox, photon, windriver, openwrt, ubios, plcnext, mageia, defaultLinux},
980+
Children: []*PlatformResolver{archFamily, redhatFamily, debianFamily, suseFamily, eulerFamily, bottlerocket, amazonlinux, alpine, gentoo, busybox, photon, windriver, openwrt, ubios, plcnext, mageia, defaultLinux},
940981
Detect: func(r *PlatformResolver, pf *inventory.Platform, conn shared.Connection) (bool, error) {
941982
detected := false
942983
osrd := NewOSReleaseDetector(conn)

providers/os/detector/detector_platform_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,16 @@ func TestAmazon2022LinuxDetector(t *testing.T) {
557557
assert.Equal(t, []string{"linux", "unix", "os"}, di.Family)
558558
}
559559

560+
func TestBottlerocketDetector(t *testing.T) {
561+
di, err := detectPlatformFromMock("./testdata/detect-bottlerocket.toml")
562+
assert.Nil(t, err, "was able to create the provider")
563+
564+
assert.Equal(t, "bottlerocket", di.Name, "os name should be identified")
565+
assert.Equal(t, "Bottlerocket OS 1.33.0 (aws-ecs-2-fips)", di.Title, "os title should be identified")
566+
assert.Equal(t, "1.33.0", di.Version, "os version should be identified")
567+
assert.Equal(t, []string{"linux", "unix", "os"}, di.Family)
568+
}
569+
560570
func TestScientificLinuxDetector(t *testing.T) {
561571
di, err := detectPlatformFromMock("./testdata/detect-scientific.toml")
562572
assert.Nil(t, err, "was able to create the provider")
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
[commands."uname -s"]
2+
stdout = "Linux"
3+
4+
[commands."uname -m"]
5+
stdout = "x86_64"
6+
7+
[commands."uname -r"]
8+
stdout = "4.14.177-139.253.amzn2.x86_64"
9+
10+
[files."/etc/os-release"]
11+
content = """
12+
NAME="Amazon Linux"
13+
VERSION="2"
14+
ID="amzn"
15+
ID_LIKE="centos rhel fedora"
16+
VERSION_ID="2"
17+
PRETTY_NAME="Amazon Linux 2"
18+
ANSI_COLOR="0;33"
19+
CPE_NAME="cpe:2.3:o:amazon:amazon_linux:2"
20+
HOME_URL="https://amazonlinux.com/"
21+
"""
22+
23+
[files."/etc/bottlerocket-release"]
24+
content = """
25+
NAME=Bottlerocket
26+
ID=bottlerocket
27+
VERSION="1.33.0 (aws-ecs-2-fips)"
28+
PRETTY_NAME="Bottlerocket OS 1.33.0 (aws-ecs-2-fips)"
29+
VARIANT_ID=aws-ecs-2-fips
30+
VERSION_ID=1.33.0
31+
BUILD_ID=cc306b6f
32+
HOME_URL="https://github.com/bottlerocket-os/bottlerocket"
33+
SUPPORT_URL="https://github.com/bottlerocket-os/bottlerocket/discussions"
34+
BUG_REPORT_URL="https://github.com/bottlerocket-os/bottlerocket/issues"
35+
DOCUMENTATION_URL="https://bottlerocket.dev"
36+
"""

0 commit comments

Comments
 (0)