µtemplate, a PEX tool for Docker

le jeudi 23 octobre 2014

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.

Service Conseil et accompagnement docker

Bearstech vous propose ses services Conseil et accompagnement docker

Découvrir ce service

Partager cet article

Flux RSS

flux rss

Partager cet article :

Nos expertises technologiques