mirror of
https://github.com/jupyterhub/the-littlest-jupyterhub.git
synced 2025-12-18 21:54:05 +08:00
Allow extending traefik dynamic config
This commit is contained in:
@@ -9,7 +9,13 @@ import toml
|
|||||||
from tornado.httpclient import HTTPClient, HTTPRequest, HTTPClientError
|
from tornado.httpclient import HTTPClient, HTTPRequest, HTTPClientError
|
||||||
import pytest
|
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):
|
def test_manual_https(preserve_config):
|
||||||
@@ -72,7 +78,7 @@ def test_manual_https(preserve_config):
|
|||||||
shutil.rmtree(ssl_dir)
|
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")
|
extra_config_dir = os.path.join(CONFIG_DIR, "traefik_config.d")
|
||||||
os.makedirs(extra_config_dir, exist_ok=True)
|
os.makedirs(extra_config_dir, exist_ok=True)
|
||||||
|
|
||||||
@@ -116,3 +122,36 @@ def test_extra_traefik_config():
|
|||||||
# cleanup
|
# cleanup
|
||||||
os.remove(os.path.join(extra_config_dir, "extra.toml"))
|
os.remove(os.path.join(extra_config_dir, "extra.toml"))
|
||||||
reload_component("proxy")
|
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")
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ c.JupyterHub.hub_port = 15001
|
|||||||
|
|
||||||
c.TraefikTomlProxy.should_start = False
|
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.TraefikTomlProxy.toml_dynamic_config_file = dynamic_conf_file_path
|
||||||
c.JupyterHub.proxy_class = TraefikTomlProxy
|
c.JupyterHub.proxy_class = TraefikTomlProxy
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ PrivateTmp=yes
|
|||||||
PrivateDevices=yes
|
PrivateDevices=yes
|
||||||
ProtectKernelTunables=yes
|
ProtectKernelTunables=yes
|
||||||
ProtectKernelModules=yes
|
ProtectKernelModules=yes
|
||||||
ReadWritePaths={install_prefix}/state/rules.toml
|
ReadWritePaths={install_prefix}/state/rules
|
||||||
ReadWritePaths={install_prefix}/state/acme.json
|
ReadWritePaths={install_prefix}/state/acme.json
|
||||||
WorkingDirectory={install_prefix}/state
|
WorkingDirectory={install_prefix}/state
|
||||||
ExecStart={install_prefix}/hub/bin/traefik \
|
ExecStart={install_prefix}/hub/bin/traefik \
|
||||||
|
|||||||
@@ -131,7 +131,7 @@ def ensure_traefik_config(state_dir):
|
|||||||
os.fchmod(f.fileno(), 0o600)
|
os.fchmod(f.fileno(), 0o600)
|
||||||
toml.dump(new_toml, f)
|
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)
|
os.fchmod(f.fileno(), 0o600)
|
||||||
|
|
||||||
# ensure acme.json exists and is private
|
# ensure acme.json exists and is private
|
||||||
|
|||||||
@@ -70,5 +70,5 @@ entryPoint = "https"
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
[file]
|
[file]
|
||||||
filename = "rules.toml"
|
directory = "rules"
|
||||||
watch = true
|
watch = true
|
||||||
|
|||||||
Reference in New Issue
Block a user