Skip to content

plx deploy, plx-ci setup and the templates read environment files (PLX-299, with PLX-298) - #121

Merged
davidjalbers merged 41 commits into
stacks-2from
davidjalbers/plx-299-plx-deploy-plx-ci-setup-and-the
Dec 6, 2026
Merged

davidjalbers merged 41 commits into
stacks-2from
davidjalbers/plx-299-plx-deploy-plx-ci-setup-and-the

Conversation

@davidjalbers

@davidjalbers davidjalbers commented Dec 6, 2026 •

Copy link
Copy Markdown
Contributor

This pull request carries the commits of two issues: PLX-298 (up to 917c85a, the stack playbook that applies an environment from its file, with its fix round) and PLX-299 (the commits after it: the PathPrefix removal on, with the merge of stacks-2 at cae1f44 and the merge of PLX-298's fix round).

PLX-299: what it does

  • plx deploy deploys, for the given environment, every stack that has that environment's file, to the host the file names, by handing the file to the stack playbook. It has no --inventory flag and reads no operations record. A stack without the file is listed as no <env>.yaml; not deployed; a file with problems refuses the whole run before anything is deployed.
  • plx-ci setup deploy mints no token for a second repo and checks out nothing but its own repo. It loads the deploy key from the repository secret into an ssh-agent, installs op if absent and puts it on the PATH, logs in to the registry, and reads the vault only to join the overlay.
  • The rendered workflows (app repo on_push, operations repo deploy) no longer check out the operations repo and pass no inventory.
  • The template stack renders production.yaml and staging.yaml with host, hostname, env, secrets; plx doctor passes on a newborn.
  • repo-operations no longer renders plexus_apps, plexus_up, plexus_deploy_root, and names no apps or secrets tag.
  • PLX-Stack/PathPrefix and PLX-Ingress/PrefixInRecord checks and citations are removed, as a test-first commit pair of their own.

Readings

  1. The vault token is handed to the plx deploy step alone (not through GITHUB_ENV), as OP_SERVICE_ACCOUNT_TOKEN: ${{ secrets.DEPLOY_VAULT_TOKEN }}.
  2. The verb step runs env -u OP_CONNECT_HOST -u OP_CONNECT_TOKEN plx deploy: 1Password documents that Connect's variables take precedence over a service account token, and that they are to be cleared to use the token.
  3. The stack template renders literal production.yaml and staging.yaml at a birth only (new engine policy birth-only): an update adds none to an existing stack and touches none that exists, as for its compose.yaml and marker. An existing stack has no environment file: where no stack has the file the run fails (no stack has a <environment>.yaml), but where one stack has its file each stack without one is a - … not deployed line and the run exits 0, so a person must write the files. The next milestone's declared environments replace the literal names.
  4. Outcome no file is new for a stack without the environment's file.
  5. Placeholders use host.example.com.
  6. The setup step holds the CI vault token only to join the netbird overlay.
  7. isOperationsRepo is removed; deployTargets.ts keeps its name but holds only the branch map.
  8. Two test-fix amendments landed in the code commit rather than the test commit.

PLX-284 and PLX-278

  • PLX-278: the deploy job reads no vault unless it joins the overlay; a missing DEPLOY_SSH_KEY still fails the job, deliberately.
  • PLX-284: not resolved, and this change makes it worse. A repo now needs two new secrets, the update's pull request stays green without them, and the first push fails. The update PR's listing of read secrets and variables, and the changeset and update App credentials, are untouched.

Search

grep for plexus_apps, operations-token, operationsRepo, isOperationsRepo, --inventory over packages, templates and newborns finds only the test asserting the flag is unknown and one sample string in a lint fixture.

What no test covers

Real GitHub secrets and runners; a real host over ssh.

For the release notes

  • A repo that takes this version needs the two repository secrets before its first push, and the update's pull request stays green without them.
  • A hand-written workflow that passes --operations-repo to plx-ci setup breaks.
  • The update's pull request says "Nothing needs a hand" and plx doctor stays green, although every existing stack needs its environment files before its next deploy.
  • An existing stack gets no environment file and deploys nothing until a person writes them (<stack>/<environment>.yaml: host, hostname, env, secrets).
  • Repositories that deploy hold two repository secrets: DEPLOY_SSH_KEY and DEPLOY_VAULT_TOKEN (read-only token of the tenant's vault).
  • A repo moves its stacks' host, hostname, values and secrets into <stack>/<environment>.yaml; an operations repo drops plexus_apps, plexus_up, plexus_deploy_root from its inventory.
  • To run plx deploy -e <env> from a checkout, a person needs op signed in to the vault (or OP_SERVICE_ACCOUNT_TOKEN), ssh access to the hosts, and ansible with the plexus.platform collection.

Size

Against stacks-2, both issues together: +1892 / -1236 lines, of which tests (test files and newborns) +1070 / -653.

Review round

The variables go to the playbook as one JSON object (a checkout path with a space or = deploys); the loader's refusal keeps op://; a deviation under the two removed requirements is told so and the index names neither; environment files are birth-only; in CI a run with secrets and no DEPLOY_VAULT_TOKEN is refused naming the secret; a path holding {{ or {% is refused before anything runs; a run that exits 0 without a Result line is a failure (test added); DEFAULT_ENVIRONMENT is gone.

Verification

mise run e2e whole: exit 0, 198 pass. TURBO_FORCE=true mise run test: exit 0. Proof outside the suite: built plx in a scratch repo, deployed against this machine's Docker with an op stand-in: deployed, then unchanged on rerun, a stack without the file skipped, a bad host refused, --inventory rejected as unknown.


PLX-298

What it does

The stack playbook applies one environment of a stack from its environment's file:

  1. Where it runs, it checks the file, reads each op:// pointer under secrets with op read under a timeout, and adds the host that host names.
  2. Where the environment has a hostname, it takes the lock /opt/stacks/.lock, which a second deploy waits for.
    Under the lock, it refuses a hostname that another environment's fragment serves.
    It keeps the port that the environment's .env names, or else takes the lowest port of stack_port_range (20000-20999) that no other .env or fragment names and nothing on the host listens on.
    It writes /etc/caddy/stacks/<stack>-<env>.caddy and reloads the proxy through sudo -n /usr/bin/systemctl reload caddy, only when the fragment's text changed.
    Where the proxy refuses the reload, it puts the fragment back and gives caddy validate's reason.
  3. It creates /opt/stacks/<stack>-<env>/ with mode 0750.
    It writes .env from env plus COMPOSE_PROJECT_NAME and PLEXUS_LOOPBACK_PORT.
    It writes .env.secret, mode 0600, from the secrets.
  4. It keeps a .prev of each of .env, .env.secret and compose.yaml that changes, then pulls, migrates and brings the stack up as before.
    A failure restores all three files and brings the previous files up again.
    The route is not rolled back.

No secret's value appears in any output, with -v or --check --diff either.
A run in which nothing changed changes no file, reloads nothing and re-creates no container.

Interface for PLX-299

ansible-playbook plexus.platform.stack \
  -e stack_name=<stack> \
  -e stack_environment_file=<repo>/stack/<environment>.yaml \
  -e stack_compose_file=<rendered compose file>
  • Pass no inventory, no --limit, no --tags or --skip-tags, no -u and no ansible_port.
    The playbook refuses a --limit, --tags or --skip-tags it sees.
    A --limit that leaves out localhost, or --skip-tags always, runs none of its tasks and exits 0 without a Result line.
    The host is the file's host, [user@]address[:port].
    Without a user it connects as plexus_deploy_user (now defaulted to plexus in the deploy_user role); without a port it uses 22.
  • stack_environment is gone.
    The environment is the file's base name, which must match ^[a-z]+\.yaml$.
  • Connection arguments still apply: --ssh-common-args, --private-key, and so on.
  • Where the environment has secrets, op must be on the PATH where the playbook runs, with a session or OP_SERVICE_ACCOUNT_TOKEN.
  • PLEXUS_TAG and PLEXUS_COMMIT_SHA are the caller's: the rendered compose file pins each app's image by digest in place of ${PLEXUS_TAG} and the commit in place of ${PLEXUS_COMMIT_SHA}.
    The playbook writes neither.
  • Otherwise the compose file must reach the playbook uninterpolated.
    ${PLEXUS_LOOPBACK_PORT} and other values are interpolated on the host from .env.
  • The Result line keeps its form.
    A run exits 0 only after a Result line that says deployed, unchanged or would deploy, apart from the two runs of no task above.
    An unreachable host ends the run with Ansible's error and exit code 4.
  • op read gets stack_secret_timeout seconds (default 30) per secret.

Readings

  1. The interface is the path of the environment's file.
    The environment is named after the file, and the playbook takes no inventory.
  2. Ports named in other environments' fragments count as taken, as well as ports named in other directories' .env.
    An existing .env's port is kept even when it lies outside the range.
  3. The port range is 20000-20999.
    That is above the ports hand-picked records use, and below the Linux ephemeral range (32768-60999), so an allocated port never collides with an outbound connection's source port.
  4. When the proxy refuses the reload, route.sh puts the previous fragment back, or removes a new one, and the deploy fails before anything else is written.
  5. A failed first deploy removes its containers and compose.yaml.
    It keeps .env and .env.secret, so the port stays claimed.
  6. .env.secret is written whenever the environment has secrets, or a file is already there.
    When the last secret is dropped, the file ends empty with mode 0600, and the services that loaded it are re-created.
  7. Pull and migrate run only when compose.yaml changed, as before.
    A change of values alone re-creates the affected containers through up.
  8. hostname must be a DNS name and is lowercased.
    It has no wildcard and no port.
    The hostname check is case-insensitive against the addresses that other fragments serve.
  9. plexus_deploy_user has a default, plexus, in deploy_user's defaults.
    The stack playbook reads it from that file.
  10. /opt/stacks is written once, as deploy_user_root in the deploy_user role's vars/main.yml.
    The deploy_user task uses it, and the stack playbook reads that file for stack_root's default, which -e stack_root still overrides.
  11. The lock waits at most 300 seconds.
  12. Values are written double-quoted, with \ " $ and the line breaks and tabs escaped.
    Compose reads them back byte for byte from env_file and for interpolation.
    A secret's trailing newline is kept.
  13. The previous files are kept as .env.prev, .env.secret.prev (0600) and compose.yaml.prev.
    A file the failed run created is removed in the rollback.
  14. The playbook refuses only the two platform names it writes, COMPOSE_PROJECT_NAME and PLEXUS_LOOPBACK_PORT, as names in env or secrets.
    PLEXUS_TAG and PLEXUS_COMMIT_SHA are left to plx doctor.
  15. On a rollback, a service whose configuration changed runs its previous files again in a re-created container.
    Services the run did not touch keep their containers.
  16. An environment whose hostname is removed loses PLEXUS_LOOPBACK_PORT from .env, and its fragment stays.
    A changed hostname rewrites the fragment and keeps the port.
  17. PLX-Stack/PreparedHost was appended by hand to packages/lib/src/standard-index.json, which ship regenerates.
  18. A new port also skips any port something on the host listens on (TCP, IPv4 and IPv6), as /proc/net/tcp and /proc/net/tcp6 list it.
    Every Linux host has these files, so no command is needed.
    This goes beyond the issue's "by reading the .env files".
    It is checked under the lock, only when a port is first taken.
  19. A secret that the vault holds empty is refused.
    The message names the pointer, never a value.
  20. op read is run by the Python that runs Ansible, which kills it after stack_secret_timeout seconds.
    The message names the usual cause, an unlock nobody answers.
  21. When the proxy refuses a reload, the message gives the last Error: line of caddy validate --config /etc/caddy/Caddyfile --adapter caddyfile, run as the deploy user.
    Where that says nothing, the message says only that the proxy refused.
    The legacy apps*.caddy is not parsed: a hostname it serves is refused by the proxy.
  22. The playbook refuses --limit, --tags and --skip-tags.
    Every task is tagged always so that the refusal runs.
  23. The forms of host and hostname end in \Z, so a trailing line break is refused, and the route script's arguments are quoted.

What no test covers

  • An SSH connection to a real host.
    The tests use the local and Docker connections.
    The parsing of host into user, address and port was checked by hand.
  • The real op CLI.
    A stand-in on the PATH is used.
  • The 300-second limit of the lock, and a host without flock.
  • An environment whose hostname is removed, or changed to a free one.
  • Two runs of the same environment at once, which are not supported.
  • A --limit that leaves out localhost, and --skip-tags always: no task runs, and the playbook cannot say so.
  • A host that cannot be reached.

For the release notes

  • The stack playbook takes stack_environment_file, an environment's file, in place of stack_environment and an inventory.
    The host is the file's host.
  • It writes .env and .env.secret itself.
    op:// pointers are resolved where the playbook runs, so op must be available there.
  • It allocates each environment's loopback port from 20000-20999 and keeps it.
    Ports already written in an environment's .env are kept.
  • It writes the environment's route fragment and reloads the proxy only when the fragment changed.
    It refuses a hostname that another environment serves.
  • A failed deploy restores .env and .env.secret together with compose.yaml.
  • deploy_user defaults plexus_deploy_user to plexus.
    A deploy user with another name must be written into the host of each environment's file, as user@address, since a deploy does not read the inventory's value.
  • A port that something on the host already listens on is never handed out.
  • op read times out after stack_secret_timeout seconds (30), and a secret the vault holds empty is refused.

Size

+1130 / -430 lines.
Tests are +529 / -94: 47% of the added lines, and 40% of all changed lines.

🤖 Generated with Claude Code

davidjalbers and others added 23 commits December 6, 2026 04:03
Every case hands the playbook an environment's file instead of a directory
the platform laid out: the playbook creates the directory and writes .env
from `env`, and .env.secret from `secrets` through a stand-in of the vault's
CLI. New cases: values and secrets reach the containers byte for byte and no
secret reaches the output, with -v or --diff; a changed value beside a
rotated secret that breaks the healthcheck ends with the previous .env,
.env.secret, compose.yaml and containers; a secret the vault does not hold;
files the playbook cannot write; a dry run of a new environment.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…er cites; ship regenerates the file at the cut

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The playbook takes the environment's file (stack_environment_file) in place
of the environment's name and an inventory: a first play where it runs reads
the file, refuses one it cannot write faithfully, resolves each pointer under
`secrets` with `op read`, and adds the host `host` names, as the user it names
or plexus_deploy_user, which the role deploy_user now gives a default. On the
host it creates the environment's directory, writes .env from `env` with the
project name and .env.secret from the secrets, each value double-quoted and
escaped so that Compose reads it back as written, keeps the previous copy of
each of the three files that changes, and on a failed deploy restores them
together. No task that holds a secret prints it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
host-image.sh builds what platform-playbook.sh built for itself, with
Docker's CLI and compose plugin and PyYAML added, and Caddy without a site,
so that it listens on nothing until the platform playbook configures it. The
platform playbook's test mounts its stand-in for docker over the CLI; the
stack playbook's test will run the real one against this machine's daemon.

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

A second part runs the playbook against a host the platform playbook
prepared, a container booted with systemd in this machine's network, whose
proxy listens on 127.0.0.1 and ports of the run's own: a first deploy takes
the lowest port of the range and writes the route, which serves the
environment and refuses /healthz; a run in which nothing changed changes no
file and reloads nothing; two first deploys started at once end with
different ports; a hostname another environment serves is refused; a changed
value that breaks the healthcheck is rolled back and its route kept; a port a
directory holds is kept; no free port; a route the proxy refuses; a dry run.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Where the environment has a hostname, files/route.sh runs on the host under
one lock file under /opt/stacks, which a second deploy waits for: it refuses
a hostname another environment's fragment serves, keeps the port the
environment's .env names or takes the lowest of stack_port_range
(20000-20999) that no other .env and no other fragment names, and writes the
route fragment and reloads the proxy only where the fragment's text changes,
putting back what was there where the proxy refuses. .env carries the port as
PLEXUS_LOOPBACK_PORT. A rollback restores the files and leaves the route,
which joins the hostname to a port that does not change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…or a released name as a citation

The maintainer removed path prefixes: a deviation under PLX-Stack/PathPrefix has no meaning the index of an older version could still give it, so the test of released names holds only the renamed one, spelled at run time.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Path prefixes are gone by the maintainer's decision; the requirement's name stays in the index of the last version until the next one is cut, and nothing here cites it.

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

Each stack's file for an environment names its host; the playbook is handed the file and no inventory, user, port or environment name, an environment file with a problem refuses the run before any host, and --inventory is an unknown option.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…ecret, nothing from the vault, no token for a second repo

Setup holds the key in an agent, puts op on the PATH for the playbook that reads the secrets, and reads the vault only to join the overlay; --operations-repo is gone.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…holds the two repository secrets of a deploy

The step of plx deploy holds the read-only vault token, setup holds the deploy key, and no step names an operations repo or an inventory.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…e host the file names, and reads no inventory

The stack playbook gets the file and no inventory, user, port or environment name; a file with a problem refuses the run before any host or registry; --inventory is gone with the operations record the deploy targets read, and deployTargets.ts keeps only the map from a branch to its environment.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…ads nothing from the vault and mints no token for a second repo

It puts op where the stack playbook finds it, reads the vault only to join the overlay, and no longer knows an operations repo: --operations-repo, operations-token and isOperationsRepo are gone.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…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>
@davidjalbers davidjalbers self-assigned this Dec 6, 2026
davidjalbers and others added 6 commits December 6, 2026 05:46
…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>
davidjalbers and others added 12 commits December 6, 2026 06:07
…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>
@davidjalbers
davidjalbers merged commit 61d97da into stacks-2 Dec 6, 2026
2 checks passed
@davidjalbers
davidjalbers deleted the davidjalbers/plx-299-plx-deploy-plx-ci-setup-and-the branch December 6, 2026 06:26
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