Setting "Service Variables" with docker-compose

Hello,

i am changing the basicstation project (lorawan / ttn gateway) from single docker to docker-compose atm and i run into the problem to set service variables for the different containers automaticly. In the original project inside the balena.yml the variables are set this way:

data:
applicationEnvironmentVariables:
- GW_GPS: false
- GW_RESET_PIN: 11
- GW_RESET_GPIO: 17
- MODEL: SX1301
- TTN_STACK_VERSION: 2
- TTN_REGION: eu
- GW_ID: 0
- GW_KEY: 0
- TC_KEY: 0

now it moved everything in a sub folder and created a docker-compose.yml and i would love to created service variables (those above for a container named “gateway”) and not environment variables like in the example above. Is there a way to achieve this? Or does the user have to create the service variables “by hand”?

thank you very much!

Cheers Caspar

Hey @Caspar!

This is a great question, but no straightforward answer as such so forgive me for the long reply! The balena.yml file applies to a single or multicontainer application as a whole and is used whenever the ‘Deploy with balena’ button is clicked to set up the environment variables automatically. At the moment, there’s no way to specify within the balena.yml file what service a variable belongs to in order to specify service variables and so they are all added at the application level. This is something we would want to enable in the future for sure, but ultimately you’re right in that today we don’t have a way to add these automatically in the same way as the application environment variables. I’ll log this internally to make sure we’re recording your need for the feature. :slight_smile:

The application level variables from the balena.yml as you have it above will still apply to the new gateway container you’ve created in the multicontainer application, but they’ll also apply to all of the other containers as well. This shouldn’t be a problem unless you need to set one of these variables to different values on a per-container basis.

There are options to create the service variables programmatically via the API and I appreciate this may not be of use in the scenario you describe, but I’m linking here for completeness anyway.

I hope this helps but if not let us know, maybe in a bit more detail and we’ll see if we can come up with any other methods to help achieve the same result.

1 Like