Skip to content

Commit 96e28c3

Browse files
committed
Allow changing prefix for the installations
If /usr/local is read-only, you can override the prefix to use something like /opt instead. But it is assumed that /etc is always read-write... Signed-off-by: Anders F Björklund <[email protected]>
1 parent c11f1bf commit 96e28c3

File tree

10 files changed

+33
-8
lines changed

10 files changed

+33
-8
lines changed

examples/default.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,10 @@ caCerts:
158158
# YOUR-ORGS-TRUSTED-CA-CERT-HERE
159159
# -----END CERTIFICATE-----
160160

161+
# Prefix to use for installing guest agent, and containerd with dependencies (if configured)
162+
# 🟢 Builtin default: /usr/local
163+
guestInstallPrefix: null
164+
161165
containerd:
162166
# Enable system-wide (aka rootful) containerd and its dependencies (BuildKit, Stargz Snapshotter)
163167
# Note that `nerdctl.lima` only works in rootless mode; you have to use `lima sudo nerdctl ...`

pkg/cidata/cidata.TEMPLATE.d/boot/25-guestagent-base.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ if [ "${LIMA_CIDATA_MOUNTTYPE}" = "reverse-sshfs" ]; then
1515
fi
1616

1717
# Install or update the guestagent binary
18-
install -m 755 "${LIMA_CIDATA_MNT}"/lima-guestagent /usr/local/bin/lima-guestagent
18+
install -m 755 "${LIMA_CIDATA_MNT}"/lima-guestagent "${LIMA_CIDATA_PREFIX}"/bin/lima-guestagent
1919

2020
# Launch the guestagent service
2121
if [ -f /sbin/openrc-run ]; then
@@ -27,7 +27,7 @@ supervisor=supervise-daemon
2727
name="lima-guestagent"
2828
description="Forward ports to the lima-hostagent"
2929
30-
command=/usr/local/bin/lima-guestagent
30+
command=${LIMA_CIDATA_PREFIX}/bin/lima-guestagent
3131
command_args="daemon"
3232
command_background=true
3333
pidfile="/run/lima-guestagent.pid"
@@ -40,5 +40,5 @@ else
4040
# Remove legacy systemd service
4141
rm -f "/home/${LIMA_CIDATA_USER}.linux/.config/systemd/user/lima-guestagent.service"
4242

43-
sudo /usr/local/bin/lima-guestagent install-systemd
43+
sudo "${LIMA_CIDATA_PREFIX}"/bin/lima-guestagent install-systemd
4444
fi

pkg/cidata/cidata.TEMPLATE.d/boot/40-install-containerd.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,18 @@ command -v systemctl >/dev/null 2>&1 || exit 0
1313
tmp_extract_nerdctl="$(mktemp -d)"
1414
tar Cxzf "${tmp_extract_nerdctl}" "${LIMA_CIDATA_MNT}"/nerdctl-full.tgz bin/nerdctl
1515

16-
if [ ! -f /usr/local/bin/nerdctl ] || [[ "${tmp_extract_nerdctl}"/bin/nerdctl -nt /usr/local/bin/nerdctl ]]; then
17-
if [ -f /usr/local/bin/nerdctl ]; then
16+
if [ ! -f "${LIMA_CIDATA_PREFIX}"/bin/nerdctl ] || [[ "${tmp_extract_nerdctl}"/bin/nerdctl -nt "${LIMA_CIDATA_PREFIX}"/bin/nerdctl ]]; then
17+
if [ -f "${LIMA_CIDATA_PREFIX}"/bin/nerdctl ]; then
1818
(
1919
set +e
2020
echo "Upgrading existing nerdctl"
21-
echo "- Old: $(/usr/local/bin/nerdctl --version)"
21+
echo "- Old: $("${LIMA_CIDATA_PREFIX}"/bin/nerdctl --version)"
2222
echo "- New: $("${tmp_extract_nerdctl}"/bin/nerdctl --version)"
2323
systemctl disable --now containerd buildkit stargz-snapshotter
2424
sudo -iu "${LIMA_CIDATA_USER}" "XDG_RUNTIME_DIR=/run/user/${LIMA_CIDATA_UID}" "PATH=${PATH}" containerd-rootless-setuptool.sh uninstall
2525
)
2626
fi
27-
tar Cxzf /usr/local "${LIMA_CIDATA_MNT}"/nerdctl-full.tgz
27+
tar Cxzf "${LIMA_CIDATA_PREFIX}" "${LIMA_CIDATA_MNT}"/nerdctl-full.tgz
2828

2929
mkdir -p /etc/bash_completion.d
3030
nerdctl completion bash >/etc/bash_completion.d/nerdctl

