Skip to content

Commit d7f8415

Browse files
nenbaktech
andauthored
Fix bug in jhub-app-proxy path (#648)
Co-authored-by: Amit Kumar <[email protected]>
1 parent e69dad3 commit d7f8415

File tree

1 file changed

+34
-6
lines changed

1 file changed

+34
-6
lines changed

jhub_apps/spawner/spawner_creation.py

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,30 +56,58 @@ def wrap_command_with_proxy_installer(cmd_list, proxy_version):
5656
cmd_str = ' '.join(shlex.quote(str(arg)) for arg in cmd_list)
5757

5858
install_script = f'''
59-
# Ensure ~/.local/bin and /tmp/.local/bin are in PATH
60-
export PATH="$HOME/.local/bin:/tmp/.local/bin:$PATH"
59+
INSTALL_DIR="/tmp/.local/bin/jhub-app-proxy-versions/{proxy_version}"
60+
BIN="$INSTALL_DIR/jhub-app-proxy"
61+
62+
mkdir -p "$INSTALL_DIR"
63+
64+
export PATH="$INSTALL_DIR:$PATH"
65+
66+
# Add /tmp/.local/bin only if it's not already present.
67+
# (legacy binaries were stored here)
68+
if [ -d "/tmp/.local/bin" ] && [[ ":$PATH:" != *":/tmp/.local/bin:"* ]]; then
69+
export PATH="$PATH:/tmp/.local/bin"
70+
fi
71+
72+
# Add ~/.local/bin only if it's not already present.
73+
# Must be added AFTER /tmp binaries for legacy reasons.
74+
# (legacy binaries were stored here)
75+
if [ -d "$HOME/.local/bin" ] && [[ ":$PATH:" != *":$HOME/.local/bin:"* ]]; then
76+
export PATH="$PATH:$HOME/.local/bin"
77+
fi
6178
6279
# Install jhub-app-proxy (overrides if already present)
6380
echo "Installing jhub-app-proxy version {proxy_version}..."
6481
6582
# Try curl, wget, then Python as fallbacks
6683
if command -v curl >/dev/null 2>&1; then
6784
echo "Using curl to download installer..."
68-
curl -fsSL {JHUB_APP_PROXY_INSTALL_URL} | sh -s -- -v {proxy_version} -d /tmp/.local/bin
85+
curl -fsSL {JHUB_APP_PROXY_INSTALL_URL} | sh -s -- -v {proxy_version} -d "$INSTALL_DIR"
6986
elif command -v wget >/dev/null 2>&1; then
7087
echo "Using wget to download installer..."
71-
wget -qO- {JHUB_APP_PROXY_INSTALL_URL} | sh -s -- -v {proxy_version} -d /tmp/.local/bin
88+
wget -qO- {JHUB_APP_PROXY_INSTALL_URL} | sh -s -- -v {proxy_version} -d "$INSTALL_DIR"
7289
elif command -v python3 >/dev/null 2>&1; then
7390
echo "Using python3 to download installer..."
74-
python3 -c "import urllib.request; import sys; response = urllib.request.urlopen('{JHUB_APP_PROXY_INSTALL_URL}'); sys.stdout.buffer.write(response.read())" | sh -s -- -v {proxy_version} -d /tmp/.local/bin
91+
python3 -c "import urllib.request; import sys; response = urllib.request.urlopen('{JHUB_APP_PROXY_INSTALL_URL}'); sys.stdout.buffer.write(response.read())" | sh -s -- -v {proxy_version} -d "$INSTALL_DIR"
7592
elif command -v python >/dev/null 2>&1; then
7693
echo "Using python to download installer..."
77-
python -c "import urllib.request; import sys; response = urllib.request.urlopen('{JHUB_APP_PROXY_INSTALL_URL}'); sys.stdout.buffer.write(response.read())" | sh -s -- -v {proxy_version} -d /tmp/.local/bin
94+
python -c "import urllib.request; import sys; response = urllib.request.urlopen('{JHUB_APP_PROXY_INSTALL_URL}'); sys.stdout.buffer.write(response.read())" | sh -s -- -v {proxy_version} -d "$INSTALL_DIR"
7895
else
7996
echo "Error: No download tool found (tried: curl, wget, python3, python). Cannot download jhub-app-proxy installer." >&2
8097
exit 1
8198
fi
8299
100+
# Air-gapped-friendly fallback:
101+
# If we couldn't install into /tmp, use whatever is already available on PATH.
102+
if [ ! -x "$BIN" ]; then
103+
if command -v jhub-app-proxy >/dev/null 2>&1; then
104+
echo "Warning: could not install requested version; using existing jhub-app-proxy from PATH." >&2
105+
else
106+
echo "Error: jhub-app-proxy not available and cannot download installer." >&2
107+
exit 1
108+
fi
109+
fi
110+
83111
# Execute the original command
84112
echo "Running command: {cmd_str}"
85113
exec {cmd_str}

0 commit comments

Comments
 (0)