Skip to content
Coritan Docs

Set environments and variables

Give production, previews and development their own variables, share them across deployments with env groups, and import or export a .env file.

View as Markdown

A web service, a static site or a hybrid site reads its settings from variables, such as a database address or an API key. Each deployment keeps its variables per environment, so production and previews can use different values, and env groups share one set of variables across several deployments. You set them on the deployment's Variables tab. A game server or a database keeps its settings as startup variables instead (Server settings).

How a release finds its values

Section titled How a release finds its values

A deployment has four environments:

production
What production releases read.
preview
What previews read (Turn on previews). A preview variable can also name a branch, and then only that branch's previews read it.
development
What you run on your own computer. coritan env pull writes these values to .env.local (The Coritan CLI).
all
Every environment, unless it has a value of its own.

When a key has several values, a release takes the first of these that exists: the value for its branch, then the value for its environment, then the all value, then the env groups linked to the deployment, in the order they were linked, and last the bindings.

Each variable also says where it is read: by the build, by the running instances, or by both. A variable the build reads, such as a public API address that a static site bakes into its pages, needs a rebuild before it changes anything.

  1. In the dashboard, go to App Deployment, open the deployment and select the Variables tab.
  2. Select Add variable…. The Add a variable page opens with the environment of the filter you had on the list. To change a saved variable, open the menu at the end of its row and select Replace value… (or Set again… when its value cannot be read). The page is titled "Replace" followed by the variable's name.
  3. Under Name and value, type the Name and the Value. When you replace a variable, leave Value empty to keep the saved one and change only how it is used.
  4. Under Where it applies, choose the Environment, and for Preview the Branch, if it is for one branch only.
  5. Under How it is used, choose under Available at whether the build, the running instances or both read it. A new variable is secret unless you clear Secret.
  6. Select Add variable (Save variable when you replace one). The page closes and the list shows the variable. For a variable that production reads, a notice at the top of the page says what applies it: Rebuild to apply your changes when the build reads the variable, such as one that starts with NEXT_PUBLIC_, or Redeploy to apply your changes when only the running instances read it. Select the button in the notice to start the release now (The three ways to start a release).

The page keeps what you typed when we refuse a variable, and names the field or the reason above the buttons. Select Cancel, or Variables at the top, to leave without saving.

A key uses upper-case letters, digits and underscores, starts with a letter or an underscore, and has up to 128 characters. A value can be up to 32 KiB. The platform sets some keys itself, so you cannot: PORT, TZ, STARTUP, SERVER_MEMORY, SERVER_IP, SERVER_PORT, and any key that starts with CORITAN_ or P_SERVER_. Three keys that start with CORITAN_ are the exception, because the platform never sets them and your own app reads them: CORITAN_ORG_API_KEY, CORITAN_WEBHOOK_SECRET and CORITAN_MICROSOFT_ADS_FEED_URL. Choose Runtime only under Available at for each one: the build leaves out every key that starts with CORITAN_, so a build never reads them. Redeploy after you set one. Your app reads the port to listen on from PORT.

Secret values are sealed when you save them, and nobody can read one back afterwards, you included. Only the last four characters of a value of eight or more are shown, to tell values apart. To change a secret, enter a new value.

To bring many variables at once, import a .env file into one environment (and branch) from the Variables tab. The file holds KEY=value lines, and may use export before a key, # comments, single quotes and double quotes, including values over several lines. It can be up to 256 KiB with up to 200 variables. If any line is wrong, nothing is saved and the error names the line, such as Line 3: This is not KEY=value.

  1. On the Variables tab, open the More actions for variables menu and select Import a .env file…. The Import a .env file page opens.
  2. Under The file, paste the lines into Lines to import, or select Choose file… (you can also drop a file on the box). We read the file as you type: a line we cannot read is named under Review, and Import variables refuses the file until it is fixed.
  3. Under Where it goes, choose the Environment (and the Branch for a preview) and Available at. Under How it is saved, keep Secret ticked to hide every value in build logs, and tick Replace what is there to delete the variables of that environment the file does not list.
  4. Under Review, check what the import does: each name is Adds (new), Sets again (already saved, so its value is replaced) or Deletes (only with Replace what is there). The What will change card beside the page counts them and shows how many variables the environment holds afterwards, out of 200. Saved values are never shown, so a name that is already saved always counts as set again.
  5. Select Import variables. A message says how many variables were imported, and the list shows them.

