Synpse
🤖 Devices⚡ ApplicationsTry Synpse!
  • Intro to Synpse
  • Start here
    • Quick Start (web user)
    • Quick Start (CLI)
  • Agent
    • Install
      • Raspberry Pi
      • Linux (Docker)
      • MacOS
      • NVIDIA Jetson
      • Headless (Ubuntu)
      • BeagleBoard AI
      • Bulk Provisioning
      • 🪄Beta - Universal Synpse image
      • Containerized agent
      • Configuration
    • Uninstall
  • CLI
    • Install & Usage
  • synpse core
    • Devices
      • Device Provisioning
      • HTTPS Tunnel Access
      • SSH Access
      • Device Labels
      • Environment Variables
      • Proxy Application Ports
      • OS & Architectures
      • Operations
      • Device API
    • Applications
      • Deploy
      • Secrets
      • Environment variables
      • Substitution (dynamic templates)
      • Volumes
      • Networking
      • Scheduling
      • Registry authentication
      • Using GPUs
      • Tips & Tricks
      • Logs and status
      • Application specification (API reference)
    • Account
      • Personal Access Tokens
      • Service (Robot) Accounts
      • Teams (Share Devices)
    • Monitoring (beta)
      • Device Monitoring
      • Application Monitoring
  • Manage
    • Projects
    • Namespaces
    • Quotas
  • Examples
    • 🏠Home Automation
      • Gladys Assistant
      • Home Assistant
    • 🛠️Preparing OS Images
      • Synpse CLI Builder
      • Build a custom Raspberry Pi image
      • Cloud-init (advanced)
    • 💡Dynamic Templates
    • ☁️Public Cloud IoT
      • AWS IoT Core
      • Azure IoT Hub
      • GCP IoT Core
    • 🚀Device management
      • VNC to remove devices
      • Ansible
  • On-prem Deployment
    • 🐳Docker Compose
    • 🌤️kubernetes
  • Resources
    • API Documentation
    • Deployment patterns
    • Security & Tech
Powered by GitBook
On this page
  • Substitution
  • Available Environment Variables
  • Dynamic Application Spec
  • Example Image Based On CPU Arch
  • Example Device Env Substitution
  • String Operations
  • Escaping
  • Caveats

Was this helpful?

  1. synpse core
  2. Applications

Substitution (dynamic templates)

Substitution provides a powerful mechanism to dynamically transform application configuration that is tailored for each device.

PreviousEnvironment variablesNextVolumes

Last updated 3 years ago

Was this helpful?

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,)

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

name: example-app
scheduling:
  type: AllDevices
spec:
  containers:
  - name: my-app
    image: docker.io/my-org/my-app-${SYNPSE_DEVICE_ARCH}:latest

On a regular amd64 (x86) machine it will be:

name: example-app
scheduling:
  type: AllDevices
spec:
  containers:
  - name: my-app
    image: docker.io/my-org/my-app-amd64:latest

While on a 32-bit arm machine the spec will become:

name: example-app
scheduling:
  type: AllDevices
spec:
  containers:
  - name: my-app
    image: docker.io/my-org/my-app-arm:latest 

Example Device Env 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}

Caveats

If your environment variable contains *, it will be automatically quoted to avoid parsing issues. For example:

    env:
    - name: MY_DOMAIN
      value: ${MY_DOMAIN}

Where MY_DOMAIN=*.example.com will be rendered as:

    env:
    - name: MY_DOMAIN
      value: *.example.com

However, the following example

    env:
    - name: MY_DOMAIN
      value: https://${MY_DOMAIN}

Will be rendered as:

    env:
    - name: MY_DOMAIN
      value: https://"*.example.com"

Which can lead to issues in your applications. In these scenarios, try to avoid using environment variable substitution.

If you have an application that is deployed on multiple devices of various CPU architectures (amd64, arm, arm64), you can specify image substitution ():

reference here
see available environment variables