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
- 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
backend: $( [ ${DEVSPACE_NAMESPACE} == "test" ] && cat deployment.yaml || echo "" )
# Multi-Line If-Else
frontend: |-
$(
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" )
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:
backend:
helm:
chart: ...
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.
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.