Owners and admins can export the .env that a release of an environment would read, env groups included. On the same page, under Download a .env file, choose the Environment, the Branch for a preview and Values for (build, runtime or both), then select Download .env file. The Download a .env file… item in the menu opens the page at that section. Secret values are never exported: their keys are listed at the top of the file, so you can fill them in by hand.

Share variables with env groups

Section titled Share variables with env groups

An env group is a set of variables that several deployments of your account, or of one organization, read, such as the address of a shared database. Change a value in the group, and every linked deployment reads it from its next release.

  • A group has its own production, preview, development and all values, without branches.
  • A deployment can link up to 10 groups, and the group linked first wins when two hold the same key. The deployment's own variables win over every group.
  • An account, or an organization, can have up to 50 groups.
  • Deleting a group unlinks it, and its deployments lose its values with their next release.

An organization's groups can be linked only to that organization's deployments, and an account's only to its own.

To link a group, open the Variables tab and select Link group… on the Env groups card. The Link an env group page lists the groups you can link, with how many variables each holds and how many deployments read it. Choose one, or choose A new group and type its Name, then select Link group (Make and link group for a new one). A notice at the top of the page says to rebuild or redeploy.

To change a group's variables, open the menu at the end of its row on the Env groups card and select Edit variables… (View variables… if you cannot change them). The page is named after the group and lists its variables, with the deployments that read it. Under Add or replace a variable, type the Name, the Environment and the Value, and select Save to group. Saving a name the group already has for that environment replaces its value. Each save stays on the page. Use the menu on a row to delete a variable, then select Done to go back to the Variables tab.

Variables from Coritan services

Section titled Variables from Coritan services

A binding connects a deployment to another service you have with us and sets the variables that reach it, so no key or password is copied by hand:

Object Storage
A bucket, new or one you have, and an access key made for this deployment alone that reaches only that bucket, to read and write or only to read. It sets S3_ENDPOINT, S3_BUCKET, S3_ACCESS_KEY_ID, S3_SECRET_ACCESS_KEY and S3_REGION.
A database
One of your database deployments. It sets DATABASE_URL, DATABASE_HOST, DATABASE_PORT, DATABASE_USER, DATABASE_PASSWORD and DATABASE_NAME, or REDIS_URL, REDIS_HOST, REDIS_PORT and REDIS_PASSWORD for Redis. They are read from the database for each release, so a changed password reaches the next one.
SMTP Relay
A sending login made for this deployment. It sets SMTP_HOST, SMTP_PORT, SMTP_USER and SMTP_PASSWORD.
DNS
The CNAME and TXT records of each of the deployment's custom domains that is in one of your Coritan DNS zones (Add a custom domain).
DDoS Shield
The floating IPs of a game server or a database, put under one of your Shield profiles.

To add one in the dashboard, open the Variables tab (a game server or a database has it on the Settings tab) and select Add a binding… on the Bindings card. The Add a binding page lists the kinds this deployment can take, and says why a kind is unavailable. Choose the Kind and fill in what the kind needs: the bucket and whether the key may read and write or only read, the database, the sending domain, the domains to publish records for, or the Shield profile. For the kinds that set variables, Variable prefix puts a name and an underscore before each variable it sets, and Builds read them too makes the build read them as well. Select Add binding. You can also make one with the API (With the API). Their variables reach the next release, and any variable you set yourself wins over them. Removing a binding deletes the key, the login or the records it made, while a bucket and its files stay. A deployment can have up to 20 bindings, with one for DNS and one for Shield at most.

The next release reads the new values. The live release keeps the values it started with until a new release replaces it.

