LocalMode development global environment variables

Hi,
I know that in local mode the environment variables need to be set in the docker-compose file, but I wonder if there’s a way to define environment variables that are common for all services, while services also can have their own settings?

I tried using an .env file like in the following:
version: ‘2’
env_file:
globals.env
services:
my-first-service:

but this give this error:
data should NOT have additional properties

Any idea’s?
thnx, Bart

Hey @bartjanszoon ,

Currently we don’t support the env_file attribute in docker-compose.yml. There have been internal discussions to add it, but discussions have stalled. I have added to the discussion internally, and I invite you to upvote this feature request in our roadmap so we can look at assessing its priority.

In the meantime, you can add the env vars under the environment of each service, although this is repetitive. You could automate it with a pre-balena push script which takes a global .env file and interpolates each variable at the correct location in docker-compose.yml.

Regards,
Christina

EDIT: I’ve specified that this attribute is unsupported in our docs: Specify env_file attribute as unsupported by cywang117 · Pull Request #3113 · balena-io/docs · GitHub

Hi @bartjanszoon,
we came across a similar issue. We managed to do it that way:

  1. Add your env-variables and value to a file named .env.balena-local
  2. Add the following script element to the package.json file:
    "balena-local-device": "grep -Ev '^#|^$' .env.balena-local | sed 's/^/--env /' | xargs balena push --debug $@"
  3. Run it from command line using: npm run balena-local-device <deviceUuid>

Hope that helps.

Best regards,
Fritz

Although we’re not using npm but yalm docker-compose files with multiple services, I think I get the general idea.
Thanks for your feedback,
Bart