Groundfloor Docs

Configuration and secrets

Give your Coderunner settings and secrets, set CPU, memory and scaling, and add a persistent disk.

A deployment carries three kinds of configuration: environment variables for ordinary settings, secrets, and the resources your code runs with. A Function or Service can also have a persistent disk for files it must keep.

Environment variables

Use environment variables for settings that aren't secret: URLs, feature switches, region names. Set them when you deploy:

Add them in the deploy dialog, as JSON:

{ "API_URL": "https://api.example.com", "REPORT_REGION": "eu" }
gf deploy -e API_URL=https://api.example.com -e REPORT_REGION=eu

Pass envVariable in the body of POST …/coderunners/{coderunner_id}/deploy. See the Coderunners API.

Read them the usual way for your language:

LanguageRead API_URL
Node.jsprocess.env.API_URL
Pythonos.environ.get("API_URL")
.NETEnvironment.GetEnvironmentVariable("API_URL")
Goos.Getenv("API_URL")
Ruststd::env::var("API_URL")

Deploy them every time

Groundfloor doesn't keep the values of your variables between deploys, only their names. Each deploy runs with exactly the variables you send with it:

  • With the CLI, keep them in groundfloor.json so every gf deploy sends them. gf deploy names any variable the previous deployment had that this one doesn't send, and on a terminal gf deploy -c <coderunner> asks before deploying without it. See Confirmations.
  • In the Client Portal, enter them in the deploy dialog each time.
  • Deploys started automatically — a push to a connected Git repository, or promotion to another environment — send no variables. Settings your code always needs belong in the code or the image: a config file in your ZIP, or ENV lines in a Service's Dockerfile.

Names that are never passed

To stop credentials leaking through deploy settings, Groundfloor rejects a deploy that sends variables whose names look like secrets. The API answers 422 and lists the offending names, and the gf CLI refuses before it sends anything. The variables are not silently dropped, so remove them from your deploy and the deploy goes through. These names are rejected:

  • names ending in _PASSWORD, _SECRET, _SECRET_KEY, _PRIVATE_KEY, _API_KEY or _ACCESS_KEY
  • names starting with MANAGED_DB_
  • DATABASE_URL, DATABASE_URI, DATABASE_USER, DATABASE_USERNAME, DATABASE_PASSWORD, DB_URL, DB_URI, POSTGRES_URL, POSTGRES_URI, POSTGRES_USER, POSTGRES_PASSWORD, MYSQL_URL, MYSQL_PASSWORD, MONGO_URI, MONGODB_URI, MONGODB_URL

Store those in Secrets (gf secrets set KEY -) and read them at runtime.

Secrets

Store API keys, passwords and tokens in Secrets, never in your code, your ZIP, a .env file, your logs or a response.

A deploy can't name secrets, and Groundfloor doesn't put your secrets into the container as environment variables. Instead, your code reads each secret when it runs, from the Secrets API, using the machine client attached to the Coderunner. That means:

  • Your secrets never appear in the deployment's configuration, and a changed secret reaches your code without a redeploy.
  • The only secrets Groundfloor puts in the container are the attached client's ID and secret, which your code uses to ask for the others.

Deploys used to accept secret references (gf deploy --secret, and secrets, envSecrets or inject_secret_keys in the API). They were removed. A deploy that still sends any of them is refused with 422 (secret_refs_removed) and nothing is deployed; send no secrets field, or an empty one. With gf 0.2.9 or later, the --secret and --no-secrets flags no longer exist. Move to the runtime read below.

Set it up

Store the secret

In the Client Portal, go to Data → Secrets and add it, or run gf secrets set STRIPE_API_KEY - and paste the value, then press Ctrl+D.

Give the Coderunner an M2M client that can read secrets

Go to Administer → Access → Machine clients, create a client with Can read secrets turned on, and attach it on the Coderunner's Machine client card. See Give a Coderunner a machine client.

Deploy again

Your code now has these variables. You never set them yourself; Groundfloor fills them in at each deploy, so a newly attached, changed or rotated client applies after the next deploy.

