Config Variables
DevSpace allows you to make your configuration dynamic by using variables.
While there is no need to explicitly define a config variable, it allows you to customize the behavior of DevSpace when working with the variable. If you do not explicitly define a variable, DevSpace will try to load it from the user's local environment variables.
Built-In Variables
DevSpace provides a set of built-in variables:
${DEVSPACE_CONTEXT}
contains the name of the current kube-context (e.g.minikube
)${DEVSPACE_EXECUTABLE}
contains the path to the devspace binary used${DEVSPACE_GIT_BRANCH}
contains the name of the local git branch that the user is currently on${DEVSPACE_GIT_COMMIT}
contains the hash of the latest git commit in the current repository${DEVSPACE_KUBECTL_EXECUTABLE}
contains the path to the kubectl binary${DEVSPACE_NAME}
contains the value of thename
field of the currentdevspace.yaml
file${DEVSPACE_NAMESPACE}
contains the current namespace${DEVSPACE_PROFILE}
contains the profile that is currently active in DevSpace (e.g. the string provided via-p / --profile
in a command such asdevspace dev -p my-profile
)${DEVSPACE_RANDOM}
contains a random 6 character long string${DEVSPACE_TIMESTAMP}
contains the current UNIX timestamp${DEVSPACE_TMPDIR}
contains a path to a temporary folder that DevSpace cleans up after thedevspace
command terminates${DEVSPACE_USER_HOME}
contains the path to the current user's home directory${DEVSPACE_VERSION}
contains the version of DevSpace that is currently running
Custom Variables
DevSpace lets you define custom varables inside devspace.yaml
within the vars
section.
You can define several types of variables in the same config file, e.g. one devspace.yaml
can contain static variables, env variables and more.
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}
.
With Static Value
To add variables with static value, just provide the value for the respective variable:
vars:
MY_VAR: "some value"
ANOTHER_VAR: "some value"
If you want to overwrite a static variable, you can use the --var MY_VAR=new-value
flag, e.g. devspace dev --var MY_VAR=value
.
From Env Vars
To load variables from the user's environment variables, you can just use them in the config as ${VAR_NAME}
without the need to explicitly define them.
In order to specify a default value for an environment variable that is not defined, you can use:
vars:
MY_ENV_VAR:
source: env
default: my-default
From Command
You can load the values from commands from custom commands via config expressions or using the long form by specifying the command
field:
vars:
VAR_FROM_COMMAND: $(git rev-parse HEAD)
ANOTHER_VAR_FROMCOMMAND:
command: git
args: ["rev-parse", "HEAD"]
From User Input (Question)
DevSpace can also ask the user to provide a value for a variable and you can provide a custom question and configure other input attributes for the question:
- Question
- Options/Picker
- Password
- No Cache
images:
database:
image: "mysql:${MYSQL_VERSION}"
vars:
MYSQL_VERSION:
question: Which mysql version do you want to use?
default: "5.7"
images:
database:
image: "mysql:${MYSQL_VERSION}"
vars:
MYSQL_VERSION:
question: Which mysql version do you want to use?
default: "5.7"
options:
- "5.5"
- "5.6"
- "5.7"
images:
database:
image: "mysql:${MYSQL_VERSION}"
vars:
MYSQL_VERSION:
question: Which mysql version do you want to use?
password: true
images:
database:
image: "mysql:${MYSQL_VERSION}"
vars:
MYSQL_VERSION:
question: Which mysql version do you want to use?
noCache: true
$DEVSPACE_ENV_FILE
for .env
File definition
DevSpace can also read environment variables from an environment file such as .env
inside your project. Point DevSpace to your env file via the DEVSPACE_ENV_FILE
environment variable.
This can also be used inside a devspace.yaml
under the vars section:
vars:
DEVSPACE_ENV_FILE: ".env"
The syntax of the .env
file is the same as for docker-compose:
- Each line should have the format
VAR_NAME=VAR_VALUE
. - There is no special handling of quotation marks. This means that they are part of the
VAR_VALUE
. - Lines beginning with # are processed as comments and ignored.
- Environment variables defined in your terminal session (including system variables) always take precedence over the variables in your
.env
file. - Variables defined in your
.env
file take precedence over the default values defined for config variables (configured in thevars
section ofdevspace.yaml
).
$DEVSPACE_CONFIG
For Config Path
You can tell DevSpace to load a different config via the DEVSPACE_CONFIG
environment variable. You can specify this before actually executing DevSpace via:
DEVSPACE_CONFIG=my-other-devspace.yaml devspace dev
$DEVSPACE_FLAGS
For Default Flags
A common use case for the .env
file is to set default flags for the devspace
commands such as devspace dev
or devspace deploy
. You can define the following environment variables to set default flags:
DEVSPACE_FLAGS
for global flags that should be added to each commands (e.g.DEVSPACE_FLAGS=-s -p dev
)DEVSPACE_[COMMAND]_FLAGS
to add default flags for single commands (e.g.DEVSPACE_DEV_FLAGS=-s --verbose-dependencies
)
DEVSPACE_FLAGS=-s -n default-namespace
DEVSPACE_DEV_FLAGS=-s --verbose-dependencies
Specifying flags for a command will overwrite the default flags, e.g. if DEVSPACE_FLAGS=-s -p dev
is configured and you run devspace dev -p production
, the following command would be executed: devspace dev -s -p production
You can also use these default flags without a specialized .env
file in a regular devspace.yaml
:
vars:
DEVSPACE_FLAGS: '-n my-default-namespace'
Useful Commands
devspace list vars
To get a list of all variables defined in the devspace.yaml
, you can run this command:
devspace list vars
devspace reset vars
Once DevSpace asks you to provide a value for a variable, this value will be stored in the variables cache, so you will not asked about this variable again. To reset the variables cache, run:
devspace reset vars
DevSpace will fill the variables cache again, once you run the next build or deployment command.
devspace print
The following command prints the config after all variables have been replaced:
devspace print
You can optionally add the -p / --profiles
flag to this command.
export VAR_NAME=value
The value for a config variable can also be set by defining an environment variable named [VAR_NAME]
. Setting the value of a config variable with name ${IMAGE_NAME}
would be possible by setting an environment value IMAGE_NAME
.
- Windows Powershell
- Mac Terminal
- Linux Bash
$env:IMAGE_NAME = "some-value"
export IMAGE_NAME="some-value"
export IMAGE_NAME="some-value"
Config Reference
vars
required <var_name>:object
Vars are config variables that can be used inside other config sections to replace certain values dynamically
vars
required <var_name>:object <var_name>
required string
Name is the name of the variable
<var_name>
required string value
required string|integer|boolean
Value is a shortcut for using source: none and default: my-value
value
required string|integer|boolean question
required string
Question can be used to define a custom question if the variable was not yet used
question
required string default
required string|integer|boolean
Default is the default value the variable should have if not set by the user
default
required string|integer|boolean options
required string[]
Options are options that can be selected when the variable question is asked
options
required string[] password
required boolean false
Password signals that this variable should not be visible if entered
password
required boolean false validationPattern
required string
ValidationPattern can be used to verify the user input
validationPattern
required string validationMessage
required string
ValidationMessage can be used to tell the user the format of the variable value
validationMessage
required string noCache
required boolean false
NoCache can be used to prompt the user on every run for this variable
noCache
required boolean false command
required string
Command is the command how to retrieve the variable. If args is omitted, command is parsed as a shell
command.
command
required string args
required string[]
Args are optional args that will be used for the command
args
required string[] commands
required object[]
Commands are additional commands that can be used to run a different command on a different operating
system.
commands
required object[] os
required string
OperatingSystem is optional and defines the operating system this
command should be executed on
os
required string command
required string
Command is the command to use to retrieve the value for this variable. If no
args are specified the command is run within a pseudo shell.
command
required string args
required string[]
Args are optional arguments for the command
args
required string[] alwaysResolve
required boolean false
AlwaysResolve makes sure this variable will always be resolved and not only if it is used somewhere. Defaults to false.
alwaysResolve
required boolean false source
required string all all
env
input
command
none
Source defines where the variable should be taken from
source
required string all allenv
input
command
none