Variable types
You can set variables at different levels. All variables can be strings or base64-encoded JSON-serialized values. The following table defines what types of variables are available to you:| Type | Definer | Scope | Precedence | Build | Runtime | Uses |
|---|---|---|---|---|---|---|
| Application | Application | Application | 4 | Yes | Yes | Non-secret values that are the same across all environments |
| Project | User | Project | 3 | Yes | Yes | Secret values that are the same across all environments, such as database credentials |
| Environment | User | Environment | 2 | Some | Yes | Values that vary by environment, such as which database to connect to or which payment API keys to use |
| Upsun | Pre-defined | Environment | 1 | Some | Yes | For information about your Upsun project |
Choosing a variable type
Choose how to set the variable based on what you are trying to do. Some environment variables should be the same for all environments. For example:- Build tool versions. If you have scripts that use specific versions of build tools (such as a specific Node.js version), You want the tools to be versioned along with your code so you can track the impact of changes. Set those variables in the application.
- Credentials for common services. If you have credentials for services shared across your environments, you don’t want to commit these secrets to code. Set them as sensitive project variables.
- Service configuration for databases and such.
This information be read from the service environment variables,
or the Upsun-provided
PLATFORM_RELATIONSHIPSvariable. It varies by environment automatically. - Mode toggles such as enabling
debugmode, disabling certain caches, and displaying more verbose errors. This information might vary by environment type and should be set on the environment level. - API keys for remote services, especially payment gateways. If you have a different payment gateway for production and for testing, set its keys on the environment level.
Overrides
If the names of variables at different levels match, an environment variable overrides a variable with the same name in a parent environment and both override a project variable. All variables can also be overridden via script. For an example of how the different levels work, suppose you have the following inheritable variables defined for themain environment:
feature-x environment, a child environment of main:
main environment, you can access $PLATFORM_VARIABLES:
feature-x environment, it looks like this:
feature-x environment: