BackgroundIf you are working in a really big project you are using Agile methodologies I am 99% sure.
You know all the "definitions" why it is good, how it speeds up the development, etc...
But there is one thing what I have faced many times. The big projects can react the customer needs in a short time frame (being agile you know), but sometimes it is not flexible enough to keep up with developer needs and infrastructure changes.
We are living in a time where we release our new features in 2 weeks or couple of hours.
But in the background, where security is in the first place, it is hard to change anything, because it requires audits, approvals and money.
All in all we are still using Docker 1.9.1 and docker-compose 1.3.3. Yeah, I know it's shitty, but this is what we have and what we have to improve.
The problemWe were building a test environment which can be started with one command and with some parameters to help everyone spin up our app in local env.
Of course we targeted to use vagrant/VirtualBox/docker.
But we would like to specify which version of the app or dependecies we want to use.
The SolutionIt's in evidence we need some variables and use it in the compose file
But there is one little thing. Docker-compose got this feature in 1.5.0+(release notes)
How can we "workaround" this?
We have infinite number of possible solution.
Just some hints:
- Use templating engines like: Jinja2, Freemarker, etc.
- Use string replace
- Or what we have choose use small script to do it
To install it:
Let's try it with a small example. We would like to start a python container for backward compatibility testing (maybe not the best example, but it's good enough)
Here is our docker-compose file:
Now run docker-compose up with 1.3.3 version
Yes, as we expected it's failed because "python_version" variable has not been resolved.
Let's try it with a newer version of compose (1.9.0)
Is it better now? Of course it is. But we cannot update the production server :/
So let's use envsubst.
The usage is really simple: pipe the input to the script and it will print to the output.
It's really simple.
After that we can use our generated docker-compose file to start up our services.
Here is an example how we use it: