contrib/sni-router: render mtg-config.toml from a tracked .example#525
Conversation
Track `mtg-config.toml.example` with `secret = "${MTG_SECRET}"`; the
rendered `mtg-config.toml` and local `.env` are gitignored, so the
secret never lands in a tracked file.
Quick start switches from "paste the secret into mtg-config.toml" to
either `envsubst < mtg-config.toml.example > mtg-config.toml` or
`cp` + hand-edit `${MTG_SECRET}` for users without envsubst.
After #502 made DOMAIN env-driven, the secret was the last hand-edit
of a tracked file in the example. Follow-up to #506.
…ples `MTG_SECRET=<placeholder> envsubst < ...` was shell-broken on literal copy-paste — bash parses `<placeholder>` as redirection from a non-existent file. Two-line `export MTG_SECRET=...` + plain envsubst form removes the ambiguity. Applies to README, docker-compose.yml, and the .example header.
|
Nah, the system should synchronize secret/domains in all the 3 places itself, no manual steps should be involved.
And this is the problem. Upstream compose (or rather contrib, as there is no upstream) should provide all the needed for the above, and compensate lack of mtg's abilities if needed. Nothing bad if it's not minimal, this is for a reason. Having that, the patch seems useful, but definitely not enough. |
|
The shape you're describing — runtime template rendering inside the container, On the "3 places" — after #502 + this PR, the only substitution surface is two env vars ( Leaving the merge call to @9seconds. |
|
@bam80 but this is just a suggested configuration, and it is not specific to mtg, this is just a general Unix stuff. I think that for this scope this is already quite good and reasonable PR. If we want to have some generic mechanism, sure, we can just put envsubst in a docker container. |
Summary
Track
mtg-config.toml.examplewithsecret = "${MTG_SECRET}"; the renderedmtg-config.toml(and.env) are now gitignored. The secret never lands in a tracked file, which is the gap discussed in #506.Quick start step 3 switches from:
to either:
or, for users without
envsubst:Single placeholder file works for either workflow.
Why this shape
#506 asked for env-var support inside the TOML loader; @9seconds settled that with "TOML stays static, templating belongs in deploy-layer CLI tools" (composability). That principle leaves the contrib example as the right place to show the standard templating step, not mtg itself. This PR does exactly that — keeps mtg static, keeps the compose minimal (no init container, no entrypoint rewrites, no
apk addat startup), and uses the tool @9seconds named (envsubst) as the documented path while still working with a plaincp+ edit for users on platforms without it.After #502 made DOMAIN env-driven for HAProxy + Caddy, the secret was the last manual touch of a tracked file in the example. This closes that gap.
Test plan
envsubst < mtg-config.toml.example > mtg-config.tomlproduces a valid TOML file withsecret = "<resolved>".gitignorecovers bothmtg-config.tomland.envexport MTG_SECRET=... ; envsubst < ...form is shell-safe on literal copy-paste (the earlierMTG_SECRET=<placeholder>form parsed<placeholder>as a redirection — fixed in 3d0899d)