diff --git a/cmd/coreos-assembler.go b/cmd/coreos-assembler.go index 42a08b68ed2d17bed6af640a110603d1b4c7a50a..7579ad8773d85feb2549950af17ab7b5a38e94b1 100644 --- a/cmd/coreos-assembler.go +++ b/cmd/coreos-assembler.go @@ -15,7 +15,7 @@ import ( var buildCommands = []string{"init", "fetch", "build", "run", "prune", "clean", "list"} var advancedBuildCommands = []string{"buildfetch", "buildupload", "oc-adm-release", "push-container", "upload-oscontainer"} var buildextendCommands = []string{"aliyun", "aws", "azure", "digitalocean", "exoscale", "gcp", "ibmcloud", "kubevirt", "live", "metal", "metal4k", "nutanix", "openstack", "qemu", "secex", "virtualbox", "vmware", "vultr"} -var utilityCommands = []string{"aws-replicate", "build-extensions-container", "compress", "generate-hashlist", "koji-upload", "kola", "remote-build-container", "remote-prune", "remote-session", "sign", "tag"} +var utilityCommands = []string{"aws-replicate", "build-extensions-container", "compress", "generate-hashlist", "koji-upload", "kola", "remote-build-container", "remote-prune", "remote-session", "sign", "tag", "update-variant"} var otherCommands = []string{"shell", "meta"} func init() { @@ -84,6 +84,8 @@ func run(argv []string) error { switch cmd { case "clean": return runClean(argv) + case "update-variant": + return runUpdateVariant(argv) case "remote-session": return runRemoteSession(argv) case "build-extensions-container": diff --git a/cmd/update-variant.go b/cmd/update-variant.go new file mode 100644 index 0000000000000000000000000000000000000000..9ec4affb75e87de03423779695ca73e3fa77f7eb --- /dev/null +++ b/cmd/update-variant.go @@ -0,0 +1,64 @@ +// See usage below +package main + +import ( + "fmt" + "os" +) + +func runUpdateVariant(argv []string) error { + const updateVariantUsage = `Usage: coreos-assembler update-variant --help + +Update symlinks for manifests in the config repo to use the specified version +for the given variant. + +Use the "default" variant to update the default manifests with a variant suffix. + +Example to update the rhel-coreos-9 variant to RHEL 9.2: +$ coreos-assembler update-variant rhel-coreos-9 rhel-9.2 + +Example to set SCOS as the default manifest: +$ coreos-assembler update-variant default scos +` + for _, arg := range argv { + switch arg { + case "-h": + case "--help": + fmt.Print(updateVariantUsage) + return nil + } + } + + if len(argv) != 2 { + fmt.Print(updateVariantUsage) + return nil + } + variant := argv[0] + version := argv[1] + + var suffix string + if variant == "default" { + suffix = "" + } else { + suffix = fmt.Sprintf("-%s", variant) + } + + manifests := [3]string{"image", "extensions", "manifest"} + for _, m := range manifests { + target := fmt.Sprintf("%s-%s.yaml", m, version) + linkname := fmt.Sprintf("%s%s.yaml", m, suffix) + _, err := os.Stat(fmt.Sprintf("src/config/%s", target)) + if err != nil { + return err + } + err = os.Remove(fmt.Sprintf("src/config/%s", linkname)) + if err != nil { + return err + } + err = os.Symlink(target, fmt.Sprintf("src/config/%s", linkname)) + if err != nil { + return err + } + } + return nil +}