diff docker/base/scripts/set_account_domain @ 105:b69056368901

docker: images optimisation: - reduced the number of layers by grouping many instructions - moved stuff which don't change a lot at the beginning, and hg/apt at the end - scripts are not now in scripts/ subdirectories - prosody.cfg.lua is added using ADD instead of getting it online - .hg/dirstate is copied in base (backend) and libervia, so mercurial revision is known - removed lot of useless WORKDIR instruction, they are replaced by "cd" inside RUN instructions - cleaning (apt-clean, rm) is done on the same instruction as the one than generate the data, to avoid useless data in layers
author Goffi <goffi@goffi.org>
date Sun, 28 Feb 2016 02:01:20 +0100
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/docker/base/scripts/set_account_domain	Sun Feb 28 02:01:20 2016 +0100
@@ -0,0 +1,49 @@
+#!/usr/bin/env python2
+
+# This script set account domain in sat.conf if not already set
+# if not set, domain is got from prosody container or DOMAIN environment variable
+
+import os, os.path, xmlrpclib, ConfigParser, socket, subprocess
+from sat.core.constants import Const as C
+from sat.tools import config as sat_config
+
+SECTION = "plugin account"
+OPTION = "new_account_domain"
+CONFIG_PATH = "/home/sat/.config/sat/sat.conf"
+
+try:
+    os.makedirs(os.path.dirname(CONFIG_PATH))
+except OSError:
+    pass
+
+config = ConfigParser.SafeConfigParser()
+config.read(C.CONFIG_FILES)
+domain = sat_config.getConfig(config, SECTION, OPTION)
+
+if domain is None:
+    os.getenv("DOMAIN")
+    if domain is None:
+        proxy = xmlrpclib.ServerProxy("http://prosody:9999/")
+        try:
+            if "prosody" not in open("/etc/hosts").read():
+                raise socket.gaierror # this avoid waiting for timeout if prosody is not linked
+            domain = proxy.getenv("DOMAIN")
+        except socket.gaierror:
+            print "No prosody container connected or known domain, using \"localhost\" for new domains"
+            domain = "localhost"
+
+    config = ConfigParser.SafeConfigParser()
+    config.readfp(open(CONFIG_PATH, "a+"))
+
+    try:
+        config.add_section(SECTION)
+    except ConfigParser.DuplicateSectionError:
+        pass
+
+    config.set(SECTION, OPTION, domain)
+    config.write(open(CONFIG_PATH, "w"))
+
+subprocess.call(["add_host", domain, "prosody"])
+
+for subdomain in ("chat", "proxy", "upload", "pubsub", "salut"):
+    subprocess.call(["add_host", "{}.{}".format(subdomain, domain), "prosody"])