Skip to content

Commit

Permalink
Support bridged networking (#75)
Browse files Browse the repository at this point in the history
* Support bridged networking

Fixes #74

* reverted formatting

* fixed type

* Use ARP resolver for bridged network
  • Loading branch information
fkorotkov authored May 3, 2024
1 parent 756c5c5 commit 4d29d8d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ that required paid sponsorship upon exceeding a free limit.
| `TART_EXECUTOR_INSECURE_PULL` | false | Set to `true` to connect the OCI registry via insecure HTTP protocol |
| `TART_EXECUTOR_PULL_CONCURRENCY` | | Override the Tart's default network concurrency parameter (`--concurrency`) when pulling remote VMs from the OCI-compatible registries |
| `TART_EXECUTOR_SOFTNET` | false | Whether to enable [Softnet](https://github.com/cirruslabs/softnet) software networking (`true`) or disable it (`false`) |
| `TART_EXECUTOR_BRIDGED` | | Use bridged networking, for example, "en0". Use `tart run --net-bridged=list` to see names of all available interfaces. |
| `TART_EXECUTOR_HOST_DIR`<sup>1</sup> | false | Whether to mount a temporary directory from the host for performance reasons (`true`) or use a directory inside of a guest (`false`) |
| `TART_EXECUTOR_SHELL` | system default | Alternative [Unix shell](https://en.wikipedia.org/wiki/Unix_shell) to use (e.g. `bash -l`) |
| `TART_EXECUTOR_INSTALL_GITLAB_RUNNER` | | Set to `brew` to install GitLab Runner [via Homebrew](https://docs.gitlab.com/runner/install/osx.html#homebrew-installation-alternative), `curl` to install the latest version [using cURL](https://docs.gitlab.com/runner/install/osx.html#manual-installation-official) or `major.minor.patch` to install a specific version [using cURL](https://docs.gitlab.com/runner/install/bleeding-edge.html#download-any-other-tagged-release) |
Expand Down
1 change: 1 addition & 0 deletions internal/tart/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ type Config struct {
SSHUsername string `env:"SSH_USERNAME" envDefault:"admin"`
SSHPassword string `env:"SSH_PASSWORD" envDefault:"admin"`
SSHPort uint16 `env:"SSH_PORT" envDefault:"22"`
Bridged string `env:"BRIDGED"`
Softnet bool `env:"SOFTNET"`
Headless bool `env:"HEADLESS" envDefault:"true"`
AlwaysPull bool `env:"ALWAYS_PULL" envDefault:"true"`
Expand Down
14 changes: 11 additions & 3 deletions internal/tart/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ func (vm *VM) Start(
runArgs = append(runArgs, "--net-softnet")
}

if config.Bridged != "" {
runArgs = append(runArgs, "--net-bridged", config.Bridged)
}

if config.Headless {
runArgs = append(runArgs, "--no-graphics")
}
Expand Down Expand Up @@ -190,7 +194,7 @@ func (vm *VM) MonitorTartRunOutput() {
}

func (vm *VM) OpenSSH(ctx context.Context, config Config) (*ssh.Client, error) {
ip, err := vm.IP(ctx)
ip, err := vm.IP(ctx, config)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -231,8 +235,12 @@ func (vm *VM) OpenSSH(ctx context.Context, config Config) (*ssh.Client, error) {
return sshClient, nil
}

func (vm *VM) IP(ctx context.Context) (string, error) {
stdout, _, err := TartExec(ctx, "ip", "--wait", "60", vm.id)
func (vm *VM) IP(ctx context.Context, config Config) (string, error) {
resolver := "dhcp"
if config.Bridged != "" {
resolver = "arp"
}
stdout, _, err := TartExec(ctx, "ip", "--wait", "60", "--resolver", resolver, vm.id)
if err != nil {
return "", err
}
Expand Down

0 comments on commit 4d29d8d

Please sign in to comment.