-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Closed
Labels
Description
To support https://12factor.net/ application loading their database connection strings from ENV variables, we should enhance our DataSource booter to provide variable substitution similar to what https://github.com/strongloop/loopback-boot already provides for LB3 applications.
Example LB3 config file:
// server/datasources.json
{
"db": {
"connector": "mysql",
"url": "${MYSQL_URL}",
}
}Proposed format for LB4:
// src/datasources/db.json
{
"name": "db",
"connector": "mysql",
"url": "${ENV.MYSQL_URL}",
}By using ENV. prefix, we are keeping doors open to add other variable sources in the future, e.g. APP. prefix to access application-level bindings.
To support numeric values, allow the following format (notice the + sign after the opening bracket):
{
"port": "${+ENV.PORT}",
}Acceptance criteria
- A new helper function accepting configuration object loaded from the JSON file, an object with values to use for substitutions (conceptually
{ENV: process.env}), and returning modified configuration object with substitutions resolved according to rules described above. Include comprehensive test coverage. - Substitution should be applied to values at all levels, including deeply nested properties.
- Support conversion to numeric values as described above.
-
@loopback/bootrecognizes and replaces variables in datasource configuration. Leverage the already implemented helper function. -
process.envmust not be accessed directly from individual booters. Instead, the environment object should be provided viaapp.boot()arguments. For example, we can add a new property toBootExecutionOptions. - Modify examples and CLI templates to pass
process.envvalue toapp.boot(), so that variable substitution can be performed. - Documentation
- Blog post
Out of scope
- Allow extensions to contribute custom convention for environment-specific operational configuration - see the spike [Spike] Allow extensions to contribute custom convention for environment-specific operational configuration #1464
mightytyphoon, juleskreutzer, emilianosuarez, tioteath, aeremin and 4 more