Helm Docs

Preview Variables

Your app reads its settings, such as its database address or an API key, from environment variables. This page explains the variables you add yourself, the two variables Helm sets in every preview, how they reach your services, and how to rename or turn off Helm's two variables.

What you're about to do, in plain English

An environment variable is a named value, such as DATABASE_URL, that a program reads when it starts. Frameworks such as Django, Laravel, Rails and Express read their settings this way. Each preview gets two kinds of variables:

  • Project variables, which you add in Helm. They are the same for every preview of the project.
  • Helm's two variables, PREVIEW_DOMAIN and PREVIEW_URL, which hold the preview's own address.

Helm places both kinds in every container of your Compose file; the next section explains how. Everything else your app needs, such as DEBUG, ALLOWED_HOSTS, SECRET_KEY or the database address, you set yourself, in your Compose file or as project variables. The complete example is in Write the Compose File.

Both live on the Container Environment Variables card. To open it, open your project in Helm, click Settings in the sidebar, and under Build click Preview Environments. Changing the card needs the Project Admin role or higher; other members see it read-only.

How variables reach your preview

The same explanation is in the information list at the top of the Container Environment Variables card.

  • Every variable and secret you set in the portal, plus PREVIEW_DOMAIN and PREVIEW_URL, is placed in the environment of every container of your Compose file, including third-party images such as postgres and redis. Helm does this by adding its own env file to every service, so your Compose file does not need env_file or environment entries for them.
  • A value written under environment: in your Compose file wins over a portal value. To let the portal override a default, write it as NAME: ${NAME:-default}.
  • Avoid portal variable names that third-party images read (for example POSTGRES_PASSWORD, POSTGRES_DB, REDIS_PASSWORD, PORT) unless you mean the value for those containers too.
  • The same variables are available to ${NAME} substitution in the Compose file and to the pre-deploy, start and first-deploy commands.

Helm's env file comes after any env_file: entries of your own, so a portal value also replaces the same name in your repository's own env file. If your Compose file still has the line env_file: /run/helm/preview.env from an earlier version of these pages, you can delete it; it does no harm.

Add your own variables

Add every setting your app needs that Helm does not set for you, for example the keys for services your app calls.

  1. On the Container Environment Variables card, click Edit.
  2. Click Add Variable, then type the variable's name and value.
  3. To keep the value secret, click the lock next to the value. An encrypted variable is stored encrypted in Helm, is never shown again, and is decrypted only inside the preview, where it reaches your containers like any other variable. Use it for passwords and keys, such as SECRET_KEY.

    A plain variable is stored and shown as plain text. Use it for values that are not secret.

    A value may span several lines, for example a PEM private key that starts -----BEGIN PRIVATE KEY-----. It reaches your services whole.

  4. Repeat for each variable, then click Save Changes. The card shows "Environment variables saved."

To add many variables at once, click Bulk Edit and type one NAME=value pair per line. Blank lines and lines starting with # are ignored. Encrypted values appear as ********; leave them unchanged to keep the stored value.

A new preview gets the variables saved when it is created. A rebuild of a running preview uses the variables saved at the time of the rebuild, including encrypted values you changed, added or deleted.

Name rules

  • A name starts with a letter and contains only letters, digits and _, at most 64 characters.
  • Lowercase letters are allowed. Names are case-sensitive: environment and ENVIRONMENT are two different variables.
  • Two kinds of name are reserved for Helm's own use, in capitals or lowercase: HELM_PREVIEW_ID, and any name that starts with HELM_AGENT_. Helm refuses to save them. Other names that start with HELM_, such as HELM_API_BASE_URL for the Helm SDK, are fine.

DJANGO_SETTINGS_MODULE is a normal variable

Helm does not set DJANGO_SETTINGS_MODULE. If your Django app needs it, add it as a plain project variable, for example DJANGO_SETTINGS_MODULE=myproject.settings.preview, or set it under environment: in your Compose file. The previous Django Settings Module field has been removed; projects that had filled it in already have a plain variable with that value.

The two variables Helm sets for you

Helm sets exactly these two variables in every preview, under the names in the first column unless you rename them:

VariableWhat it holdsExample
PREVIEW_DOMAINThe preview's domain, without https://.tastyspread-pr-118-x7k2q9.preview.helmcode.dev
PREVIEW_URLThe preview's address, starting with https://.https://tastyspread-pr-118-x7k2q9.preview.helmcode.dev

They reach every container and your three commands in the same way as your own variables. So your Compose file can also use them in its own values:

services:
  app:
    build: .
    environment:
      ALLOWED_HOSTS: ${PREVIEW_DOMAIN},localhost
      CSRF_TRUSTED_ORIGINS: ${PREVIEW_URL}

