Skip to main content

Application Variables

Application variables are very powerful, they can be used both in configuration files and as environment variables.

note

This describes how to declare your own variables, for built-in variables see the reference docs

The example application below illustrates the usage of variables. You declare variables within the context of a service and use them as input to your containers in different ways. A variable has a name and a value, where the value can be explicitely set (SECRET_NUMBER) or picked up from a vault secret (DB_USERNAME, DB_PASSWORD).

The example below shows two ways of passing the variable values to the container:

  • Expanded into a config file via a volume mount.
  • Passed as environment variables.

The environment variable list in the example below also illustrates the usage of Avassa built-in variables. SITE_NAME will be assigned the name of the site in the Avassa system.

name: my-app
version: "1.0"
services:
- name: my-svc
variables:
- name: DB_USERNAME
value-from-vault-secret:
vault: my-db
secret: credentials
key: username
- name: DB_PASSWORD
value-from-vault-secret:
vault: my-db
secret: credentials
key: password
- name: SECRET_NUMBER
value: "42"
volumes:
- name: config
config-map:
- name: my-config
data: |
This is my config file
${DB_USERNAME} will be replaced at instantiation, ${DB_PASSWORD} as well.
The secret number is ${SECRET_NUMBER} at site ${SYS_SITE}.
containers:
- name: my-db
env:
USERNAME: ${DB_USERNAME}
PASSWORD: ${DB_PASSWORD}
SECRET_NUMBER: ${SECRET_NUMBER}
SITE_NAME: ${SYS_SITE}
mounts:
- name: config
files:
- name: my-config
mount-path: /etc/my-cfg

if the my-db vault secret (credentials) contains username=fredrik and password=foobar, the container will be started with environment variables:

USERNAME=fredrik
PASSWORD=foobar
SECRET_NUMBER=42
SITE_NAME=my-site-name

The config file (mounted at /etc/my-cfg) will look like this:

 This is my config file
fredrik will be replaced at instantiation, foobar as well.
The secret number is 42 at site my-site-name.