My idea is to either create Chains or Middlewares externally using the providers.File, which I could then call in my compose file with:
- traefik.http.routers.test.middlewares=https-only@file
.
If I create a chain in the compose file, I can then reference it in other routers/compose files, but doing it this way ties the middleware to a particular router/compose. For example, if I stop that router/compose the middleware would be removed. I feel like this is an intended use of the file property, but I'm having trouble getting it to work.
I'm calling the file in my traefik.toml as:
[providers.file]
##Provide a dedicated file, or a directory of several dedicated files
## filename = "/etc/traefik/rules/middlewares.toml"
directory = "/etc/traefik/rules"
watch = true
At first I was getting the error:
"Cannot start the provider *file.Provider: toml: cannot load TOML value of type string into a Go boolean"
So I edited my middlewares.toml trying to follow the docs:
[http.middlewares]
{{ range $i, $e := until 100 }}
[http.middlewares.https-only.redirectScheme{{ $e }}]
scheme = "https-{{ $e }}"
{{ end }}
but I'm now getting the error:
error msg="middleware \"https-only@file\" does not exist" entryPointName=https routerName=traefik@docker
I feel like modifying the middlewares.toml with Go templating per the docs helped the file to be read, but I'm still not having any luck creating middlewares with the file property. I tried adding a fake router and service in my middlewares.toml, hoping that the middleware would be created, but wouldn't route any traffic, but didn't have luck there either.
Is anyone doing something similar?
I feel like the issue may have to do with my middlewares.toml file and not having the right context or Go templating.