Skip to main content

Mass Alpha Stash

mass alpha stash​

Share values between deployments, scripts, and the Massdriver UI

Synopsis​

Manage the Stash

Every project, environment, component, instance, and deployment has a stash of key and value entries. Deployment steps, CI jobs, scripts, and automations write to it. Later steps read the values back, and the Massdriver UI shows them as canvas widgets, deployment results, and metadata.

Stash is an alpha API. It can change or be removed at any time, without notice.

Full guide: https://docs.massdriver.cloud/guides/stash

What you can do with it​

  • Pass a value between deployment steps. One step writes the database host to the deployment's stash. A later step reads it.
  • Record what a deployment did. Write a well-known result key, such as md/v1/changes/<step> or md/v1/cost_estimate. The deployment's details show a Results section.
  • Show live health, usage, and traffic on the canvas. Write md/v1/health, md/v1/usage, or md/v1/traffic on an instance.
  • Put links or a banner on an environment. Write md/v1/links or md/v1/banner on the environment.
  • Run a task once. An --immutable write fails when the key already has a value.
  • Keep a value for a set time. Set --ttl. The entry is deleted when the time ends.
  • Keep a secret that a later step needs. Set --sensitive. The value is encrypted.

Keys that start with md/ are well-known keys. The server checks each md/ write against the key's schema. See https://docs.massdriver.cloud/guides/stash/well-known-keys

Addresses​

An address is <scope>.<key>. The first . ends the scope, so a key can contain more dots. In billing-dev-app.schema.version, the scope is billing-dev-app and the key is schema.version.

Keys use letters, digits, and _ . / -, up to 255 characters.

The scope is an identifier. Its shape tells the kind of entity:

ScopeKind
billingproject
billing-devenvironment or component
billing-dev-appinstance
a UUIDdeployment

An environment and a component have the same shape. The CLI looks up both. When both exist, add a prefix to choose one: env:billing-app or component:billing-app. The prefixes project:, env:, environment:, component:, instance:, and deployment: are always accepted.

How it works​

  • Stashes do not inherit. A key on an environment is not visible from the stash of its instances or deployments. Read the environment's stash to get it.
  • A set replaces the whole entry. The value, format, label, TTL, and flags all come from the new write. A flag that you leave out goes back to its default.
  • Labels. An entry with a --label shows as a row on the Metadata panels in the UI. A label is not encrypted.
  • Sensitive values are encrypted. Callers without stash:export see them masked. They are never sent in events and never shown in notes or widgets.
  • Limits. A value can be up to 65536 bytes. A stash can hold up to 1000 keys.

Signing in​

Outside a deployment, the CLI uses your mass profile, or MASSDRIVER_API_KEY and MASSDRIVER_ORGANIZATION_ID. For CI jobs and scripts, use a service account's access token. You need stash:view to read, stash:write to set and delete, and stash:export to read sensitive values.

Inside a provisioner, when no API key is set, the CLI signs in with the deployment's token (MASSDRIVER_DEPLOYMENT_ID and MASSDRIVER_TOKEN). That token can read and write the stash of its deployment and of the deployment's instance, environment, component, and project. It can also read the stash of the instances that its instance depends on.

Examples​

Pass a value from one step to a later step:

shell
mass alpha stash set "$MASSDRIVER_DEPLOYMENT_ID.db/hostname" "$DB_HOST" --label "Database hostname"
DB_HOST=$(mass alpha stash get "$MASSDRIVER_DEPLOYMENT_ID.db/hostname")

Record a step's changes as a deployment result:

shell
mass alpha stash set "$MASSDRIVER_DEPLOYMENT_ID.md/v1/changes/$MASSDRIVER_STEP_PATH" \
'{"tool": "opentofu", "add": 2, "change": 3, "destroy": 0}' --format json

Show an instance's health on the canvas for ten minutes:

shell
mass alpha stash set billing-dev-app.md/v1/health degraded --ttl 600

Show a maintenance banner on an environment for two hours:

shell
mass alpha stash set billing-dev.md/v1/banner \
'{"message": "Database upgrade from 22:00 to 23:00 UTC", "level": "warning"}' \
--format json --ttl 7200

Run migrations only once per deployment:

shell
if mass alpha stash set "$MASSDRIVER_DEPLOYMENT_ID.migrations/ran" true --immutable; then
./run-migrations.sh
fi

Cache a value for a day, and compute it again when it is gone:

shell
AMI=$(mass alpha stash get billing-dev-app.ami-id) || {
AMI=$(./find-latest-ami.sh)
mass alpha stash set billing-dev-app.ami-id "$AMI" --ttl 86400
}

Options​

  -h, --help   help for stash

Options inherited from parent commands​

      --profile string   Configuration profile to use (overrides MASSDRIVER_PROFILE and the active profile)

SEE ALSO​