-
Notifications
You must be signed in to change notification settings - Fork 305
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Setup spin cli templates and plugins
We only install templates and plugins when the there are non installed before. If the user has already configured spin, then we don't want to modify their setup, as we would overwrite them on each app start. Signed-off-by: Jan Dubois <[email protected]>
- Loading branch information
Showing
8 changed files
with
155 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
# All Linux scripts should have LF line endings | ||
# But only text files should be changed (not any binaries / images / etc.) | ||
resources/linux/** text=auto eol=lf | ||
resources/setup-spin text=auto eol=lf | ||
pkg/rancher-desktop/assets/scripts/** text=auto eol=lf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -794,6 +794,7 @@ userpreference | |
UTCTIME | ||
vcenter | ||
vcpus | ||
vcruntime | ||
vcs | ||
vde | ||
ventura | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
#!/bin/sh | ||
# This script uses sh instead of bash to be compatible with as many distros as possible. | ||
|
||
# The script is located in the Rancher Desktop resources/ directory. | ||
resources_dir=$(dirname "$0") | ||
|
||
# We run setup-spin in the rancher-desktop distro to setup spin on the Win32 host. | ||
if [ "$WSL_DISTRO_NAME" = "rancher-desktop" ]; then | ||
app_data_dir=$(/bin/wslpath "$(powershell.exe -Command "Write-Output \${Env:LOCALAPPDATA}")" | tr -d "\r") | ||
system_root=$(/bin/wslpath "$(powershell.exe -Command "Write-Output \${Env:SystemRoot}")" | tr -d "\r") | ||
spin="${resources_dir}/win32/bin/spin.exe" | ||
elif [ "$(uname)" = "Linux" ]; then | ||
app_data_dir="${XDG_DATA_HOME:-$HOME/.local/share}" | ||
spin="${resources_dir}/linux/bin/spin" | ||
else | ||
app_data_dir="${HOME}/Library/Application Support" | ||
spin="${resources_dir}/darwin/bin/spin" | ||
fi | ||
|
||
if [ ! -x "$spin" ]; then | ||
echo "Cannot execute '${spin}' (or does not exist)" | ||
exit 1 | ||
fi | ||
|
||
spin_dir="${app_data_dir}/spin" | ||
|
||
# shellcheck disable=SC2012 # Using `ls` is fine | ||
if [ -d "${spin_dir}/templates" ] && [ "$(ls -1 "${spin_dir}/templates" | wc -l)" -gt 0 ]; then | ||
echo "'${spin_dir}/templates' already exists and is not empty" | ||
exit 0 | ||
fi | ||
|
||
# shellcheck disable=SC2012 # Using `ls` is fine | ||
if [ -d "${spin_dir}/plugins" ] && [ "$(ls -1 "${spin_dir}/plugins" | wc -l)" -gt 0 ]; then | ||
echo "'${spin_dir}/plugins' already exists and is not empty" | ||
exit 0 | ||
fi | ||
|
||
if [ "$WSL_DISTRO_NAME" = "rancher-desktop" ]; then | ||
echo "Waiting for github.com to become resolvable" | ||
for _ in $(seq 30); do | ||
curl --head --silent http://github.com >/dev/null | ||
rc=$?; test $rc -ne 0 && echo "curl exit status is $rc" | ||
if [ $rc -ne 6 ]; then | ||
break | ||
fi | ||
sleep 2 | ||
done | ||
fi | ||
|
||
# The reason for this complexity is to be able to run on systems without git. | ||
# We do need either curl or wget to be on the PATH though. | ||
install_templates() { | ||
repo=$1 | ||
branch=main | ||
tmpdir="${spin_dir}/rancher-desktop.$$" | ||
tarball="${tmpdir}/${repo}.tar.gz" | ||
|
||
url="https://github.com/fermyon/${repo}/archive/refs/heads/${branch}.tar.gz" | ||
|
||
if [ "$WSL_DISTRO_NAME" = "rancher-desktop" ]; then | ||
# Download and extract tarball on Win32 host side to avoid 9p syncing issues | ||
tmpdir=$(/bin/wslpath -w "$tmpdir") | ||
tarball=$(/bin/wslpath -w "$tarball") | ||
|
||
"${system_root}/system32/cmd.exe" /c mkdir "$tmpdir" | ||
|
||
echo "Downloading '${url}' to '${tarball}' with curl.exe" | ||
"${system_root}/system32/curl.exe" --silent --location "$url" --output "$tarball" | ||
rc=$?; test $rc -ne 0 && echo "curl.exe exit status is $rc" | ||
|
||
if [ $rc -eq 0 ]; then | ||
echo "Unpacking '${tarball}'" | ||
"${system_root}/system32/tar.exe" xfz "$tarball" -C "$tmpdir" | ||
rc=$?; test $rc -ne 0 && echo "tar.exe exit status is $rc" | ||
|
||
dir="${tmpdir}\\${repo}-${branch}" | ||
echo "Installing templates from '${dir}'" | ||
"$spin" templates install --update --dir "$dir" | ||
rc=$?; test $rc -ne 0 && echo "Exit status is $rc" | ||
else | ||
echo "Could not download '${url}'" | ||
fi | ||
"${system_root}/system32/cmd.exe" /c rmdir /s /q "$tmpdir" | ||
return | ||
fi | ||
|
||
mkdir -p "$tmpdir" | ||
if command -v curl >/dev/null; then | ||
echo "Downloading '${url}' to '${tarball}' with curl" | ||
curl --silent --location "$url" --output "$tarball" | ||
rc=$?; test $rc -ne 0 && echo "curl exit status is $rc" | ||
elif command -v wget >/dev/null; then | ||
echo "Downloading '${url}' to '${tarball}' with wget" | ||
wget --no-verbose "$url" -O "$tarball" | ||
rc=$?; test $rc -ne 0 && echo "wget exit status is $rc" | ||
fi | ||
if [ -f "$tarball" ]; then | ||
echo "Unpacking '${tarball}'" | ||
tar xfz "$tarball" -C "$tmpdir" | ||
rc=$?; test $rc -ne 0 && echo "tar exit status is $rc" | ||
|
||
dir="${tmpdir}/${repo}-${branch}" | ||
echo "Installing templates from '${dir}'" | ||
"$spin" templates install --update --dir "$dir" | ||
rc=$?; test $rc -ne 0 && echo "Exit status is $rc" | ||
else | ||
echo "Could not download '${url}' (maybe no curl/wget)" | ||
fi | ||
rm -rf "$tmpdir" | ||
} | ||
|
||
install_plugin() { | ||
plugin=$1 | ||
url="https://raw.githubusercontent.com/fermyon/spin-plugins/main/manifests/${plugin}/${plugin}.json" | ||
echo "Installing plugin from '${url}'" | ||
"$spin" plugins install --yes --url "$url" | ||
rc=$?; test $rc -ne 0 && echo "Exit status is $rc" | ||
} | ||
|
||
install_templates spin | ||
install_templates spin-python-sdk | ||
install_templates spin-js-sdk | ||
|
||
install_plugin js2wasm | ||
install_plugin kube | ||
|
||
echo "'${spin}' setup complete" |