comparison docker/libervia/Dockerfile @ 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 bcba1966e6db
children 8b228fd053bc
comparison
equal deleted inserted replaced
104:b59491821a8a 105:b69056368901
8 8
9 FROM salutatoi/media:latest 9 FROM salutatoi/media:latest
10 10
11 MAINTAINER Goffi <goffi@goffi.org> 11 MAINTAINER Goffi <goffi@goffi.org>
12 12
13 ############## 13 #####################
14 # txJSON-RPC # 14 # FIRST LAUNCH TEST #
15 ############## 15 #####################
16 16
17 RUN pip install txJSON-RPC 17 COPY scripts/libervia_cont_launch /usr/bin/
18 18
19 ########### 19 RUN chown root:root /usr/bin/libervia_cont_launch && \
20 # PYJAMAS # 20 chmod 0555 /usr/bin/libervia_cont_launch && \
21 ###########
22 21
23 WORKDIR /usr/share 22 #########
23 # D-Bus #
24 #########
24 25
25 # as the situation with pyjamas is complicated, we get the archive from our own ftp 26 cp /usr/local/bin/dbus_wrap /usr/local/bin/libervia_cont_launch && \
26 RUN python -c 'import urllib2,tarfile,cStringIO;tar=tarfile.open(fileobj=cStringIO.StringIO(urllib2.urlopen("https://ftp.goffi.org/pyjamas/pyjamas.tar.bz2").read()));tar.extractall()'
27
28 WORKDIR pyjamas
29
30 RUN python bootstrap.py
31
32 RUN ln -s /usr/share/pyjamas/bin/pyjsbuild /usr/local/bin/pyjsbuild
33
34 ############
35 # LIBERVIA #
36 ############
37
38 WORKDIR /tmp
39
40 RUN apt-get install -y --no-install-recommends python-jinja2
41
42 RUN hg clone https://repos.goffi.org/libervia
43
44 WORKDIR libervia
45
46 RUN python setup.py install
47
48 WORKDIR /tmp
49
50 RUN rm -rf libervia
51 27
52 ################# 28 #################
53 # CONFIGURATION # 29 # CONFIGURATION #
54 ################# 30 #################
55 31
56 # we want to use certificates in /usr/share/sat/certificates 32 # we want to use certificates in /usr/share/sat/certificates
57 RUN echo "\n[libervia]\n\ 33 echo "\n[libervia]\n\
58 tls_private_key = /usr/share/sat/certificates/libervia.key\n\ 34 tls_private_key = /usr/share/sat/certificates/libervia.key\n\
59 tls_certificate = /usr/share/sat/certificates/libervia.crt\n\ 35 tls_certificate = /usr/share/sat/certificates/libervia.crt\n\
60 connection_type = both\n\ 36 connection_type = both\n\
61 redirect_to_https = 0" >> /etc/sat.conf 37 redirect_to_https = 0" >> /etc/sat.conf
62 38
63 ##################### 39 ################
64 # FIRST LAUNCH TEST # 40 # dependencies #
65 ##################### 41 ################
66 42
67 # this script check if libervia and admin accounts exist, and create them if necessary 43 RUN pip install txJSON-RPC && \
68 # then it launch libervia
69 RUN echo '#!/usr/bin/env python2\n\
70 import os, sys, subprocess, string, random\n\
71 from sat.plugins import plugin_misc_account as account\n\
72 from sat.tools import config\n\
73 from sat_frontends.bridge import DBus\n\
74 def generate_pwd():\n\
75 chars = string.letters + string.digits\n\
76 length = 12\n\
77 return "".join(random.choice(chars) for _ in range(length))\n\
78 sat=DBus.DBusBridgeFrontend()\n\
79 sat.getReady()\n\
80 admin_email = sat.getConfig(account.CONFIG_SECTION, "admin_email") or account.default_conf["admin_email"]\n\
81 for profile in ["libervia", "admin"]:\n\
82 try:\n\
83 sat.getProfileName(profile)\n\
84 except Exception as e:\n\
85 print "{} profile doesn'\''t exists, creating it".format(profile)\n\
86 print "registering {}@{}".format(profile, sat.getNewAccountDomain())\n\
87 pwd = generate_pwd()\n\
88 if profile == "libervia":\n\
89 config.fixConfigOption("libervia", "passphrase", pwd)\n\
90 elif profile == "admin":\n\
91 with open("/home/sat/ADMIN_PWD", "w") as f:\n\
92 f.write("%s\\n" % pwd)\n\
93 sat.registerSatAccount(admin_email, pwd, profile)\n\
94 os.execvp("libervia", ["libervia"] + sys.argv[1:])\n\
95 ' > /usr/bin/libervia_cont_launch && chmod 555 /usr/bin/libervia_cont_launch
96 44
97 ######### 45 apt-get install -y --no-install-recommends python-jinja2 && apt-get clean && \
98 # D-Bus #
99 #########
100 46
101 RUN cp /usr/local/bin/dbus_wrap /usr/local/bin/libervia_cont_launch && chmod 555 /usr/local/bin/libervia_cont_launch 47 ###########
48 # PYJAMAS #
49 ###########
50
51 cd /tmp && \
52
53 # as the situation with pyjamas is complicated, we get the archive from our own ftp
54 python -c 'import urllib2,tarfile,cStringIO;tar=tarfile.open(fileobj=cStringIO.StringIO(urllib2.urlopen("https://ftp.goffi.org/pyjamas/pyjamas.tar.bz2").read()));tar.extractall()' && \
55
56 cd pyjamas && \
57
58 python bootstrap.py && \
59
60 ln -s /tmp/pyjamas/bin/pyjsbuild /usr/local/bin/pyjsbuild && \
61
62 ############
63 # LIBERVIA #
64 ############
65
66 hg clone https://repos.goffi.org/libervia && \
67
68 cd libervia && \
69
70 python setup.py install && \
71
72 # as for SàT backend, we copy .hg/dirstate so
73 # Libervia can get repository version
74 # TODO: should be done in setup.py in the future
75 cp --parents .hg/dirstate /usr/local/lib/python2.7/dist-packages/libervia && \
76
77 # some cleaning before finishing the layer
78 cd /tmp && rm -rf libervia pyjamas /usr/local/bin/pyjsbuild
102 79
103 ######### 80 #########
104 # Ports # 81 # Ports #
105 ######### 82 #########
106 83
107 # HTTP 84 # HTTP and HTTPS
108 EXPOSE 8080 85 EXPOSE 8080 8443
109
110 # HTTPS
111 EXPOSE 8443
112 86
113 ########## 87 ##########
114 # LAUNCH # 88 # LAUNCH #
115 ########## 89 ##########
116 90