Environment variables
Environment variables are specific to each environment and can only be accessed within the environment they belong to.
You can create multiple projects in Zerops, each representing different environments (development, staging, production). Alternatively, each developer can have a project with their own environment.
You do not have to create an .env
file. Zerops handles the environment variables for you.
Types of environment variables​
Build & Runtime Variables​
These are variables defined in your zerops.yml
file and are accessible within the build or runtime containers.
Secret Variables​
Secret variables are used to store all the sensitive data you don't want to store in your source repository, they are also useful for testing, where you need to frequently change the environment values.
You don't need to redeploy your application when you update them and can only be managed via Zerops GUI.
You can reference another variable of the same service or even a variable of another service within the same project.
Setting environment variables​
To set environment variables for the build or runtime environment, add the envVariables
attribute to the build
or run
section in your zerops.yml
.
It is always necessary to redeploy your application when updating or creating environmental variables inside zerops.yml
.
Setting secret variables​
Use secret variables to store passwords, tokens and other sensitive information that shouldn't be part of your repository and listed in zerops.yml.
To configure environment variables for an existing service, go to the service detail and find Environment variables in the left menu. Click on the Add secret variable button and set values for Key
and Value
.
To edit an environment variable, click on the menu on the right side of its row.
After making changes, click the Commit x changes button to apply your updates. Zerops will automatically propagate these changes to the environment variables across all containers in your project's services.
It is necessary to restart the service whenever you commit changes in environment variables.
Restrictions​
Key​
- It should be alphanumeric characters without spaces, you can use
_
to separate words - Keys in the same service must be unique
- Keys are case-sensitive
Value​
- Must contain only ASCII characters
- Any EOL character is forbidden
These restrictions apply to all types of environment variables.
Referencing other environment variables​
You can reference variables either from the same service or from different services within the same project. Below are examples of how to do this.
Referencing a local variable in another variable​
In this example, we're referencing a variable defined in the runtime container from the build container. This can be helpful if you need to use the same environment variables across different stages.
Referencing a variable of another project service​
Let's say your project contains two PostgreSQL services dbtest
and dbprod
. Both services have a connectionString
variable.
Then you can create a dbConnectionString
env variable in your application runtime and set ${dbtest_connectionString}
as the variable value. Zerops will fill in the value of the connectionString
variable of the dbtest
service.
Referencing a variable from runtime to build service​
Generated environment variables​
Zerops automatically generates several variables when a runtime service is created, such as hostname
and PATH
. Some of these variables (like hostname
) are read-only, while others (like PATH
) can be edited. These variables cannot be deleted and are always listed at the bottom of the Environment Variables page.
Runetime specific tutorials​
Environment variables with the same key​
If you have a secret environment variable and a build or runtime variable with the same key, Zerops prioritizes your build or runtime variables.
Having the same key in both build and runtime variables has no effect because they exist in completely separate containers.