Skip to content

Allow changing prefix for the installations #1655

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
Jul 23, 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
4 changes: 4 additions & 0 deletions examples/default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,10 @@ hostResolver:
# - 1.1.1.1
# - 1.0.0.1

# Prefix to use for installing guest agent, and containerd with dependencies (if configured)
# 🟢 Builtin default: /usr/local
guestInstallPrefix: null

# ===================================================================== #
# GLOBAL DEFAULTS AND OVERRIDES
# ===================================================================== #
Expand Down
6 changes: 3 additions & 3 deletions pkg/cidata/cidata.TEMPLATE.d/boot/25-guestagent-base.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ if [ "${LIMA_CIDATA_MOUNTTYPE}" = "reverse-sshfs" ]; then
fi

# Install or update the guestagent binary
install -m 755 "${LIMA_CIDATA_MNT}"/lima-guestagent /usr/local/bin/lima-guestagent
install -m 755 "${LIMA_CIDATA_MNT}"/lima-guestagent "${LIMA_CIDATA_GUEST_INSTALL_PREFIX}"/bin/lima-guestagent

# Launch the guestagent service
if [ -f /sbin/openrc-run ]; then
Expand All @@ -27,7 +27,7 @@ supervisor=supervise-daemon
name="lima-guestagent"
description="Forward ports to the lima-hostagent"

command=/usr/local/bin/lima-guestagent
command=${LIMA_CIDATA_GUEST_INSTALL_PREFIX}/bin/lima-guestagent
command_args="daemon"
command_background=true
pidfile="/run/lima-guestagent.pid"
Expand All @@ -40,5 +40,5 @@ else
# Remove legacy systemd service
rm -f "/home/${LIMA_CIDATA_USER}.linux/.config/systemd/user/lima-guestagent.service"

sudo /usr/local/bin/lima-guestagent install-systemd
sudo "${LIMA_CIDATA_GUEST_INSTALL_PREFIX}"/bin/lima-guestagent install-systemd
fi
8 changes: 4 additions & 4 deletions pkg/cidata/cidata.TEMPLATE.d/boot/40-install-containerd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@ command -v systemctl >/dev/null 2>&1 || exit 0
tmp_extract_nerdctl="$(mktemp -d)"
tar Cxzf "${tmp_extract_nerdctl}" "${LIMA_CIDATA_MNT}"/nerdctl-full.tgz bin/nerdctl

if [ ! -f /usr/local/bin/nerdctl ] || [[ "${tmp_extract_nerdctl}"/bin/nerdctl -nt /usr/local/bin/nerdctl ]]; then
if [ -f /usr/local/bin/nerdctl ]; then
if [ ! -f "${LIMA_CIDATA_GUEST_INSTALL_PREFIX}"/bin/nerdctl ] || [[ "${tmp_extract_nerdctl}"/bin/nerdctl -nt "${LIMA_CIDATA_GUEST_INSTALL_PREFIX}"/bin/nerdctl ]]; then
if [ -f "${LIMA_CIDATA_GUEST_INSTALL_PREFIX}"/bin/nerdctl ]; then
(
set +e
echo "Upgrading existing nerdctl"
echo "- Old: $(/usr/local/bin/nerdctl --version)"
echo "- Old: $("${LIMA_CIDATA_GUEST_INSTALL_PREFIX}"/bin/nerdctl --version)"
echo "- New: $("${tmp_extract_nerdctl}"/bin/nerdctl --version)"
systemctl disable --now containerd buildkit stargz-snapshotter
sudo -iu "${LIMA_CIDATA_USER}" "XDG_RUNTIME_DIR=/run/user/${LIMA_CIDATA_UID}" "PATH=${PATH}" containerd-rootless-setuptool.sh uninstall
)
fi
tar Cxzf /usr/local "${LIMA_CIDATA_MNT}"/nerdctl-full.tgz
tar Cxzf "${LIMA_CIDATA_GUEST_INSTALL_PREFIX}" "${LIMA_CIDATA_MNT}"/nerdctl-full.tgz

