progrium/registrator — pull request #76 by bheatwole (2014-12-18 22:42:43+00:00)
Title: Upload etcd keys by template.

Currently the etcd backend only creates a very specific style of key in etcd. If you need etcd to contain more information (such as tags and attributes) or for the format to be different for different types of services, you're stuck.

This pull requests adds an additional etcd backend that creates keys based on templates with access to all the information from docker. For example the template below uses the exposed port from the container as part of the key, but uses the published host IP and port in the value.
```
/services/{{.Published.ExposedPort}}/{{.Name}} {{.Published.HostIP}}:{{.Published.HostPort}}
```
Since templates allow if...else, you can write add a template that only adds a key if a specific attribute is present.
```
{{if .Attrs.proxy}}/proxies/{{.Name}} {{.Published.HostIP}}:{{.Published.HostPort}}{{end}}
```
Usage:
Start registrator with one or more ETCD_TMPL_XXXX environment variables. These variables should contain a template of the key value pair you wish published to etcd. Also be sure to use the 'etcd-tmpl' scheme.
```
docker run -d -v /var/run/docker.sock:/tmp/docker.sock \
-e ETCD_TMPL_PROXY="{{if .Attrs.proxy}}/load_balancer/{{.Published.ExposedPort}}/{{.Name}} {{.Published.HostIP}}:{{.Published.HostPort}}{{end}}" \
-e ETCD_TMPL_HTTP="{{if .Published.HostPort eq 80}}/http/{{.Name}} {{.Published.HostIP}}:{{.Published.HostPort}}{{end}}" \
-e ETCD_TMPL_ALL="/services/{{.Name}} {{.Published.HostIP}}:{{.Published.HostPort}}" \
progrium/registrator etcd-tmpl://${PRIVATE_IPV4}:4001/
```