The app still reads the old value
Variables apply with the next release. Select Redeploy… for a variable the running instances read, and Rebuild… for one the build reads: a redeploy runs the old build again (The three ways to start a release).
PORT is set by the platform and cannot be changed
The platform sets that key. Read it in your app instead of setting it, or rename your variable. Every key that starts with CORITAN_ or P_SERVER_ gets this answer too, except CORITAN_ORG_API_KEY, CORITAN_WEBHOOK_SECRET and CORITAN_MICROSOFT_ADS_FEED_URL.
API_TOKEN needs a value
A new variable needs a value. An existing one keeps its saved value when you leave the value out.
Only a preview variable can be limited to one branch
Only the preview environment has values for one branch. Choose preview, or leave the branch out.
The production environment can have at most 200 variables
One environment (and branch) holds up to 200 variables and 256 KiB. Move shared values to an env group, or remove ones you no longer use. A deployment holds up to 1,000 values across all its environments and branches.
A deployment can link at most 10 env groups
Unlink a group, or merge two groups into one.

The routes are under /api/v1/client/deployments/{uuid} for your own deployment and /api/v1/orgs/{org_slug}/deployments/{uuid} for an organization's. Any member of an organization reads them; owners and admins change them. No answer carries a value once it is saved: value is always null, and hint holds the last four characters.

PUT /variables sets several variables of one environment and branch. A variable listed without value keeps its saved one, and "replace": true deletes the ones you did not list:

Shell
curl -X PUT https://api.coritan.com/api/v1/client/deployments/$DEPLOYMENT/variables \
  -H "Authorization: Bearer $CORITAN_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"environment": "production", "vars": [{"key": "DATABASE_URL", "value": "postgres://shop@db.example.com/shop", "secret": true, "target": "runtime"}]}'

The answer lists what was created, updated and deleted, and redeploy_required. GET /variables lists every variable by environment and branch, PUT /variables/{key}?environment=preview&branch=feature-login sets one, and DELETE /variables/{key}?environment=production deletes one.

POST /variables/import takes the file's text in content, with environment, branch, secret, target and replace. GET /variables/export?environment=development answers the file in content and the secret keys it left out in withheld. GET /variables/resolved?environment=production names where each key a release would read comes from, without values.

Env groups are under /api/v1/client/env-groups for your account and /api/v1/orgs/{org_slug}/env-groups for an organization. POST / with {"name": "Shared database"} creates one, and PUT /{group}/variables sets its variables as on a deployment. POST /env-groups on a deployment, with {"group": "<uuid>"}, links a group, and DELETE /env-groups/{group} unlinks it.

GET /bindings/options on a deployment says which kinds of binding it can take and lists the resources you could name. POST /bindings makes one, with kind (object_storage, database, smtp, dns or shield) and, where the kind needs it, ref: a bucket, the database deployment's UUID, a sending domain or a Shield profile. env_prefix puts a prefix and _ before each key it sets, so two buckets can be bound side by side:

Shell
curl -X POST https://api.coritan.com/api/v1/client/deployments/$DEPLOYMENT/bindings \
  -H "Authorization: Bearer $CORITAN_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"kind": "object_storage", "ref": "new", "env_prefix": "UPLOADS"}'

service_id picks the Object Storage or SMTP Relay service when you have several, "mode": "read" gives a bucket's key read access only, and "target": "both" lets builds read the variables too. GET /bindings lists the bindings with the keys each sets, never the values, and DELETE /bindings/{id} removes one. Two bindings that would set the same key answer 409 with variable_conflict.

API operations on this page