Secrets (filled by the platform), from the machine client attached to the Coderunner:

VariableValue
GROUNDFLOOR_M2M_CLIENT_IDThe attached client's ID
GROUNDFLOOR_M2M_CLIENT_SECRETThe attached client's secret

Environment variables:

VariableValue
CONTROLPLANE_URLThe Groundfloor API's base URL
GROUNDFLOOR_WORKSPACE_IDYour workspace's ID
GROUNDFLOOR_ENVIRONMENT_IDThe environment the Coderunner is bound to

The Secrets card on the Coderunner's page lists them by name (Filled from the attached machine client, and Platform setting for CONTROLPLANE_URL) never values. In the API they are secrets and platform_environment, with an empty value meaning filled by the platform. The two secrets never appear in the deployment's configuration. Your code reads all of them as ordinary environment variables.

Read it in your code

Exchange the client's credentials for a token, then read the secret:

secrets.js
const base = `${process.env.CONTROLPLANE_URL}/v1/workspaces/${process.env.GROUNDFLOOR_WORKSPACE_ID}`;
let cached; // { token, expiresAt }

async function token() {
  if (cached && Date.now() < cached.expiresAt) return cached.token;
  const res = await fetch(`${base}/m2m/token`, {
    method: "POST",
    headers: { "content-type": "application/json" },
    body: JSON.stringify({
      client_id: process.env.GROUNDFLOOR_M2M_CLIENT_ID,
      client_secret: process.env.GROUNDFLOOR_M2M_CLIENT_SECRET,
    }),
  });
  const { access_token, expires_in } = await res.json();
  cached = { token: access_token, expiresAt: Date.now() + expires_in * 800 }; // refresh at 80% of its life
  return access_token;
}

async function getSecret(key) {
  const env = process.env.GROUNDFLOOR_ENVIRONMENT_ID ?? "";
  const res = await fetch(`${base}/secrets/${key}?environment_id=${encodeURIComponent(env)}`, {
    headers: { authorization: `Bearer ${await token()}` },
  });
  return (await res.json()).value;
}

module.exports = { getSecret };

Pass environment_id to choose which environment's secrets to read: GROUNDFLOOR_ENVIRONMENT_ID is the Coderunner's own. Without it, Groundfloor reads the workspace's dev environment (or its only environment), so a production Service would get your development keys. environment_id doesn't limit what the code can read: an M2M client with Can read secrets can read the secrets of every environment in the workspace.

Reuse the token until shortly before it expires. Minting a new one on every request runs into the token endpoint's rate limit (20 a minute by default) and starts failing with 429.

In a container you didn't write

A Service running someone else's image can't call the Secrets API itself. Read the secret in a small entrypoint script, then start the application. See Example: run WordPress.

If a deploy is refused for naming secrets

ReasonStatusLikely causeWhat to do
secret_refs_removed422The deploy sent secrets, envSecrets, env_secrets or inject_secret_keys with a value (or an old gf sent --secret)Remove the field, upgrade gf to 0.2.9 or later, and read the secrets at runtime

An absent, null or empty field is accepted and ignored, so a script that always sends "secrets": {} keeps working.

Bind a Coderunner to an environment

Coderunners created in an environment always belong to it. One that doesn't shows No environment on the Build → Coderunner list and on its page, and its code gets no GROUNDFLOOR_ENVIRONMENT_ID, so it can't tell which environment's secrets to read. Bind it once:

Click Bind to environment. It's on the Coderunner list under No environment, on the Coderunner's page, and in the alert shown when a deploy is refused for this reason. Choose an active environment and click Bind to environment. The button appears only if you can bind; otherwise ask a workspace Writer or Admin.

gf coderunner bind-environment -c <coderunner> -e <environment>

-c takes the Coderunner's ID or slug, -e an environment ID or name, such as prod (see gf environments list). It shows what it will bind and asks you to confirm on a terminal; without one, pass --yes. --json prints the updated Coderunner.

PUT …/coderunners/{coderunner_id}/environment with { "environment_id": "…" }. See Bind to an environment.

