SCOP d'ingénieurs experts du logiciel libre depuis 2004
+33 1 70 61 60 16

µtemplate, a PEX tool for Docker

I need my template tools. I’m using Docker, and I need settings for starting services, real ones, not simple command line arguments. The official way to parameter a...

Notre prochain webinar

I need my template tools.

I’m using Docker, and I need settings for starting services, real ones, not simple command line arguments.

The official way to parameter a new Docker instance is environment variables.

Some services accept key/value settings from the command line, fewer accept environment variables, but I want something more readable, more explicit, and even something dynamic, with etcd or something similar.

Consul provides such features with its consul-template .

I don’t want to learn yet another template language. Jinja2 is the de facto standard for python users, it’s boring, complete, without surprises, and used by Ansible.

So, lets hack something.

Something using a template from a path or STDIN, filling it with environment variables. Something without boring dependencies, nor NIH. I don’t trust python system packages : half are rotten. Virtualenv + Pip, just for providing a tool inside Docker? Oversized.

Lets PEX. PEX is one of the secret weapons of Twitter. PEX is for Python EXecutable. PEX is a single file, embeding dependencies and an executable module. This file is a ZIP archive. The ZIP format accepts arbitrary headers, and python can load modules in a ZIP, PEX married both.

PEX is picky, it needs real modules, with a setup.py using setuptools, for building a wheel (the new python packaging tool). You can add modules from pipy, too.

Have a look at µtemplate sources.

Lets try this new pex file:

zipinfo mtemplate.pex echo 'Hello {{ ENV.USER }}' | ./mtemplate.pex 

You can now COPY your PEX inside your docker image, with only python installed.


Mathieu Lecarme

Inscrivez-vous à notre newsletter

Mieux comprendre le monde du DevOps et de l'administration système.

Abonnez-vous à notre newsletter

Hébergement & Infogérance

  • ✓ Service Astreinte 24h/7j/365
  • ✓ Supervision, monitoring & Alertes
  • ✓ Mises à jour en continu
  • ✓ Certificat SSL letsencrypt
  • ✓ Hébergement dédié sécurisé en France
  • ✓ Backup vers datacenter distant
Découvrir notre offre

Expertise Technologique

Notre équipe possède une vaste expertise technologique.