Environment Variables
If the source
is env
, DevSpace will not ask the user a question and instead use environment variables to determine the value of the variable.
images:
database:
image: "mysql:${MYSQL_VERSION}"
vars:
- name: MYSQL_VERSION
source: env
default: "5.5"
If source
is env
and the environment variable is not defined, DevSpace will use the default
value or terminate with a fatal error, if there is no default
value configured.
By default, the type (string, int, bool) of variable will be determined by the type of its default
value (if defined) or automatically detected if no default value is defined. To explicitly use the value of a variable as a string, use $!{VAR_NAME}
instead of ${VAR_NAME}
.
Configuration
name
The name
option expects a string stating the name of the config variable that will be used to reference it within the remainder of the configuration.
The name
of a config variable must be unique and is mandatory when defining a config variable.
default
The default
option expects a string, integer or boolean defining the default value for the variable. You can also use other variables in a default value, with one of the following conditions being true:
- The used variable is defined before the variable that wants to use it
- The used variable is a predefined variable
If a default value is specified, DevSpace will assume the type of the default value as the type for the variable, i.e. when default: "123"
is defined and a value of 123
(int) is provided it would be casted to "123"
(string). To explicitly use the value of a variable as a string within devspace.yaml
, use $!{VAR_NAME}
instead of ${VAR_NAME}
.
Example:
images:
default:
image: ${IMAGE}
vars:
- name: IMAGE_REPOSITORY
default: myrepository
source: none
- name: IMAGE_NAME
default: devspace
source: none
- name: IMAGE
default: ${IMAGE_REPOSITORY}/${IMAGE_NAME}
source: none
- name: NAMESPACE
default: ${devspace.namespace}
source: none
alwaysResolve
If enabled, the variable will be loaded even though it is not used within the config. This might be useful for variables that should be resolved after a config expression is applied. E.g.:
devspace.yaml
:
vars:
- name: my-var
value: my-value
alwaysResolve: true
hooks:
- name: my-hook
command: $(cat command.txt)
events: ["after:deploy"]
command.txt
:
echo Hello ${my-var}!