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