Skip to content

Commit 98e0f62

Browse files
authored
Merge pull request #39 from AkihiroSuda/dev
Follow-up to "Implement system and user provisioning scripts" (#38)
2 parents e048992 + 64d4b1e commit 98e0f62

File tree

4 files changed

+39
-22
lines changed

4 files changed

+39
-22
lines changed

cmd/limactl/shell.go

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -55,30 +55,38 @@ func shellAction(clicontext *cli.Context) error {
5555
return err
5656
}
5757

58-
// Buildup changeDirCmd to "cd workDir || cd currentDir || cd homeDir"
58+
// When workDir is explicitly set, the shell MUST have workDir as the cwd, or exit with an error.
59+
//
60+
// changeDirCmd := "cd workDir || exit 1" if workDir != ""
61+
// := "cd hostCurrentDir || cd hostHomeDir" if workDir == ""
5962
var changeDirCmd string
60-
workDir := clicontext.String("workdir")
61-
if workDir == "" {
62-
changeDirCmd = "false"
63-
} else {
64-
changeDirCmd = fmt.Sprintf("cd %q", workDir)
65-
}
66-
if len(y.Mounts) > 0 {
67-
currentDir, err := os.Getwd()
63+
if workDir := clicontext.String("workdir"); workDir != "" {
64+
changeDirCmd = fmt.Sprintf("cd %q || exit 1", workDir)
65+
// FIXME: check whether y.Mounts contains the home, not just len > 0
66+
} else if len(y.Mounts) > 0 {
67+
hostCurrentDir, err := os.Getwd()
6868
if err == nil {
69-
changeDirCmd = fmt.Sprintf("%s || cd %q", changeDirCmd, currentDir)
69+
changeDirCmd = fmt.Sprintf("cd %q", hostCurrentDir)
7070
} else {
71+
changeDirCmd = "false"
7172
logrus.WithError(err).Warn("failed to get the current directory")
7273
}
73-
homeDir, err := os.UserHomeDir()
74+
hostHomeDir, err := os.UserHomeDir()
7475
if err == nil {
75-
changeDirCmd = fmt.Sprintf("%s || cd %q", changeDirCmd, homeDir)
76+
changeDirCmd = fmt.Sprintf("%s || cd %q", changeDirCmd, hostHomeDir)
7677
} else {
7778
logrus.WithError(err).Warn("failed to get the home directory")
7879
}
80+
} else {
81+
logrus.Debug("the host home does not seem mounted, so the guest shell will have a different cwd")
82+
}
83+
84+
if changeDirCmd == "" {
85+
changeDirCmd = "false"
7986
}
87+
logrus.Debugf("changeDirCmd=%q", changeDirCmd)
8088

81-
script := fmt.Sprintf(" %s ; exec bash --login", changeDirCmd)
89+
script := fmt.Sprintf("%s ; exec bash --login", changeDirCmd)
8290
if clicontext.NArg() > 1 {
8391
script += fmt.Sprintf(" -c %q", shellescape.QuoteCommand(clicontext.Args().Tail()))
8492
}

examples/k3s.yaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,16 @@
1010
# lima-k3s Ready control-plane,master 69s v1.21.1+k3s1
1111

1212
images:
13-
- location: "~/Downloads/hirsute-server-cloudimg-amd64.img"
13+
- location: "https://cloud-images.ubuntu.com/hirsute/current/hirsute-server-cloudimg-amd64.img"
1414
arch: "x86_64"
1515

16+
# Mounts are disabled in this example, but can be enabled optionally.
1617
mounts: []
1718

1819
ssh:
1920
localPort: 60022
2021

22+
# containerd is managed by k3s, not by Lima, so the values are set to false here.
2123
containerd:
2224
system: false
2325
user: false
@@ -38,5 +40,5 @@ probes:
3840
fi
3941
hint: |
4042
The k3s kubeconfig file has not yet been created.
41-
Run "lima bash sudo journalctl -u k3s" to check the log.
43+
Run "limactl shell k3s sudo journalctl -u k3s" to check the log.
4244
If that is still empty, check the bottom of the log at "/var/log/cloud-init-output.log".

pkg/cidata/user-data.TEMPLATE

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,24 +103,31 @@ write_files:
103103
if [ ! -x /usr/local/bin/nerdctl ]; then
104104
version="0.8.3"
105105
goarch="amd64"
106-
if [ "$(uname -m )" = "aarch64 "]; then
106+
if [ "$(uname -m )" = "aarch64" ]; then
107107
goarch="arm64"
108108
fi
109109
curl -fsSL https://github.com/containerd/nerdctl/releases/download/v${version}/nerdctl-full-${version}-linux-${goarch}.tar.gz | tar Cxz /usr/local
110110
fi
111111
{{- if .Containerd.System}}
112-
systemctl enable containerd
113-
systemctl start containerd
112+
cat >"/etc/containerd/config.toml" <<EOF
113+
version = 2
114+
[proxy_plugins]
115+
[proxy_plugins."stargz"]
116+
type = "snapshot"
117+
address = "/run/containerd-stargz-grpc/containerd-stargz-grpc.sock"
118+
EOF
119+
systemctl enable --now containerd buildkit stargz-snapshotter
114120
{{- end}}
115121
{{- if .Containerd.User}}
116122
modprobe tap || true
117123
if [ ! -e "/home/{{.User}}.linux/.config/containerd/config.toml" ]; then
118124
mkdir -p "/home/{{.User}}.linux/.config/containerd"
119125
cat >"/home/{{.User}}.linux/.config/containerd/config.toml" <<EOF
126+
version = 2
120127
[proxy_plugins]
121128
[proxy_plugins."stargz"]
122-
type = "snapshot"
123-
address = "/run/user/{{.UID}}/containerd-stargz-grpc/containerd-stargz-grpc.sock"
129+
type = "snapshot"
130+
address = "/run/user/{{.UID}}/containerd-stargz-grpc/containerd-stargz-grpc.sock"
124131
EOF
125132
chown -R "{{.User}}" "/home/{{.User}}.linux/.config"
126133
fi

pkg/limayaml/default.TEMPLATE.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,10 @@ video:
5959
display: "none"
6060

6161
containerd:
62-
# Enable system-wide containerd (systemctl enable containerd)
62+
# Enable system-wide (aka rootful) containerd and its dependencies (BuildKit, Stargz Snapshotter)
6363
# Default: false
6464
system: false
65-
# Enable user-scoped containerd (systemctl --user enable containerd)
65+
# Enable user-scoped (aka rootless) containerd and its dependencies
6666
# Default: true
6767
user: true
6868

0 commit comments

Comments
 (0)