Tiller 0.1.4 has just been released, and brings a few new improvements. Firstly, you can now use
-e command-line flags to set the
enviroment values respectively. This makes things a little neater when debugging or testing new configurations on the command line.
I also added a environment_json data source, based on idea by Florent Valdelievre (thanks for the feedback, Florent!)
This means you can now pass in arbitrary JSON data through the
tiller_json environment variable, and use the resulting structure in your templates. As it merges values with the rest of the global values from other data sources, you can also use it to over-ride a default setting in your environment files; this may be particularly useful if you build Docker containers that are provided to end-users who wish to customise their settings.
To illustrate this, here are a few quick examples, also showing the new command-line flags when developing your templates.
Note: Please note that although this feature was added in Tiller 0.1.4, I’m using 0.6.5 in these examples as it includes the defaults module, newline suppression for ERb templates (the
-%> syntax you’ll see below) which makes templates with loop constructs much neater, and lots of other assorted bug fixes.
Note 2: Tiller v0.7.0 and later support a new configuration system, where you can place most configuration blocks in one file, instead of splitting it out over different environment files. However, this article still refers to the old “one file per environment” approach as it’s still supported and won’t be removed. Check out this blog post to see an updated example in the new format, using this post as a reference.
Note 3: Tiller v0.7.6 and later allow a slightly modified form of the JSON structure, which lets you specify global AND local values, which may be useful when over-riding template defaults. See http://www.markround.com/blog/2016/04/25/tiller-0-dot-7-6-and-environment-json-v2/
Firstly, install the Tiller gem, create a work directory with the usual Tiller structure and change into it :
1 2 3 4
Then, create your common.yaml which enables the relevant data & template sources :
1 2 3 4 5 6
Create your environment file (environments/development.yaml) :
And a defaults file containing a global value (defaults.yaml) :
And your template (templates/json_template.erb) :
1 2 3 4 5
Now, run Tiller and pass in your JSON as an environment variable (you can add the
-v flag to tiller to make the output more verbose) :
1 2 3 4 5 6 7 8 9 10 11
As mentioned above, you can also use this to over-ride a default. Notice that Tiller will warn you of this :
1 2 3 4 5 6 7 8 9 10 11 12
More complicated structures can easily be built up. However, these can be quite error prone to pass “on the fly”, so instead create a file called config.json with the following contents :
1 2 3 4 5 6 7 8 9 10 11 12 13 14
This is much easier to read and check for syntax errors! This example contains a list of server configuration hashes, and a couple of simple key:value pairs.
Edit your template as follows :
1 2 3 4 5 6
Now you get the following produced :
1 2 3 4 5 6 7 8 9
Assuming you use Tiller as your Docker
ENTRYPOINT command and set up a suitable
exec in your
common.yaml, you can now include complex configuration in your Docker containers at runtime simply by doing something like :
Hope that’s of some help! If you have any feedback, just use the comments feature on this blog and I’ll reply ASAP. You may also want to check out some of my other articles on Tiller, particularly the walkthrough with a sample Dockerfile, and how to use the API to query a running Docker container.