Skip to content

Env files

moira edits the *.env files a stack’s services load with env_file. Every save is conditional on the version you read, backed up first, and followed by an offer to apply the change.

A file is editable when it:

  • sits directly in the stack directory and is named <something>.env;
  • is referenced as an env_file by the stack’s current Compose model;
  • is a regular file: not a symlink and not hard-linked;
  • is valid UTF-8 and at most 1 MiB.

Edit anything else over SSH.

Terminal window
moira env shop-prod # the file shop-prod uses (or pick from a list)
moira env edge/shop/ staging.env # a specific file in a stack
  1. moira downloads the file and opens a private copy (mode 0600) in $VISUAL, $EDITOR or vi. The copy is deleted when the editor exits, even on failure or Ctrl-C.

  2. It prints a masked diff on stderr. Values never appear:

    ~ DATABASE_URL=***
    + FEATURE_FLAGS=***
    - LEGACY_TOKEN=***
  3. You confirm with y (or pass --yes).

  4. The save sends the version you read in If-Match. On success, moira prints the backup path:

    Backup .history/prod.env.20261122T140000Z
  5. For each service that uses the file it asks apply now? [Y/n]. --yes accepts every apply; --no-apply skips them. Apply output is hidden because it could contain env values; only the job status is shown.

An unchanged file prints no changes.

If the file changed on the host while you were editing, the server rejects the save. moira then compares both versions with the one you started from:

  • Disjoint changes (different keys) are merged. moira shows the masked diff against the current file and asks again.
  • Overlapping changes (the same key, duplicate assignments, or conflicting reorders) need manual reconciliation. On a terminal, moira opens a copy of the current server file, shows the path of a private copy of your edit, and asks before saving. Without a terminal, it exits 1.

Every save first copies the previous version to <stack>/.history/<file>.<UTC timestamp> (mode 0600). The newest 20 automatic backups per file are kept. Hand-made <file>.bak-<suffix> copies next to the file also appear in history and are never pruned.

Terminal window
moira env shop-prod history
moira env shop-prod restore 20261122T140000Z
moira env shop-prod restore bak-cutover --yes --no-apply

A restore is an ordinary save of the old content: same masked review, same conflict check, and it gets its own backup.

The env editor in moira ui shows keys with masked values. Reveal a single value with an explicit click, stage edits per key, review the masked diff, then Save or Save & Apply. Files with ambiguous dotenv syntax open in a raw editor.