Using Environment Variables to Override App Property Values
The use of environment variables to assign new values to your app properties at runtime is a handy method that you can use to test your app with multiple data sets.
Step 1: Create environment variables for your app properties
export <app-property-name>="<value>"
For example, if your app property name is username, run export username="abc@xyz.com" or export USERNAME="abc@xyz.com"
- Since special characters (such as `! | < > &@ `) are shell command directives, if they appear in value, enclosing the value in double quotes tells the system to treat such characters as literal values instead of shell command directives.
- The app-property-name must match the app property exactly or it can use all uppercase letters. For example, the app property, Message, can either be entered as Message or MESSAGE, but not as message.
- If you want to use a hierarchy for your app property, be sure to use underscores (_) between each level instead of the dot notation. For example, for an app property named x.y.z, the environment variable name should be either x_y_z or X_Y_Z.
Step 2: Set FLOGO_APP_PROPS_ENV=auto environment variable
To use the environment variables during app runtime, set the FLOGO_APP_PROPS_ENV=auto environment variable.
FLOGO_APP_PROPS_ENV=auto ./<app-binary>
For example, FLOGO_APP_PROPS_ENV=auto MESSAGE="This is variable 1." LOGLEVEL=DEBUG ./Timer-darwin-amd64
Setting the FLOGO_APP_PROPS_ENV=auto directs your app to search the list of environment variables for each app property by matching the environment variable name to the app property name. When it finds a matching environment variable for a property, the app pulls the value for the property from the environment variable and runs the app with those values. Hence, it is mandatory that the app property name exactly match the environment variable name for the property.
App properties that were not set as environment variables will pick up the default values set for them in the app. You will see a warning message similar to the following in the output: <property_name> could not be resolved. Using default values.