MethodPathWhat it does
GET/api/v1/client/deployments/{deployment_uuid}/variablesList variables
PUT/api/v1/client/deployments/{deployment_uuid}/variablesSet or replace variables
GET/api/v1/client/deployments/{deployment_uuid}/variables/exportExport variables
POST/api/v1/client/deployments/{deployment_uuid}/variables/importImport a .env file into one environment (and branch)
GET/api/v1/client/deployments/{deployment_uuid}/variables/resolvedResolved variables
PUT/api/v1/client/deployments/{deployment_uuid}/variables/{key}Set a variable
DELETE/api/v1/client/deployments/{deployment_uuid}/variables/{key}Delete one variable of one environment
GET/api/v1/client/deployments/{deployment_uuid}/env-groupsList linked environment groups
POST/api/v1/client/deployments/{deployment_uuid}/env-groupsLink an environment group
DELETE/api/v1/client/deployments/{deployment_uuid}/env-groups/{group_uuid}Unlink an environment group
GET/api/v1/client/deployments/{deployment_uuid}/bindingsList bindings
POST/api/v1/client/deployments/{deployment_uuid}/bindingsBind a resource
GET/api/v1/client/deployments/{deployment_uuid}/bindings/optionsBinding options
DELETE/api/v1/client/deployments/{deployment_uuid}/bindings/{binding_id}Remove binding
GET/api/v1/client/env-groupsList groups
POST/api/v1/client/env-groupsCreate an env group
GET/api/v1/client/env-groups/{group_uuid}One env group, its variables without values, and the deployments it is linked to
PATCH/api/v1/client/env-groups/{group_uuid}Rename an env group
DELETE/api/v1/client/env-groups/{group_uuid}Delete an env group and its variables
PUT/api/v1/client/env-groups/{group_uuid}/variablesSet or replace a group's variables
PUT/api/v1/client/env-groups/{group_uuid}/variables/{key}Set a group variable
DELETE/api/v1/client/env-groups/{group_uuid}/variables/{key}Delete one variable of one environment of a group; 404 when it has none
GET/api/v1/orgs/{org_slug}/deployments/{deployment_uuid}/variablesList variables
PUT/api/v1/orgs/{org_slug}/deployments/{deployment_uuid}/variablesSet or replace variables
GET/api/v1/orgs/{org_slug}/deployments/{deployment_uuid}/variables/exportExport variables
POST/api/v1/orgs/{org_slug}/deployments/{deployment_uuid}/variables/importImport a .env file into one environment (and branch)
GET/api/v1/orgs/{org_slug}/deployments/{deployment_uuid}/variables/resolvedResolved variables
PUT/api/v1/orgs/{org_slug}/deployments/{deployment_uuid}/variables/{key}Set a variable
DELETE/api/v1/orgs/{org_slug}/deployments/{deployment_uuid}/variables/{key}Delete one variable of one environment
GET/api/v1/orgs/{org_slug}/deployments/{deployment_uuid}/env-groupsList linked environment groups
POST/api/v1/orgs/{org_slug}/deployments/{deployment_uuid}/env-groupsLink an environment group
DELETE/api/v1/orgs/{org_slug}/deployments/{deployment_uuid}/env-groups/{group_uuid}Unlink an environment group
GET/api/v1/orgs/{org_slug}/env-groupsList groups
POST/api/v1/orgs/{org_slug}/env-groupsCreate an env group
GET/api/v1/orgs/{org_slug}/env-groups/{group_uuid}One env group, its variables without values, and the deployments it is linked to
PATCH/api/v1/orgs/{org_slug}/env-groups/{group_uuid}Rename an env group
DELETE/api/v1/orgs/{org_slug}/env-groups/{group_uuid}Delete an env group and its variables
PUT/api/v1/orgs/{org_slug}/env-groups/{group_uuid}/variablesSet or replace a group's variables
PUT/api/v1/orgs/{org_slug}/env-groups/{group_uuid}/variables/{key}Set a group variable
DELETE/api/v1/orgs/{org_slug}/env-groups/{group_uuid}/variables/{key}Delete one variable of one environment of a group; 404 when it has none
GET/api/v1/orgs/{org_slug}/deployments/{deployment_uuid}/bindingsList bindings
POST/api/v1/orgs/{org_slug}/deployments/{deployment_uuid}/bindingsBind a resource
GET/api/v1/orgs/{org_slug}/deployments/{deployment_uuid}/bindings/optionsBinding options
DELETE/api/v1/orgs/{org_slug}/deployments/{deployment_uuid}/bindings/{binding_id}Remove binding