Skip to content

Stacks and environments, milestone 2: environments in the repo - #124

Open
davidjalbers wants to merge 100 commits into
mainfrom
stacks-2
Open

davidjalbers wants to merge 100 commits into
mainfrom
stacks-2

Conversation

@davidjalbers

Copy link
Copy Markdown
Contributor

Milestone 2 of the project "Stacks and environments": an environment of a stack is a file in its repo, <stack>/<environment>.yaml, and plx deploy hands it to the stack playbook, which does everything that environment needs on its host.
It goes with compendium#27, which holds the pages.

Important

What merging starts.
Nothing deploys and nothing is published by the merge.
The next step is yours: mise ship, after both pull requests are merged, cuts the version that carries this.
That version is breaking for every consumer, in an order that matters: each host runs the new platform playbook once before any repo on it takes the version, and each repo needs its environment files and two repository secrets before its first deploy.
The update's pull request stays green and says "Nothing needs a hand" in a repo that has neither.
The release notes are drafted in a comment on PLX-300.

What it holds

Issue Pull request What
PLX-296 #116 lib reads environment files; plx doctor checks them against each other and against the compose file.
PLX-297 #117 The platform playbook prepares a host for stacks and knows none: the deploy user and its root, the proxy with its fragment directory, the one sudo rule for a reload.
PLX-327 #118 plx update lands a version on the default branch the origin names.
PLX-298 #121 The stack playbook applies an environment: values, secrets, the loopback port, the hostname's claim and the route, under one lock, with a rollback of all three files.
PLX-299 #121 plx deploy, plx-ci setup and the templates read environment files; the inventory flag and the second repo's token are gone.

PLX-298 had no pull request of its own: its branch alone could not pass the whole verify, since the deploy verb's test called the playbook by its old interface, so PLX-299 was stacked on it and each was reviewed by its own range of commits.

To know before merging

  • ship regenerates packages/lib/src/standard-index.json from the compendium; during the milestone, names were appended and removed by hand.
  • The template engine has a second merge policy, birth-only: a path is written only when its directory is born. A stack's environment files use it.
  • The deploy job needs two repository secrets, DEPLOY_SSH_KEY and DEPLOY_VAULT_TOKEN; creating a vault service account and setting them is yours.
  • plexus.platform's stack playbook resolves op:// pointers where it runs, so op must be on the PATH of whoever deploys.
  • PLX-284 is not resolved and is worse: a repo needs two new secrets, and nothing but the first failed push tells it.
  • PLX-278 is partly resolved: the deploy job reads no vault unless it joins the overlay.

Decided by the maintainer during the milestone

  • host is an SSH destination, [user@]address[:port].
  • A secret reaches a container through env_file only; the compose file is never interpolated with one.
  • Path prefixes are gone: one hostname per environment.
  • plx update lands a version on the repo's default branch.

The Decisions document still lacks these four.

Open with you, work done under my suggestion:

  • attn 094289: environment files are born with a stack and never added by plx update.
  • attn 19c899: PLX-329, the compendium's pass, is still in Triage although its pull request is merged into the compendium's stacks-2.
  • attn 79ac91: PLX-Stack/Deploy says migrate runs on every deploy; the playbook runs it only where the compose file changed.

Readings made without the maintainer, to confirm or correct

Environment files and plx doctor (PLX-296):

  1. An environment's name is letters only ([a-z]+); compose is no name, and a file <name>.yml is refused.
  2. Only host is required; env and secrets may be absent and read as empty; values under env are strings.
  3. A secret that is a string but no pointer is reported once, under its own name.
  4. The check of the variables a compose file interpolates does not count B in ${A:-${B}}.
  5. A deviation listed under a renamed requirement is told its new name; one under a removed requirement is told it can go.

