Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RHOAIENG-17306, RHOAIENG-17307, RHOAIENG-17308: feat(workbenches): support IPv6 environments in codeserver, jupyterlab and rstudio #827

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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/intel/ml/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
2 changes: 1 addition & 1 deletion jupyter/intel/pytorch/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 @@ -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
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'
Comment on lines +65 to +69
Copy link
Member

@jiridanek jiridanek Jan 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm inclined to replace all this with return '::', because that should work just everywhere; We have ubi9 images that do support ipv6; and jupyterlab/etc. all use socket.AF_INET6 in effect. But your version feels somewhat more cautious and safer.

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(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'--www-port=' + str(port),
'--www-verify-user-agent=0',
'--rsession-which-r=' + get_rstudio_executable('R'),
Expand Down