Config Expressions
Config expressions are a powerful feature to load the devspace.yaml
in a more dynamic way. A config expression works by specifying $( my bash expression )
instead of a field and the stdout of the bash expression is taken as value for the option or complete section. Config expressions are evaluated after variables and profiles are applied to the config and can change parts of the config.
- Load From File
- If Else
- Only in dev
- If Variable
- Generate Section
- Return JSON
- Force String
Load a deployment specification from file:
deployments:
- $(cat deployment.yaml)
You can use either inline or multi-line if else:
deployments:
# Inline If-Else
- $( [ ${devspace.namespace} == "test" ] && cat deployment.yaml || echo "" )
# Multi-Line If-Else
- |-
$(
if [ ${devspace.context} == "minikube" ]; then
cat minikube.yaml
else
echo ""
fi
)
Disable image building during devspace dev
:
images:
deploy:
build:
disabled: $( [ $1 == "dev" ] && echo "true" || echo "false" )
Add sync path if profile is "debug"
dev:
sync:
- |-
$(
if [ "${DEVSPACE_PROFILE}" == "debug" ]; then
syncConfig="
imageSelector: test
excludePaths:
- test
- test2
"
echo "$syncConfig"
else
echo ""
fi
)
Generate a whole section through a script:
dev: $(./my-script.sh ${devspace.namespace} ${devspace.context} ${DEVSPACE_PROFILE})
Since json is a subset of yaml, you can also return regular json in a expression:
images:
test:
image: my-image/image
build: '$( echo {"disabled": true} )'
By default, DevSpace will try to convert the stdout to a number, bool or yaml value, however you can also force the return value to be a string by using $!()
:
deployments:
- name: quickstart
helm:
componentChart: true
values:
labels:
test: '$!(echo true)'
Expressions are run in a golang shell that is syntax compatible to a regular POSIX shell and works on all operating systems. Check the github repository for a complete list of available commands
Variables are resolved before and after applying expressions, which means that you can load a section from file within an expression that contains a variable which will still be resolved afterwards.
Expressions are not supported in these configuration properties:
vars
profiles[*].name
profiles[*].parent
profiles[*].parents
profiles[*].activations
profiles[*].patches[*].op
profiles[*].patches[*].path
Testing Config Expressions
The command devspace print
can be used to test your config expressions and shows the config after all profiles, variables and expressions were applied.