A super-lightweight tool for templating config files from environment variables – and nothing else.
$ envtemplate < my-template-file > my-output-file
Templating is done by the go template package, where the only configured variables are the process's environment variables.
For example, a simple template might look like:
Hello {{ .USER }}! {{ if .HOME }}Your home dir is {{ .HOME }}.{{ else }}You don't appear to have a home dir set.{{ end }}
Assuming a working go installation, just git clone
, cd
and go build
. A binary named envtemplate
should appear.
A binary is attached to each github release. If you're happy to trust that, just fetch it with curl/similar (being sure to follow redirects):
curl -L https://github.com/orls/envtemplate/releases/download/0.0.3/envtemplate > /usr/bin/envtemplate && chmod +x /usr/bin/envtemplate
This was borne out of frustration with using regular shell techniques – heredocs, sed
, and similar – in various docker image-building and container-runtime configuration arrangements; for many config file formats (hi, nginx!) it starts to become unwieldy to manage conditional blocks, escaping, etc.
It is a kind of hybrid of gotpl and envtpl. In the target environment of docker container management, it's useful to:
- have small, easily-installable binary tools
- ...ruling out
envtpl
; the extra docker image bloat of a python+pip install is.... far from zero
- ...ruling out
- provide variables directly as env vars
- ...ruling out
gotpl
, which takes a yml file, needing extra pre-processing if env vars are your only means of configuring.
- ...ruling out
It shares some spiritual affinity to confd, in the way that a butter knife shares some spiritual affinity to a swiss-army knife.
If you want config pulled from remote datastores, or from yml files, or already have python in the relevant envs and like jinja syntax, then those projects may be better fits.