Skip to content

Commit fb5721d

Browse files
authored
make jhub-app-proxy installer script resilient (#643)
1 parent 1040d82 commit fb5721d

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

jhub_apps/spawner/spawner_creation.py

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,14 @@ def get_proxy_version(config, app_env=None):
4343

4444
def wrap_command_with_proxy_installer(cmd_list, proxy_version):
4545
"""
46-
Wraps a command list in a bash script that installs jhub-app-proxy.
46+
Wraps a command list in a shell script that installs jhub-app-proxy.
4747
4848
Args:
4949
cmd_list: List of command arguments (e.g., ['jhub-app-proxy', '--authtype=oauth', ...])
5050
proxy_version: Version of jhub-app-proxy to install
5151
5252
Returns:
53-
List with bash wrapper: ['/bin/bash', '-c', '<script>']
53+
List with shell wrapper: ['/bin/sh', '-c', '<script>']
5454
"""
5555
# Convert command list to a shell-escaped string
5656
cmd_str = ' '.join(shlex.quote(str(arg)) for arg in cmd_list)
@@ -61,15 +61,31 @@ def wrap_command_with_proxy_installer(cmd_list, proxy_version):
6161
6262
# Install jhub-app-proxy (overrides if already present)
6363
echo "Installing jhub-app-proxy version {proxy_version}..."
64-
echo "Running: curl -fsSL {JHUB_APP_PROXY_INSTALL_URL} | bash -s -- -v {proxy_version} -d /tmp/.local/bin"
65-
curl -fsSL {JHUB_APP_PROXY_INSTALL_URL} | bash -s -- -v {proxy_version} -d /tmp/.local/bin
64+
65+
# Try curl, wget, then Python as fallbacks
66+
if command -v curl >/dev/null 2>&1; then
67+
echo "Using curl to download installer..."
68+
curl -fsSL {JHUB_APP_PROXY_INSTALL_URL} | sh -s -- -v {proxy_version} -d /tmp/.local/bin
69+
elif command -v wget >/dev/null 2>&1; then
70+
echo "Using wget to download installer..."
71+
wget -qO- {JHUB_APP_PROXY_INSTALL_URL} | sh -s -- -v {proxy_version} -d /tmp/.local/bin
72+
elif command -v python3 >/dev/null 2>&1; then
73+
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
75+
elif command -v python >/dev/null 2>&1; then
76+
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
78+
else
79+
echo "Error: No download tool found (tried: curl, wget, python3, python). Cannot download jhub-app-proxy installer." >&2
80+
exit 1
81+
fi
6682
6783
# Execute the original command
6884
echo "Running command: {cmd_str}"
6985
exec {cmd_str}
7086
'''.strip()
7187

72-
return ['/bin/bash', '-c', install_script]
88+
return ['/bin/sh', '-c', install_script]
7389

7490

7591
def subclass_spawner(base_spawner):

jhub_apps/tests/tests_unit/test_command_template.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def test_wrap_command_with_proxy_installer():
2424
wrapped = wrap_command_with_proxy_installer(cmd_list, proxy_version)
2525

2626
assert len(wrapped) == 3
27-
assert wrapped[0] == "/bin/bash"
27+
assert wrapped[0] == "/bin/sh"
2828
assert wrapped[1] == "-c"
2929
assert "jhub-app-proxy" in wrapped[2]
3030
assert "Installing jhub-app-proxy" in wrapped[2]

0 commit comments

Comments
 (0)