Skip to main content
Skip to main content
🚧 Work in Progress

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.

Tip

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.

zerops.yml
build:
envVariables:
DB_NAME: db
DB_HOST: 127.0.0.1
DB_USER: db
DB_PASS: password

run:
envVariables:
DB_NAME: db
DB_HOST: 127.0.0.1
DB_USER: db
DB_PASS: password
Note

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.

Runtime Secret Variables

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.

Note

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.

envVariables:
id: 42069
hostname: app
name: ${id}-${hostname} # 42069-app

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.

setup: dbtest
run:
envVariables:
connectionString: 127.0.0.1

setup: dbprod
run:
envVariables:
connectionString: 10.0.0.1

setup: app
run:
envVariables:
connectionString: ${dbtest_connectionString}
# Or if you want to use dbprod
connectionString: ${dbprod_connectionString}

Referencing a variable from runtime to build service​

build:
envVariables:
variable: RUNTIME_someVariable
run:
envVariables:
someVariable: hello world

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.

🙌Quick Links to Runtime-Specific Guides

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.