Skip to content

Add "plain" mode (disables mounts, port forwarding, containerd, etc.) #1840

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 8, 2023
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
3 changes: 3 additions & 0 deletions cmd/limactl/editflags/editflags.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ func RegisterCreate(cmd *cobra.Command, commentPrefix string) {
_ = cmd.RegisterFlagCompletionFunc("vm-type", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
return []string{"qemu", "vz"}, cobra.ShellCompDirectiveNoFileComp
})

flags.Bool("plain", false, commentPrefix+"plain mode. Disable mounts, port forwarding, containerd, etc.")
}

func defaultExprFunc(expr string) func(v *flag.Flag) (string, error) {
Expand Down Expand Up @@ -225,6 +227,7 @@ func YQExpressions(flags *flag.FlagSet, newInstance bool) ([]string, error) {

{"disk", d(".disk= \"%sGiB\""), true, false},
{"vm-type", d(".vmType = %q"), true, false},
{"plain", d(".plain = %s"), true, false},
}
var exprs []string
for _, def := range defs {
Expand Down
8 changes: 8 additions & 0 deletions examples/default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,14 @@ hostResolver:
# 🟢 Builtin default: /usr/local
guestInstallPrefix: null

# When the "plain" mode is enabled:
# - the YAML properties for mounts, port forwarding, containerd, etc. will be ignored
# - guest agent will not be running
# - dependency packages like sshfs will not be installed into the VM
# User-specified provisioning scripts will be still executed.
# 🟢 Builtin default: false
plain: null

# ===================================================================== #
# GLOBAL DEFAULTS AND OVERRIDES
# ===================================================================== #
Expand Down
18 changes: 11 additions & 7 deletions pkg/cidata/cidata.TEMPLATE.d/boot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,17 @@ CODE=0
# has run because it might move the directories to /mnt/data on first boot. In that
# case changes made on restart would be lost.

for f in "${LIMA_CIDATA_MNT}"/boot/*; do
INFO "Executing $f"
if ! "$f"; then
WARNING "Failed to execute $f"
CODE=1
fi
done
if [ "$LIMA_CIDATA_PLAIN" = "1" ]; then
INFO "Plain mode. Skipping to run boot scripts. Provisioning scripts will be still executed. Guest agent will not be running."
else
for f in "${LIMA_CIDATA_MNT}"/boot/*; do
INFO "Executing $f"
if ! "$f"; then
WARNING "Failed to execute $f"
CODE=1
fi
done
fi

if [ -d "${LIMA_CIDATA_MNT}"/provision.system ]; then
for f in "${LIMA_CIDATA_MNT}"/provision.system/*; do
Expand Down
5 changes: 5 additions & 0 deletions pkg/cidata/cidata.TEMPLATE.d/lima.env
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,8 @@ LIMA_CIDATA_SKIP_DEFAULT_DEPENDENCY_RESOLUTION=
{{- end}}
LIMA_CIDATA_VMTYPE={{ .VMType }}
LIMA_CIDATA_VSOCK_PORT={{ .VSockPort }}
{{- if .Plain}}
LIMA_CIDATA_PLAIN=1
{{- else}}
LIMA_CIDATA_PLAIN=
{{- end}}
1 change: 1 addition & 0 deletions pkg/cidata/cidata.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ func GenerateISO9660(instDir, name string, y *limayaml.LimaYAML, udpDNSLocalPort
RosettaBinFmt: *y.Rosetta.BinFmt,
VMType: *y.VMType,
VSockPort: vsockPort,
Plain: *y.Plain,
}

firstUsernetIndex := limayaml.FirstUsernetIndex(y)
Expand Down
1 change: 1 addition & 0 deletions pkg/cidata/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ type TemplateArgs struct {
SkipDefaultDependencyResolution bool
VMType string
VSockPort int
Plain bool
}

func ValidateTemplateArgs(args TemplateArgs) error {
Expand Down
9 changes: 7 additions & 2 deletions pkg/hostagent/hostagent.go
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,9 @@ func (a *HostAgent) Info(_ context.Context) (*hostagentapi.Info, error) {
}

func (a *HostAgent) startHostAgentRoutines(ctx context.Context) error {
if *a.y.Plain {
logrus.Info("Running in plain mode. Mounts, port forwarding, containerd, etc. will be ignored. Guest agent will not be running.")
}
a.onClose = append(a.onClose, func() error {
logrus.Debugf("shutting down the SSH master")
if exitMasterErr := ssh.ExitMaster(a.instSSHAddress, a.sshLocalPort, a.sshConfig); exitMasterErr != nil {
Expand All @@ -451,7 +454,7 @@ sudo chown -R "${USER}" /run/host-services`
errs = append(errs, fmt.Errorf("stdout=%q, stderr=%q: %w", stdout, stderr, err))
}
}
if *a.y.MountType == limayaml.REVSSHFS {
if *a.y.MountType == limayaml.REVSSHFS && !*a.y.Plain {
mounts, err := a.setupMounts()
if err != nil {
errs = append(errs, err)
Expand Down Expand Up @@ -483,7 +486,9 @@ sudo chown -R "${USER}" /run/host-services`
return errors.Join(unlockErrs...)
})
}
go a.watchGuestAgentEvents(ctx)
if !*a.y.Plain {
go a.watchGuestAgentEvents(ctx)
}
if err := a.waitForRequirements("optional", a.optionalRequirements()); err != nil {
errs = append(errs, err)
}
Expand Down
8 changes: 6 additions & 2 deletions pkg/hostagent/requirements.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,11 @@ true
Make sure that the YAML field "ssh.localPort" is not used by other processes on the host.
If any private key under ~/.ssh is protected with a passphrase, you need to have ssh-agent to be running.
`,
},
})
if *a.y.Plain {
return req
}
req = append(req,
requirement{
description: "user session is ready for ssh",
script: `#!/bin/bash
Expand Down Expand Up @@ -156,7 +160,7 @@ A possible workaround is to run "lima-guestagent install-systemd" in the guest.

func (a *HostAgent) optionalRequirements() []requirement {
req := make([]requirement, 0)
if *a.y.Containerd.System || *a.y.Containerd.User {
if (*a.y.Containerd.System || *a.y.Containerd.User) && !*a.y.Plain {
req = append(req,
requirement{
description: "systemd must be available",
Expand Down
24 changes: 24 additions & 0 deletions pkg/limayaml/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,30 @@ func FillDefault(y, d, o *LimaYAML, filePath string) {
if y.Rosetta.BinFmt == nil {
y.Rosetta.BinFmt = pointer.Bool(false)
}

if y.Plain == nil {
y.Plain = d.Plain
}
if o.Plain != nil {
y.Plain = o.Plain
}
if y.Plain == nil {
y.Plain = pointer.Bool(false)
}

fixUpForPlainMode(y)
}

func fixUpForPlainMode(y *LimaYAML) {
if !*y.Plain {
return
}
y.Mounts = nil
y.PortForwards = nil
y.Containerd.System = pointer.Bool(false)
y.Containerd.User = pointer.Bool(false)
y.Rosetta.BinFmt = pointer.Bool(false)
y.Rosetta.Enabled = pointer.Bool(false)
}

func executeGuestTemplate(format string) (bytes.Buffer, error) {
Expand Down
3 changes: 3 additions & 0 deletions pkg/limayaml/defaults_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ func TestFillDefault(t *testing.T) {
CACertificates: CACertificates{
RemoveDefaults: pointer.Bool(false),
},
Plain: pointer.Bool(false),
}
if IsAccelOS() {
if HasHostCPU() {
Expand Down Expand Up @@ -405,6 +406,7 @@ func TestFillDefault(t *testing.T) {
BinFmt: pointer.Bool(true),
}
}
expect.Plain = pointer.Bool(false)

y = LimaYAML{}
FillDefault(&y, &d, &LimaYAML{}, filePath)
Expand Down Expand Up @@ -617,6 +619,7 @@ func TestFillDefault(t *testing.T) {
Enabled: pointer.Bool(false),
BinFmt: pointer.Bool(false),
}
expect.Plain = pointer.Bool(false)

FillDefault(&y, &d, &o, filePath)
assert.DeepEqual(t, &y, &expect, opts...)
Expand Down
1 change: 1 addition & 0 deletions pkg/limayaml/limayaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type LimaYAML struct {
PropagateProxyEnv *bool `yaml:"propagateProxyEnv,omitempty" json:"propagateProxyEnv,omitempty"`
CACertificates CACertificates `yaml:"caCerts,omitempty" json:"caCerts,omitempty"`
Rosetta Rosetta `yaml:"rosetta,omitempty" json:"rosetta,omitempty"`
Plain *bool `yaml:"plain,omitempty" json:"plain,omitempty"`
}

type OS = string
Expand Down
6 changes: 5 additions & 1 deletion pkg/start/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,11 @@ func watchHostAgentEvents(ctx context.Context, inst *store.Instance, haStdoutPat
return true
}

logrus.Infof("READY. Run `%s` to open the shell.", LimactlShellCmd(inst.Name))
if *inst.Config.Plain {
logrus.Infof("READY. Run `ssh -F %q lima-%s` to open the shell.", inst.SSHConfigFile, inst.Name)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Y not use LimactlShellCmd(inst.Name) here ?? Ssh connection stays the same right evn for plan mode ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because plain mode users are less likely to prefer lima-ist commands.
The limactl shell command continue to work.

Copy link
Member

@afbjorklund afbjorklund Sep 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still think the lima wrapper (but only that script, not the others) belongs to the "minimal" footprint.

But I suppose ssh is even more "plain".

Or maybe: lima-ssh lima-default

} else {
logrus.Infof("READY. Run `%s` to open the shell.", LimactlShellCmd(inst.Name))
}
ShowMessage(inst)
err = nil
return true
Expand Down
1 change: 1 addition & 0 deletions pkg/vz/vz_driver_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ func (l *LimaVzDriver) Validate() error {
"Audio",
"Video",
"OS",
"Plain",
); len(unknown) > 0 {
logrus.Warnf("vmType %s: ignoring %+v", *l.Yaml.VMType, unknown)
}
Expand Down
1 change: 1 addition & 0 deletions pkg/wsl2/wsl_driver_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ func (l *LimaWslDriver) Validate() error {
"DNS",
"HostResolver",
"PropagateProxyEnv",
"Plain",
); len(unknown) > 0 {
logrus.Warnf("Ignoring: vmType %s: %+v", *l.Yaml.VMType, unknown)
}
Expand Down
28 changes: 28 additions & 0 deletions website/content/en/docs/faq/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ weight: 6
- ["Can I run other container engines such as Docker and Podman? What about Kubernetes?"](#can-i-run-other-container-engines-such-as-docker-and-podman-what-about-kubernetes)
- ["Can I run Lima with a remote Linux machine?"](#can-i-run-lima-with-a-remote-linux-machine)
- ["Advantages compared to Docker for Mac?"](#advantages-compared-to-docker-for-mac)
- [Configuration](#configuration)
- ["Is it possible to disable mounts, port forwarding, containerd, etc. ?"](#is-it-possible-to-disable-mounts-port-forwarding-containerd-etc-)
- [QEMU](#qemu)
- ["QEMU crashes with `HV_ERROR`"](#qemu-crashes-with-hv_error)
- ["QEMU is slow"](#qemu-is-slow)
Expand Down Expand Up @@ -105,6 +107,32 @@ and forward `localhost:8080` to the port 80 of the remote machine.
#### "Advantages compared to Docker for Mac?"
Lima is free software (Apache License 2.0), while Docker for Mac is not.

### Configuration
#### "Is it possible to disable mounts, port forwarding, containerd, etc. ?"

Yes, since Lima v0.18:

{{< tabpane text=true >}}
{{% tab header="CLI" %}}
```bash
limactl start --plain
```
{{% /tab %}}
{{% tab header="YAML" %}}
```yaml
plain: true
```
{{% /tab %}}
{{< /tabpane >}}


When the "plain" mode is enabled:
- the YAML properties for mounts, port forwarding, containerd, etc. will be ignored
- guest agent will not be running
- dependency packages like sshfs will not be installed into the VM

User-specified provisioning scripts will be still executed.

### QEMU
#### "QEMU crashes with `HV_ERROR`"
If you have installed QEMU v6.0.0 or later on macOS 11 via homebrew, your QEMU binary should have been already automatically signed to enable HVF acceleration.
Expand Down