comparison docker/base/Dockerfile @ 21:0e78c8a4626e

Added Dockerfiles to create Docker images for easy installation + scripts to manages them. see README for details.
author Goffi <goffi@goffi.org>
date Sun, 19 Oct 2014 15:14:40 +0200
parents
children 686a8c982c3f
comparison
equal deleted inserted replaced
20:703a394b9780 21:0e78c8a4626e
1 ###############################################################
2 # #
3 # Salut à Toi/base #
4 # This Dockerfile build a « Salut à Toi » base image #
5 # Salut à Toi is a multi-frontends multi-purposes XMPP client #
6 # #
7 ###############################################################
8
9 FROM debian:jessie
10
11 MAINTAINER Goffi <goffi@goffi.org>
12
13 ########
14 # BASE #
15 ########
16
17 ENV DEBIAN_FRONTEND noninteractive
18
19 RUN apt-get update
20 RUN apt-get upgrade -y
21 RUN apt-get install -y --no-install-recommends locales dbus-x11 python python-gobject-2 python-dbus python-lxml python-mutagen python-pil python-crypto python-feed python-potr python-twisted-core python-twisted-mail python-twisted-web python-twisted-words python-wokkel python-xdg python-xe python-zope.interface python-gi python-urwid python-markdown python-html2text mercurial
22 RUN apt-get clean
23
24 # we need UTF-8 locale
25 RUN sed -i "s/# en_US.UTF-8/en_US.UTF-8/" /etc/locale.gen
26 RUN locale-gen
27 ENV LC_ALL en_US.UTF-8
28
29 # it's better to have a dedicated user
30 RUN useradd -m sat
31
32 # will be used to put many SàT specific data
33 RUN mkdir -p /usr/share/sat
34
35 ################
36 # URWID SÀTEXT #
37 ################
38
39 WORKDIR /tmp
40
41 RUN hg clone http://repos.goffi.org/urwid-satext
42
43 WORKDIR urwid-satext
44
45 RUN python setup.py install --prefix /usr --install-lib /usr/lib/python2.7/dist-packages
46
47 WORKDIR /tmp
48
49 RUN rm -rf urwid-satext
50
51 #####################
52 # CORE INSTALLATION #
53 #####################
54
55 WORKDIR /tmp
56
57 RUN hg clone http://repos.goffi.org/sat
58
59 WORKDIR sat
60
61 RUN SAT_INSTALL=nox python setup.py install --prefix /usr --install-lib /usr/lib/python2.7/dist-packages
62
63 WORKDIR /tmp
64
65 RUN rm -rf sat
66
67 ######################
68 # SàT CONFIGURATION #
69 ######################
70
71 # Following scripts make the configuration as automatic and easy as possible
72
73 # we auto-create libervia account if it doesn't exists in Libervia container
74 # so we remove it from reserved_list in plugin account
75 RUN echo '[plugin account]\nreserved_list=' >> /etc/sat.conf
76
77 # This script set account domain in sat.conf is not already set
78 # if not set, domain is gotted from prosody container or DOMAIN environment variable
79 RUN echo '#!/usr/bin/env python2\n\
80 import os, xmlrpclib, ConfigParser, socket, subprocess\n\
81 from sat.core.constants import Const as C\n\
82 from sat.tools import config as sat_config\n\
83 SECTION = "plugin account"\n\
84 OPTION = "new_account_domain"\n\
85 CONFIG_PATH = "/home/sat/sat.conf"\n\
86 config = ConfigParser.SafeConfigParser()\n\
87 config.read(C.CONFIG_FILES)\n\
88 domain = sat_config.getConfig(config, SECTION, OPTION)\n\
89 if domain is None:\n\
90 os.getenv("DOMAIN")\n\
91 if domain is None:\n\
92 proxy = xmlrpclib.ServerProxy("http://prosody:9999/")\n\
93 try:\n\
94 if "prosody" not in open("/etc/hosts").read():\n\
95 raise socket.gaierror # this avoid waiting for timeout if prosody is not linked\n\
96 domain = proxy.getenv("DOMAIN")\n\
97 except socket.gaierror:\n\
98 print "No prosody container connected or known domain, using \"localhost\" for new domains"\n\
99 domain = "localhost"\n\
100 config = ConfigParser.SafeConfigParser()\n\
101 config.readfp(open(CONFIG_PATH, "a+"))\n\
102 try:\n\
103 config.add_section(SECTION)\n\
104 except ConfigParser.DuplicateSectionError:\n\
105 pass\n\
106 config.set(SECTION, OPTION, domain)\n\
107 config.write(open(CONFIG_PATH, "w"))\n\
108 subprocess.call(["add_host", domain, "prosody"])\n\
109 ' > /usr/local/bin/set_account_domain && chmod 0555 /usr/local/bin/set_account_domain
110
111 # account domain is set, then sat is launcher with D-Bus activated
112 RUN echo '#!/bin/sh\n\
113 chmod a+w /etc/hosts\n\
114 su -c "set_account_domain && dbus-launch /usr/bin/sat $@" sat\n\
115 '> /usr/local/bin/sat && chmod 0500 /usr/local/bin/sat
116
117 # this script add aliases to /etc/hosts
118 RUN echo '#!/usr/bin/env python2\n\
119 import sys, re\n\
120 if len(sys.argv) < 2 or len(sys.argv) > 3:\n\
121 sys.exit(1)\n\
122 host = sys.argv[1]\n\
123 alias = sys.argv[2] if len(sys.argv) == 3 else "localhost"\n\
124 if host == "localhost" or host == alias:\n\
125 sys.exit(0)\n\
126 print "Adding host {} as an alias of {}".format(host, alias)\n\
127 with open("/etc/hosts", "r+") as f:\n\
128 buf = re.sub(r"\\b{}\\b".format(alias), "{}\\t{}".format(alias, host), f.read(), 1)\n\
129 f.seek(0)\n\
130 f.write(buf)\
131 ' > /usr/local/bin/add_host && chmod 0555 /usr/local/bin/add_host
132
133 # This script simulate prosodyctl adduser/passwd/deluser and call it on the prosody container
134 RUN echo '#!/usr/bin/env python2\n\
135 import sys, xmlrpclib\n\
136 proxy = xmlrpclib.ServerProxy("http://prosody:9999/")\n\
137 def pwd():\n\
138 pwd1=raw_input(); pwd2=raw_input(); assert pwd1==pwd2\n\
139 return pwd1\n\
140 password = pwd() if sys.argv[1] in ["adduser", "passwd"] else ""\n\
141 sys.exit(proxy.prosodyctl(sys.argv[1], sys.argv[2], password))\n\
142 ' > /usr/local/bin/prosodyctl
143
144 #########
145 # D-Bus #
146 #########
147
148 # we need a TCP socket
149 RUN sed -i "s&<listen>unix:tmpdir=/tmp</listen>&\0\n <listen>tcp:host=localhost,bind=*,port=55555,family=ipv4</listen>\n <auth>ANONYMOUS</auth>\n <allow_anonymous/>&" /etc/dbus-1/session.conf
150
151 # this script will launch the command with good D-BUS parameters
152 # it needs to be copied and made executable by frontends
153 RUN echo "#!/bin/sh\nexport DBUS_SESSION_BUS_ADDRESS=tcp:host=sat,port=55555,family=ipv4\nexec /usr/bin/\$(basename \$0) \$@" > /usr/local/bin/dbus_wrap
154
155 ##########
156 # LAUNCH #
157 ##########
158
159 WORKDIR /home/sat
160
161 ENTRYPOINT ["/bin/bash"]