Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,9 @@ func init() {
startCmd.Flags().StringVarP(&startCmdArgs.DiskImage, "disk-image", "i", "", "file path to a custom disk image")
startCmd.Flags().BoolVar(&startCmdArgs.Flags.Template, "template", true, "use the template file for initial configuration")

// port forwarder
startCmd.Flags().StringVar(&startCmdArgs.PortForwarder, "port-forwarder", "ssh", "port forwarder to use (ssh, grpc)")

// retain cpu flag for backward compatibility
startCmd.Flags().IntVar(&startCmdArgs.Flags.LegacyCPU, "cpu", defaultCPU, "number of CPUs")
startCmd.Flag("cpu").Hidden = true
Expand Down Expand Up @@ -490,6 +493,9 @@ func prepareConfig(cmd *cobra.Command) {
if !cmd.Flag("ssh-port").Changed {
startCmdArgs.SSHPort = current.SSHPort
}
if !cmd.Flag("port-forwarder").Changed {
startCmdArgs.PortForwarder = current.PortForwarder
}
if !cmd.Flag("dns").Changed {
startCmdArgs.Network.DNSResolvers = current.Network.DNSResolvers
}
Expand Down
1 change: 1 addition & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ type Config struct {
Binfmt *bool `yaml:"binfmt,omitempty"`
NestedVirtualization bool `yaml:"nestedVirtualization,omitempty"`
DiskImage string `yaml:"diskImage,omitempty"`
PortForwarder string `yaml:"portForwarder,omitempty"` // "ssh", "grpc"

// volume mounts
Mounts []Mount `yaml:"mounts,omitempty"`
Expand Down
6 changes: 6 additions & 0 deletions config/configmanager/configmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ func LoadFrom(file string) (config.Config, error) {
// ValidateConfig validates config before we use it
func ValidateConfig(c config.Config) error {
validMountTypes := map[string]bool{"9p": true, "sshfs": true}
validPortForwarders := map[string]bool{"grpc": true, "ssh": true}

if util.MacOS13OrNewer() {
validMountTypes["virtiofs"] = true
}
Expand All @@ -84,6 +86,10 @@ func ValidateConfig(c config.Config) error {
}
}

if _, ok := validPortForwarders[c.PortForwarder]; !ok {
return fmt.Errorf("invalid port forwarder: '%s'", c.PortForwarder)
}

return nil
}

Expand Down
7 changes: 7 additions & 0 deletions embedded/defaults/colima.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,13 @@ docker: {}
# Default: qemu
vmType: qemu

# Port forwarder for the virtual machine (ssh, grpc).
# ssh is more stable but supports only TCP.
# grpc supports both TCP and UDP, but is experimental.
#
# Default: ssh
portForwarder: ssh

# Utilise rosetta for amd64 emulation (requires m1 mac and vmType `vz`)
# Default: false
rosetta: false
Expand Down
11 changes: 11 additions & 0 deletions environment/vm/lima/lima.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"os"
"path/filepath"
"strconv"
"time"

"github.com/abiosoft/colima/cli"
Expand Down Expand Up @@ -78,6 +79,8 @@ func (l limaVM) Dependencies() []string {
func (l *limaVM) Start(ctx context.Context, conf config.Config) error {
a := l.Init(ctx)

l.prepareHost(conf)

if l.Created() {
return l.resume(ctx, conf)
}
Expand Down Expand Up @@ -447,3 +450,11 @@ func (l *limaVM) assertQemu() error {
}
return nil
}

const envLimaSSHPortForwarder = "LIMA_SSH_PORT_FORWARDER"

func (l *limaVM) prepareHost(conf config.Config) {
useSSHPortForwarder := conf.PortForwarder != "grpc"

l.host = l.host.WithEnv(envLimaSSHPortForwarder + "=" + strconv.FormatBool(useSSHPortForwarder))
}