Using environment variables in OSGI configuration files

1k Views Asked by At

We are using OSGI enRoute (https://enroute.osgi.org/), and would like to include environment variables within our configuration.json files.

The idea is to then assign values to these environment variables within Dockerfile for subsequent deployment in Kubernetes.

Example configuration.json files with environment variables are appreciated so we can see the necessary syntax.

Thanks in advance, Randy

1

There are 1 best solutions below

0
On

OSGi still allows for accessing of environment variables using the standard Java API System.getenv

However, the more modular (and OSGi-y) way would be to have a application configuration service that your application interfaces with. The application configuration service would then handle the accessing of environment variables and allow your application to be portable and readily testable outside of Docker. This service can handle type conversion for things String to Integer (all environment variables are treated like strings). This enables your Java application to not have to do type-conversion all over the place.

Note: You'll need to clarify your question regarding json configuration. Docker injects Linux process environment variables that are simple key-value. Did you perhaps mean to indicate a specific JSON configuration type used to configure the Docker container that is used by a specific Docker container toolchain?