diff --git a/integration-tests/test_proxy.py b/integration-tests/test_proxy.py index fd8946c..ced51a3 100644 --- a/integration-tests/test_proxy.py +++ b/integration-tests/test_proxy.py @@ -9,7 +9,13 @@ import toml from tornado.httpclient import HTTPClient, HTTPRequest, HTTPClientError import pytest -from tljh.config import reload_component, set_config_value, CONFIG_FILE, CONFIG_DIR +from tljh.config import ( + reload_component, + set_config_value, + CONFIG_FILE, + CONFIG_DIR, + STATE_DIR, +) def test_manual_https(preserve_config): @@ -72,7 +78,7 @@ def test_manual_https(preserve_config): shutil.rmtree(ssl_dir) -def test_extra_traefik_config(): +def test_extra_traefik_static_config(): extra_config_dir = os.path.join(CONFIG_DIR, "traefik_config.d") os.makedirs(extra_config_dir, exist_ok=True) @@ -116,3 +122,36 @@ def test_extra_traefik_config(): # cleanup os.remove(os.path.join(extra_config_dir, "extra.toml")) reload_component("proxy") + + +def test_extra_traefik_dynamic_config(): + dynamic_config_dir = os.path.join(STATE_DIR, "rules") + os.makedirs(dynamic_config_dir, exist_ok=True) + + extra_config = { + "frontends": { + "test": { + "backend": "test", + "routes": {"rule1": {"rule": "Path: /test/proxy"}}, + } + }, + "backends": { + "test": {"servers": {"server1": {"url": "https://mybinder.org/"}}} + }, + } + + # Load the extra config + with open( + os.path.join(dynamic_config_dir, "extra_rules.toml"), "w+" + ) as extra_config_file: + toml.dump(extra_config, extra_config_file) + reload_component("proxy") + + req = HTTPRequest("http://127.0.0.1/test/", method="GET") + resp = HTTPClient().fetch(req) + print(resp) + assert resp.code == 200 + + # cleanup + # os.remove(os.path.join(dynamic_config_dir, "extra_rules.toml")) + # reload_component("proxy") diff --git a/tljh/jupyterhub_config.py b/tljh/jupyterhub_config.py index 38fbaa9..e31e6e2 100644 --- a/tljh/jupyterhub_config.py +++ b/tljh/jupyterhub_config.py @@ -53,7 +53,7 @@ c.JupyterHub.hub_port = 15001 c.TraefikTomlProxy.should_start = False -dynamic_conf_file_path = os.path.join(INSTALL_PREFIX, 'state', 'rules.toml') +dynamic_conf_file_path = os.path.join(INSTALL_PREFIX, 'state', 'rules', 'rules.toml') c.TraefikTomlProxy.toml_dynamic_config_file = dynamic_conf_file_path c.JupyterHub.proxy_class = TraefikTomlProxy diff --git a/tljh/systemd-units/traefik.service b/tljh/systemd-units/traefik.service index 5884fa4..1a27a5c 100644 --- a/tljh/systemd-units/traefik.service +++ b/tljh/systemd-units/traefik.service @@ -14,7 +14,7 @@ PrivateTmp=yes PrivateDevices=yes ProtectKernelTunables=yes ProtectKernelModules=yes -ReadWritePaths={install_prefix}/state/rules.toml +ReadWritePaths={install_prefix}/state/rules ReadWritePaths={install_prefix}/state/acme.json WorkingDirectory={install_prefix}/state ExecStart={install_prefix}/hub/bin/traefik \ diff --git a/tljh/traefik.py b/tljh/traefik.py index 2cbb312..1a3105a 100644 --- a/tljh/traefik.py +++ b/tljh/traefik.py @@ -131,7 +131,7 @@ def ensure_traefik_config(state_dir): os.fchmod(f.fileno(), 0o600) toml.dump(new_toml, f) - with open(os.path.join(state_dir, "rules.toml"), "w") as f: + with open(os.path.join(state_dir, 'rules', "rules.toml"), "w") as f: os.fchmod(f.fileno(), 0o600) # ensure acme.json exists and is private diff --git a/tljh/traefik.toml.tpl b/tljh/traefik.toml.tpl index 1b6de8f..4364c16 100644 --- a/tljh/traefik.toml.tpl +++ b/tljh/traefik.toml.tpl @@ -70,5 +70,5 @@ entryPoint = "https" {% endif %} [file] -filename = "rules.toml" +directory = "rules" watch = true