diff --git a/internal/agent/upgrade.go b/internal/agent/upgrade.go index ea849db..f7a5af6 100644 --- a/internal/agent/upgrade.go +++ b/internal/agent/upgrade.go @@ -47,11 +47,11 @@ func ListReleases(includePrereleases bool) semver.Collection { } func Upgrade( - version, image string, force, debug, strictValidations bool, dirs []string, preReleases bool, + version, source string, force, debug, strictValidations bool, dirs []string, preReleases, isLocal bool, ) error { bus.Manager.Initialize() - if version == "" && image == "" { + if version == "" && source == "" { fmt.Println("Searching for releases") if preReleases { fmt.Println("Including pre-releases") @@ -101,12 +101,12 @@ func Upgrade( if discoveredImage != "" { img = discoveredImage } - if image != "" { - img = image + if source != "" { + img = source } if debug { - fmt.Printf("Upgrading to image: '%s'\n", img) + fmt.Printf("Upgrading to source: '%s'\n", img) } c, err := config.Scan(collector.Directories(dirs...), collector.StrictValidation(strictValidations)) @@ -125,13 +125,16 @@ func Upgrade( upgradeConfig.Logger.SetLevel(log.DebugLevel) } + // Set image to local if true + upgradeConfig.LocalImage = isLocal + // Generate the upgrade spec upgradeSpec, err := elementalConfig.NewUpgradeSpec(upgradeConfig.Config) if err != nil { return err } // Add the image source - imgSource, err := v1.NewSrcFromURI(fmt.Sprintf("docker:%s", img)) + imgSource, err := v1.NewSrcFromURI(img) if err != nil { return err } diff --git a/main.go b/main.go index 0cdedb6..df1920b 100644 --- a/main.go +++ b/main.go @@ -9,6 +9,7 @@ import ( "github.com/kairos-io/kairos/v2/pkg/utils" "github.com/sirupsen/logrus" "path/filepath" + "regexp" "runtime" "os" @@ -63,9 +64,14 @@ var cmds = []*cli.Command{ }, &cli.StringFlag{ Name: "image", - Usage: "Specify an full image reference, e.g.: quay.io/some/image:tag", + Usage: "[DEPRECATED] Specify a full image reference, e.g.: quay.io/some/image:tag", + }, + &cli.StringFlag{ + Name: "source", + Usage: "Source for upgrade. Composed of `type:address`. Accepts `file:`,`dir:` or `oci:` for the type of source.\nFor example `file:/var/share/myimage.tar`, `dir:/tmp/extracted` or `oci:repo/image:tag`", }, &cli.BoolFlag{Name: "pre", Usage: "Include pre-releases (rc, beta, alpha)"}, + &cli.BoolFlag{Name: "local", Usage: "Get the upgrade source image from local daemon"}, }, Description: ` Manually upgrade a kairos node. @@ -103,17 +109,39 @@ See https://kairos.io/docs/upgrade/manual/ for documentation. }, }, }, - + Before: func(c *cli.Context) error { + source := c.String("source") + if source != "" { + r, err := regexp.Compile(`^oci:|dir:|file:`) + if err != nil { + return nil + } + if !r.MatchString(source) { + return fmt.Errorf("source %s does not match any of oci:, dir: or file: ", source) + } + } + return nil + }, Action: func(c *cli.Context) error { var v string if c.Args().Len() == 1 { v = c.Args().First() } + image := c.String("image") + source := c.String("source") + + if image != "" { + fmt.Println("--image flag is deprecated, please use --source") + // override source with image for now until we drop it + source = fmt.Sprintf("oci:%s", image) + } + + isLocal := c.Bool("local") return agent.Upgrade( - v, c.String("image"), c.Bool("force"), c.Bool("debug"), + v, source, c.Bool("force"), c.Bool("debug"), c.Bool("strict-validation"), configScanDir, - c.Bool("pre"), + c.Bool("pre"), isLocal, ) }, },