mkdir -p /etc/bash_completion.d
nerdctl completion bash >/etc/bash_completion.d/nerdctl
Expand Down
1 change: 1 addition & 0 deletions pkg/cidata/cidata.TEMPLATE.d/lima.env
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ LIMA_CIDATA_DISKS={{ len .Disks }}
LIMA_CIDATA_DISK_{{$i}}_NAME={{$disk.Name}}
LIMA_CIDATA_DISK_{{$i}}_DEVICE={{$disk.Device}}
{{- end}}
LIMA_CIDATA_GUEST_INSTALL_PREFIX={{ .GuestInstallPrefix }}
{{- if .Containerd.User}}
LIMA_CIDATA_CONTAINERD_USER=1
{{- else}}
Expand Down
21 changes: 11 additions & 10 deletions pkg/cidata/cidata.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,16 +118,17 @@ func GenerateISO9660(instDir, name string, y *limayaml.LimaYAML, udpDNSLocalPort
return err
}
args := TemplateArgs{
Name: name,
User: u.Username,
UID: uid,
Containerd: Containerd{System: *y.Containerd.System, User: *y.Containerd.User},
SlirpNICName: networks.SlirpNICName,
SlirpGateway: networks.SlirpGateway,
SlirpDNS: networks.SlirpDNS,
SlirpIPAddress: networks.SlirpIPAddress,
RosettaEnabled: *y.Rosetta.Enabled,
RosettaBinFmt: *y.Rosetta.BinFmt,
Name: name,
User: u.Username,
UID: uid,
GuestInstallPrefix: *y.GuestInstallPrefix,
Containerd: Containerd{System: *y.Containerd.System, User: *y.Containerd.User},
SlirpNICName: networks.SlirpNICName,
SlirpGateway: networks.SlirpGateway,
SlirpDNS: networks.SlirpDNS,
SlirpIPAddress: networks.SlirpIPAddress,
RosettaEnabled: *y.Rosetta.Enabled,
RosettaBinFmt: *y.Rosetta.BinFmt,
}

