mirror of
https://github.com/kairos-io/kairos-sdk.git
synced 2025-05-12 18:17:25 +00:00
* Introduce versioneer package to replace the naming.sh script in kairos-io/kairos Signed-off-by: Dimitris Karakasilis <dimitris@karakasilis.me> * Implement BootableName for bootable artifacts also introduce Version and SoftwareVersion fields Signed-off-by: Dimitris Karakasilis <dimitris@karakasilis.me> * Refactor to introduce commondName to be used with ContainerName Signed-off-by: Dimitris Karakasilis <dimitris@karakasilis.me> * Implement ContainerName and add missing tests Signed-off-by: Dimitris Karakasilis <dimitris@karakasilis.me> * Introduce NewArtifactFromJSON Signed-off-by: Dimitris Karakasilis <dimitris@karakasilis.me> * Introduce NewFromOSRelease to be used within a Kairos image See also discussion: https://github.com/kairos-io/kairos/discussions/2035 Signed-off-by: Dimitris Karakasilis <dimitris@karakasilis.me> * Introduce 3 methods to find releases (TODO: implement them) Signed-off-by: Dimitris Karakasilis <dimitris@karakasilis.me> * Use existing OSRelease method and remove the new one the existing method had to be adapted to accept and optional path to the os-release file to allow the tests to pass a tmp file. Signed-off-by: Dimitris Karakasilis <dimitris@karakasilis.me> * Introduce TagList and some basic filtering of tags also introduce RegistryInspector which finds tags from a container registry for a specific repository. Signed-off-by: Dimitris Karakasilis <dimitris@karakasilis.me> * Implement OtherVersions method of TagList to return different Kairos versions of the exact same artifact. Signed-off-by: Dimitris Karakasilis <dimitris@karakasilis.me> * [WIP] Add TODOs for 2 more methods Signed-off-by: Dimitris Karakasilis <dimitris@karakasilis.me> * Implement Sorted() method on TagList Signed-off-by: Dimitris Karakasilis <dimitris@karakasilis.me> * Implement RSorted and change OtherVersions test to ensure it also returns older versions too. Signed-off-by: Dimitris Karakasilis <dimitris@karakasilis.me> * Implement NewerVersions method Signed-off-by: Dimitris Karakasilis <dimitris@karakasilis.me> * Make json file pretty Signed-off-by: Dimitris Karakasilis <dimitris@karakasilis.me> * Implement OtherSoftwareVersions and NewerSoftwareVersions Signed-off-by: Dimitris Karakasilis <dimitris@karakasilis.me> * Implement NewerAnyVersions and OtherAnyVersions Signed-off-by: Dimitris Karakasilis <dimitris@karakasilis.me> * Make TagList a struct so that it has an "Artifact" field Now the Artifact has a TagList method that returns a TagList which is associated to the specific Artifact. All methods of TagList are now available to the Artifact. E.g. tagList, _ := artifact.TagList("quay.io/kairos") tagList.NewerAnyVersion(...) Signed-off-by: Dimitris Karakasilis <dimitris@karakasilis.me> * Use the field Artifact in TagList methods instead of needing an argument Signed-off-by: Dimitris Karakasilis <dimitris@karakasilis.me> * Fix linting errors Signed-off-by: Dimitris Karakasilis <dimitris@karakasilis.me> * Restructure files and introduce main.go for versioneer to provide a user interface that will replace naming.sh script of the kairos repository Signed-off-by: Dimitris Karakasilis <dimitris@karakasilis.me> * Fix imports Signed-off-by: Dimitris Karakasilis <dimitris@karakasilis.me> * Implement bootable-artifact-name cli command Signed-off-by: Dimitris Karakasilis <dimitris@karakasilis.me> * Implement BaseContainerName method Signed-off-by: Dimitris Karakasilis <dimitris@spectrocloud.com> * Create a wrapper command base-container-artifact-name Signed-off-by: Mauro Morales <mauro.morales@spectrocloud.com> * Extract the cli command to the packag to be re-used in kairos-agent Signed-off-by: Dimitris Karakasilis <dimitris@spectrocloud.com> * Go back to original package structure and just nest the cli Signed-off-by: Dimitris Karakasilis <dimitris@karakasilis.me> * Move the versioneer "main" package outside the tree to allow it to be imported in kairos-agent Signed-off-by: Dimitris Karakasilis <dimitris@karakasilis.me> * Allow setting the cli flags using environment variables Signed-off-by: Dimitris Karakasilis <dimitris@karakasilis.me> * Implement os-release-variables command to replace the logic in Earthly and Dockerfiles Signed-off-by: Dimitris Karakasilis <dimitris@karakasilis.me> * Fix test Signed-off-by: Dimitris Karakasilis <dimitris@karakasilis.me> * Fix TODO in Readme Signed-off-by: Dimitris Karakasilis <dimitris@karakasilis.me> * Dry the creation of the Artifact Signed-off-by: Dimitris Karakasilis <dimitris@karakasilis.me> --------- Signed-off-by: Dimitris Karakasilis <dimitris@karakasilis.me> Signed-off-by: Dimitris Karakasilis <dimitris@spectrocloud.com> Signed-off-by: Mauro Morales <mauro.morales@spectrocloud.com> Co-authored-by: Mauro Morales <mauro.morales@spectrocloud.com> Co-authored-by: Dimitris Karakasilis <dimitris@spectrocloud.com>
194 lines
4.8 KiB
Go
194 lines
4.8 KiB
Go
package versioneer
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/urfave/cli/v2"
|
|
)
|
|
|
|
var (
|
|
flavorFlag *cli.StringFlag = &cli.StringFlag{
|
|
Name: "flavor",
|
|
Value: "",
|
|
Usage: "the OS flavor (e.g. opensuse)",
|
|
EnvVars: []string{EnvVarFlavor},
|
|
}
|
|
|
|
flavorReleaseFlag *cli.StringFlag = &cli.StringFlag{
|
|
Name: "flavor-release",
|
|
Value: "",
|
|
Usage: "the OS flavor release (e.g. leap-15.5)",
|
|
EnvVars: []string{EnvVarFlavorRelease},
|
|
}
|
|
|
|
variantFlag *cli.StringFlag = &cli.StringFlag{
|
|
Name: "variant",
|
|
Value: "",
|
|
Usage: "the Kairos variant (core, standard)",
|
|
EnvVars: []string{EnvVarVariant},
|
|
}
|
|
|
|
modelFlag *cli.StringFlag = &cli.StringFlag{
|
|
Name: "model",
|
|
Value: "",
|
|
Usage: "the model for which the OS was built (e.g. rpi4)",
|
|
EnvVars: []string{EnvVarModel},
|
|
}
|
|
|
|
archFlag *cli.StringFlag = &cli.StringFlag{
|
|
Name: "arch",
|
|
Value: "",
|
|
Usage: "the architecture of the OS",
|
|
EnvVars: []string{EnvVarArch},
|
|
}
|
|
|
|
versionFlag *cli.StringFlag = &cli.StringFlag{
|
|
Name: "version",
|
|
Value: "",
|
|
Usage: "the Kairos version (e.g. v2.4.2)",
|
|
EnvVars: []string{EnvVarVersion},
|
|
}
|
|
|
|
softwareVersionFlag *cli.StringFlag = &cli.StringFlag{
|
|
Name: "software-version",
|
|
Value: "",
|
|
Usage: "the software version (e.g. k3sv1.28.2+k3s1)",
|
|
EnvVars: []string{EnvVarSoftwareVersion},
|
|
}
|
|
|
|
registryAndOrgFlag *cli.StringFlag = &cli.StringFlag{
|
|
Name: "registry-and-org",
|
|
Value: "",
|
|
Usage: "the container registry and org (e.g. \"quay.io/kairos\")",
|
|
EnvVars: []string{EnvVarRegistryAndOrg},
|
|
}
|
|
|
|
idFlag *cli.StringFlag = &cli.StringFlag{
|
|
Name: "id",
|
|
Value: "",
|
|
Usage: "a identifier for the artifact (e.g. \"master\")",
|
|
EnvVars: []string{EnvVarID},
|
|
}
|
|
|
|
githubRepoFlag *cli.StringFlag = &cli.StringFlag{
|
|
Name: "github-repo",
|
|
Value: "",
|
|
Usage: "the Github repository where the code is hosted",
|
|
EnvVars: []string{EnvVarGithubRepo},
|
|
}
|
|
|
|
bugReportURLFlag *cli.StringFlag = &cli.StringFlag{
|
|
Name: "bug-report-url",
|
|
Value: "",
|
|
Usage: "the url where bugs can be reported",
|
|
EnvVars: []string{EnvVarBugReportURL},
|
|
}
|
|
|
|
projectHomeURLFlag *cli.StringFlag = &cli.StringFlag{
|
|
Name: "project-home-url",
|
|
Value: "",
|
|
Usage: "the url where more information about the project can be found",
|
|
EnvVars: []string{EnvVarHomeURL},
|
|
}
|
|
)
|
|
|
|
func CliCommands() []*cli.Command {
|
|
return []*cli.Command{
|
|
{
|
|
Name: "container-artifact-name",
|
|
Usage: "generates an artifact name for Kairos OCI images",
|
|
Flags: []cli.Flag{
|
|
flavorFlag, flavorReleaseFlag, variantFlag, modelFlag, archFlag,
|
|
versionFlag, softwareVersionFlag, registryAndOrgFlag,
|
|
},
|
|
Action: func(cCtx *cli.Context) error {
|
|
a := artifactFromFlags(cCtx)
|
|
|
|
result, err := a.ContainerName(cCtx.String(registryAndOrgFlag.Name))
|
|
if err != nil {
|
|
return err
|
|
}
|
|
fmt.Println(result)
|
|
|
|
return nil
|
|
},
|
|
},
|
|
{
|
|
Name: "bootable-artifact-name",
|
|
Usage: "generates a name for bootable artifacts (e.g. iso files)",
|
|
Flags: []cli.Flag{
|
|
flavorFlag, flavorReleaseFlag, variantFlag, modelFlag, archFlag,
|
|
versionFlag, softwareVersionFlag,
|
|
},
|
|
Action: func(cCtx *cli.Context) error {
|
|
a := artifactFromFlags(cCtx)
|
|
|
|
result, err := a.BootableName()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
fmt.Println(result)
|
|
|
|
return nil
|
|
},
|
|
},
|
|
{
|
|
Name: "base-container-artifact-name",
|
|
Usage: "generates a name for base (not yet Kairos) images",
|
|
Flags: []cli.Flag{
|
|
flavorFlag, flavorReleaseFlag, variantFlag, modelFlag, archFlag,
|
|
registryAndOrgFlag, idFlag,
|
|
},
|
|
Action: func(cCtx *cli.Context) error {
|
|
a := artifactFromFlags(cCtx)
|
|
|
|
result, err := a.BaseContainerName(
|
|
cCtx.String(registryAndOrgFlag.Name), cCtx.String(idFlag.Name))
|
|
if err != nil {
|
|
return err
|
|
}
|
|
fmt.Println(result)
|
|
|
|
return nil
|
|
},
|
|
},
|
|
{
|
|
Name: "os-release-variables",
|
|
Usage: "generates a set of variables to be appended in the /etc/os-release file",
|
|
Flags: []cli.Flag{
|
|
flavorFlag, flavorReleaseFlag, variantFlag, modelFlag, archFlag, versionFlag,
|
|
softwareVersionFlag, registryAndOrgFlag, bugReportURLFlag, projectHomeURLFlag,
|
|
githubRepoFlag,
|
|
},
|
|
Action: func(cCtx *cli.Context) error {
|
|
a := artifactFromFlags(cCtx)
|
|
|
|
result, err := a.OSReleaseVariables(
|
|
registryAndOrgFlag.Get(cCtx),
|
|
githubRepoFlag.Get(cCtx),
|
|
bugReportURLFlag.Get(cCtx),
|
|
projectHomeURLFlag.Get(cCtx),
|
|
)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
fmt.Println(result)
|
|
|
|
return nil
|
|
},
|
|
},
|
|
}
|
|
}
|
|
|
|
func artifactFromFlags(cCtx *cli.Context) Artifact {
|
|
return Artifact{
|
|
Flavor: flavorFlag.Get(cCtx),
|
|
FlavorRelease: flavorReleaseFlag.Get(cCtx),
|
|
Variant: variantFlag.Get(cCtx),
|
|
Model: modelFlag.Get(cCtx),
|
|
Arch: archFlag.Get(cCtx),
|
|
Version: versionFlag.Get(cCtx),
|
|
SoftwareVersion: softwareVersionFlag.Get(cCtx),
|
|
}
|
|
}
|