Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Merge pull request #5562 from matrix-org/rav/docker/no-generate-keys
Browse files Browse the repository at this point in the history
Docker: only run --generate-keys when generating config on-the-fly.
  • Loading branch information
richvdh authored Jun 27, 2019
2 parents 02aeb5a + 7c45347 commit 53faa6a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
1 change: 1 addition & 0 deletions changelog.d/5562.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Update Docker image to deprecate the use of environment variables for configuration, and make the use of a static configuration the default.
31 changes: 23 additions & 8 deletions docker/start.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,11 @@ def generate_config_from_template(environ, ownership):
# generate a new secret and write it to a file

if os.path.exists(filename):
log("Reading %s from %s" % (secret, filename))
with open(filename) as handle:
value = handle.read()
else:
log("Generating a random secret for {}".format(name))
log("Generating a random secret for {}".format(secret))
value = codecs.encode(os.urandom(32), "hex").decode()
with open(filename, "w") as handle:
handle.write(value)
Expand Down Expand Up @@ -100,6 +101,24 @@ def generate_config_from_template(environ, ownership):
convert("/conf/homeserver.yaml", config_path, environ)
convert("/conf/log.config", "/compiled/log.config", environ)
subprocess.check_output(["chown", "-R", ownership, "/data"])

# Hopefully we already have a signing key, but generate one if not.
subprocess.check_output(
[
"su-exec",
ownership,
"python",
"-m",
"synapse.app.homeserver",
"--config-path",
config_path,
# tell synapse to put generated keys in /data rather than /compiled
"--keys-directory",
"/data",
"--generate-keys",
]
)

return config_path


Expand Down Expand Up @@ -145,19 +164,15 @@ def main(args, environ):
config_path = generate_config_from_template(environ, ownership)

args = [
"su-exec",
ownership,
"python",
"-m",
"synapse.app.homeserver",
"--config-path",
config_path,
# tell synapse to put any generated keys in /data rather than /compiled
"--keys-directory",
"/data",
]

# Generate missing keys and start synapse
subprocess.check_output(args + ["--generate-keys"])
os.execv("/sbin/su-exec", ["su-exec", ownership] + args)
os.execv("/sbin/su-exec", args)


if __name__ == "__main__":
Expand Down

0 comments on commit 53faa6a

Please sign in to comment.