[et_pb_section fb_built=”1″ admin_label=”section” _builder_version=”3.0.47″][et_pb_row admin_label=”row” _builder_version=”3.21.1″ background_size=”initial” background_position=”top_left” background_repeat=”repeat”][et_pb_column type=”4_4″ _builder_version=”3.0.47″][et_pb_text admin_label=”Text” _builder_version=”3.21.1″ background_size=”initial” background_position=”top_left” background_repeat=”repeat”]
Today I ran into a scenario that I just threw in the towel on. I had a largish yaml file (~300 lines) that is actually a config to a container (e.g. its not Kubernetes yaml).
I need to change one line in it per environment (a hostname). And I really didn’t feel good about copying the file into multiple output directories.
After an hour, I threw in the towel. The declarative police will come and get me, but I present to you my solution. Open sourced for your pleasure.
docker pull agilicus/envsubst
away from this big pile of perfection.
It’s simple. This container takes arguments in the form input:output. input will be passed through envsubst and redirected to output, making directories as needed.
docker run --rm -it agilicus/envsubst /etc/passwd:/dev/stdout
docker run --rm -it agilicus/envsubst /config/ifile:/etc/config/dir/ofile
will take ifile, run through envsubst,
mkdir -p /etc/config/dir
, and place the output in
Now, from Kubernetes, I make an
. I mount it (read-only) in my ultimate container, and read-write in this new one (as an initContainer). I pass args as the list of files above. Presto. All environment variables are expanded. Into that big grotty yaml file that started this problem i place a
. And I’m done.
Am I proud of this? Well, I don’t have a lot of skin in the declarative vs imperative game. So. Um. I’m done with it.