Skip to content

Commit

Permalink
Merge pull request #39 from AkihiroSuda/dev
Browse files Browse the repository at this point in the history
Follow-up to "Implement system and user provisioning scripts" (#38)
  • Loading branch information
AkihiroSuda authored Jun 9, 2021
2 parents e048992 + 64d4b1e commit 98e0f62
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 22 deletions.
34 changes: 21 additions & 13 deletions cmd/limactl/shell.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,30 +55,38 @@ func shellAction(clicontext *cli.Context) error {
return err
}

// Buildup changeDirCmd to "cd workDir || cd currentDir || cd homeDir"
// When workDir is explicitly set, the shell MUST have workDir as the cwd, or exit with an error.
//
// changeDirCmd := "cd workDir || exit 1" if workDir != ""
// := "cd hostCurrentDir || cd hostHomeDir" if workDir == ""
var changeDirCmd string
workDir := clicontext.String("workdir")
if workDir == "" {
changeDirCmd = "false"
} else {
changeDirCmd = fmt.Sprintf("cd %q", workDir)
}
if len(y.Mounts) > 0 {
currentDir, err := os.Getwd()
if workDir := clicontext.String("workdir"); workDir != "" {
changeDirCmd = fmt.Sprintf("cd %q || exit 1", workDir)
// FIXME: check whether y.Mounts contains the home, not just len > 0
} else if len(y.Mounts) > 0 {
hostCurrentDir, err := os.Getwd()
if err == nil {
changeDirCmd = fmt.Sprintf("%s || cd %q", changeDirCmd, currentDir)
changeDirCmd = fmt.Sprintf("cd %q", hostCurrentDir)
} else {
changeDirCmd = "false"
logrus.WithError(err).Warn("failed to get the current directory")
}
homeDir, err := os.UserHomeDir()
hostHomeDir, err := os.UserHomeDir()
if err == nil {
changeDirCmd = fmt.Sprintf("%s || cd %q", changeDirCmd, homeDir)
changeDirCmd = fmt.Sprintf("%s || cd %q", changeDirCmd, hostHomeDir)
} else {
logrus.WithError(err).Warn("failed to get the home directory")
}
} else {
logrus.Debug("the host home does not seem mounted, so the guest shell will have a different cwd")
}

if changeDirCmd == "" {
changeDirCmd = "false"
}
logrus.Debugf("changeDirCmd=%q", changeDirCmd)

script := fmt.Sprintf(" %s ; exec bash --login", changeDirCmd)
script := fmt.Sprintf("%s ; exec bash --login", changeDirCmd)
if clicontext.NArg() > 1 {
script += fmt.Sprintf(" -c %q", shellescape.QuoteCommand(clicontext.Args().Tail()))
}
Expand Down
6 changes: 4 additions & 2 deletions examples/k3s.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,16 @@
# lima-k3s Ready control-plane,master 69s v1.21.1+k3s1

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

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

ssh:
localPort: 60022

# containerd is managed by k3s, not by Lima, so the values are set to false here.
containerd:
system: false
user: false
Expand All @@ -38,5 +40,5 @@ probes:
fi
hint: |
The k3s kubeconfig file has not yet been created.
Run "lima bash sudo journalctl -u k3s" to check the log.
Run "limactl shell k3s sudo journalctl -u k3s" to check the log.
If that is still empty, check the bottom of the log at "/var/log/cloud-init-output.log".
17 changes: 12 additions & 5 deletions pkg/cidata/user-data.TEMPLATE
Original file line number Diff line number Diff line change
Expand Up @@ -103,24 +103,31 @@ write_files:
if [ ! -x /usr/local/bin/nerdctl ]; then
version="0.8.3"
goarch="amd64"
if [ "$(uname -m )" = "aarch64 "]; then
if [ "$(uname -m )" = "aarch64" ]; then
goarch="arm64"
fi
curl -fsSL https://github.com/containerd/nerdctl/releases/download/v${version}/nerdctl-full-${version}-linux-${goarch}.tar.gz | tar Cxz /usr/local
fi
{{- if .Containerd.System}}
systemctl enable containerd
systemctl start containerd
cat >"/etc/containerd/config.toml" <<EOF
version = 2
[proxy_plugins]
[proxy_plugins."stargz"]
type = "snapshot"
address = "/run/containerd-stargz-grpc/containerd-stargz-grpc.sock"
EOF
systemctl enable --now containerd buildkit stargz-snapshotter
{{- end}}
{{- if .Containerd.User}}
modprobe tap || true
if [ ! -e "/home/{{.User}}.linux/.config/containerd/config.toml" ]; then
mkdir -p "/home/{{.User}}.linux/.config/containerd"
cat >"/home/{{.User}}.linux/.config/containerd/config.toml" <<EOF
version = 2
[proxy_plugins]
[proxy_plugins."stargz"]
type = "snapshot"
address = "/run/user/{{.UID}}/containerd-stargz-grpc/containerd-stargz-grpc.sock"
type = "snapshot"
address = "/run/user/{{.UID}}/containerd-stargz-grpc/containerd-stargz-grpc.sock"
EOF
chown -R "{{.User}}" "/home/{{.User}}.linux/.config"
fi
Expand Down
4 changes: 2 additions & 2 deletions pkg/limayaml/default.TEMPLATE.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ video:
display: "none"

containerd:
# Enable system-wide containerd (systemctl enable containerd)
# Enable system-wide (aka rootful) containerd and its dependencies (BuildKit, Stargz Snapshotter)
# Default: false
system: false
# Enable user-scoped containerd (systemctl --user enable containerd)
# Enable user-scoped (aka rootless) containerd and its dependencies
# Default: true
user: true

Expand Down

0 comments on commit 98e0f62

Please sign in to comment.