Files
kairos-agent/internal/agent/upgrade.go
Ettore Di Giacinto db2bcc0451 art: Write only version to VERSION in os-release
Add FLAVOR and VARIANT to handle those separately, this should also fix upgrades.

Fixes https://github.com/c3os-io/c3os/issues/80
2022-08-17 08:02:18 +00:00

46 lines
1008 B
Go

package agent
import (
"context"
"fmt"
"os"
"os/exec"
"github.com/c3os-io/c3os/internal/github"
"github.com/c3os-io/c3os/pkg/utils"
)
func Upgrade(version, image string, force bool) error {
if version == "" && image == "" {
githubRepo, err := utils.OSRelease("GITHUB_REPO")
if err != nil {
return err
}
releases, _ := github.FindReleases(context.Background(), "", githubRepo)
version = releases[0]
fmt.Println("latest release is ", version)
}
if utils.Version() == version && !force {
fmt.Println("latest version already installed. use --force to force upgrade")
return nil
}
registry, err := utils.OSRelease("IMAGE_REPO")
if err != nil {
return err
}
img := fmt.Sprintf("%s:%s", registry, version)
if image != "" {
img = image
}
args := []string{"upgrade", "--system.uri", fmt.Sprintf("docker:%s", img)}
cmd := exec.Command("elemental", args...)
cmd.Env = os.Environ()
cmd.Stdout = os.Stdout
cmd.Stdin = os.Stdin
cmd.Stderr = os.Stderr
return cmd.Run()
}