Repository navigation
plx deploy, plx-ci setup and the templates read environment files (PLX-299, with PLX-298) - #121
Merged
davidjalbers merged 41 commits intoDec 6, 2026
Conversation
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>
…299-plx-deploy-plx-ci-setup-and-the
…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>
…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>
davidjalbers
deleted the
davidjalbers/plx-299-plx-deploy-plx-ci-setup-and-the
branch
December 6, 2026 06:26
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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-2at cae1f44 and the merge of PLX-298's fix round).PLX-299: what it does
plx deploydeploys, 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--inventoryflag and reads no operations record. A stack without the file is listed asno <env>.yaml; not deployed; a file with problems refuses the whole run before anything is deployed.plx-ci setup deploymints 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, installsopif absent and puts it on the PATH, logs in to the registry, and reads the vault only to join the overlay.on_push, operations repodeploy) no longer check out the operations repo and pass no inventory.stackrendersproduction.yamlandstaging.yamlwithhost,hostname,env,secrets;plx doctorpasses on a newborn.repo-operationsno longer rendersplexus_apps,plexus_up,plexus_deploy_root, and names noappsorsecretstag.PLX-Stack/PathPrefixandPLX-Ingress/PrefixInRecordchecks and citations are removed, as a test-first commit pair of their own.Readings
plx deploystep alone (not throughGITHUB_ENV), asOP_SERVICE_ACCOUNT_TOKEN: ${{ secrets.DEPLOY_VAULT_TOKEN }}.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.stacktemplate renders literalproduction.yamlandstaging.yamlat a birth only (new engine policybirth-only): an update adds none to an existing stack and touches none that exists, as for itscompose.yamland 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 deployedline and the run exits 0, so a person must write the files. The next milestone's declared environments replace the literal names.no fileis new for a stack without the environment's file.host.example.com.isOperationsRepois removed;deployTargets.tskeeps its name but holds only the branch map.PLX-284 and PLX-278
DEPLOY_SSH_KEYstill fails the job, deliberately.Search
grepforplexus_apps,operations-token,operationsRepo,isOperationsRepo,--inventoryover 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
--operations-repotoplx-ci setupbreaks.plx doctorstays green, although every existing stack needs its environment files before its next deploy.<stack>/<environment>.yaml:host,hostname,env,secrets).DEPLOY_SSH_KEYandDEPLOY_VAULT_TOKEN(read-only token of the tenant's vault).<stack>/<environment>.yaml; an operations repo dropsplexus_apps,plexus_up,plexus_deploy_rootfrom its inventory.plx deploy -e <env>from a checkout, a person needsopsigned in to the vault (orOP_SERVICE_ACCOUNT_TOKEN), ssh access to the hosts, and ansible with theplexus.platformcollection.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 keepsop://; 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 noDEPLOY_VAULT_TOKENis 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_ENVIRONMENTis gone.Verification
mise run e2ewhole: exit 0, 198 pass.TURBO_FORCE=true mise run test: exit 0. Proof outside the suite: builtplxin a scratch repo, deployed against this machine's Docker with anopstand-in: deployed, then unchanged on rerun, a stack without the file skipped, a badhostrefused,--inventoryrejected as unknown.PLX-298
What it does
The stack playbook applies one environment of a stack from its environment's file:
op://pointer undersecretswithop readunder a timeout, and adds the host thathostnames./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
.envnames, or else takes the lowest port ofstack_port_range(20000-20999) that no other.envor fragment names and nothing on the host listens on.It writes
/etc/caddy/stacks/<stack>-<env>.caddyand reloads the proxy throughsudo -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./opt/stacks/<stack>-<env>/with mode 0750.It writes
.envfromenvplusCOMPOSE_PROJECT_NAMEandPLEXUS_LOOPBACK_PORT.It writes
.env.secret, mode 0600, from the secrets..prevof each of.env,.env.secretandcompose.yamlthat 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
-vor--check --diffeither.A run in which nothing changed changes no file, reloads nothing and re-creates no container.
Interface for PLX-299
--limit, no--tagsor--skip-tags, no-uand noansible_port.The playbook refuses a
--limit,--tagsor--skip-tagsit sees.A
--limitthat 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 toplexusin thedeploy_userrole); without a port it uses 22.stack_environmentis gone.The environment is the file's base name, which must match
^[a-z]+\.yaml$.--ssh-common-args,--private-key, and so on.opmust be on the PATH where the playbook runs, with a session orOP_SERVICE_ACCOUNT_TOKEN.PLEXUS_TAGandPLEXUS_COMMIT_SHAare 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.
${PLEXUS_LOOPBACK_PORT}and other values are interpolated on the host from.env.Resultline 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 readgetsstack_secret_timeoutseconds (default 30) per secret.Readings
The environment is named after the file, and the playbook takes no inventory.
.env.An existing
.env's port is kept even when it lies outside the range.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.
route.shputs the previous fragment back, or removes a new one, and the deploy fails before anything else is written.compose.yaml.It keeps
.envand.env.secret, so the port stays claimed..env.secretis 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.
compose.yamlchanged, as before.A change of values alone re-creates the affected containers through
up.hostnamemust 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.
plexus_deploy_userhas a default,plexus, indeploy_user's defaults.The stack playbook reads it from that file.
/opt/stacksis written once, asdeploy_user_rootin thedeploy_userrole'svars/main.yml.The deploy_user task uses it, and the stack playbook reads that file for
stack_root's default, which-e stack_rootstill overrides.\ " $and the line breaks and tabs escaped.Compose reads them back byte for byte from
env_fileand for interpolation.A secret's trailing newline is kept.
.env.prev,.env.secret.prev(0600) andcompose.yaml.prev.A file the failed run created is removed in the rollback.
COMPOSE_PROJECT_NAMEandPLEXUS_LOOPBACK_PORT, as names inenvorsecrets.PLEXUS_TAGandPLEXUS_COMMIT_SHAare left toplx doctor.Services the run did not touch keep their containers.
PLEXUS_LOOPBACK_PORTfrom.env, and its fragment stays.A changed hostname rewrites the fragment and keeps the port.
PLX-Stack/PreparedHostwas appended by hand topackages/lib/src/standard-index.json, whichshipregenerates./proc/net/tcpand/proc/net/tcp6list it.Every Linux host has these files, so no command is needed.
This goes beyond the issue's "by reading the
.envfiles".It is checked under the lock, only when a port is first taken.
The message names the pointer, never a value.
op readis run by the Python that runs Ansible, which kills it afterstack_secret_timeoutseconds.The message names the usual cause, an unlock nobody answers.
Error:line ofcaddy 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*.caddyis not parsed: a hostname it serves is refused by the proxy.--limit,--tagsand--skip-tags.Every task is tagged
alwaysso that the refusal runs.hostandhostnameend in\Z, so a trailing line break is refused, and the route script's arguments are quoted.What no test covers
The tests use the local and Docker connections.
The parsing of
hostinto user, address and port was checked by hand.opCLI.A stand-in on the PATH is used.
flock.--limitthat leaves out localhost, and--skip-tags always: no task runs, and the playbook cannot say so.For the release notes
stack_environment_file, an environment's file, in place ofstack_environmentand an inventory.The host is the file's
host..envand.env.secretitself.op://pointers are resolved where the playbook runs, soopmust be available there.Ports already written in an environment's
.envare kept.It refuses a hostname that another environment serves.
.envand.env.secrettogether withcompose.yaml.deploy_userdefaultsplexus_deploy_usertoplexus.A deploy user with another name must be written into the
hostof each environment's file, asuser@address, since a deploy does not read the inventory's value.op readtimes out afterstack_secret_timeoutseconds (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