Skip to content

Commit

Permalink
cli: add update command
Browse files Browse the repository at this point in the history
Signed-off-by: Abiola Ibrahim <[email protected]>
  • Loading branch information
abiosoft committed Oct 29, 2024
1 parent 34e84e6 commit 4fb057a
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 1 deletion.
20 changes: 20 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type App interface {
Status(extended bool) error
Version() error
Runtime() (string, error)
Update() error
Kubernetes() (environment.Container, error)
}

Expand Down Expand Up @@ -454,6 +455,25 @@ func (c colimaApp) Active() bool {
return c.guest.Running(context.Background())
}

func (c *colimaApp) Update() error {
ctx := context.Background()
if !c.guest.Running(ctx) {
return fmt.Errorf("%s is not running", config.CurrentProfile().DisplayName)
}

runtime, err := c.currentRuntime(ctx)
if err != nil {
return err
}

container, err := c.containerEnvironment(runtime)
if err != nil {
return err
}

return container.Update(ctx)
}

func generateSSHConfig(modifySSHConfig bool) error {
instances, err := limautil.Instances()
if err != nil {
Expand Down
3 changes: 2 additions & 1 deletion cmd/root/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,14 @@ var rootCmd = &cobra.Command{
switch cmd.Name() {

// special case handling for commands directly interacting with the VM
// start, stop, restart, delete, status, version, ssh-config
// start, stop, restart, delete, status, version, update, ssh-config
case "start",
"stop",
"restart",
"delete",
"status",
"version",
"update",
"ssh-config":

// if an arg is passed, assume it to be the profile (provided --profile is unset)
Expand Down
22 changes: 22 additions & 0 deletions cmd/update.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package cmd

import (
"github.com/abiosoft/colima/cmd/root"
"github.com/spf13/cobra"
)

// statusCmd represents the status command
var updateCmd = &cobra.Command{
Use: "update [profile]",
Aliases: []string{"u", "up"},
Short: "update the container runtime",
Long: `Update the current container runtime.`,
Args: cobra.MaximumNArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
return newApp().Update()
},
}

func init() {
root.Cmd().AddCommand(updateCmd)
}
2 changes: 2 additions & 0 deletions environment/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ type Container interface {
Stop(ctx context.Context) error
// Teardown tears down/uninstall the container runtime.
Teardown(ctx context.Context) error
// Update the container runtime.
Update(ctx context.Context) error
// Version returns the container runtime version.
Version(ctx context.Context) string
// Running returns if the container runtime is currently running.
Expand Down
4 changes: 4 additions & 0 deletions environment/container/containerd/containerd.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,7 @@ func (c containerdRuntime) Version(ctx context.Context) string {
version, _ := c.guest.RunOutput("sudo", "nerdctl", "version", "--format", `client: {{.Client.Version}}{{printf "\n"}}server: {{(index .Server.Components 0).Version}}`)
return version
}

func (c *containerdRuntime) Update(ctx context.Context) error {
return nil
}
8 changes: 8 additions & 0 deletions environment/container/docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,3 +133,11 @@ func (d dockerRuntime) Version(ctx context.Context) string {
version, _ := d.host.RunOutput("docker", "version", "--format", `client: v{{.Client.Version}}{{printf "\n"}}server: v{{.Server.Version}}`)
return version
}

func (d *dockerRuntime) Update(ctx context.Context) error {
return d.guest.Run(
"sh",
"-c",
"sudo apt-get -qq update -y && sudo apt-get -qq install -y --allow-change-held-packages docker-ce docker-ce-cli containerd.io",
)
}
8 changes: 8 additions & 0 deletions environment/container/incus/incus.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,3 +278,11 @@ type networkInfo struct {
Managed bool `json:"managed"`
Type string `json:"type"`
}

func (c *incusRuntime) Update(ctx context.Context) error {
return c.guest.Run(
"sh",
"-c",
"sudo apt-get -qq update -y && sudo apt-get -qq install -y --allow-change-held-packages incus incus-base incus-client incus-extra incus-ui-canonical",
)
}
5 changes: 5 additions & 0 deletions environment/container/kubernetes/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,3 +263,8 @@ func (c kubernetesRuntime) Version(context.Context) string {
version, _ := c.host.RunOutput("kubectl", "--context", config.CurrentProfile().ID, "version", "--short")
return version
}

func (c *kubernetesRuntime) Update(ctx context.Context) error {
// update not supported
return nil
}

0 comments on commit 4fb057a

Please sign in to comment.