las2peer
las2peer copied to clipboard
[ENH] Overwrite service properties using environment variables
1. Motivation
It's quite common for docker containers to support configuration by environment variables. las2peer uses service specific .properties
files for configuration, which is fine. If we want to overwrite the complete configuration, we can use custom Docker volumes and overwrite the whole configuration file.
However, it would be comfortable if we are also able to overwrite only single properties (e.g., a database URL). This could be done using special environment variables.
Example from NGINX config in docker-compose:
web:
image: nginx
ports:
- "8080:80"
environment:
- NGINX_HOST=foobar.com
- NGINX_PORT=80
5. Specification
The environment variables would be derived from the services class name and the field name in the class. Currently, the behavior is as follows:
- Assume a class
com.example.MyService
with a field namedmyProperty
. - las2peer searches for a file
com.example.MyService.properties
in certain directories https://github.com/rwth-acis/las2peer/blob/9fcd2733b0396debd7d28da06932a553f2a10ea8/core/src/main/java/i5/las2peer/api/Configurable.java#L274 - If it exists, the value of the property
myProperty
in that file is used to initialize themyProperty
field of the service object.
New behavior
First, the field value is resolved as before. Additionally, we check if there is an environment variable for the service property. If the variable exists, we overwrite the field value again.
There are different options for the naming style of the environment variables:
- Use the full service class name, e.g.,
com_example_MyService_myProprty
- Use only the simple class name, e.g,
MyService_myProperty
- Use one of the previous options, but in upper case, which is more common for environment variables, e.g.,
COM_EXAMPLE_MY_SERVICE_MY_PROPERTY
orMY_SERVICE_MY_PROPERTY
7. Finalized state
For example, in the Gamification Framework, I'd be able to overwrite the database URL, which is specified in the file i5.las2peer.services.gamificationGameService.GamificationGameService.properties
(property name jdbcUrl
). I'd just need to define an environment variable as follows (docker compose syntax):
gamificationFramework:
image: registry.tech4comp.dbis.rwth-aachen.de/rwthacis/gamification:latest
ports:
- "8080:8080"
environment:
- GAMIFICATION_GAME_SERVICE_JDBC_URL=jdbc:postgresql://localhost:5432/