Syntax
Overview / Deploy Config / Syntax
#
Injecting environment variables in config.yamlconfig.yaml supports dynamic injection of environment variables. You can take advantage of this feature when you want to control something dynamically during deployment. The basic syntax of environment variables injection is ${ENV}
. The actual values of the environment variables will be read from the current process.
Setting default values for environment variables
The syntax is ${ENV:-DEFAULT_VALUE}
. The DEFAULT_VALUE will be used if the environment variable ENV
was not found.
#
Exampleenv:
RESULT:
#
Using the include syntax in config.yaml to introduce other file's contentconfiguring with config.yaml supports the use of include syntax to achieve a high degree of encapsulation, such as "abstraction", "inheritance", "rewriting" and so on. The basic syntax of include is ${_INCLUDE_:- file/rel/path | nindent 2}
, where nindent is the overall indentation when the file is imported.
#
Example 1: Combining config.yaml with the include syntaxHere we use Deployment configuration example to demonstrate.
config.yaml:
/service/productpage.yaml:
/service/details.yaml:
The structure of the directories is:
How to verify
You can use nhctl render ./config.yaml
to verify the result, which will get the rendered result.
#
Example 2: Abstracting the configurationThe configuration of many services is likely to be similar. If you need to modify, then you must modify them altogether. For those common configurations, they can be abstracted:
config.yaml:
/service/productpage.yaml:
/service/details.yaml:
/base/dev-config.yaml:
The structure of the directories is:
Using nhctl render ./config.yaml
to get the result:
#
Example 3: "Reloading" the configurationThe configurations may not be exactly identical. For example, the development image and startup command used by each service are different. How to customize them when use abstracted configuration?
Taking Example 2
as an example, productpage uses the basic dev-config.yaml for the dev part. But at the same time, the definition of gitUrl
and image
overrides the already defined content in dev-config.yaml. In addition, resources
is also defined to expand the dev-config.yaml.
/service/productpage.yaml:
/base/dev-config.yaml:
The structure of the directories is:
Using nhctl render ./service/productpage.yaml
to get the result: