Amending Config.ini

I have a config.ini file that gets copied into the container on build. At the moment, there are only a couple of variables that are set static. COT_URL is an IP address and port. For example:

COT_URL = tcp://12.34.56.789:8087
DUMP1090_URL = tcp+beast:dump1090-fa:30005

How would I amend the config.ini file to pick up env variables set within Balena please? I have tried the following, however get the error:

ValueError: invalid literal for int() with base 10: ‘${PORT}’’

COT_URL = tcp://${SERVER}:${PORT}
DUMP1090_URL = tcp+beast:dump1090-fa:30005

Thank you for any help.

Do you really need to modify config.ini? That file is a mechanism to pass in runtime specific values to your application. However, the balena environment variables already provide the same facility, so just use them directly in your application. For example in Python, if you have a ‘PORT’ env variable you might write:

import os

print(f"My port is {os.getenv('PORT', 80)}")

If you really want to modify config.ini, you could read in the file from within your application, substitute the values from the environment variables like above, and the write the file out again.

Does this solution make sense for your app?