Vercel environment
Varlock is optional. processEnv.js hydrates from a frozen .varlock.blob when one ships, and otherwise uses the variables the function was started with.[1] Pick one option per project. The variables themselves are described in environment.[2]
Option: vercel.json env
Add the env of a launch configuration to vercel.json; the file is committed, so only for values which are not secret:
"env": { "WORKSPACE": "file:./public/workspace.json" }Option: Vercel project variables
Set the variables in the project settings, then deploy with vercel --prod or vercel --target=preview. Nothing is frozen, and Git-integration deploys work. Schema validation, gsm() references and Varlock's log and response redaction do not run without a blob.
vercel env add <NAME> production # one variable
pnpm push-env --dry-run # list the keys of .env
pnpm push-env --env=production # upload .env
pnpm push-env --file=.env.preview --env=previewpnpm push-env (utils/sync-vercel-env.js) upserts each key encrypted and skips VERCEL_* keys. --env defaults to development. It needs a linked project and a token from --token=, VERCEL_TOKEN or a VERCEL_TOKEN entry in .env.vercel; keep the token out of .env.[3] Vercel applies variables at build time, so redeploy after a change.
Option: frozen Varlock blob
.env + .env.schema ──pnpm freeze-env──▶ .varlock.blob ──includeFiles──▶ deployment
(+ gsm() refs) (encrypted) │
processEnv.js decrypts with _VARLOCK_ENV_KEYpnpm freeze-env --env=<APP_ENV> validates the whole schema, so a missing variable or failed gsm() lookup fails before the deployment.[3:1] The varlock/ schemas set @encryptInjectedEnv=forEnv(production), so production blobs are encrypted and the project needs _VARLOCK_ENV_KEY. Blob values override project variables of the same name. .varlock.blob is gitignored, so a Git-integration deploy never carries one.
pnpm deploy:vercel --env=production # rotates the key
pnpm deploy:vercel --env=preview --varlock-env=staging # APP_ENV differspnpm deploy:vercel builds the bundles, generates a key, freezes the blob with it, stores the key in the target environment, then deploys; the key must exist before the blob is frozen.[3:2] Vercel CLI flags such as --scope, --token, --local-config and --force pass through. To keep the existing key, set _VARLOCK_ENV_KEY locally and in the project, then:
pnpm build --filter=@geolytix/mapp --filter=@geolytix/mapp-ui
pnpm freeze-env --env=production
vercel --prodAn encrypted blob without _VARLOCK_ENV_KEY throws at startup; a missing blob shows as missing configuration.
Google Secret Manager
Start from varlock/gsm-adc.env and varlock/gsm-adc.env.schema, copied to .env and .env.schema. The schema loads @varlock/google-secret-manager-plugin with GCP_PROJECT_ID and GOOGLE_CREDENTIALS. Reference secrets as SECRET=gsm("xyz-secret"), or PUBLIC=gsm() for a secret named after the key.[4]
Leave GOOGLE_CREDENTIALS empty to use Application Default Credentials (gcloud auth application-default login); set it to a service account JSON where there is no interactive login, eg. in CI.
Whoever runs pnpm freeze-env resolves gsm(), never the deployed function. The deployment needs no GCP credentials and makes no Secret Manager calls, the freezing machine needs read access to the secrets, and a rotated secret only reaches the deployment after the next freeze and deploy. Check resolution with pnpm exec varlock load --compact.
CI
A deploying workflow builds the bundles, freezes the blob, and deploys:
- run: pnpm install --ignore-scripts
- run: pnpm build --filter=@geolytix/mapp --filter=@geolytix/mapp-ui
- run: pnpm freeze-env --env=production
env:
_VARLOCK_ENV_KEY: ${{ secrets.VARLOCK_ENV_KEY }}
GOOGLE_CREDENTIALS: ${{ secrets.GOOGLE_CREDENTIALS }}
- run: pnpm exec vercel --prod --yes --token=${{ secrets.VERCEL_TOKEN }}Pin the Vercel CLI version and pass --yes so the job cannot wait on a prompt.
Troubleshooting
- Defaults used instead of variables: no blob ships and the project lacks the variables, or got them after the build. Check
vercel env lsand redeploy, or check the blob is in the root and inincludeFiles. .varlock.blob is encrypted but _VARLOCK_ENV_KEY is not set: add the key to the Vercel environment and deploy again.- Decryption fails: the project key differs from the freezing key. Run
pnpm deploy:vercel --env=<target>to regenerate both. gsm()fails during freeze: log in with ADC, checkGCP_PROJECT_ID.- Stale frontend: rebuild with
--forceand deploy again. - 404 on every route: check
DIR;COOKIE_PROPSderives itsPathfrom it.