Skip to content

Commit

Permalink
Fix #370: standardize rsiviz port configuration and enable devbox for…
Browse files Browse the repository at this point in the history
… rsiviz
  • Loading branch information
e-carlin committed Aug 24, 2023
1 parent ad7d476 commit 3ace76e
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 26 deletions.
54 changes: 39 additions & 15 deletions rsconf/component/devbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from pykern.pkcollections import PKDict
from pykern.pkdebug import pkdp
from rsconf import component
import ipaddress


class T(component.T):
Expand Down Expand Up @@ -94,6 +95,16 @@ def internal_build_write(self):
for k, v in self.secrets.items():
self.install_abspath(v, z.host[k])

def _env(self, name, value, path):
v = str(value)
# TODO probably could recursively quote
if "'" in v:
raise ValueError(f"single quote in value={v} of bash variable name={name}")
self.rsconf_append(
path,
f"export {name}='{v}'",
)

def _gen_paths(self, z, db_d, ssh_d):
res = PKDict(ssh_d=db_d.join(ssh_d))
res.pkupdate(sshd_config=res.ssh_d.join("sshd_config"))
Expand All @@ -108,34 +119,47 @@ def _gen_secrets(self, jc):
self.secrets = PKDict({k: s[k] for k in ("host_key_f", "identity_pub_f")})

def _jupyter_bashrc(self, z, path):
def _env(name, value):
v = str(value)
# TODO probably could recursively quote
if "'" in v:
raise ValueError(
f"single quote in value={v} of bash variable name={name}"
)
self.rsconf_append(
path,
f"export {name}='{v}'",
)

