Fork me on GitHub

Introducing diecutter


Some days ago we started a proof of concept about a template generation service called diecutter.

Benoit wrote a blog post about it.

Diecutter is an API service that will give you back a configuration file from a template and variables.

Today we are proud to present your the first release.

A lot of people didn't understand why we were so exited about this project.

Let me explain what is my feeling about it.

When you want to deploy a system or a project, you need to configure it for your environment it can be quite simple, i.e configure the of your django project for instance.

But if you want to keep it configured in you dev environment where you might be using sqlite3 as well as in production where you might want to use postgres then you will like diecutter.

Simple example of how we handle this

We create a config.ini file that will keep all our variables:

name = Webmaster
email = webmaster@localhost

type = sqlite3
name = db.sqlite3

When you POST this config.ini file diecutter convert it to a context for your template:

{{ }}
{{ }}
{{ database.type }}
{{ }}

Diecutter also add some information:

{{ diecutter.api_url }}
{{ diecutter.version }}
{{ }}

We create our template

# Generated with diecutter-{{ diecutter.version }} at {{ }}
    {% if admin %}('{{ }}', '{{ }}'),{% endif %}

    'default': {
        'ENGINE': 'django.db.backends.{% if database and database.type %}{{ database.type }}{% else %}sqlite3{% endif %}',
        'NAME': '{% if database and database.type %}{{ }}{% else %}db.sqlite{% endif %}',
        'USER': '{% if database and database.user %}{{ database.user }}{% endif %}',
        'PASSWORD': '{% if database and database.passwd %}{{ database.passwd }}{% endif %}',
        'HOST': '{% if database and %}{{ }}{% endif %}',
        'PORT': '{% if database and database.port %}{{ database.port }}{% endif %}',

We store our new template in diecutter:

$ curl -XPUT http://localhost:8106/ -F ""

And we can query our template:

$ curl -X POST --data-binary '@config.ini' -H "Content-Type: text/plain" http://localhost:8106/
# Generated with diecutter-0.1 at 2013-01-29 18:49:42.543776
    ('Webmaster', 'webmaster@localhost'),

    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': 'db.sqlite3',
        'USER': '',
        'PASSWORD': '',
        'HOST': '',
        'PORT': '',

Going futher

The magic comes with the directory feature since you can configure all your app in one request with one config.ini file. All you components are then linked together with one file that is related to your environment.

More over you don't need to install anything in your host to configure it. So you can even configure the provisionning using diecutter.

Comments !