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.

Follow these two steps to set up the environment variables and use them during app runtime.

Step 1: Create environment variables for your app properties

You start by creating one environment variable for each app property that you want to externalize. To do so, run:
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"

A few things to note about this command:
  • Since special characters (such as `! | &lt; &gt; &amp;@ `) 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.

To do so, run:
FLOGO_APP_PROPS_ENV=auto ./<app-binary>

For example, FLOGO_APP_PROPS_ENV=auto MESSAGE="This is variable 1." LOGLEVEL=DEBUG ./Timer-darwin-amd64

Note: When setting variables of type password be sure encrypt its value for security reasons. See Encrypting Password Values for more details.

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.