Skip to content

Commit

Permalink
fix(multi-arch): run multi-arch script on every startup (#51)
Browse files Browse the repository at this point in the history
Signed-off-by: Abiola Ibrahim <abiola89@gmail.com>
  • Loading branch information
abiosoft committed Oct 31, 2021
1 parent c2a8642 commit 519a372
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 21 deletions.
13 changes: 2 additions & 11 deletions environment/container/containerd/containerd.go
Expand Up @@ -3,7 +3,6 @@ package containerd
import (
"github.com/abiosoft/colima/cli"
"github.com/abiosoft/colima/environment"
"strconv"
)

// Name is container runtime name
Expand Down Expand Up @@ -42,24 +41,16 @@ func (c containerdRuntime) Provision() error {
return nil
}

const multiArchKey = "containerd_multi_arch"

func (c containerdRuntime) Start() error {
a := c.Init()
a.Stage("starting")
a.Add(func() error {
return c.guest.Run("sudo", "service", "containerd", "start")
})

// tonistiigi/binfmt
a.Add(func() error {
enabled, _ := strconv.ParseBool(c.guest.Get(multiArchKey))
if !enabled {
err := c.guest.Run("sudo", "nerdctl", "run", "--privileged", "--rm", "tonistiigi/binfmt", "--install", "all")
if err == nil {
_ = c.guest.Set(multiArchKey, "true")
_ = c.guest.Run("sudo", "nerdctl", "rmi", "tonistiigi/binfmt")
}
}
_ = c.guest.Run("sudo", "nerdctl", "run", "--privileged", "--rm", "tonistiigi/binfmt", "--install", "all")
return nil
})

Expand Down
11 changes: 1 addition & 10 deletions environment/container/docker/docker.go
Expand Up @@ -96,8 +96,6 @@ func (d dockerRuntime) Provision() error {
return a.Exec()
}

const multiArchKey = "docker_multi_arch"

func (d dockerRuntime) Start() error {
a := d.Init()
a.Stage("starting")
Expand All @@ -109,14 +107,7 @@ func (d dockerRuntime) Start() error {
return d.host.RunQuiet("launchctl", "load", d.launchd.File())
})
a.Add(func() error {
enabled, _ := strconv.ParseBool(d.guest.Get(multiArchKey))
if !enabled {
err := d.guest.RunQuiet("docker", "run", "--privileged", "--rm", "tonistiigi/binfmt", "--install", "all")
if err == nil {
_ = d.guest.Set(multiArchKey, "true")
_ = d.guest.Run("docker", "rmi", "-f", "tonistiigi/binfmt")
}
}
_ = d.guest.Run("docker", "run", "--privileged", "--rm", "tonistiigi/binfmt", "--install", "all")
return nil
})

Expand Down

0 comments on commit 519a372

Please sign in to comment.