mirror of
https://github.com/kairos-io/kairos-sdk.git
synced 2025-08-19 15:36:58 +00:00
Move to use kairos-release instead of os-release (#506)
This commit is contained in:
parent
000e297982
commit
5f9d126442
@ -67,11 +67,13 @@ func UUID() string {
|
|||||||
return fmt.Sprintf("%s-%s", id, hostname)
|
return fmt.Sprintf("%s-%s", id, hostname)
|
||||||
}
|
}
|
||||||
|
|
||||||
// OSRelease finds the value of the specified key in the /etc/os-release file
|
// OSRelease finds the value of the specified key in the /etc/kairos-release file
|
||||||
|
// As a fallback on the /etc/os-release
|
||||||
// or, if a second argument is passed, on the file specified by the second argument.
|
// or, if a second argument is passed, on the file specified by the second argument.
|
||||||
// (optionally file argument is there for testing reasons).
|
// (optionally file argument is there for testing reasons).
|
||||||
func OSRelease(key string, file ...string) (string, error) {
|
func OSRelease(key string, file ...string) (string, error) {
|
||||||
var osReleaseFile string
|
var osReleaseFile string
|
||||||
|
osReleaseFallback := "/etc/os-release"
|
||||||
|
|
||||||
if len(file) > 1 {
|
if len(file) > 1 {
|
||||||
return "", errors.New("too many arguments passed")
|
return "", errors.New("too many arguments passed")
|
||||||
@ -79,7 +81,7 @@ func OSRelease(key string, file ...string) (string, error) {
|
|||||||
if len(file) > 0 {
|
if len(file) > 0 {
|
||||||
osReleaseFile = file[0]
|
osReleaseFile = file[0]
|
||||||
} else {
|
} else {
|
||||||
osReleaseFile = "/etc/os-release"
|
osReleaseFile = "/etc/kairos-release"
|
||||||
}
|
}
|
||||||
release, err := godotenv.Read(osReleaseFile)
|
release, err := godotenv.Read(osReleaseFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -91,9 +93,23 @@ func OSRelease(key string, file ...string) (string, error) {
|
|||||||
// We try with the old naming without the prefix in case the key wasn't found
|
// We try with the old naming without the prefix in case the key wasn't found
|
||||||
v, exists = release[key]
|
v, exists = release[key]
|
||||||
if !exists {
|
if !exists {
|
||||||
return "", KeyNotFoundErr{Err: fmt.Errorf("%s key not found", kairosKey)}
|
// We try with fallback file
|
||||||
|
release, err = godotenv.Read(osReleaseFallback)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
kairosKey = "KAIROS_" + key
|
||||||
|
v, exists = release[kairosKey]
|
||||||
|
if !exists {
|
||||||
|
// We try with the old naming without the prefix in case the key wasn't found
|
||||||
|
v, exists = release[key]
|
||||||
|
if !exists {
|
||||||
|
return "", KeyNotFoundErr{Err: fmt.Errorf("%s key not found", kairosKey)}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return v, nil
|
return v, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -168,7 +168,7 @@ func CliCommands() []*cli.Command {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "os-release-variables",
|
Name: "os-release-variables",
|
||||||
Usage: "generates a set of variables to be appended in the /etc/os-release file",
|
Usage: "generates a set of variables to be appended in the /etc/kairos-release file",
|
||||||
Flags: []cli.Flag{
|
Flags: []cli.Flag{
|
||||||
flavorFlag, flavorReleaseFlag, variantFlag, modelFlag, archFlag, versionFlag,
|
flavorFlag, flavorReleaseFlag, variantFlag, modelFlag, archFlag, versionFlag,
|
||||||
softwareVersionFlag, softwareVersionPrefixFlag, registryAndOrgFlag, bugReportURLFlag, projectHomeURLFlag,
|
softwareVersionFlag, softwareVersionPrefixFlag, registryAndOrgFlag, bugReportURLFlag, projectHomeURLFlag,
|
||||||
|
@ -14,7 +14,7 @@ var _ = Describe("NewArtifactFromOSRelease", func() {
|
|||||||
var osReleaseContent string
|
var osReleaseContent string
|
||||||
|
|
||||||
BeforeEach(func() {
|
BeforeEach(func() {
|
||||||
tmpOSReleaseFile, err = os.CreateTemp("", "os-release")
|
tmpOSReleaseFile, err = os.CreateTemp("", "kairos-release")
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
|
||||||
osReleaseContent = "KAIROS_FLAVOR=opensuse\n" +
|
osReleaseContent = "KAIROS_FLAVOR=opensuse\n" +
|
||||||
|
@ -10,7 +10,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// KAIROS_VERSION was already used in os-release and we avoided breaking it
|
// KAIROS_VERSION was already used in kairos-release and we avoided breaking it
|
||||||
// for consumers by using a new variable KAIROS_RELEASE instead. But it's the
|
// for consumers by using a new variable KAIROS_RELEASE instead. But it's the
|
||||||
// "Artifact.Version".
|
// "Artifact.Version".
|
||||||
EnvVarVersion = "RELEASE"
|
EnvVarVersion = "RELEASE"
|
||||||
@ -49,8 +49,8 @@ func NewArtifactFromJSON(jsonStr string) (*Artifact, error) {
|
|||||||
return result, err
|
return result, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewArtifactFromOSRelease generates an artifact by inpecting the variables
|
// NewArtifactFromOSRelease generates an artifact by inspecting the variables
|
||||||
// in the /etc/os-release file of a Kairos image. The variable should be
|
// in the /etc/kairos-release file of a Kairos image. The variable should be
|
||||||
// prefixed with "KAIROS_". E.g. KAIROS_VARIANT would be used to set the Variant
|
// prefixed with "KAIROS_". E.g. KAIROS_VARIANT would be used to set the Variant
|
||||||
// field. The function optionally takes an argument to specify a different file
|
// field. The function optionally takes an argument to specify a different file
|
||||||
// path (for testing reasons).
|
// path (for testing reasons).
|
||||||
@ -199,7 +199,7 @@ func (a *Artifact) SoftwareVersionForTag() string {
|
|||||||
return strings.ReplaceAll(a.SoftwareVersion, "+", "-")
|
return strings.ReplaceAll(a.SoftwareVersion, "+", "-")
|
||||||
}
|
}
|
||||||
|
|
||||||
// OSReleaseVariables returns a set of variables to be appended in /etc/os-release
|
// OSReleaseVariables returns a set of variables to be appended in /etc/kairos-release
|
||||||
func (a *Artifact) OSReleaseVariables(registryAndOrg, githubRepo, bugURL, homeURL string) (string, error) {
|
func (a *Artifact) OSReleaseVariables(registryAndOrg, githubRepo, bugURL, homeURL string) (string, error) {
|
||||||
if registryAndOrg == "" {
|
if registryAndOrg == "" {
|
||||||
return "", errors.New("registry-and-org must be set")
|
return "", errors.New("registry-and-org must be set")
|
||||||
|
Loading…
Reference in New Issue
Block a user