Configuration files should be more templatable in the standard images #11489
Description
Description:
In container driven worlds, when simple templating of a config file is desired, there are a few ways to go about it, but they're not 100% easy to use, for example cases like these require extending the synapse container with scripts or even extra docker containers:
- a live deployment where the database credentials cycle automatically and are configured based on environment variables (possibly sourced from a kubernetes or other secret)
- complement needing to bundle it's own templating of configuration: https://github.com/matrix-org/complement/blob/master/dockerfiles/synapse/homeserver.yaml & https://github.com/matrix-org/complement/blob/master/dockerfiles/synapse/start.sh
- a stateless container that doesn't provide the ability to write config file changes to disk
- test servers that are spun up on demand for non-technical users, wanting minimal configuration options.
A while ago we were able to provide templating via some fixed environment variables but removed that due to maintenance complexity as everything needed to be a environment variable.
We have the debian system that templates from debconf: https://github.com/matrix-org/synapse/blob/develop/debian/manage_debconf.pl
We currently have the --generate-config option which templates out synapse configuration based on environment variables, but only a limited number of values are supported https://github.com/matrix-org/synapse/blob/develop/docker/start.py#L130 and it relies on being able to write the generated result back out and have it persisted.
We can also currently use a conf.d/ type configuration, and be responsible for writing parts of the config out from different sources, but that gets complicated if the configuration is nested, eg sharing the database password from one source and the database hostname from another requires merging two trees of configuration.
We could create some specific syntax for use in the config file, eg hostname: "${ENV['POSTGRES_HOST']}"
to allow values to be read from environment variables, which might deal with a lot of the cases - provide a static config file and specify which two or three secrets are to be provided.
Or maybe we could get value from loosening up the existing --generate-config
templating so it could run before every start (so doesn't run and exit) but only templates the configuration files; not the other files it currently makes.
We find ourselves repeating these slight configurations in a lot of tiny built images, and I wonder if we could replace them with a single standard templating option.
I'm not sure of the right answer here; but it's currently painful to have to reimplement the templating of synapse config files again and again in each usecase, so creating this issue to see if we can make something simpler here.