Skip to content

Commit

Permalink
vm: ensure user added to docker group (#886)
Browse files Browse the repository at this point in the history
  • Loading branch information
abiosoft authored Nov 18, 2023
1 parent 776ae16 commit 0f4b7f6
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
5 changes: 0 additions & 5 deletions environment/container/docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,6 @@ func (d dockerRuntime) Provision(ctx context.Context) error {
a.Add(d.useContext)
}

// validate docker socket access
a.Add(func() error {
return d.guest.RunQuiet("sh", "-c", "sudo chown ${USER} /var/run/docker.sock")
})

return a.Exec()
}

Expand Down
13 changes: 11 additions & 2 deletions environment/vm/lima/lima.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/abiosoft/colima/daemon"
"github.com/abiosoft/colima/environment"
"github.com/abiosoft/colima/environment/container/containerd"
"github.com/abiosoft/colima/environment/container/docker"
"github.com/abiosoft/colima/environment/vm/lima/limautil"
"github.com/abiosoft/colima/util"
"github.com/abiosoft/colima/util/osutil"
Expand Down Expand Up @@ -107,14 +108,22 @@ func (l *limaVM) Start(ctx context.Context, conf config.Config) error {
return os.Remove(configFile)
})

l.addPostStartActions(a, conf)

// adding it to command chain to execute only after successful startup.
a.Add(func() error {
l.conf = conf
return nil
})

// restart needed for docker user
if conf.Runtime == docker.Name {
a.Add(func() error {
ctx := context.WithValue(ctx, cli.CtxKeyQuiet, true)
return l.Restart(ctx)
})
}

l.addPostStartActions(a, conf)

return a.Exec()
}

Expand Down
10 changes: 6 additions & 4 deletions environment/vm/lima/yaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,9 @@ func newConf(ctx context.Context, conf config.Config) (l Config, err error) {
// add user to docker group
// "sudo", "usermod", "-aG", "docker", user
l.Provision = append(l.Provision, Provision{
Mode: ProvisionModeDependency,
Script: "groupadd -f docker && usermod -aG docker $LIMA_CIDATA_USER",
Mode: ProvisionModeDependency,
Script: "groupadd -f docker && usermod -aG docker $LIMA_CIDATA_USER",
SkipResolution: true,
})

// set hostname
Expand Down Expand Up @@ -430,8 +431,9 @@ const (
)

type Provision struct {
Mode ProvisionMode `yaml:"mode" json:"mode"` // default: "system"
Script string `yaml:"script" json:"script"`
Mode ProvisionMode `yaml:"mode" json:"mode"` // default: "system"
Script string `yaml:"script" json:"script"`
SkipResolution bool `yaml:"skipDefaultDependencyResolution,omitempty" json:"skipDefaultDependencyResolution,omitempty"`
}

type NineP struct {
Expand Down

0 comments on commit 0f4b7f6

Please sign in to comment.