We’ve currently got a growing list of ENV vars that we’re adding to Circle and our config each time we run into a new one.
Is there anything we can do to automatically pass all Circle ENV vars along to the containers instead of having a huge list of explicitly declared variables in each call to docker-compose?
Right now we’ve got steps with several of these lines, and we’ll likely be adding more as development proceeds:
-e "SOME_CIRCLE_VAR=$SOME_CIRCLE_VAR" \
EDIT: Variables can also be passed with a shorthand of -e SOME_CIRCLE_VAR
Yep. Write a script that lists your env vars available at shell level, and generates a docker-compose shell script as output.
Alternatively, and this might be a bit neater, you could get it to write a YAML file that you provide to your docker-compose up command. It’s not well known that if you provide multiple -f configuration files, they will be read in order and merged, with later ones overriding earlier ones. You can use a (generated) secondary file to inject the variables.
We don’t check-in our .env because it contains sensitive data, so this option doesn’t work for us.
The easiest way seems to be manually adding any necessary env vars to compose commands with the -e SOME_CIRCLE_VAR syntax, but if the list will ever get annoyingly long it’s best to write a script to generate the docker-compose commands.
I don’t think that’s what @rohara meant. The command env produces a source file from the environment vars set up from the UI. Using this file, you can use it as a .env directly in DC, or source it as Ryan suggests, inside your container.