The platform playbook (PLX-297):

  1. The deploy user's registry login is a fifth thing beyond the four the decisions name for a prepared host; it stays on the host.
  2. The refusal of /healthz is a convention of the fragment's shape: it lives in the root's snippet, and a fragment that does not import it escapes it.
  3. /opt/stacks is 0750 and the deploy user's; plexus_deploy_root is no longer read, and a host that sets another path is told so.
  4. A proxy configuration Caddy refuses fails the run in a last play, after firewall and sshd have run.
  5. The message about plexus_apps is shown only where it holds records, and the run continues.
  6. The removal of /etc/caddy/tenants is dropped.

The update (PLX-327):

  1. An origin that cannot be reached is a skip with exit 1, not a guess of main.
  2. The origin is asked on every run.

The stack playbook (PLX-298; numbers in brackets are those of #121's body):

  1. The interface is the path of the environment's file; the environment is named after the file (1).
  2. The port range is 20000 to 20999; ports in other environments' fragments and .env files count as taken, and so does any port something on the host listens on, which goes beyond the issue's wording (2, 3, 18).
  3. A refused reload puts the previous fragment back, and the deploy fails before anything else is written (4).
  4. A failed first deploy removes its containers and compose file and keeps .env and .env.secret, so the port stays claimed (5).
  5. .env.secret ends empty at 0600 when the last secret goes (6); the previous files are kept as .env.prev, .env.secret.prev and compose.yaml.prev (13), so a removed secret's last value stays on the host until .env.secret changes again.
  6. hostname is a DNS name, lowercased, with no wildcard and no port (8).
  7. plexus_deploy_user defaults to plexus; a deploy user with another name is written into each file's host (9).
  8. The lock waits at most 300 seconds (11).
  9. An environment whose hostname is removed loses its port from .env, and its fragment stays (16).
  10. New rule: a secret the vault holds empty is refused (19).
  11. New rule: op read is stopped after 30 seconds (20).
  12. New rule: the playbook refuses --limit, --tags and --skip-tags (22).

The deploy verb and the templates (PLX-299):

  1. The vault token is handed to the plx deploy step alone, and the step clears the Connect variables, which 1Password documents as taking precedence over a service account token.
  2. A stack without the environment's file is a "not deployed" line; the run fails only where no stack has the file.
  3. In CI, a run whose files list secrets is refused without the vault token, before any host; CI is GITHUB_ACTIONS=true.
  4. A checkout path, environment-file path or scratch directory that holds {{ or {% is refused, since Ansible would template it.
  5. The stack template renders production.yaml and staging.yaml by those literal names; milestone 3's declared environments replace them.
  6. The setup step holds the CI vault token only to join the overlay.

Known and recorded, not fixed

  • PLX-328: the deploy verb's test leaves containers when it is stopped from outside.
  • PLX-330: one garbled sentence and migration history in the headers of the platform playbook, the ingress role and the stack template; two literal /opt/stacks; route.sh discards sudo's own error, so a missing sudo rule reads as "the proxy refused".
  • A run of the stack playbook that reaches no host (--limit without localhost, --skip-tags always) exits 0 without a result line; the deploy verb reports that as failed.
  • Two deploys of one environment at once are not supported.
  • PLEXUS_COMMIT_SHA is still delivered to the stack at run time; the decisions of milestone 3 remove it.
  • Two mutations of the stack playbook survive its test: the hostname compared case-sensitively, and the lock released before the fragment is written.
  • The last small round of plx deploy, plx-ci setup and the templates read environment files (PLX-299, with PLX-298) #121 (the {{ refusal, the list of removed names) was read by the coordinator and not by the reviewer.
  • plx update lands a version on the default branch of origin #118's end-to-end run was red once after two clean reviews: a test fixture that only the forge's run exercised, fixed in the same pull request. The end-to-end suite runs only on the forge; authors now run the files they touch.

Not tried

  • The stack playbook against a remote host over SSH, the real op CLI, real repository secrets and runners.
  • The platform playbook's role caddy and the registry login.

Verification

  • TURBO_FORCE=true mise run test at 52862a6, run by the coordinator alone: 7 of 7 tasks, none cached, exit 0. The head of stacks-2, 61d97da, has the identical tree (1088b83).
  • mise e2e (the newborn tests) in the pull request run of plx deploy, plx-ci setup and the templates read environment files (PLX-299, with PLX-298) #121 at 52862a6: green.
  • The push run on stacks-2 at 61d97da (run 47617908474): green.
  • plx requirements . --compendium against the compendium's stacks-2 at 6f42a96: citations resolve.

🤖 Generated with Claude Code

davidjalbers and others added 30 commits December 6, 2026 01:36
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
… file

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
… compose file

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
… version as they were

A run on a host that carries a deployment and the routes the earlier
version rendered, with plexus_apps still set: it says the variable is no
longer read, changes none of the deployment's files nor apps.caddy, runs
no docker command, and the route still answers. Red: the roles still
read the records.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The roles apps and secrets go, and with them every per-deployment task:
no directory, .env, .env.secret or docker compose up from the records.
ingress renders no routes any more; the root Caddyfile imports the
apps.caddy earlier versions rendered for as long as it is there, by its
absolute path, so the root is validated as a whole before it replaces
the one in place. A host that still sets plexus_apps is told the
variable is no longer read. The registry login of the deploy user moves
to deploy_user.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
On a host without records: /opt/stacks is the deploy user's, the deploy
user writes a route fragment that the proxy serves after a reload, and a
second run changes nothing. Red: no deploy root, no fragment directory.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…oute fragments

deploy_user creates /opt/stacks (plexus_deploy_root) owned by the deploy
user, 0750; the test now expects that mode. ingress creates
ingress_fragments_dir, /etc/caddy/stacks, owned by the deploy user, and
the root Caddyfile imports every *.caddy in it. Neither recurses.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…else

As the deploy user, sudo -n /usr/bin/systemctl reload caddy reloads the
proxy with a changed fragment; sudo lists one rule; restart, another
unit, extra arguments, another target user and a shell are refused; the
host's sudo rules pass visudo -c. Red: there is no rule.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ingress writes /etc/sudoers.d/reload-caddy, validated with visudo -cf:
<deploy user> ALL=(root) NOPASSWD: /usr/bin/systemctl reload caddy.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…he root

A fragment of the form <hostname> { import stack <port> } reaches the
stack on its loopback port, /healthz is refused although the stack
answers it, and a port where nothing answers gets the maintenance page.
Red: the root configuration defines no snippet stack.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…and port

The snippet stack encodes, refuses /healthz, proxies to 127.0.0.1 on the
port it is given, and serves the maintenance page while the stack does
not answer; a fragment is <hostname> { import stack <port> }. The
maintenance page's variables get their defaults in the role's defaults.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A fragment beside apps.caddy is served with the old routes; one for a
hostname apps.caddy still serves is refused by the proxy, which goes on
serving the old route; once the block is out of apps.caddy the hostname
moves to its fragment; once apps.caddy is deleted, reloads work before
and after the next platform run. Red: the root imports apps.caddy by
its path, and a reload fails once it is gone.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…only .env covers them

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…ed by env alone

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…s are findings

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…orm's names refused, compose file names stated once

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…latform run

Caddy refuses a missing import path but imports nothing for a pattern
that matches no file, so the root imports /etc/caddy/apps*.caddy where
apps.caddy was there when the root was written. The role's header names
what the stack playbook uses (the fragment directory and form, the
snippet stack, the reload rule and how a reload fails) and how old
routes and fragments coexist while a host migrates.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…bind no port

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…hostname needs one

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…mes are not also reported missing

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…atform names are reported once

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…epo is

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
… update lands on it

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
A repo's kind no longer decides the branch: it is read from origin/HEAD of the
checkout, else from origin's own HEAD, and a repo with neither is skipped.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…ates the file at the cut

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
davidjalbers and others added 28 commits December 6, 2026 04:43
…y and the vault token as repository secrets

The workflows hand setup DEPLOY_SSH_KEY and the step of plx deploy DEPLOY_VAULT_TOKEN as its OP_SERVICE_ACCOUNT_TOKEN; the CI vault's token reaches setup only to join the overlay. repo-operations renders no plexus_apps, plexus_up or plexus_deploy_root, and names no tag the platform playbook dropped.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…eploy, with host, hostname, env and secrets

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…r environment files, with the deploy key a secret of the repo

The stand-in playbook takes its host from the file, setup reads nothing from the vault, and the verb has no inventory.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…ch the doctor passes as born

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…eploy: host, hostname, env and secrets

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…onment file, with no inventory

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…ent files, as the doctor asks

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…mpty or does not answer

An environment whose last secret is dropped deploys, under --check too:
.env.secret stays, empty and 0600, the services that loaded it are
re-created, and a second run changes nothing. A value the vault holds empty
is refused, naming the pointer; a read that does not answer within
stack_secret_timeout is refused, naming the usual cause, and leaves no op
running. The vault CLI's stand-in waits for a pointer ending in /locked.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…et, and gives op read a timeout

The template lookup gives none rather than an empty string for an
environment without secrets, so writing .env.secret after the last secret
was dropped failed, and the dry run's undo failed with it: the text is now
an empty string, and a dry run, which wrote nothing, undoes nothing. Each
op read runs under the Python that runs Ansible, which kills op after
stack_secret_timeout seconds (30) and says that it mostly waits for an
unlock nobody answers; a value the vault holds empty is refused.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…with a line break

A run given --limit, --tags or --skip-tags fails with a Result line that says
the playbook takes none of them, since each leaves out the deploy or the line
that says how it ended. A host or a hostname whose text ends in a line break
is refused with the environment's file.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ing in a line break

Every task is tagged always, so that the first, a check of the arguments,
runs under --tags too, and refuses a --limit, --tags or --skip-tags with a
Result line: each would leave out the deploy, or the line that says how it
ended. The forms of host and hostname end in \Z, where $ let a trailing
line break pass, and the route script's arguments are quoted.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ostname of an earlier version's routes

The prepared host carries a route of an earlier version in apps.caddy, as a
host in migration does. A new environment claiming its hostname ends refused
with the proxy's own reason, its fragment gone and nothing else written; an
environment whose fragment changes to it ends with the fragment as it was. A
port of the range that something on the host listens on is skipped. A
fragment that does not parse gives caddy validate's reason.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…proxy refused

A new port skips every port in state LISTEN that /proc/net/tcp and
/proc/net/tcp6 list, which every Linux host has, so that a first deploy does
not claim a port it cannot bind and keep it for good. Where the proxy
refuses the reload, the line gives the error of caddy validate, which the
deploy user can run, instead of a cause the script does not know; where that
says nothing, only that the proxy refused. A host without flock is told so.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… what its caller must know

deploy_user_root, in the role deploy_user's vars, which no inventory
overrides, is the one place /opt/stacks is written: the role's task uses it,
and the stack playbook reads the file for stack_root's default, which -e
still overrides. The header says that the caller passes no -i, --limit,
--tags or --skip-tags, and which runs of no task Ansible ends with exit 0
and no Result line; that PLEXUS_TAG and PLEXUS_COMMIT_SHA are rendered into
the compose file by the caller; that .env.secret ends empty once the
environment has no secrets, and .env.secret.prev keeps the previous ones;
and step 3 points at the route script's header instead of repeating it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ut whose path has a space and an =

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…the loader's refusal as it wrote it and names the missing vault secret in CI

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…e requirement was removed

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…is told the requirement was removed; the index names neither

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
… update

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…dded by an update

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…irth renders both

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
… none to a stack born without them

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…from an update, and one a person wrote stays

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…o davidjalbers/plx-299-plx-deploy-plx-ci-setup-and-the
…failure

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
… runs

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…d requirements are listed by module and suffix

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…y-plx-ci-setup-and-the

plx deploy, plx-ci setup and the templates read environment files (PLX-299, with PLX-298)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant