Environment variables
Environment variables allows you to inject configuration into the applications running in the edge
Environment variables are a standard way to configure your applications. Typically, you can set them directly on the application:
name: example-app
scheduling:
type: AllDevices
spec:
containers:
- name: my-app
image: docker.io/my-org/my-app:latest
env:
- name: ADMIN_PASSWORD
fromSecret: credentials # Value taken from secret named 'credentials'
- name: ADMIN_USERNAME
value: administrator # Value taken directly

Inheriting From Device

Synpse provides a mechanism to inject device environment variables to your applications.
You can either manually specify custom environment variables for each device or you can also specify them on the registration token during the provisioning.

Setting environment variables on a device (web user)

To set an environment variable for a device:
  1. 1.
    Open the device details
  2. 2.
    Click on the "New env var" button
  3. 3.
    Enter environment variable name and value
Adding environment variable to the device
Now, any application that is deployed on that device, will get the environment variable:
TZ=Europe/London
You can have multiple environment variables on each device.
You can use device environment variables to specify some customer related data so your applications can display tailored information based on where they get deployed.

Synpse Provided Environment Variables

Synpse provides certain metadata for the applications as environment variables. It's up to the application to use these environment variables or ignore them.
Environment Variable
Description
Example Value
SYNPSE_DEVICE_NAME
Device name in Synpse
powerplant-42
SYNPSE_DEVICE_IP
Device IP address
192.168.1.111
SYNPSE_DEVICE_HOSTNAME
Device hostname
rasp4-node
SYNPSE_DEVICE_ARCH
CPU architecture
arm
SYNPSE_PROJECT_ID
Project ID
prj_1r1pqWAG...
SYNPSE_NAMESPACE_ID
Namespace ID
nms_1r1pqW4d...
SYNPSE_APPLICATION_ID
Application ID
app_1a812qwe...
These environment variables are always available for applications running under Synpse. No additional settings are required.

Substitution

Synpse provides the ability to expand, or substitute, application and device metadata to facilitate dynamic application configurations.

Example Device Substitution

Let's say you have set an environment variable on the device called:
REGION=sillicon-valley
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.):
name: example-app
scheduling:
type: AllDevices
spec:
containers:
- name: my-app
image: docker.io/my-org/my-app:latest
env:
- name: PUBLIC_ADDRESS
value: https://${REGION}.example.com
And your application will then see an environment variable which equals
PUBLIC_ADDRESS=https://sillicon-valley.example.com

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:
name: example-app
scheduling:
type: AllDevices
spec:
containers:
- name: my-app
image: docker.io/my-org/my-app:latest
env:
- name: CUSTOMER
value: ${CUSTOMER_ID:0:4} # Getting first 4 symbols
Synpse emulates the below string operations:
${parameter^}
${parameter^^}
${parameter,}
${parameter,,}
${parameter:position}
${parameter:position:length}
${parameter#substring}
${parameter##substring}
${parameter%substring}
${parameter%%substring}
${parameter/substring/replacement}
${parameter//substring/replacement}
${parameter/#substring/replacement}
${parameter/%substring/replacement}
${#parameter}
${parameter=default}
${parameter:=default}
${parameter:-default}
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:
name: example-app
scheduling:
type: AllDevices
spec:
containers:
- name: my-app
image: docker.io/my-org/my-app:latest
env:
- name: DEVICE_NAME
value: ${MY_DEVICE_NAME}
​