Values per environment

Keep environment variable and secret values out of git, set them per CLI context, and provide them from CI with SPICA_VALUE_ variables.

Environment variables and secrets are declared in the project (env-var/<KEY>/schema.yaml, secret/<KEY>/schema.yaml), but their values usually differ between instances, and secret values must never be committed. The CLI resolves values for the current context.

Declare a key

env-var/SITE_URL/schema.yaml
key: SITE_URL
secret/STRIPE_KEY/schema.yaml
key: STRIPE_KEY

An environment variable's schema.yaml may also contain a value, which then acts as the default for every context.

Set values for the current context

Terminal
spica env SITE_URL https://blog.example.com
spica secret STRIPE_KEY
Text
Saved SITE_URL to .spica/local.env.

spica secret prompts for the value without echoing it. Both commands write to .spica/<context>.env (file mode 600) in the project folder:

.spica/local.env
SITE_URL=https://blog.example.com
STRIPE_KEY='sk_test_...'

A key must be declared before you can set it, otherwise the CLI answers "SITE_URL" is not declared. Create env-var/SITE_URL/schema.yaml first.

How values are resolved

For each key, plan, apply and dev use the first value they find:

  1. The SPICA_VALUE_<KEY> environment variable, for example SPICA_VALUE_STRIPE_KEY.
  2. .spica/<context>.env.
  3. The value in the environment variable's schema.yaml.

When an environment variable has no value anywhere, or a secret doesn't exist on the instance yet and has no value, the plan stops:

Text
Missing values for: env-var/SITE_URL
Set them with "spica env <KEY>" / "spica secret <KEY>" or the SPICA_VALUE_<KEY> environment variable.

A secret that already exists on the instance doesn't need a value. Its current value is kept.

In CI

Provide values as environment variables from your CI's secret store:

YAML
env:
  SPICA_VALUE_STRIPE_KEY: ${{ secrets.STRIPE_KEY }}
  SPICA_VALUE_SITE_URL: https://blog.example.com