Then deploy again. Before you bind:

  • Binding is permanent. A bound Coderunner can't move to another environment, and the binding can't be undone. Binding it again to the environment it already has changes nothing.
  • Nothing changes for the running service until the next deploy. The next deploy gives the code its environment's ID.
  • To run the code in another environment, create a Coderunner there, or promote this one into it from Build → Environments once it's bound. See Environments.
  • Push deploys pause. If the Coderunner has a connected Git repository, a push no longer deploys it until a workspace member saves its Git source again.
  • Who can bind: the Writer, Admin or Owner role. A machine client needs Can deploy services.
  • The environment must be active and in the same workspace. A suspended one is refused: resume it first, or pick another.

Resources and scaling

SettingWhat it doesSet it from
CPU (e.g. 250m)CPU available to each instanceDeploy dialog, gf deploy --cpu, or groundfloor.json
Memory (e.g. 256Mi)Memory available to each instanceDeploy dialog, gf deploy --memory, or groundfloor.json
Minimum and maximum instancesThe range Coderunner scales within, for Functions and ServicesDeploy dialog or the API (minReplicas, maxReplicas). The CLI has no flag for this yet

If you don't set CPU and memory, a deploy uses 250m and 256Mi. Minimum and maximum instances can each be from 0 to 100, and no higher than your plan allows (see Plan limits).

A minimum of 0 lets an idle Function or Service scale to zero, and it costs nothing while idle. A minimum of 1 or more keeps instances warm, and they're billed all the time. A Service that should always answer quickly needs a minimum of at least 1. Instances above the minimum are billed only while they run. See How compute is billed.

A Coderunner with a persistent disk runs at most one instance: its minimum and maximum can each be only 0 or 1.

Size limits

Two limits apply to the size of a Coderunner, and the lower one wins: your cell's maximum, below, and your plan's limits.

Each instance of a Coderunner has a maximum CPU and memory for the Groundfloor cell your workspace runs on. It can differ between cells, Groundfloor can change it for a cell, and you can't change it from your workspace. It applies to every workload type. To see the current maximum for your workspace, read GET /v1/workspaces/{workspace_id}/limits.

Write CPU as cores (0.5, 2) or millicores (250m), and memory with a unit (256Mi, 1Gi). Asking for more than the maximum, 0, or a value in another format is refused with 422 and nothing is deployed or saved. The error states the current maximum on your cell, in this form:

  • cpu must be at most <N> cores
  • memory must be at most <N>Gi
  • cpu must be greater than 0

Deploy again with a --cpu or --memory within the maximum (or fix cpu and memory in groundfloor.json), or run more instances instead of bigger ones. If you need a larger size, open a support request. In a manifest, the same errors start with coderunner.deploy..

A Coderunner saved with a size above the maximum, because it was set before the maximum applied or before the maximum was lowered, keeps running at that size and is billed at it until its next deploy. At that deploy, the larger size is refused with 422; a deploy that leaves out cpu or memory, a redeploy from Git and a promotion use the maximum instead, and a size that can't be read uses the default (250m and 256Mi).

Plan limits

Your organization's plan also limits each Coderunner (any workload type):

PlanCPU per instanceMemory per instanceInstances
Free0.5 vCPU1 GiB1
Indie2 vCPU4 GiB2
Business4 vCPU16 GiB5
EnterpriseCell maximumCell maximum100

Instances is the highest of the minimum and maximum you set. Plans also limit how many Coderunners a workspace can have; see Quotas and limits.

In the deploy dialog, CPU and memory sizes above what your workspace allows (your plan's limit or your cell's maximum, whichever is lower) are greyed out, and the instance fields stop at your plan's number. A note says what's allowed and that larger sizes need a support request: the link opens New request with the subject and workspace filled in. A deploy, or a manifest saved with a larger cpu, memory or instance count, is refused with 409 and a message such as "Your Free plan allows up to 0.5 vCPU per service. Contact us to change your plan." Nothing is deployed or saved. Choose a smaller size, or contact support to change your plan.

