Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose containerpilot template processing #272

Closed
BobDickinson opened this issue Jan 24, 2017 · 3 comments
Closed

Expose containerpilot template processing #272

BobDickinson opened this issue Jan 24, 2017 · 3 comments

Comments

@BobDickinson
Copy link

BobDickinson commented Jan 24, 2017

TL;DR

containerpilot -template /etc/containerpilot.json:/ect/containerpilot.json.out

Details:

We are in the process of modifying our AutoPilot project so that we can scale consul and redis.

On the consul side, we use the pattern here to selectively configure/enable consul agent:

https://github.com/autopilotpattern/wordpress/blob/master/etc/containerpilot.json

This uses Go template logic, which is cool. I looked and did not find any documentation for the template support, but I checked out the code to make sure I understood how it worked and what was going on. In particular, you load the runtime environment into the Go template converter such that environment vars can be accessed with dot notation (like .CONSUL). All good so far.

We then went to add Redis scaling, based largely on the example here:

https://github.com/Faithlife/redis-autopilot

To handle Redis scaling, some relatively complex script logic and consul interaction is used (to determine if a given instance should attempt to promote itself to master, among other things). That logic is here:

https://github.com/Faithlife/redis-autopilot/blob/master/bin/manage.sh

That logic uses jq (https://stedolan.github.io/jq/) in order to read and re-write it's containerpilot.json file (so that it is advertising the proper set of services, specifically master vs replica).

The problem, if it's not obvious already, is that the containerpilot.json files using the consul agent Go template logic are not valid JSON files, and thus cannot be processed with jq.

I attempted to use consul-template to pre-process the containerpilot.json file in the same way ContainerPilot does, but I could not figure out a way to load the environment such that the template would render properly. I don't particularly want to write my own Go program just to do this, and then figure out how to drag that into my container.

What would be super cool is if ContainerPilot exposed a mechanism of pre-processing the containerpilot.json file, maybe the ability to run containerpilot with a -template param (using the same format as consul-template)? That way I could have ContainerPilot pre-process the containerpilot.json file, then I could interact with it (using jq or whatever) as a JSON file. This would also encapsulate the other features that are creeping into the ContainerPilot template support (which are great, they would just be a hassle to duplicate and maintain if I had to write my own separate program to do this).

@tgross
Copy link
Contributor

tgross commented Jan 24, 2017

I believe that's the use case intended for #271. What do you think, @BobDickinson? Would something like that work for you?

@BobDickinson
Copy link
Author

I don't know how I missed that (I swear I looked before opening this issue).

Yeah, I think that would be fine.

@tgross
Copy link
Contributor

tgross commented Jan 31, 2017

@tgross tgross closed this as completed Jan 31, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants