Repository: matrix-org/synapse

Issue:
Deprecate the env-var way of running under docker
We've decided to stop supporting the configuration of synapse via environment variables.

The main reason for this is that you're bound to end up needing to do more things than it's possible to do with the environment variables, and the incomplete support leads to problems like #5430.

An alternative might have been to make it genuinely possible to configure everything via environment variables in some consistent fashion, but that sounds hard and more work than we're able to do.


Discussion:
For clarity: we'll provide documentation on how to convert your environment-variable-configured docker image to a yaml-configured one.

Resolving patch:
diff --git a/docker/start.py b/docker/start.py
--- a/docker/start.py
+++ b/docker/start.py
@@ -131,12 +131,13 @@ def run_generate_config(environ, ownership):
 
     Never returns.
     """
-    for v in ("SYNAPSE_SERVER_NAME", "SYNAPSE_REPORT_STATS", "SYNAPSE_CONFIG_PATH"):
+    for v in ("SYNAPSE_SERVER_NAME", "SYNAPSE_REPORT_STATS"):
         if v not in environ:
             error("Environment variable '%s' is mandatory in `generate` mode." % (v,))
 
     server_name = environ["SYNAPSE_SERVER_NAME"]
     config_dir = environ.get("SYNAPSE_CONFIG_DIR", "/data")
+    config_path = environ.get("SYNAPSE_CONFIG_PATH", config_dir + "/homeserver.yaml")
     data_dir = environ.get("SYNAPSE_DATA_DIR", "/data")
 
     # create a suitable log config from our template
@@ -157,7 +158,7 @@ def run_generate_config(environ, ownership):
         "--report-stats",
         environ["SYNAPSE_REPORT_STATS"],
         "--config-path",
-        environ["SYNAPSE_CONFIG_PATH"],
+        config_path,
         "--config-directory",
         config_dir,
         "--data-directory",
@@ -176,11 +177,30 @@ def main(args, environ):
     if mode == "generate":
         return run_generate_config(environ, ownership)
 
-    # In normal mode, generate missing keys if any, then run synapse
-    if "SYNAPSE_CONFIG_PATH" in environ:
-        config_path = environ["SYNAPSE_CONFIG_PATH"]
-    else:
+    if "SYNAPSE_SERVER_NAME" in environ:
+        # backwards-compatibility generate-a-config-on-the-fly mode
+        if "SYNAPSE_CONFIG_PATH" in environ:
+            error(
+                "SYNAPSE_SERVER_NAME and SYNAPSE_CONFIG_PATH are mutually exclusive "
+                "except in `generate` mode."
+            )
+
         config_path = generate_config_from_template(environ, ownership)
+    else:
+        config_dir = environ.get("SYNAPSE_CONFIG_DIR", "/data")
+        config_path = environ.get(
+            "SYNAPSE_CONFIG_PATH", config_dir + "/homeserver.yaml"
+        )
+        if not os.path.exists(config_path):
+            error(
+                "Config file '%s' does not exist. You should either create a new "
+                "config file by running with the `generate` argument (and then edit "
+                "the resulting file before restarting) or specify the path to an "
+                "existing config file with the SYNAPSE_CONFIG_PATH variable."
+                % (config_path,)
+            )
+
+    log("Starting synapse with config file " + config_path)
 
     args = [
         "su-exec",


Test patch: