mirror of
https://github.com/kairos-io/kairos-sdk.git
synced 2025-04-28 03:20:52 +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)
|
||||
}
|
||||
|
||||
// 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.
|
||||
// (optionally file argument is there for testing reasons).
|
||||
func OSRelease(key string, file ...string) (string, error) {
|
||||
var osReleaseFile string
|
||||
osReleaseFallback := "/etc/os-release"
|
||||
|
||||
if len(file) > 1 {
|
||||
return "", errors.New("too many arguments passed")
|
||||
@ -79,7 +81,7 @@ func OSRelease(key string, file ...string) (string, error) {
|
||||
if len(file) > 0 {
|
||||
osReleaseFile = file[0]
|
||||
} else {
|
||||
osReleaseFile = "/etc/os-release"
|
||||
osReleaseFile = "/etc/kairos-release"
|
||||
}
|
||||
release, err := godotenv.Read(osReleaseFile)
|
||||
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
|
||||
v, exists = release[key]
|
||||
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
|
||||
}
|
||||
|
||||
|
@ -168,7 +168,7 @@ func CliCommands() []*cli.Command {
|
||||
},
|
||||
{
|
||||
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{
|
||||
flavorFlag, flavorReleaseFlag, variantFlag, modelFlag, archFlag, versionFlag,
|
||||
softwareVersionFlag, softwareVersionPrefixFlag, registryAndOrgFlag, bugReportURLFlag, projectHomeURLFlag,
|
||||
|
@ -14,7 +14,7 @@ var _ = Describe("NewArtifactFromOSRelease", func() {
|
||||
var osReleaseContent string
|
||||
|
||||
BeforeEach(func() {
|
||||
tmpOSReleaseFile, err = os.CreateTemp("", "os-release")
|
||||
tmpOSReleaseFile, err = os.CreateTemp("", "kairos-release")
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
osReleaseContent = "KAIROS_FLAVOR=opensuse\n" +
|
||||
|
@ -10,7 +10,7 @@ import (
|
||||
)
|
||||
|
||||
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
|
||||
// "Artifact.Version".
|
||||
EnvVarVersion = "RELEASE"
|
||||
@ -49,8 +49,8 @@ func NewArtifactFromJSON(jsonStr string) (*Artifact, error) {
|
||||
return result, err
|
||||
}
|
||||
|
||||
// NewArtifactFromOSRelease generates an artifact by inpecting the variables
|
||||
// in the /etc/os-release file of a Kairos image. The variable should be
|
||||
// NewArtifactFromOSRelease generates an artifact by inspecting the variables
|
||||
// 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
|
||||
// field. The function optionally takes an argument to specify a different file
|
||||
// path (for testing reasons).
|
||||
@ -199,7 +199,7 @@ func (a *Artifact) SoftwareVersionForTag() string {
|
||||
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) {
|
||||
if registryAndOrg == "" {
|
||||
return "", errors.New("registry-and-org must be set")
|
||||
|
Loading…
Reference in New Issue
Block a user