self.install_access(mode="600")
self.install_ensure_file_exists(path)
for n in ("package_path", "sim_types"):
if n in z:
_env(f"SIREPO_FEATURE_CONFIG_{n.upper()}", ":".join(z[n]))
self._env(f"SIREPO_FEATURE_CONFIG_{n.upper()}", ":".join(z[n]), path)
z.service_port = z.ssh_port + z.ssh_service_port_difference
z.job_supervisor_port = z.service_port + z.ssh_service_port_difference
for n in ("service_port", "job_supervisor_port"):
_env(f"SIREPO_PKCLI_{n.upper()}", z[n])
self._env(f"SIREPO_PKCLI_{n.upper()}", z[n], path)
for n in ("DRIVER_LOCAL", "API"):
_env(
self._env(
f"SIREPO_JOB_{n}_SUPERVISOR_URI",
f"http://127.0.0.1:{z.job_supervisor_port}",
path,
)
self._rsiviz(z, path)

def _network(self, jc, z):
n = self.buildt.get_component("network")
z.ip = n.unchecked_public_ip() or n.ip_and_net_for_host(jc.rsconf_db.host)[0]
n.add_public_tcp_ports([str(z.ssh_port)])

def _rsiviz(self, z, path):
u = z.users[self.user_name]
if not isinstance(u, PKDict) or not "rsiviz" in u:
return
self._env(
"PYKERN_PKASYNCIO_SERVER_PORT",
u.rsiviz.port_base,
path,
)
self._env(
"RSIVIZ_PKCLI_SERVICE_DICE_NETWORK_CLUSTER_INTERFACE_ADDRESS",
ipaddress.ip_address(u.rsiviz.ip_base) + 1,
path,
)
self._env(
"RSIVIZ_PKCLI_SERVICE_DICE_NETWORK_NETWORK_DISCOVERY_ADDRESS",
f"{u.rsiviz.ip_base}:5555",
path,
)
self._env(
"RSIVIZ_PKCLI_SERVICE_INDEX_IFRAME_PORT", u.rsiviz.port_base + 1, path
)
20 changes: 11 additions & 9 deletions rsconf/component/rsiviz.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,33 @@ def internal_build_compile(self):
jc, z = self.j2_ctx_init()
z._run_u = jc.rsconf_db.run_u
self.j2_ctx_pksetdefault(
PKDict(pykern=PKDict(pkconfig=PKDict(channel=jc.rsconf_db.channel)))
PKDict(
pykern=PKDict(
pkconfig=PKDict(channel=jc.rsconf_db.channel),
pkasyncio=PKDict(server_port=8002),
),
rsiviz=PKDict(pkcli=PKDict(service=PKDict(index_iframe_port=8000))),
)
)
self.__run_d = systemd.docker_unit_prepare(
self,
jc,
# TODO(e-carlin): This is the default command (set by build_docker_cmd)
# is there a way to just use it and not specify cmd?
docker_exec=f"bash {db.user_home_path(z._run_u)}/.radia-run/start",
)

def internal_build_write(self):
from rsconf.component import db_bkp
from rsconf.component import nginx
from rsconf.component import docker

jc = self.j2_ctx
z = jc[self.name]
d = self.__run_d.join(_DB_SUBDIR)
jc.nginx.pkupdate(
index_port=8880,
flask_port=8882,
docker_index_port=8000,
docker_flask_port=8002,
docker_index_port=z.pkcli.service.index_iframe_port,
docker_flask_port=jc.pykern.pkasyncio.server_port,
)
nginx.install_vhost(
self,
Expand All @@ -54,10 +60,6 @@ def internal_build_write(self):
exclude_re=r"^rsiviz(?:__|_docker_image|_url_secret)",
),
image=z.docker_image,
ports=(
(jc.nginx.docker_index_port, 8080),
(jc.nginx.docker_flask_port, 8082),
),
)
self.install_access(mode="700", owner=z._run_u)
self.install_directory(d)
9 changes: 9 additions & 0 deletions tests/pkcli/build_data/1.in/db/000.yml
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,15 @@ host:
custom_image:
docker_image: radiasoft/custom-image
ssh_port: 3102
rsivizdevbox:
rsiviz:
ip_base: 127.2.0.0
port_base: 20000
ssh_port: 3103
systemd:
extra_run_flags:
rsivizdevbox:
gpus: "all"
jupyterhub:
jupyter_docker_image: radiasoft/custom-jupyter:latest
jupyter_docker_image_is_local: true
Expand Down
1 change: 1 addition & 0 deletions tests/pkcli/build_data/1.out/srv/host/v9.radia.run/000.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ rsconf_require docker
rsconf_require devbox_devtech3
rsconf_require devbox_fullstackdude
rsconf_require devbox_custom_image
rsconf_require devbox_rsivizdevbox
rsconf_require devbox
rsconf_require dovecot
rsconf_require github_bkp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
-A INPUT -i lo -j ACCEPT
-A INPUT -i em1 -j ACCEPT
-A INPUT -i em2 -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -i em2 -p tcp -m state --state NEW -m tcp --match multiport --dports 3100,3101,3102,9999,http,pop3s,smtp,submission -j ACCEPT
-A INPUT -i em2 -p tcp -m state --state NEW -m tcp --match multiport --dports 3100,3101,3102,3103,9999,http,pop3s,smtp,submission -j ACCEPT
-A INPUT -i em2 -s 192.168.1.0/24 -p tcp -m state --state NEW -m tcp --dport https -j ACCEPT
-A INPUT -i em2 -s 127.0.0.1 -p tcp -m state --state NEW -m tcp --dport https -j ACCEPT
-A INPUT -i em2 -m state --state INVALID -j REJECT --reject-with icmp-port-unreachable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ rsconf_install_access '444' 'root' 'root'
rsconf_install_file '/etc/resolv.conf' 'c333a7a816c03062d4e61effd6d2a8ce'
rsconf_install_file '/etc/sysconfig/network-scripts/ifcfg-em1' 'e225a3f7b4b071e5c204b1182c17ab94'
rsconf_install_file '/etc/sysconfig/network-scripts/ifcfg-em2' '4f8c01335a3bf1a8a89ba5d09fdf28df'
rsconf_install_file '/etc/sysconfig/iptables' '422d9959bcaf8e047c266a168ba2638e'
rsconf_install_file '/etc/sysconfig/iptables' '797fdace2e6dd01371697aa815251bc5'
network_main
}
#!/bin/bash
Expand Down

0 comments on commit 3ace76e

Please sign in to comment.