annotate docker/libervia/scripts/libervia_cont_launch @ 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 5d8b9ca2afd4
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 check if libervia and admin accounts exist, and create them if necessary
b69056368901 docker: images optimisation:
Goffi <goffi@goffi.org>
parents:
diff changeset
4 # then it launch libervia
b69056368901 docker: images optimisation:
Goffi <goffi@goffi.org>
parents:
diff changeset
5 import os, sys, string, random
b69056368901 docker: images optimisation:
Goffi <goffi@goffi.org>
parents:
diff changeset
6 from sat.plugins import plugin_misc_account as account
b69056368901 docker: images optimisation:
Goffi <goffi@goffi.org>
parents:
diff changeset
7 from sat.tools import config
b69056368901 docker: images optimisation:
Goffi <goffi@goffi.org>
parents:
diff changeset
8 from sat_frontends.bridge import DBus
b69056368901 docker: images optimisation:
Goffi <goffi@goffi.org>
parents:
diff changeset
9
b69056368901 docker: images optimisation:
Goffi <goffi@goffi.org>
parents:
diff changeset
10 def generate_pwd():
b69056368901 docker: images optimisation:
Goffi <goffi@goffi.org>
parents:
diff changeset
11 chars = string.letters + string.digits
b69056368901 docker: images optimisation:
Goffi <goffi@goffi.org>
parents:
diff changeset
12 length = 12
b69056368901 docker: images optimisation:
Goffi <goffi@goffi.org>
parents:
diff changeset
13 return "".join(random.choice(chars) for _ in range(length))
b69056368901 docker: images optimisation:
Goffi <goffi@goffi.org>
parents:
diff changeset
14
b69056368901 docker: images optimisation:
Goffi <goffi@goffi.org>
parents:
diff changeset
15 sat=DBus.DBusBridgeFrontend()
b69056368901 docker: images optimisation:
Goffi <goffi@goffi.org>
parents:
diff changeset
16 sat.getReady()
b69056368901 docker: images optimisation:
Goffi <goffi@goffi.org>
parents:
diff changeset
17 admin_email = sat.getConfig(account.CONFIG_SECTION, "admin_email") or account.default_conf["admin_email"]
b69056368901 docker: images optimisation:
Goffi <goffi@goffi.org>
parents:
diff changeset
18
b69056368901 docker: images optimisation:
Goffi <goffi@goffi.org>
parents:
diff changeset
19 for profile in ["libervia", "admin"]:
b69056368901 docker: images optimisation:
Goffi <goffi@goffi.org>
parents:
diff changeset
20 try:
b69056368901 docker: images optimisation:
Goffi <goffi@goffi.org>
parents:
diff changeset
21 sat.getProfileName(profile)
b69056368901 docker: images optimisation:
Goffi <goffi@goffi.org>
parents:
diff changeset
22 except Exception as e:
b69056368901 docker: images optimisation:
Goffi <goffi@goffi.org>
parents:
diff changeset
23 print "{} profile doesn'\''t exists, creating it".format(profile)
b69056368901 docker: images optimisation:
Goffi <goffi@goffi.org>
parents:
diff changeset
24 print "registering {}@{}".format(profile, sat.getNewAccountDomain())
b69056368901 docker: images optimisation:
Goffi <goffi@goffi.org>
parents:
diff changeset
25 pwd = generate_pwd()
b69056368901 docker: images optimisation:
Goffi <goffi@goffi.org>
parents:
diff changeset
26 if profile == "libervia":
b69056368901 docker: images optimisation:
Goffi <goffi@goffi.org>
parents:
diff changeset
27 config.fixConfigOption("libervia", "passphrase", pwd)
b69056368901 docker: images optimisation:
Goffi <goffi@goffi.org>
parents:
diff changeset
28 elif profile == "admin":
b69056368901 docker: images optimisation:
Goffi <goffi@goffi.org>
parents:
diff changeset
29 with open("/home/sat/ADMIN_PWD", "w") as f:
b69056368901 docker: images optimisation:
Goffi <goffi@goffi.org>
parents:
diff changeset
30 f.write("%s\\n" % pwd)
b69056368901 docker: images optimisation:
Goffi <goffi@goffi.org>
parents:
diff changeset
31 sat.registerSatAccount(admin_email, pwd, profile)
b69056368901 docker: images optimisation:
Goffi <goffi@goffi.org>
parents:
diff changeset
32
b69056368901 docker: images optimisation:
Goffi <goffi@goffi.org>
parents:
diff changeset
33 os.execvp("libervia", ["libervia"] + sys.argv[1:])