From c58a6e6108d2891d10ce7f29e4b0169a3e026787 Mon Sep 17 00:00:00 2001 From: Richard van der Hoff Date: Tue, 25 Jun 2019 15:09:22 +0100 Subject: [PATCH 1/3] document supported env vars for docker 'generate' option --- docker/README.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/docker/README.md b/docker/README.md index 5a596eecb9..10af88844b 100644 --- a/docker/README.md +++ b/docker/README.md @@ -179,3 +179,10 @@ docker run -d --name synapse \ -e SYNAPSE_CONFIG_PATH=/data/homeserver.yaml \ matrixdotorg/synapse:latest ``` + +The following environment variables are supported in this mode: + +* `SYNAPSE_SERVER_NAME` (mandatory): the server public hostname. +* `SYNAPSE_REPORT_STATS` (mandatory, `yes` or `no`): whether to enable + anonymous statistics reporting. +* `SYNAPSE_CONFIG_PATH` (mandatory): path to the file to be generated. From 7e433beb65946a39442f025705429227bfa3e429 Mon Sep 17 00:00:00 2001 From: Richard van der Hoff Date: Tue, 25 Jun 2019 15:18:30 +0100 Subject: [PATCH 2/3] Docker image: add support for SYNAPSE_DATA_DIR parameter Fixes #4830. --- docker/README.md | 4 ++++ docker/start.py | 17 +++++++++++++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/docker/README.md b/docker/README.md index 10af88844b..5c85c538a8 100644 --- a/docker/README.md +++ b/docker/README.md @@ -186,3 +186,7 @@ The following environment variables are supported in this mode: * `SYNAPSE_REPORT_STATS` (mandatory, `yes` or `no`): whether to enable anonymous statistics reporting. * `SYNAPSE_CONFIG_PATH` (mandatory): path to the file to be generated. +* `SYNAPSE_DATA_DIR`: where the generated config will put persistent data + such as the datatase and media store. Defaults to `/data`. +* `UID`, `GID`: the user id and group id to use for creating the data + directories. Defaults to `991`, `991`. diff --git a/docker/start.py b/docker/start.py index bdb703aebd..ad968b2a67 100755 --- a/docker/start.py +++ b/docker/start.py @@ -103,11 +103,12 @@ def generate_config_from_template(environ, ownership): return config_path -def run_generate_config(environ): +def run_generate_config(environ, ownership): """Run synapse with a --generate-config param to generate a template config file Args: - environ (dict): environment dictionary + environ (dict): env var dict + ownership (str): "userid:groupid" arg for chmod Never returns. """ @@ -115,6 +116,11 @@ def run_generate_config(environ): if v not in environ: error("Environment variable '%s' is mandatory in `generate` mode." % (v,)) + data_dir = environ.get("SYNAPSE_DATA_DIR", "/data") + + # make sure that synapse has perms to write to the data dir. + subprocess.check_output(["chown", ownership, data_dir]) + args = [ "python", "-m", @@ -125,8 +131,11 @@ def run_generate_config(environ): environ["SYNAPSE_REPORT_STATS"], "--config-path", environ["SYNAPSE_CONFIG_PATH"], + "--data-directory", + data_dir, "--generate-config", ] + # log("running %s" % (args, )) os.execv("/usr/local/bin/python", args) @@ -134,9 +143,9 @@ def main(args, environ): mode = args[1] if len(args) > 1 else None ownership = "{}:{}".format(environ.get("UID", 991), environ.get("GID", 991)) - # In generate mode, generate a configuration, missing keys, then exit + # In generate mode, generate a configuration and missing keys, then exit if mode == "generate": - return run_generate_config(environ) + return run_generate_config(environ, ownership) # In normal mode, generate missing keys if any, then run synapse if "SYNAPSE_CONFIG_PATH" in environ: From a0f2921ccfd5eac2b660274d4de3d05fdc0f390d Mon Sep 17 00:00:00 2001 From: Richard van der Hoff Date: Wed, 26 Jun 2019 15:41:10 +0100 Subject: [PATCH 3/3] changelog --- changelog.d/5563.bugfix | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/5563.bugfix diff --git a/changelog.d/5563.bugfix b/changelog.d/5563.bugfix new file mode 100644 index 0000000000..09c4381a23 --- /dev/null +++ b/changelog.d/5563.bugfix @@ -0,0 +1 @@ +Docker: Use a sensible location for data files when generating a config file. \ No newline at end of file