Mercurial > sat_docs
comparison 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 |
comparison
equal
deleted
inserted
replaced
104:b59491821a8a | 105:b69056368901 |
---|---|
1 #!/usr/bin/env python2 | |
2 | |
3 # This script set account domain in sat.conf if not already set | |
4 # if not set, domain is got from prosody container or DOMAIN environment variable | |
5 | |
6 import os, os.path, xmlrpclib, ConfigParser, socket, subprocess | |
7 from sat.core.constants import Const as C | |
8 from sat.tools import config as sat_config | |
9 | |
10 SECTION = "plugin account" | |
11 OPTION = "new_account_domain" | |
12 CONFIG_PATH = "/home/sat/.config/sat/sat.conf" | |
13 | |
14 try: | |
15 os.makedirs(os.path.dirname(CONFIG_PATH)) | |
16 except OSError: | |
17 pass | |
18 | |
19 config = ConfigParser.SafeConfigParser() | |
20 config.read(C.CONFIG_FILES) | |
21 domain = sat_config.getConfig(config, SECTION, OPTION) | |
22 | |
23 if domain is None: | |
24 os.getenv("DOMAIN") | |
25 if domain is None: | |
26 proxy = xmlrpclib.ServerProxy("http://prosody:9999/") | |
27 try: | |
28 if "prosody" not in open("/etc/hosts").read(): | |
29 raise socket.gaierror # this avoid waiting for timeout if prosody is not linked | |
30 domain = proxy.getenv("DOMAIN") | |
31 except socket.gaierror: | |
32 print "No prosody container connected or known domain, using \"localhost\" for new domains" | |
33 domain = "localhost" | |
34 | |
35 config = ConfigParser.SafeConfigParser() | |
36 config.readfp(open(CONFIG_PATH, "a+")) | |
37 | |
38 try: | |
39 config.add_section(SECTION) | |
40 except ConfigParser.DuplicateSectionError: | |
41 pass | |
42 | |
43 config.set(SECTION, OPTION, domain) | |
44 config.write(open(CONFIG_PATH, "w")) | |
45 | |
46 subprocess.call(["add_host", domain, "prosody"]) | |
47 | |
48 for subdomain in ("chat", "proxy", "upload", "pubsub", "salut"): | |
49 subprocess.call(["add_host", "{}.{}".format(subdomain, domain), "prosody"]) |