Helm sets nothing else. PREVIEW_HOSTNAME is now called PREVIEW_DOMAIN, and Helm no longer sets ENVIRONMENT, DEBUG, ALLOWED_HOSTS, SERVER_BASE_URL, CORS_ALLOWED_ORIGINS, CSRF_TRUSTED_ORIGINS, SECRET_KEY, DATABASE_URL, the POSTGRES_* and MYSQL_* variables, PORT or HELM_PREVIEW_ID. If your app reads any of them, set them in your Compose file or as project variables.

Rename or turn off Helm's variables

If your app reads other names, or must not receive one of the two variables, change them for your project.

  1. On the Container Environment Variables card, click Edit.
  2. Open the list labelled How variables reach your preview, and the two variables Helm sets in each preview: PREVIEW_DOMAIN and PREVIEW_URL. You can rename those two or turn them off. It shows one row per variable, with what Helm sets it to, an example, a Set checkbox and a Name box.
  3. To stop Helm setting a variable, clear its Set checkbox. You can then set a variable with that name yourself.
  4. To have Helm set a variable under another name, type the new name in its Name box, for example APP_URL for PREVIEW_URL. Leave the box empty to keep the usual name.
  5. Click Save Changes. If a choice breaks a rule below, the card says which rule and saves nothing.

The rules:

  • A new name follows the same name rules as any variable, including the reserved names.
  • The two variables cannot end up with the same name. You can swap their names, and you can give one the name of the other when the other is turned off.
  • Your Compose file must use the name in effect. After you rename PREVIEW_DOMAIN to APP_DOMAIN, write ${APP_DOMAIN} in the Compose file.

Placeholders in project variables

Each preview's address is chosen when the preview is created, so you cannot type it into a project variable. Instead, write one of these placeholders in the value of a plain project variable, and Helm replaces it with the real value in the preview:

  • ${PREVIEW_DOMAIN} — the preview's domain.
  • ${PREVIEW_URL} — the preview's address, starting with https://.

For example, OAUTH_REDIRECT_URI=${PREVIEW_URL}/auth/callback becomes https://tastyspread-pr-118-x7k2q9.preview.helmcode.dev/auth/callback. Helm replaces only this exact text. Other ${...} text, and the values of encrypted variables, are passed on unchanged.

Which value wins

  • A value written under environment: in your Compose file wins over a portal value. To let the portal override a default, write it as NAME: ${NAME:-default}.
  • A portal value wins over the same name in an env_file: of your own, because Helm adds its env file after yours.
  • To set your own value for PREVIEW_DOMAIN or PREVIEW_URL, turn Helm's variable off first.
  • A value set with ENV in your Dockerfile or in an image is used only when neither the Compose file nor an env file sets that name.

Troubleshooting

The card refuses a name

The name breaks a name rule: it starts with a digit or _, contains a character other than letters, digits and _, is longer than 64 characters, or is reserved (HELM_PREVIEW_ID or a name starting with HELM_AGENT_, in any case). Choose another name.

The card says two variables "are both named" something, or a variable "cannot be named" something

PREVIEW_DOMAIN and PREVIEW_URL would end up with the same name. Rename or turn off the other variable too, as the message says.

My service does not see my variables, or sees a different value

  • A running preview keeps the values it started with. Rebuild it after you change a variable.
  • If the service sets the same name under environment: in your Compose file, that value wins. Write it as NAME: ${NAME:-default} to let the portal value through.
  • If you renamed or turned off PREVIEW_DOMAIN or PREVIEW_URL, use the name shown on the card.

A database or cache container behaves oddly after I add a variable

Every container receives your portal variables, including third-party images such as postgres and redis. A name those images read, such as POSTGRES_PASSWORD, POSTGRES_DB, REDIS_PASSWORD or PORT, changes them too. Rename the variable, or set the image's own value under its service's environment:, which wins.

My app no longer gets DEBUG, SECRET_KEY or DATABASE_URL

Helm no longer sets them. Set DEBUG and the database address under environment: in your Compose file, and add SECRET_KEY as an encrypted project variable, as in the example in Write the Compose File.

My app rejects the preview's domain

Set ALLOWED_HOSTS: ${PREVIEW_DOMAIN} and CSRF_TRUSTED_ORIGINS: ${PREVIEW_URL} under environment: in your Compose file, and read them in your app as comma-separated lists.

A placeholder reaches my app as text

Helm replaces placeholders only in plain project variables, and only the exact text ${PREVIEW_DOMAIN} or ${PREVIEW_URL}. Check the spelling and capital letters, and make the variable plain rather than encrypted. The old placeholders ${PREVIEW_HOSTNAME}, ${PORT} and ${DATABASE_URL} are no longer replaced.