How to pass Consul Config JSON as Base64

I was watching this recent video from Consul with Comcast where the engineer converts the configuration in base64 format and supplies it as an Environment Variable.

How did he achieve that feet ? I’m sure he must have modified his docker image, but what kind of tools will help convert the b64 to json back inside the container and supplied back to the consul agent command.

Any leads ?

Hey @iamajaz,

There is a common command line tool on most Unix systems that can handle base64 encoding and decoding very simply and it would be pretty straightforward to use it in the startup script in the docker image to do what you like. The command is unsurprisingly base64. A very simple example would be something like…

$ echo "hi" | base64 | base64 -d

You pipe “hi” to the base64 command which encodes it and then pipes the encoded text to base64 -d which decodes it so you end up with “hi” again.

Using an environment variable in that and saving the decoded text in a config file you could use could look like…

How you’d populate the config environment variable on the deployment side…

CONFIG=$(echo "my config here" | base64)

Then in the Docker startup script, you’d do something like…

echo $CONFIG | base64 -d > /path/to/config.hcl
consul-template -config=/path/to/config.hcl

If any part isn’t clear, please feel free to ask any questions.

Hope this helps.