nginx-proxy / docker-gen

Generate files from docker container meta-data
MIT License
4.45k stars 604 forks source link

Using json like type variables to feed templates #138

Open davidcassany opened 8 years ago

davidcassany commented 8 years ago

Hi all,

I am wondering how it can be done to use JSON like variables to feed a template. Basically what I am doing now is to pass a JSON as environment variable to container and then use it for templating config files (currently using python and jinja2 for templating). I'd like to use docker-gen utils for notifying and re-templating on the fly an nginx load balancer, then just to keep using the same templating engine everywhere I'd like to know how I could use docker-gen or dockerize to template nested data structures like:

{generic_var1: value1, generic_var2: value2, structured_vars: [{nested1: value3, nested2: value4}, {nested1: value5, nested2: value6}]}

Basically I am using it to define several location blocks in an nginx conf file. I don't see how to do it with not structured environment variables.

md5 commented 8 years ago

I don't think that you can currently do this with docker-gen.

I could imagine having a function like unmarshalJsonObject or some such that used Go's json.Unmarshal function to unmarshal to a generic structure like map[string]interface{}, but it isn't currently implemented.

davidcassany commented 8 years ago

Thanks for your comment, however, meanwhile I have been digging further in the code (my first contact with go language, so I suffering a little here :^P ) and I noticed there is actually this method mapped to the templates (in template.go file):

"parseJson": unmarshalJson

I guess this is what I am looking for. This method is not listed in the readme, so I guess the readme is slightly outdated.

md5 commented 8 years ago

I thought that sounded familiar... Looks like I added it back in February 2015 in https://github.com/jwilder/docker-gen/pull/64, but I missed updating the README :grimacing:

Would you mind submitting a PR to update the README?