Skip to content

Commit e590eed

Browse files
committed
[rstudio-rhds] RHOAIENG-18458: Tolerate IPv6 deployments of Workbench images in RHDS/notebooks rhel-based rstudio images
1 parent b23e7ed commit e590eed

File tree

4 files changed

+37
-4
lines changed

4 files changed

+37
-4
lines changed

rstudio/rhel9-python-3.11/nginx/httpconf/http.conf

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,12 @@ map $http_x_forwarded_proto $custom_scheme {
3737
default $scheme;
3838
https https;
3939
}
40+
41+
###############
42+
# Dual-stack causes nginx to enable the "If a domain name resolves to several addresses, all of them will be used in a round-robin fashion." behavior
43+
# https://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_next_upstream_tries
44+
###############
45+
upstream workbench_server {
46+
server localhost:8787 max_fails=0;
47+
}
48+
###############

rstudio/rhel9-python-3.11/nginx/serverconf/proxy.conf.template

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ location = /rstudio {
5050
location /rstudio/ {
5151
rewrite ^/rstudio/(.*)$ /$1 break;
5252
# Standard RStudio/NGINX configuration
53-
proxy_pass http://127.0.0.1:8787;
53+
proxy_pass http://workbench_server/;
5454
proxy_http_version 1.1;
5555
proxy_set_header Upgrade $http_upgrade;
5656
proxy_set_header Connection $connection_upgrade;

rstudio/rhel9-python-3.11/nginx/serverconf/proxy.conf.template_nbprefix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ location = / {
7777
location /rstudio/ {
7878
rewrite ^/rstudio/(.*)$ /$1 break;
7979
# Standard RStudio/NGINX configuration
80-
proxy_pass http://127.0.0.1:8787;
80+
proxy_pass http://workbench_server/;
8181
proxy_http_version 1.1;
8282
proxy_set_header Upgrade $http_upgrade;
8383
proxy_set_header Connection $connection_upgrade;

rstudio/rhel9-python-3.11/setup_rstudio.py

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,30 @@ def _support_arg(arg):
4646
ret = subprocess.check_output([get_rstudio_executable('rserver'), '--help'])
4747
return ret.decode().find(arg) != -1
4848

49+
def detect_env():
50+
import socket
51+
supports_ipv4 = supports_ipv6 = False
52+
try:
53+
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
54+
s.bind(('127.0.0.1', 0))
55+
supports_ipv4 = True
56+
except OSError:
57+
pass
58+
try:
59+
with socket.socket(socket.AF_INET6, socket.SOCK_STREAM) as s:
60+
s.bind(('::1', 0))
61+
supports_ipv6 = True
62+
except OSError:
63+
pass
64+
if supports_ipv4 and supports_ipv6:
65+
return '::' # Dual-stack
66+
elif supports_ipv6:
67+
return '::'
68+
elif supports_ipv4:
69+
return '0.0.0.0'
70+
else:
71+
raise EnvironmentError('No IPv4 or IPv6 support detected.')
72+
4973
def _get_cmd(port):
5074
ntf = tempfile.NamedTemporaryFile()
5175

@@ -60,7 +84,7 @@ def _get_cmd(port):
6084
'--server-working-dir=' + os.getenv('HOME'),
6185
'--auth-none=1',
6286
'--www-frame-origin=same',
63-
#'--www-address=0.0.0.0',
87+
'--www-address='+ detect_env(),
6488
'--www-port=' + str(port),
6589
'--www-verify-user-agent=0',
6690
'--rsession-which-r=' + get_rstudio_executable('R'),
@@ -76,7 +100,7 @@ def _get_cmd(port):
76100
cmd.append(f'--server-data-dir={server_data_dir}')
77101
if _support_arg('database-config-file'):
78102
cmd.append(f'--database-config-file={database_config_file}')
79-
103+
80104
return(' '.join(cmd))
81105

82106
if __name__ == "__main__":

0 commit comments

Comments
 (0)