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

Environment Variables

Zerops manages environment variables at two scopes: service level and project level. These variables are handled automatically without requiring .env files.

Service Variables​

Variables that are specific to individual services.

User-Defined Variables​

You can define service-level variables in two ways:

1. Build & Runtime Variables​

These variables are defined with envVariables attribute in the build or run section of your zerops.yml file and are accessible within their respective containers.

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

See how to reference variables between services and between build and runtime environments.

Note

Your application must be redeployed when updating environmental variables in zerops.yml.

2. Secret Variables​

For storing sensitive data you don't want in your source repository. They can be updated without redeployment (though services need to be restarted).

Secret variables can be managed through:

GUI Interface​

Navigate to service details and find Environment variables in the menu. You can:

  • Add individual variables using the "Add secret variable" button
  • Edit individual variables through the menu that appears on hover
  • Use the bulk editor for managing multiple variables in .env format

Runtime Secret Variables

Import Configuration​

Create secret variables for a service with envSecrets attribute. See the complete import.yml structure.

import.yml
services:
...
envSecrets:
S3_ACCESS_KEY_ID: 'your-secret-s3-key'
S3_ACCESS_SECRET: 'your-s3-access-secret'

System-Generated Variables​

Zerops automatically generates variables based on service type.

These variables cannot be deleted and are always listed at the bottom of the environment variables page. Some are read-only (like hostname), while others can be edited (like PATH).

These variables can also be referenced.

Project Variables​

Variables that apply across all services within a project. These provide a way to share common configuration across services.

They work similarly to service secret variables but at project scope - they're managed through the GUI and can be updated without redeployment (though services need to be restarted).

User-Defined Variables​

You can set project-wide variables through:

GUI Interface​

Access Project environment variables in your project detail to:

  • Add individual variables one by one
  • Edit individual variables
  • Use the bulk editor with .env format:

Import Configuration​

Create project variables with envVariables attribute. See the complete import.yml structure.

import.yml
project:
...
envVariables:
LOG_LEVEL: info
API_VERSION: v1

System-Generated Variables​

Zerops automatically generates project-level variables containing that can be referenced from services.

Variable Restrictions​

All environment variables must follow these restrictions:

Key​

  • Alphanumeric characters only (use _ to separate words)
  • Must be unique within their scope
  • Case-sensitive

Value​

  • ASCII characters only
  • No EOL characters

Variable Management​

Variable Precedence​

When the same environment variable key exists in multiple places, Zerops follows these precedence rules:

  1. Service-level variables take precedence over project variables
  2. Within service-level:
    • Build/runtime variables override secret variables
    • Build and runtime containers are separate environments

Referencing Variables​

You can reference other variables using the ${variable_name} syntax:

Within Same Service​

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

Across Services​

Prefix variables with their respective service name:

setup: dbtest
run:
envVariables:
connectionString: 127.0.0.1

setup: app
run:
envVariables:
dbConnection: ${dbtest_connectionString}

Between Build and Runtime Environments​

Build and runtime are two distinct environments in Zerops. Each environment can have its own set of variables, and you can use the same variable names in both environments since they are separate. Due to this separation, variables defined in one are not automatically accessible in the other.

To share variables between environments, you need to use specific prefixes:

  • Use RUNTIME_ prefix to access runtime variables during build
  • Use BUILD_ prefix to access build variables during runtime

Here's an example of zerops.yml file showing how to reference a runtime variable during build:

zerops.yml
build:
envVariables:
API_KEY: ${RUNTIME_API_KEY} # Using runtime variable during build
run:
envVariables:
API_KEY: "12345-abcde" # Referenced in build with RUNTIME_ prefix

Project Variables​

No prefix needed when referencing project variables:

import.yml
project:
...
envVariables:
projectName: devel
zerops.yml
envVariables:
id: 42069
hostname: app
name: ${projectName}-${hostname} # Results in: devel-app

Need help? Join our Discord community.