A Coderunner already set larger than your plan allows keeps running and can be redeployed at the same size or smaller, one setting at a time: you can keep its CPU while lowering its memory, but not raise anything above the plan. Redeploys from Git and promotions keep the stored size.

In the deploy dialog, a saved size above your plan but within your cell's maximum stays selectable and is marked (current). A saved size above your cell's maximum is shown as (saved, not available here) and can't be chosen: the dialog selects the largest allowed size instead and says so. Nothing can be deployed above the cell's maximum.

Persistent disk

A Coderunner's own file system is temporary: anything it writes is lost when it restarts, redeploys or scales to zero. A persistent disk keeps files across all of those. Use it for data your code must keep on local disk, such as an embedded database file, a cache you don't want to rebuild, or an off-the-shelf app's uploads. For data your code can store elsewhere, a database or Files is usually the better choice.

  • Functions and Services only. Jobs and Schedules can't have one. It's off unless you turn it on.
  • 1 to 5 GB. Pick the size from a list.
  • Always mounted at /data inside the container. You can't change the path, so have your code write the files it must keep under /data. Anything written anywhere else is still lost on restart.
  • Grows, never shrinks. You can make the disk bigger later, but not smaller. To get a smaller disk, remove it (which deletes its data) and add a new one.
  • One instance. A Coderunner with a disk runs at most one instance, so it can't scale out while the disk is on. See Resources and scaling.
  • Takes effect on the next deploy. Adding, growing or removing the disk is saved straight away, but nothing changes in the running Coderunner until you deploy it again. Nothing redeploys by itself. The first deploy after you add a disk creates it, empty.
  • Kept while stopped. Stopping a Service, or scaling it to zero, keeps its disk and the data on it.
  • No automatic backups. Groundfloor doesn't back up the disk. Copy anything you can't lose somewhere else yourself, for example to Files.

Add or grow a disk

Turn it on

When you create a Function or Service in Build → Coderunner, turn on Persistent disk and choose a Size. For an existing one, open it and click Add disk on the Persistent disk card (or Change to grow a disk it already has), choose a size and click Save. Sizes smaller than the current one can't be chosen.

Deploy

Deploy the Coderunner. The disk is created, or grown, by this deploy. The Persistent disk card shows its size, Mounted at /data, and Copies: At most 1.

With the API, send persistent_disk: {"size_gb": 2} when you create the Coderunner or in PATCH …/coderunners/{coderunner_id}. See Persistent disk in the API reference.

Remove a disk

Removing a disk deletes everything on it, and it can't be undone. It needs the same permission as deleting the Coderunner. Open the Coderunner, click Change on the Persistent disk card, turn off Persistent disk and click Save. To confirm, type the Coderunner's name and click Remove disk. The disk and its data are deleted at the next deploy.

Deleting the whole Coderunner deletes its disk and the data on it too, straight away. The delete confirmation warns you when the Coderunner has a disk.

Storage limit and billing

A disk is storage: its full size counts toward your organization's plan storage limit, which files and disks share, and it's billed at the storage rate for as long as it exists. A disk exists from the deploy that creates it until the deploy that removes it, or until you delete the Coderunner, whether or not the Coderunner is running. A grown disk is billed at its new size from the deploy that grows it; if that deploy doesn't finish cleanly, the larger size is billed until the next deploy confirms it. On the Free plan the limit is 1 GB, so a Free organization with no files can have one 1 GB disk.

Adding or growing a disk past the limit is refused with a message such as "Your Free plan allows up to 1 GB of storage for files and persistent disks (0.5 GB in use). Contact us to change your plan." While a Free organization is paused because it has used up its free usage, adding or growing a disk is refused too; removing one always works. See Quotas and limits.

Promoting a Coderunner with a disk

When a promotion creates the Coderunner in the target environment, the new copy gets its own, empty disk of the same size, created by its first deploy. Data on the disk is never copied between environments. The new disk counts toward your storage limit too; if it doesn't fit, that Coderunner isn't promoted and the promote panel says why.

Next steps

On this page