pkg/cidata/cidata.TEMPLATE.d/lima.env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ LIMA_CIDATA_DISKS={{ len .Disks }}
1212
LIMA_CIDATA_DISK_{{$i}}_NAME={{$disk.Name}}
1313
LIMA_CIDATA_DISK_{{$i}}_DEVICE={{$disk.Device}}
1414
{{- end}}
15+
LIMA_CIDATA_PREFIX={{ .Prefix }}
1516
{{- if .Containerd.User}}
1617
LIMA_CIDATA_CONTAINERD_USER=1
1718
{{- else}}

pkg/cidata/cidata.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ func GenerateISO9660(instDir, name string, y *limayaml.LimaYAML, udpDNSLocalPort
121121
Name: name,
122122
User: u.Username,
123123
UID: uid,
124+
Prefix: *y.Prefix,
124125
Containerd: Containerd{System: *y.Containerd.System, User: *y.Containerd.User},
125126
SlirpNICName: networks.SlirpNICName,
126127
SlirpGateway: networks.SlirpGateway,

pkg/cidata/template.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ type TemplateArgs struct {
5858
Mounts []Mount
5959
MountType string
6060
Disks []Disk
61+
Prefix string
6162
Containerd Containerd
6263
Networks []Network
6364
SlirpNICName string

pkg/hostagent/requirements.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ are set to 'false' in the config file.
158158
description: "containerd binaries to be installed",
159159
script: `#!/bin/bash
160160
set -eux -o pipefail
161-
if ! timeout 30s bash -c "until command -v nerdctl; do sleep 3; done"; then
161+
if ! timeout 30s bash -c "until command -v nerdctl || test -x ` + *a.y.Prefix + `/bin/nerdctl; do sleep 3; done"; then
162162
echo >&2 "nerdctl is not installed yet"
163163
exit 1
164164
fi

pkg/limayaml/defaults.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,10 @@ func defaultDiskSizeAsString() string {
108108
return "100GiB"
109109
}
110110

111+
func defaultPrefix() string {
112+
return "/usr/local"
113+
}
114+
111115
// FillDefault updates undefined fields in y with defaults from d (or built-in default), and overwrites with values from o.
112116
// Both d and o may be empty.
113117
//
@@ -346,6 +350,16 @@ func FillDefault(y, d, o *LimaYAML, filePath string) {
346350
}
347351
}
348352

353+
if y.Prefix == nil {
354+
y.Prefix = d.Prefix
355+
}
356+
if o.Prefix != nil {
357+
y.Prefix = o.Prefix
358+
}
359+
if y.Prefix == nil {
360+
y.Prefix = pointer.String(defaultPrefix())
361+
}
362+
349363
if y.Containerd.System == nil {
350364
y.Containerd.System = d.Containerd.System
351365
}

pkg/limayaml/defaults_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ func TestFillDefault(t *testing.T) {
7171
CPUs: pointer.Int(defaultCPUs()),
7272
Memory: pointer.String(defaultMemoryAsString()),
7373
Disk: pointer.String(defaultDiskSizeAsString()),
74+
Prefix: pointer.String(defaultPrefix()),
7475
Containerd: Containerd{
7576
System: pointer.Bool(false),
7677
User: pointer.Bool(true),
@@ -278,6 +279,7 @@ func TestFillDefault(t *testing.T) {
278279
AdditionalDisks: []Disk{
279280
"data",
280281
},
282+
Prefix: pointer.String("/opt"),
281283
Containerd: Containerd{
282284
System: pointer.Bool(true),
283285
User: pointer.Bool(false),
@@ -454,6 +456,7 @@ func TestFillDefault(t *testing.T) {
454456
AdditionalDisks: []Disk{
455457
"test",
456458
},
459+
Prefix: pointer.String("/usr"),
457460
Containerd: Containerd{
458461
System: pointer.Bool(true),
459462
User: pointer.Bool(false),

pkg/limayaml/limayaml.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ type LimaYAML struct {
2323
Video Video `yaml:"video,omitempty" json:"video,omitempty"`
2424
Provision []Provision `yaml:"provision,omitempty" json:"provision,omitempty"`
2525
Containerd Containerd `yaml:"containerd,omitempty" json:"containerd,omitempty"`
26+
Prefix *string `yaml:"guestInstallPrefix,omitempty" json:"guestInstallPrefix,omitempty"`
2627
Probes []Probe `yaml:"probes,omitempty" json:"probes,omitempty"`
2728
PortForwards []PortForward `yaml:"portForwards,omitempty" json:"portForwards,omitempty"`
2829
CopyToHost []CopyToHost `yaml:"copyToHost,omitempty" json:"copyToHost,omitempty"`

0 commit comments

Comments
 (0)