diff 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
line wrap: on
line diff
--- a/docker/libervia/Dockerfile	Sat Feb 27 00:45:58 2016 +0100
+++ b/docker/libervia/Dockerfile	Sun Feb 28 02:01:20 2016 +0100
@@ -10,105 +10,79 @@
 
 MAINTAINER Goffi <goffi@goffi.org>
 
-##############
-# txJSON-RPC #
-##############
-
-RUN pip install txJSON-RPC
+#####################
+# FIRST LAUNCH TEST #
+#####################
 
-###########
-# PYJAMAS #
-###########
-
-WORKDIR /usr/share
-
-# as the situation with pyjamas is complicated, we get the archive from our own ftp
-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()'
-
-WORKDIR pyjamas
-
-RUN python bootstrap.py
+COPY scripts/libervia_cont_launch /usr/bin/
 
-RUN ln -s /usr/share/pyjamas/bin/pyjsbuild /usr/local/bin/pyjsbuild
-
-############
-# LIBERVIA #
-############
-
-WORKDIR /tmp
-
-RUN apt-get install -y --no-install-recommends python-jinja2
+RUN chown root:root /usr/bin/libervia_cont_launch && \
+chmod 0555 /usr/bin/libervia_cont_launch && \
 
-RUN hg clone https://repos.goffi.org/libervia
-
-WORKDIR libervia
+#########
+# D-Bus #
+#########
 
-RUN python setup.py install
-
-WORKDIR /tmp
-
-RUN rm -rf libervia
+cp /usr/local/bin/dbus_wrap /usr/local/bin/libervia_cont_launch && \
 
 #################
 # CONFIGURATION #
 #################
 
 # we want to use certificates in /usr/share/sat/certificates
-RUN echo "\n[libervia]\n\
+echo "\n[libervia]\n\
 tls_private_key = /usr/share/sat/certificates/libervia.key\n\
 tls_certificate = /usr/share/sat/certificates/libervia.crt\n\
 connection_type = both\n\
 redirect_to_https = 0" >> /etc/sat.conf
 
-#####################
-# FIRST LAUNCH TEST #
-#####################
+################
+# dependencies #
+################
+
+RUN pip install txJSON-RPC && \
+
+apt-get install -y --no-install-recommends python-jinja2 && apt-get clean && \
+
+###########
+# PYJAMAS #
+###########
+
+cd /tmp && \
+
+# as the situation with pyjamas is complicated, we get the archive from our own ftp
+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()' && \
+
+cd pyjamas && \
 
-# this script check if libervia and admin accounts exist, and create them if necessary
-# then it launch libervia
-RUN echo '#!/usr/bin/env python2\n\
-import os, sys, subprocess, string, random\n\
-from sat.plugins import plugin_misc_account as account\n\
-from sat.tools import config\n\
-from sat_frontends.bridge import DBus\n\
-def generate_pwd():\n\
-    chars = string.letters + string.digits\n\
-    length = 12\n\
-    return "".join(random.choice(chars) for _ in range(length))\n\
-sat=DBus.DBusBridgeFrontend()\n\
-sat.getReady()\n\
-admin_email = sat.getConfig(account.CONFIG_SECTION, "admin_email") or account.default_conf["admin_email"]\n\
-for profile in ["libervia", "admin"]:\n\
-    try:\n\
-        sat.getProfileName(profile)\n\
-    except Exception as e:\n\
-        print "{} profile doesn'\''t exists, creating it".format(profile)\n\
-        print "registering {}@{}".format(profile, sat.getNewAccountDomain())\n\
-        pwd = generate_pwd()\n\
-        if profile == "libervia":\n\
-            config.fixConfigOption("libervia", "passphrase", pwd)\n\
-        elif profile == "admin":\n\
-            with open("/home/sat/ADMIN_PWD", "w") as f:\n\
-                f.write("%s\\n" % pwd)\n\
-        sat.registerSatAccount(admin_email, pwd, profile)\n\
-os.execvp("libervia", ["libervia"] + sys.argv[1:])\n\
-' > /usr/bin/libervia_cont_launch && chmod 555 /usr/bin/libervia_cont_launch
+python bootstrap.py && \
+
+ln -s /tmp/pyjamas/bin/pyjsbuild /usr/local/bin/pyjsbuild && \
+
+############
+# LIBERVIA #
+############
+
+hg clone https://repos.goffi.org/libervia && \
 
-#########
-# D-Bus #
-#########
+cd libervia && \
+
+python setup.py install && \
 
-RUN cp /usr/local/bin/dbus_wrap /usr/local/bin/libervia_cont_launch && chmod 555 /usr/local/bin/libervia_cont_launch
+# as for SàT backend, we copy .hg/dirstate so
+# Libervia can get repository version
+# TODO: should be done in setup.py in the future
+cp --parents .hg/dirstate /usr/local/lib/python2.7/dist-packages/libervia && \
+
+# some cleaning before finishing the layer
+cd /tmp && rm -rf libervia pyjamas /usr/local/bin/pyjsbuild
 
 #########
 # Ports #
 #########
 
-# HTTP
-EXPOSE 8080
-
-# HTTPS
-EXPOSE 8443
+# HTTP and HTTPS
+EXPOSE 8080 8443
 
 ##########
 # LAUNCH #