question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Using a custom traefik toml file or template

See original GitHub issue

I’m trying with @jhadjar to change the proxy config in /opt/tljh/state/traefik.toml but it is overwritten by traefik.toml.tpl every time the proxy is reloaded, is there any way to set a custom file or template to be used instead?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
yuvipandacommented, May 4, 2020

@GeorgianaElena yeah, an escape hatch sounds great, especially for web proxy config. Maybe something along the lines of https://github.com/jupyterhub/zero-to-jupyterhub-k8s/pull/1636?

0reactions
jhadjarcommented, May 4, 2020

Can you please explain a bit what’s your use-case and how would modifying traefik.toml.tpl help?

Sure. The issues encountered serving JupyterLab static files on slow, unstable, internet connections lead us to look into two things:

    1. Compression
    1. Caching

We failed to enable compression at the jupyterhub_config.py level (Tornado settings), as per https://github.com/tornadoweb/tornado/blob/18d7026853900c56a1879141235c6b6bd51b0a6a/tornado/web.py#L2044

c.JupyterHub.tornado_settings = {
    'headers': {
        'Content-Security-Policy': f"frame-ancestors 'self' {os.getenv('XXX_URL', '*')}",
    },
    'compress_response': True,
    # 'gzip': True,
    # We have also tried the previouly supported parameter 'gzip'
}

This did not work, which lead us to enable compression at the Traefik level:

# traefik.toml

[entryPoints.https]
address = ":8080"
compress = true      # <--------- Add this line

tljh overrides this with the line we feel hard codes the template file and reduces flexibility at https://github.com/jupyterhub/the-littlest-jupyterhub/blob/master/tljh/traefik.py#L90:

    with open(os.path.join(os.path.dirname(__file__), "traefik.toml.tpl")) as f:

Is there a reason this is hard-coded? Given that the function ensure_traefik_config loads a config, is it not sensible to make the config it loads a parameter of the function before touching other parts of the system?

Something like this:

DEFAULT_TOML_TEMPLATE = os.path.join(os.path.dirname(__file__), "traefik.toml.tpl")
TRAEFIK_TOML_TEMPLATE = os.environ.get('TRAEFIK_TOML_TEMPLATE', DEFAULT_TOML_TEMPLATE)

def ensure_traefik_config(state_dir, traefik_toml_template=None):
    ...
    traefik_toml_template = traefik_toml_template or TRAEFIK_TOML_TEMPLATE
    with open(traefik_toml_template) as f:
        template = Template(f.read())
    ...

One way to do that according to @hMED22 is:

# jupyterhub_config.py
c.TraefikTomlProxy.toml_dynamic_config_file = dynamic_conf_file_path

and changing https://github.com/jupyterhub/the-littlest-jupyterhub/blob/87bed7aaf1617960a8137055d2f8d4301a0b72b3/tljh/systemd-units/traefik.service#L21

Read more comments on GitHub >

github_iconTop Results From Across the Web

Traefik File Documentation
Traefik supports using Go templating to automatically generate repetitive sections of configuration files. These sections must be a valid Go template, and can ......
Read more >
How to use custom traefik.toml file? - Stack Overflow
And I'm trying to use my custom config: traefik.toml in my traefik folder but it's not working. This is my folder structure: traefik:...
Read more >
How To Use Traefik v2 as a Reverse Proxy for Docker ...
To configure the Traefik server, you'll create two new configuration files called traefik.toml and traefik_dynamic.toml using the TOML format.
Read more >
traefik.sample.toml · huamoran/traefik - Gitee.com
This certificates will be use for backends calls. # Note: You can use file path or cert content directly. # Optional. # Default:...
Read more >
Custom configuration snippets - The Littlest JupyterHub
The jupyterhub_config.py and traefik.toml files are created by TLJH during installation and can be edited by the user only through tljh-config .
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found