tpl: TEMPLATE | TEXT -> magic

tpl is small utility that transforms templates to text - a bare-bone confd alternative, that follows the unix philosophy of "Do One Thing and Do It Well".

In other words, it just transforms template files to text, and spits the output to stdout.

It's small, fast and is only one binary! grab it from here.

Why?

I needed a small binary that can consume dynamic data from different sources.
confd is awesome, but it does much more than just transform templates.
plus, many times specific filters are missing and I needed a way to add new filters easily

How?

The trivial, piping case would be:

# pipe your template
$ NAME=Oded
$ echo 'Hello {{ "NAME" | getenv }}.' | bin/tpl
# or get it from a file
$ bin/tpl /path/to/template/file
Hello Oded

but having a full blown templating engine at your fingertips is quite useful. what if you want to create several Dockerfile(s) for different Elasticsearch versions, and even specific plugins?

FROM elasticsearch:{{"VERSION" | getenv:"latest" }}
MAINTAINER Oded [email protected]
{% if "PLUGINS" | getenv:"" != "" %}
# install all the plugins
{% for plugin in "PLUGINS" | getenv | stringsplit:"," %}
RUN usr/share/elasticsearch/bin/plugin install {{ plugin }}
{% endfor %}
{% endif %}

now run it:

# without any arguments
$ bin/tpl /path/to/Dockerfile.tpl
FROM elasticsearch:latest
MAINTAINER Oded [email protected]

# with VERSION env variable
$ VERSION="1.7" bin/tpl /path/to/Dockerfile.tpl
FROM elasticsearch:1.7
MAINTAINER Oded [email protected]

# with the kopf and marvel plugins
$ VERSION="1.7" PLUGINS="kopf,marvel" bin/tpl /path/to/Dockerfile.tpl
FROM elasticsearch:1.7
MAINTAINER Oded [email protected]

# install all the plugins
RUN usr/share/elasticsearch/bin/plugin install kopf
RUN usr/share/elasticsearch/bin/plugin install marvel