Make nerdctl script work in both WSL and on native linux

This will detect when linux is run in WSL or by itself to know
which method to talk to nerdctl.

Note, also removed debug output accidently left in.

Signed-off-by: Matt Farina <matt.farina@suse.com>
This commit is contained in:
Matt Farina
2021-10-07 06:48:24 -04:00
parent 36c156dd85
commit 56f51eb8cc
2 changed files with 19 additions and 3 deletions

View File

@@ -1,2 +1,19 @@
#!/bin/sh
exec /mnt/wsl/rancher-desktop/bin/nerdctl "$@"
#!/bin/bash
set -eu -o pipefail
if [[ $(cat /proc/version | grep -i Microsoft) ]]; then
exec /mnt/wsl/rancher-desktop/bin/nerdctl "$@"
else
limaloc="${XDG_DATA_HOME:-$HOME/.local/share/rancher-desktop}"
scriptname="${BASH_SOURCE[0]}"
while [ -L "${scriptname}" ]; do
scriptname="$(readlink "${scriptname}")"
done
scriptdir="$(cd "$(dirname "${scriptname}")" && pwd)"
if ! LIMA_HOME="${limaloc}/lima" "${scriptdir}/../lima/bin/limactl" ls --json | grep '"name":"0"' | grep -q '"status":"Running"'; then
echo "Rancher Desktop is not running. Please start Rancher Desktop to use nerdctl";
else
LIMA_HOME="${limaloc}/lima" "${scriptdir}/../lima/bin/limactl" shell 0 sudo --preserve-env=CONTAINERD_ADDRESS nerdctl "$@"
fi
fi

View File

@@ -16,7 +16,6 @@ import (
func spawn(opts spawnOptions) error {
args := []string{"--distribution", opts.distro, "--exec", opts.nerdctl, "--address", opts.containerdSocket}
args = append(args, opts.args.args...)
log.Printf("running: %+v", args)
cmd := exec.Command("wsl.exe", args...)
cmd.Stdin = os.Stdin
cmd.Stdout = os.Stdout