Substitution (dynamic templates)
Substitution provides a powerful mechanism to dynamically transform application configuration that is tailored for each device.
Substitution
Synpse provides the ability to expand, or substitute, application and device metadata to facilitate dynamic application configurations.
Available Environment Variables
Device environment variables (defined by user)
Synpse environment variables (automatically set, reference here)
Dynamic Application Spec
Most of the values in the application spec can be changed, for example:
Container name
Image name (you can adapt image name based on architecture)
Environment variables
Secrets
Volumes
Application name, scheduling configuration or the yaml structure itself cannot be changed as it will prevent yaml from being correctly marshalled.
Example Image Based On CPU Arch
If you have an application that is deployed on multiple devices of various CPU architectures (amd64, arm, arm64), you can specify image substitution (see available environment variables):
On a regular amd64 (x86) machine it will be:
While on a 32-bit arm machine the spec will become:
Example Device Env Substitution
Let's say you have set an environment variable on the device called:
Now, you can use that environment variable to create something else, for example a URL on which the device will be accessible by users (assuming you have configured domain, etc.):
And your application will then see an environment variable which equals
String Operations
Synpse provides partial emulation for bash string operations. This can be used to manipulate string values prior to substitution.
Example variable substitution with substring:
Synpse emulates the below string operations:
Synpse makes a best-effort to emulate these operations however we do not promise perfect emulation.
Escaping
If you do not want the system to evaluate an expression it must be escaped:
Caveats
If your environment variable contains *
, it will be automatically quoted to avoid parsing issues. For example:
Where MY_DOMAIN=*.example.com
will be rendered as:
However, the following example
Will be rendered as:
Which can lead to issues in your applications. In these scenarios, try to avoid using environment variable substitution.
Last updated