// change instance id on every boot so network config will be processed again
Expand Down
1 change: 1 addition & 0 deletions pkg/cidata/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ type TemplateArgs struct {
Mounts []Mount
MountType string
Disks []Disk
GuestInstallPrefix string
Containerd Containerd
Networks []Network
SlirpNICName string
Expand Down
2 changes: 1 addition & 1 deletion pkg/hostagent/requirements.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ are set to 'false' in the config file.
description: "containerd binaries to be installed",
script: `#!/bin/bash
set -eux -o pipefail
if ! timeout 30s bash -c "until command -v nerdctl; do sleep 3; done"; then
if ! timeout 30s bash -c "until command -v nerdctl || test -x ` + *a.y.GuestInstallPrefix + `/bin/nerdctl; do sleep 3; done"; then
echo >&2 "nerdctl is not installed yet"
exit 1
fi
Expand Down
14 changes: 14 additions & 0 deletions pkg/limayaml/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ func defaultDiskSizeAsString() string {
return "100GiB"
}

func defaultGuestInstallPrefix() string {
return "/usr/local"
}

// FillDefault updates undefined fields in y with defaults from d (or built-in default), and overwrites with values from o.
// Both d and o may be empty.
//
Expand Down Expand Up @@ -346,6 +350,16 @@ func FillDefault(y, d, o *LimaYAML, filePath string) {
}
}

if y.GuestInstallPrefix == nil {
y.GuestInstallPrefix = d.GuestInstallPrefix
}
if o.GuestInstallPrefix != nil {
y.GuestInstallPrefix = o.GuestInstallPrefix
}
if y.GuestInstallPrefix == nil {
y.GuestInstallPrefix = pointer.String(defaultGuestInstallPrefix())
}

if y.Containerd.System == nil {
y.Containerd.System = d.Containerd.System
}
Expand Down
9 changes: 6 additions & 3 deletions pkg/limayaml/defaults_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,10 @@ func TestFillDefault(t *testing.T) {
X8664: "qemu64",
RISCV64: "rv64",
},
CPUs: pointer.Int(defaultCPUs()),
Memory: pointer.String(defaultMemoryAsString()),
Disk: pointer.String(defaultDiskSizeAsString()),
CPUs: pointer.Int(defaultCPUs()),
Memory: pointer.String(defaultMemoryAsString()),
Disk: pointer.String(defaultDiskSizeAsString()),
GuestInstallPrefix: pointer.String(defaultGuestInstallPrefix()),
Containerd: Containerd{
System: pointer.Bool(false),
User: pointer.Bool(true),
Expand Down Expand Up @@ -278,6 +279,7 @@ func TestFillDefault(t *testing.T) {
AdditionalDisks: []Disk{
"data",
},
GuestInstallPrefix: pointer.String("/opt"),
Containerd: Containerd{
System: pointer.Bool(true),
User: pointer.Bool(false),
Expand Down Expand Up @@ -454,6 +456,7 @@ func TestFillDefault(t *testing.T) {
AdditionalDisks: []Disk{
"test",
},
GuestInstallPrefix: pointer.String("/usr"),
Containerd: Containerd{
System: pointer.Bool(true),
User: pointer.Bool(false),
Expand Down
43 changes: 22 additions & 21 deletions pkg/limayaml/limayaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,28 @@ import (
)

type LimaYAML struct {
VMType *VMType `yaml:"vmType,omitempty" json:"vmType,omitempty"`
Arch *Arch `yaml:"arch,omitempty" json:"arch,omitempty"`
Images []Image `yaml:"images" json:"images"` // REQUIRED
CPUType map[Arch]string `yaml:"cpuType,omitempty" json:"cpuType,omitempty"`
CPUs *int `yaml:"cpus,omitempty" json:"cpus,omitempty"`
Memory *string `yaml:"memory,omitempty" json:"memory,omitempty"` // go-units.RAMInBytes
Disk *string `yaml:"disk,omitempty" json:"disk,omitempty"` // go-units.RAMInBytes
AdditionalDisks []Disk `yaml:"additionalDisks,omitempty" json:"additionalDisks,omitempty"`
Mounts []Mount `yaml:"mounts,omitempty" json:"mounts,omitempty"`
MountType *MountType `yaml:"mountType,omitempty" json:"mountType,omitempty"`
SSH SSH `yaml:"ssh,omitempty" json:"ssh,omitempty"` // REQUIRED (FIXME)
Firmware Firmware `yaml:"firmware,omitempty" json:"firmware,omitempty"`
Audio Audio `yaml:"audio,omitempty" json:"audio,omitempty"`
Video Video `yaml:"video,omitempty" json:"video,omitempty"`
Provision []Provision `yaml:"provision,omitempty" json:"provision,omitempty"`
Containerd Containerd `yaml:"containerd,omitempty" json:"containerd,omitempty"`
Probes []Probe `yaml:"probes,omitempty" json:"probes,omitempty"`
PortForwards []PortForward `yaml:"portForwards,omitempty" json:"portForwards,omitempty"`
CopyToHost []CopyToHost `yaml:"copyToHost,omitempty" json:"copyToHost,omitempty"`
Message string `yaml:"message,omitempty" json:"message,omitempty"`
Networks []Network `yaml:"networks,omitempty" json:"networks,omitempty"`
VMType *VMType `yaml:"vmType,omitempty" json:"vmType,omitempty"`
Arch *Arch `yaml:"arch,omitempty" json:"arch,omitempty"`
Images []Image `yaml:"images" json:"images"` // REQUIRED
CPUType map[Arch]string `yaml:"cpuType,omitempty" json:"cpuType,omitempty"`
CPUs *int `yaml:"cpus,omitempty" json:"cpus,omitempty"`
Memory *string `yaml:"memory,omitempty" json:"memory,omitempty"` // go-units.RAMInBytes
Disk *string `yaml:"disk,omitempty" json:"disk,omitempty"` // go-units.RAMInBytes
AdditionalDisks []Disk `yaml:"additionalDisks,omitempty" json:"additionalDisks,omitempty"`
Mounts []Mount `yaml:"mounts,omitempty" json:"mounts,omitempty"`
MountType *MountType `yaml:"mountType,omitempty" json:"mountType,omitempty"`
SSH SSH `yaml:"ssh,omitempty" json:"ssh,omitempty"` // REQUIRED (FIXME)
Firmware Firmware `yaml:"firmware,omitempty" json:"firmware,omitempty"`
Audio Audio `yaml:"audio,omitempty" json:"audio,omitempty"`
Video Video `yaml:"video,omitempty" json:"video,omitempty"`
Provision []Provision `yaml:"provision,omitempty" json:"provision,omitempty"`
Containerd Containerd `yaml:"containerd,omitempty" json:"containerd,omitempty"`
GuestInstallPrefix *string `yaml:"guestInstallPrefix,omitempty" json:"guestInstallPrefix,omitempty"`
Probes []Probe `yaml:"probes,omitempty" json:"probes,omitempty"`
PortForwards []PortForward `yaml:"portForwards,omitempty" json:"portForwards,omitempty"`
CopyToHost []CopyToHost `yaml:"copyToHost,omitempty" json:"copyToHost,omitempty"`
Message string `yaml:"message,omitempty" json:"message,omitempty"`
Networks []Network `yaml:"networks,omitempty" json:"networks,omitempty"`
// `network` was deprecated in Lima v0.7.0, removed in Lima v0.14.0. Use `networks` instead.
Env map[string]string `yaml:"env,omitempty" json:"env,omitempty"`
DNS []net.IP `yaml:"dns,omitempty" json:"dns,omitempty"`
Expand Down