Skip to content

Commit 4fb057a

Browse files
committed
cli: add update command
Signed-off-by: Abiola Ibrahim <git@abiosoft.com>
1 parent 34e84e6 commit 4fb057a

File tree

8 files changed

+71
-1
lines changed

8 files changed

+71
-1
lines changed

app/app.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ type App interface {
3333
Status(extended bool) error
3434
Version() error
3535
Runtime() (string, error)
36+
Update() error
3637
Kubernetes() (environment.Container, error)
3738
}
3839

@@ -454,6 +455,25 @@ func (c colimaApp) Active() bool {
454455
return c.guest.Running(context.Background())
455456
}
456457

458+
func (c *colimaApp) Update() error {
459+
ctx := context.Background()
460+
if !c.guest.Running(ctx) {
461+
return fmt.Errorf("%s is not running", config.CurrentProfile().DisplayName)
462+
}
463+
464+
runtime, err := c.currentRuntime(ctx)
465+
if err != nil {
466+
return err
467+
}
468+
469+
container, err := c.containerEnvironment(runtime)
470+
if err != nil {
471+
return err
472+
}
473+
474+
return container.Update(ctx)
475+
}
476+
457477
func generateSSHConfig(modifySSHConfig bool) error {
458478
instances, err := limautil.Instances()
459479
if err != nil {

cmd/root/root.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,14 @@ var rootCmd = &cobra.Command{
2222
switch cmd.Name() {
2323

2424
// special case handling for commands directly interacting with the VM
25-
// start, stop, restart, delete, status, version, ssh-config
25+
// start, stop, restart, delete, status, version, update, ssh-config
2626
case "start",
2727
"stop",
2828
"restart",
2929
"delete",
3030
"status",
3131
"version",
32+
"update",
3233
"ssh-config":
3334

3435
// if an arg is passed, assume it to be the profile (provided --profile is unset)

cmd/update.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package cmd
2+
3+
import (
4+
"github.com/abiosoft/colima/cmd/root"
5+
"github.com/spf13/cobra"
6+
)
7+
8+
// statusCmd represents the status command
9+
var updateCmd = &cobra.Command{
10+
Use: "update [profile]",
11+
Aliases: []string{"u", "up"},
12+
Short: "update the container runtime",
13+
Long: `Update the current container runtime.`,
14+
Args: cobra.MaximumNArgs(1),
15+
RunE: func(cmd *cobra.Command, args []string) error {
16+
return newApp().Update()
17+
},
18+
}
19+
20+
func init() {
21+
root.Cmd().AddCommand(updateCmd)
22+
}

environment/container.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ type Container interface {
2222
Stop(ctx context.Context) error
2323
// Teardown tears down/uninstall the container runtime.
2424
Teardown(ctx context.Context) error
25+
// Update the container runtime.
26+
Update(ctx context.Context) error
2527
// Version returns the container runtime version.
2628
Version(ctx context.Context) string
2729
// Running returns if the container runtime is currently running.

environment/container/containerd/containerd.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,7 @@ func (c containerdRuntime) Version(ctx context.Context) string {
101101
version, _ := c.guest.RunOutput("sudo", "nerdctl", "version", "--format", `client: {{.Client.Version}}{{printf "\n"}}server: {{(index .Server.Components 0).Version}}`)
102102
return version
103103
}
104+
105+
func (c *containerdRuntime) Update(ctx context.Context) error {
106+
return nil
107+
}

environment/container/docker/docker.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,3 +133,11 @@ func (d dockerRuntime) Version(ctx context.Context) string {
133133
version, _ := d.host.RunOutput("docker", "version", "--format", `client: v{{.Client.Version}}{{printf "\n"}}server: v{{.Server.Version}}`)
134134
return version
135135
}
136+
137+
func (d *dockerRuntime) Update(ctx context.Context) error {
138+
return d.guest.Run(
139+
"sh",
140+
"-c",
141+
"sudo apt-get -qq update -y && sudo apt-get -qq install -y --allow-change-held-packages docker-ce docker-ce-cli containerd.io",
142+
)
143+
}

environment/container/incus/incus.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,3 +278,11 @@ type networkInfo struct {
278278
Managed bool `json:"managed"`
279279
Type string `json:"type"`
280280
}
281+
282+
func (c *incusRuntime) Update(ctx context.Context) error {
283+
return c.guest.Run(
284+
"sh",
285+
"-c",
286+
"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",
287+
)
288+
}

environment/container/kubernetes/kubernetes.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,3 +263,8 @@ func (c kubernetesRuntime) Version(context.Context) string {
263263
version, _ := c.host.RunOutput("kubectl", "--context", config.CurrentProfile().ID, "version", "--short")
264264
return version
265265
}
266+
267+
func (c *kubernetesRuntime) Update(ctx context.Context) error {
268+
// update not supported
269+
return nil
270+
}

0 commit comments

Comments
 (0)