Ployter

Variables and shared variables

How to set environment variables, reference other services and databases, and reuse variable sets across services.

The service's environment variables are stored encrypted and go into the container on each deploy. You can write fixed values, reference variables from other services in the project and attach variable sets shared by the team.

Edit the service's variables

Open the service and go to the Variables tab. There are two editing modes, in the corner of the Environment variables card:

  • List: one variable per row. To add one, type the NAME and the value and click Add. To change one, use the pencil; to delete it, the trash can.
  • .env: the whole file, in NAME=value format, one per line. Lines with # are ignored. Save all replaces everything: whatever is no longer in the text is removed.
NODE_ENV=production
APP_URL=https://loja.com.br
# Reference to the project database
DATABASE_URL=${{mysql.MYSQL_URL}}

Variables tab of the api service in List mode
Variables tab of the api service in List mode

Names accept uppercase letters, numbers and _. Values show blurred: click to see them.

Note

Variable changes apply from the next deploy. To apply them without a build, use Restart in the More actions menu of the live deploy. See Restart with the current variables.

Variables the panel sets

  • PORT: with the Port set in Settings, the container gets PORT with that value, unless you set PORT in the variables.
  • The variables created along with the service (for example, MYSQL_ROOT_PASSWORD and MYSQL_URL for MySQL) show in the list and can be edited.

References between services

To use a value from another service in the project, write a reference in the value. When you type ${{ in the field, the panel suggests the services and variables.

Reference Value at deploy time
${{NAME}} Another variable of the same service.
${{mysql.MYSQL_URL}} The MYSQL_URL variable of the mysql service.
${{redis.INFRA_HOST}} The internal address of the redis service (its internal name).
${{redis.INFRA_PORT}} The port of the redis service.
${{pg.DATABASE_URL}} A connection variable of the project's pg managed database.

The prefix is the internal name of the service (or managed database), not its display name. It shows in Settings, under Internal address.

The value is built on the deploy of the service using it. If the MySQL password changes, the API's next deploy already gets the new connection URL. A reference can point to another one, up to 5 levels.

In the list, references show with the reference tag. If the referenced service doesn't exist in the project, service not found shows up, and the reference becomes empty text at deploy time.

Note

The internal network connects services on the same server. A reference to INFRA_HOST of a service on another server won't connect.

Connect a database in a container to another service

In the Variables tab of a database in a container (MySQL, PostgreSQL, Redis, MongoDB), the Connect another service card builds the reference for you:

  1. Under Choose the service, select who will use the database (e.g. api).
  2. Click Add MYSQL_URL to it (for PostgreSQL, DATABASE_URL; for Redis, REDIS_URL; for MongoDB, MONGO_URL).
  3. Deploy the chosen service.

Automatic variables (legacy link)

Services linked to a managed database the old way get automatic variables at deploy time, without them showing in the list. They keep working. Under Automatic variables (legacy link), the Convert to variables button creates the same variables in the list, referencing the database. A variable in the list with the same name wins over the automatic one.

Shared variables

Variables that repeat across several services (SMTP, API keys, Sentry) can live in a team set.

Create a set

  1. In the menu, open Projects → Shared variables.
  2. Click New set, give it a name (e.g. smtp) and, if you want, a description.
  3. Click Create.
  4. On the set screen, write the variables in NAME=value format and click Save.

Set variables also accept references such as ${{mysql.MYSQL_URL}}. They are resolved on the deploy of each service that uses the set.

smtp set screen with its variables and the services that use it
smtp set screen with its variables and the services that use it

Use a set in a service

  1. In the service's Variables tab, scroll down to Shared variables.
  2. Choose the set in Add set... and click Add.
  3. Adjust the order with Move up and Move down, and click Save.

When the same name shows up in more than one place:

  • The lower set wins over the one above it.
  • The service's own variable wins over all sets.

Under Inherited, the panel lists the names that come from the sets. A struck-through name is set on the service, and the service's value wins.

Shared variables card on the api service with two sets
Shared variables card on the api service with two sets

Change a set in use

After you save a set, the panel shows how many services use it. Click Restart all to start the live version of each one again, with no build, with the new variables.

To delete a set, first remove it from every service that uses it.

Who can view and edit

  • People with the View variable values permission see the values. Without it, the panel shows only the names.
  • People with Edit variables create, change and remove variables and sets.

See Teams, members and roles.

From the CLI

The CLI reads and writes the variables of the service linked to the folder:

ployter env                    # list
ployter env pull .env          # download to a file
ployter env set APP_DEBUG=false LOG_LEVEL=info
ployter env unset APP_DEBUG

See CLI.