Skip to content

Commit

Permalink
Revert "Revert "RHOAIENG-17306, RHOAIENG-17307, RHOAIENG-17308: feat(…
Browse files Browse the repository at this point in the history
…workbenches): tolerate IPv6 environments in codeserver, jupyterlab and rstudio""
  • Loading branch information
jiridanek authored Jan 31, 2025
1 parent b757f86 commit 7340e24
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 16 deletions.
2 changes: 1 addition & 1 deletion codeserver/ubi9-python-3.11/nginx/api/kernels/access.cgi
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ echo "Status: 200"
echo "Content-type: application/json"
echo
# Query the heartbeat endpoint
HEALTHZ=$(curl -s http://127.0.0.1:8888/codeserver/healthz)
HEALTHZ=$(curl -s http://localhost:8888/codeserver/healthz)
# Extract last_activity | remove milliseconds
LAST_ACTIVITY_EPOCH=$(echo $HEALTHZ | grep -Po 'lastHeartbeat":\K.*?(?=})' | awk '{ print substr( $0, 1, length($0)-3 ) }')
# Convert to ISO8601 date format
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
# Change port
/listen/s%80%8888 default_server%

# Remove listening on IPv6
/\[::\]/d

# One worker only
/worker_processes/s%auto%1%

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ location = /codeserver {

location /codeserver/ {
# Standard code-server/NGINX configuration
proxy_pass http://127.0.0.1:8787/;
proxy_pass http://localhost:8787/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ location = / {
location /codeserver/ {
rewrite ^/codeserver/(.*)$ /$1 break;
# Standard RStudio/NGINX configuration
proxy_pass http://127.0.0.1:8787;
proxy_pass http://localhost:8787;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
Expand Down
20 changes: 15 additions & 5 deletions codeserver/ubi9-python-3.11/run-code-server.sh
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,20 @@ if [ ! -d "$logs_dir" ]; then
mkdir -p "$logs_dir"
fi

# IPv6 support
echo "Checking IPv6 support..."
if [ -f /proc/net/if_inet6 ]; then
BIND_ADDR="[::]:8787" # IPv6/dual-stack
echo "IPv6 detected: binding to all interfaces (IPv4 + IPv6)"
else
BIND_ADDR="0.0.0.0:8787" # IPv4 only
echo "IPv6 not detected: falling back to IPv4 only"
fi

# Start server
start_process /usr/bin/code-server \
--bind-addr 0.0.0.0:8787 \
--disable-telemetry \
--auth none \
--disable-update-check \
/opt/app-root/src
--bind-addr "${BIND_ADDR}" \
--disable-telemetry \
--auth none \
--disable-update-check \
/opt/app-root/src
2 changes: 1 addition & 1 deletion jupyter/minimal/ubi9-python-3.11/start-notebook.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ fi

# Start the JupyterLab notebook
start_process jupyter lab ${NOTEBOOK_PROGRAM_ARGS} \
--ServerApp.ip=0.0.0.0 \
--ServerApp.ip="" \
--ServerApp.allow_origin="*" \
--ServerApp.open_browser=False
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ location = /rstudio {
location /rstudio/ {
rewrite ^/rstudio/(.*)$ /$1 break;
# Standard RStudio/NGINX configuration
proxy_pass http://127.0.0.1:8787;
proxy_pass http://localhost:8787;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ location = / {
location /rstudio/ {
rewrite ^/rstudio/(.*)$ /$1 break;
# Standard RStudio/NGINX configuration
proxy_pass http://127.0.0.1:8787;
proxy_pass http://localhost:8787;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
Expand Down
26 changes: 25 additions & 1 deletion rstudio/c9s-python-3.11/setup_rstudio.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,30 @@ def _support_arg(arg):
ret = subprocess.check_output([get_rstudio_executable('rserver'), '--help'])
return ret.decode().find(arg) != -1

def detect_env():
import socket
supports_ipv4 = supports_ipv6 = False
try:
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.bind(('127.0.0.1', 0))
supports_ipv4 = True
except OSError:
pass
try:
with socket.socket(socket.AF_INET6, socket.SOCK_STREAM) as s:
s.bind(('::1', 0))
supports_ipv6 = True
except OSError:
pass
if supports_ipv4 and supports_ipv6:
return '::' # Dual-stack
elif supports_ipv6:
return '::'
elif supports_ipv4:
return '0.0.0.0'
else:
raise EnvironmentError('No IPv4 or IPv6 support detected.')

def _get_cmd(port):
ntf = tempfile.NamedTemporaryFile()

Expand All @@ -60,7 +84,7 @@ def _get_cmd(port):
'--server-working-dir=' + os.getenv('HOME'),
'--auth-none=1',
'--www-frame-origin=same',
#'--www-address=0.0.0.0',
'--www-address='+ detect_env(),
'--www-port=' + str(port),
'--www-verify-user-agent=0',
'--rsession-which-r=' + get_rstudio_executable('R'),
Expand Down
1 change: 0 additions & 1 deletion tests/containers/workbenches/workbench_image_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ def test_image_entrypoint_starts(self, image: str, sysctls) -> None:
finally:
docker_utils.NotebookContainer(container).stop(timeout=0)

@pytest.mark.skip(reason="RHOAIENG-17305: currently our Workbench images don't tolerate IPv6")
def test_ipv6_only(self, image: str, test_frame):
"""Test that workbench image is accessible via IPv6.
Workarounds for macOS will be needed, so that's why it's a separate test."""
Expand Down

0 comments on commit 7340e24

Please sign in to comment.