pkg/utils: Support host operating systems without VERSION_ID
The VERSION_ID field in os-release(5) is optional [1]. It's absent on Arch Linux, which follows a rolling-release model and uses the BUILD_ID field instead: BUILD_ID=rolling A subsequent commit will add built-in support for Arch Linux. Hence, the code to get the default release from the host operating system can no longer assume the presence of the VERSION_ID field in os-release(5). Note that the arch-toolbox image is tagged with 'latest', in accordance with OCI conventions, not 'rolling' [2,3], which is the os-release(5) BUILD_ID. Therefore, it will be wise to use 'latest' as the default release on Arch Linux, to simplify how the default release matches with the default image's tag. This means that a os-release(5) field can't be used for the default release on Arch. [1] https://www.freedesktop.org/software/systemd/man/os-release.html [2] Commit2568528cb7
https://github.com/containers/toolbox/pull/861 [3] Commita4e5861ae5
https://github.com/containers/toolbox/pull/1308 https://github.com/containers/toolbox/pull/1303
This commit is contained in:
parent
28913fad1d
commit
d14fd7bb50
|
@ -39,12 +39,14 @@ import (
|
||||||
"golang.org/x/sys/unix"
|
"golang.org/x/sys/unix"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type GetDefaultReleaseFunc func() (string, error)
|
||||||
type GetFullyQualifiedImageFunc func(string, string) string
|
type GetFullyQualifiedImageFunc func(string, string) string
|
||||||
type ParseReleaseFunc func(string) (string, error)
|
type ParseReleaseFunc func(string) (string, error)
|
||||||
|
|
||||||
type Distro struct {
|
type Distro struct {
|
||||||
ContainerNamePrefix string
|
ContainerNamePrefix string
|
||||||
ImageBasename string
|
ImageBasename string
|
||||||
|
GetDefaultRelease GetDefaultReleaseFunc
|
||||||
GetFullyQualifiedImage GetFullyQualifiedImageFunc
|
GetFullyQualifiedImage GetFullyQualifiedImageFunc
|
||||||
ParseRelease ParseReleaseFunc
|
ParseRelease ParseReleaseFunc
|
||||||
}
|
}
|
||||||
|
@ -100,18 +102,21 @@ var (
|
||||||
"fedora": {
|
"fedora": {
|
||||||
"fedora-toolbox",
|
"fedora-toolbox",
|
||||||
"fedora-toolbox",
|
"fedora-toolbox",
|
||||||
|
getDefaultReleaseFedora,
|
||||||
getFullyQualifiedImageFedora,
|
getFullyQualifiedImageFedora,
|
||||||
parseReleaseFedora,
|
parseReleaseFedora,
|
||||||
},
|
},
|
||||||
"rhel": {
|
"rhel": {
|
||||||
"rhel-toolbox",
|
"rhel-toolbox",
|
||||||
"toolbox",
|
"toolbox",
|
||||||
|
getDefaultReleaseRHEL,
|
||||||
getFullyQualifiedImageRHEL,
|
getFullyQualifiedImageRHEL,
|
||||||
parseReleaseRHEL,
|
parseReleaseRHEL,
|
||||||
},
|
},
|
||||||
"ubuntu": {
|
"ubuntu": {
|
||||||
"ubuntu-toolbox",
|
"ubuntu-toolbox",
|
||||||
"ubuntu-toolbox",
|
"ubuntu-toolbox",
|
||||||
|
getDefaultReleaseUbuntu,
|
||||||
getFullyQualifiedImageUbuntu,
|
getFullyQualifiedImageUbuntu,
|
||||||
parseReleaseUbuntu,
|
parseReleaseUbuntu,
|
||||||
},
|
},
|
||||||
|
@ -140,7 +145,7 @@ func init() {
|
||||||
hostID, err := GetHostID()
|
hostID, err := GetHostID()
|
||||||
if err == nil {
|
if err == nil {
|
||||||
if distroObj, supportedDistro := supportedDistros[hostID]; supportedDistro {
|
if distroObj, supportedDistro := supportedDistros[hostID]; supportedDistro {
|
||||||
release, err := getHostVersionID()
|
release, err := getDefaultReleaseForDistro(hostID)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
containerNamePrefixDefault = distroObj.ContainerNamePrefix
|
containerNamePrefixDefault = distroObj.ContainerNamePrefix
|
||||||
distroDefault = hostID
|
distroDefault = hostID
|
||||||
|
@ -273,6 +278,52 @@ func getDefaultImageForDistro(distro, release string) string {
|
||||||
return image
|
return image
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getDefaultReleaseForDistro(distro string) (string, error) {
|
||||||
|
if distro == "" {
|
||||||
|
panic("distro not specified")
|
||||||
|
}
|
||||||
|
|
||||||
|
distroObj, supportedDistro := supportedDistros[distro]
|
||||||
|
if !supportedDistro {
|
||||||
|
panicMsg := fmt.Sprintf("failed to find %s in the list of supported distributions", distro)
|
||||||
|
panic(panicMsg)
|
||||||
|
}
|
||||||
|
|
||||||
|
release, err := distroObj.GetDefaultRelease()
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
return release, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func getDefaultReleaseFedora() (string, error) {
|
||||||
|
release, err := getHostVersionID()
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
return release, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func getDefaultReleaseRHEL() (string, error) {
|
||||||
|
release, err := getHostVersionID()
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
return release, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func getDefaultReleaseUbuntu() (string, error) {
|
||||||
|
release, err := getHostVersionID()
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
return release, nil
|
||||||
|
}
|
||||||
|
|
||||||
func GetEnvOptionsForPreservedVariables() []string {
|
func GetEnvOptionsForPreservedVariables() []string {
|
||||||
logrus.Debug("Creating list of environment variables to forward")
|
logrus.Debug("Creating list of environment variables to forward")
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue