Repository navigation
Deploy production on release-* tags - #81
Conversation
Setup needed before a
|
| Secret | Value |
|---|---|
PROD_DEPLOY_SSH_KEY |
Private SSH key for the sudo-capable user |
PROD_DEPLOY_HOST |
user@host for the production box |
PROD_DEPLOY_DOMAIN |
Production FQDN |
PROD_DEPLOY_ACME_EMAIL |
ACME contact |
PROD_DEPLOY_KNOWN_HOSTS |
(optional but recommended) ssh-keyscan <host> output |
These must be repository secrets, not environment-scoped. A caller passes secrets into a reusable workflow from outside any environment context, so environment secrets resolve to empty there. Environment protection rules still work normally.
3. Check where the existing DEPLOY_* secrets live — this can break staging. deploy.yml now runs in a staging environment instead of production. If those secrets are currently scoped to the production environment rather than repo-wide, they will resolve to empty and the staging deploy will fail on the first push to main after merge. The README documents them as repository secrets, so this is probably fine, but it's worth confirming before merge rather than discovering it on a green-looking run.
Also note: if production has required reviewers today, that gate no longer applies to main pushes. That's the intent — approval belongs on production releases — but it is a real change in behaviour. Add reviewers under Settings → Environments → production to gate releases.
4. Production host reachability. The box needs an A and an AAAA record and inbound 80/443. A host with public IPv6 but only a private IPv4 will pass ACME, serve fine over v6, and be invisibly unreachable to IPv4-only clients — and /status/ won't catch it if the prober has v6. Verify from an IPv4-only network before trusting a rollout.
One caveat carried over from the PR body
The ARCH=amd64 build path is untested — there was no Docker daemon available where this was authored. The arm64 path is unchanged from what has been deploying green, and both hosts are intended to stay arm64, so this shouldn't matter in practice. But if anyone ever reaches for amd64, treat it as unproven.
Generated by Claude Code
There was a problem hiding this comment.
Pull request overview
This PR introduces a two-environment deployment model: auto-deploy staging from main, and deploy production only from release-* tags (with a manual rollback path via workflow_dispatch). It also hardens the native deploy scripts/workflows by parameterizing target architecture and verifying the deployed commit on-host after restart.
Changes:
- Add a reusable native deployment workflow (
deploy-native.yml) and refactordeploy.ymlto call it for staging. - Add a production release workflow (
deploy-release.yml) triggered byrelease-*tags (and manualreffor rollback), with build/ship split across hosted + self-hosted runners. - Update native deploy scripts/docs to support
ARCH=arm64|amd64, derive Caddy arch from hostuname -m, and verify/versionreports the shipped commit.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
deploy/native/README.md |
Documents staging vs production deploy model, release/rollback procedure, and arch/reachability guidance. |
deploy/native/deploy.sh |
Adds an arch guard and makes Caddy download arch match the host. |
deploy/native/build.sh |
Adds ARCH knob and threads it through the build container platform selection. |
.github/workflows/deploy.yml |
Switches main deploy to staging and delegates mechanics to the reusable workflow. |
.github/workflows/deploy-release.yml |
New release-tag-driven production deploy workflow (with rollback input). |
.github/workflows/deploy-native.yml |
New reusable workflow implementing build/ship split and post-deploy /version verification. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
9bacf65 to
285cd16
Compare
285cd16 to
b2c87f9
Compare
b2c87f9 to
bbba564
Compare
bbba564 to
cf0101e
Compare
cf0101e to
9393842
Compare
83866be to
f05abcb
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (1)
.github/workflows/deploy-release.yml:108
- On workflow_dispatch, a bare
release-*value forinputs.refis currently passed straight through (inputs.ref || github.ref). If someone creates a moving branch namedrelease-*, Actions checkout can resolve the bare name to that branch rather than a tag, breaking the workflow’s “immutable refs only” guarantee.
To keep the convenience of typing release-… while ensuring it’s treated as a tag, normalize bare release-* inputs to refs/tags/... before passing into the reusable workflow.
arch: arm64
build_runs_on: '"ubuntu-24.04-arm"'
ref: ${{ inputs.ref || github.ref }}
secrets:
Adds a second deployment target driven by release tags. Pushing a `release-*` tag rolls that exact commit out to the production host, and nothing else moves it, so the live revision is always a named point in history rather than whatever last landed on main. Rolling back is re-running the workflow with an earlier tag as the `ref` input — no revert commit and no new tag. Reuses the deploy mechanics staging already runs on, so production inherits the build/ship split, the architecture guard and the post-deploy commit assertion without duplicating any of it. Production ships from the same on-prem runner for the same reason staging does: the host's IPv4 is RFC1918 and no GitHub-hosted runner can route to it. Production takes its own PROD_DEPLOY_* secrets rather than sharing staging's, so a stale value can never point a production rollout at the wrong box. They have to be repository-level: a caller resolves the secrets it passes into a reusable workflow outside any environment context, so environment-scoped ones would arrive empty. The environment's protection rules still apply, which is what makes `production` a usable approval gate. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01R8ZshwKmjD5fZ4Hs9dS6zh
The note said environment-scoped secrets cannot be used at all and must be repository-level. Only half of that holds. A job calling a reusable workflow with `uses:` cannot declare an `environment:`, so secrets referenced in the caller do resolve from repository/organization scope only — that part is right. But the `ship` job inside deploy-native.yml does set `environment:`, and GitHub resolves environment secrets for it, giving them precedence over whatever the caller passed in. So the guidance was not just over-broad, it hid a trap: define a secret at both repository level and on the environment and the environment copy silently wins inside ship, with no indication which one was used. Say that, and keep recommending repository level as the choice the table assumes. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01R8ZshwKmjD5fZ4Hs9dS6zh
…ique runner label The environment-secrets correction landed in the README and the PR body but missed this file's header, which still carried the original wrong claim. Same fix: the caller cannot use environment secrets because a `uses:` job takes no `environment:`, but ship inside deploy-native.yml does set one, so environment secrets resolve there and override what the caller passed. Also narrow ship_runs_on. self-hosted and linux are applied automatically to every Linux self-hosted runner, so the previous pair selected any of them for a production deploy — handing an arbitrary machine the production SSH key and reachability into that network. Requiring an imcp-prod label makes the job queue until the intended runner carries it, which is the safe direction for production to fail. Staging keeps the broad labels for now; it is mid-rollout and narrowing it here would be a separate change to a live path. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01R8ZshwKmjD5fZ4Hs9dS6zh
workflow_dispatch takes `ref` as free text, so dispatching with `main` would put whatever that branch currently points at onto production — the opposite of the property this workflow is built around, that production only ever moves to a named, reproducible point in history. The tag trigger enforces that; the manual path did not. Add a validate-ref job that accepts a release-* tag or a full 40-character commit SHA and rejects anything else, so the rollback path still works (including for a commit that never had a tag cut) while branches and abbreviated SHAs are turned away with the reason. deploy now needs that job. Because validate-ref is skipped on a tag push and a skipped dependency would skip deploy too under the default success() gate, deploy is gated on !failure() && !cancelled() instead — tag pushes proceed, a rejected dispatch ref stops the deploy. Also fix the deploy-native.yml header: it claimed the two callers differ only in environment, runner and architecture, but the release caller also pins an explicit ref. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01R8ZshwKmjD5fZ4Hs9dS6zh
The ref guard rejected two forms that are as immutable as the ones it accepted. refs/tags/release-X names the identical tag as release-X, and is the spelling github.ref uses on a tag push, so the workflow already handles it on the trigger path while the dispatch path turned it away. An uppercase hex SHA resolves to the same commit git-side. Strip only the refs/tags/ prefix and match hex case-insensitively. Stripping refs/tags/ alone is what keeps refs/heads/release-X rejected: with no stripping applied it still does not begin with "release-". Verified, along with refs/heads/main, refs/tags/v1.2.3, abbreviated SHAs, HEAD and empty — all still refused. Also spell both accepted forms out in the workflow_dispatch input description, so the form says what it takes instead of leaving it to a failed run. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01R8ZshwKmjD5fZ4Hs9dS6zh
Today's staging deploy settled both open questions. ARC runner scale sets are selected by name alone and carry none of the default self-hosted/linux/x64 labels, so production's ["self-hosted","linux","imcp-prod"] could never have matched anything — adding an imcp-prod label to a pool would not have helped. And the pods do reach a host on its RFC1918 address: staging shipped and passed the /version assertion from a dind-small pod in runner group dm1, so there is no need for a runner inside the VPC. Point production at '"dind-small"' and record why the label-list form is wrong, since that is the mistake someone would otherwise repeat. Refresh the ship_runs_on input description and the README's guidance for the same reason: both taught the label-list form as the way to select a self-hosted runner. Also drop the "UNCONFIRMED — that is what this is testing" note from staging. It was accurate when written and is not now. Production shipping from a shared pool puts its SSH key on multi-tenant pods. Accepted deliberately for now, noted at the call site; a dedicated scale set is the way to isolate it later. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01R8ZshwKmjD5fZ4Hs9dS6zh
04dc952 to
588c9ef
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
Comments suppressed due to low confidence (1)
.github/workflows/deploy-release.yml:109
- After normalizing
workflow_dispatchrefs invalidate-ref,deployshould consume that normalized output instead of passing the rawinputs.ref. Otherwise the ambiguity (tag vs same-named branch) remains in the actual checkout/build path.
ref: ${{ inputs.ref || github.ref }}
validate-ref checked the input text and then deploy checked out inputs.ref anyway, so the check only made the input look acceptable — it did not make the checkout unambiguous. A bare release-X names a tag and a branch equally well, and a textual test cannot tell them apart, so a branch of that name would have been deployed to production. validate-ref now emits the accepted ref in unambiguous form and deploy consumes that: release-X and refs/tags/release-X both normalize to refs/tags/release-X, which can only resolve to the tag and fails outright if the tag is absent. A full SHA passes through unchanged. Everything previously rejected still is. deploy falls back to github.ref when the output is empty, which is the tag-push path where validate-ref is skipped — github.ref is already refs/tags/release-* there, so both paths check out a fully-qualified tag. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01R8ZshwKmjD5fZ4Hs9dS6zh
validate-ref wrote an input-derived value straight to $GITHUB_OUTPUT. The
workflow_dispatch input is free text and the REST API accepts newlines in it,
so `release-2026-07-27\nref=refs/heads/main` produced two ref= lines, the last
one won, and deploy checked out main while the run's inputs still displayed the
tag. The guard was not merely weakened, it was bypassable while leaving a
misleading record — worse than not having it.
Vet the whole input against a single-line refname character class before
looking at its shape, then run git check-ref-format on the qualified tag. The
character class is matched with bash [[ =~ ]], not grep: grep is line-oriented
and would match a payload's first line and call the whole string good, which is
the same mistake in a different place.
check-ref-format is not belt-and-braces here. It rejects a second bypass of the
same family: release-../../heads/main passes any plausible character class and
refs/tags/release-../../heads/main can path-normalize to refs/heads/main. It
also rejects @{, a trailing .lock, and empty path components.
Verified the injection payload is refused, every previously accepted input still
normalizes as before, and everything previously rejected still is.
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01R8ZshwKmjD5fZ4Hs9dS6zh
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (2)
.github/workflows/deploy-release.yml:90
- The initial validation regex
^[A-Za-z0-9._/-]+$is stricter than git’s tag grammar and thepush.tags: ['release-*']trigger, so a tag that can deploy via tag-push may be impossible to redeploy via workflow_dispatch (rollback). If the goal here is output-injection prevention, it’s sufficient to reject newlines/CRs before writing to $GITHUB_OUTPUT and rely ongit check-ref-formatfor tag syntax.
if [[ ! "$REF" =~ ^[A-Za-z0-9._/-]+$ ]]; then
echo "::error::Refusing the dispatch ref: it must be a single line of [A-Za-z0-9._/-] characters. Pass a release-* tag or a full 40-character commit SHA."
exit 1
fi
.github/workflows/deploy-release.yml:98
if [[ "$ref" =~ ^release-[A-Za-z0-9._/-]+$ ]]rejects some refs that the workflow trigger accepts (e.g. a tag literally namedrelease-, sincerelease-*matches an empty suffix) and needlessly constrains valid tag characters. Since you already rungit check-ref-formatimmediately after, it’s simpler and more consistent to check only therelease-prefix here and let git enforce the actual tag-name rules.
if [[ "$ref" =~ ^release-[A-Za-z0-9._/-]+$ ]]; then
Post-audit merges (#87-#115) that changed user-visible or documented behavior, folded into the README: - II's consent screen requires an explicit access-level choice (Questions only vs Actions & questions); it is not a read-only-by-default opt-out. - Name the connect binding cookie correctly: mcp_connect, not sid, with Secure conditional on an https PUBLIC_URL. - Document the official pages (/privacy-policy, /support, /terms) and the OpenAI domain-verification endpoint with its env-gated 404 behavior (#109, #112, #115). - /version now reports the served II pairings via the instances array (#94). - CWE-674: note the post-parse depth bounds on interface alias chains (#87) and the type-less reply decode/render path (#108). - Companion-control note: percent-encoded slashes/dots in redirect paths are rejected (#107). - Deploy: describe the reference native deployment pipeline (staging tracks main, release-* tags ship production with the binary attached) (#81, #93). Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01TGhwpdTbUqQbR5AiiN8Ljw
Was stacked on #84, which is now merged. Rebased onto
main(which also carries #86 and #88) and retargeted by hand — the auto-retarget originally promised here only fires when the base branch is deleted on merge, andclaude/staging-onprem-runner-d74205was kept. The diff is the release workflow plus its documentation.Summary
Adds a second deployment target driven by release tags. Pushing a
release-*tag rolls that exact commit out to the production host, and nothing else moves it, so the live revision is always a named point in history rather than whatever last landed onmain. Rolling back is re-running the workflow with an earlier tag as therefinput — no revert commit and no new tag.It reuses the deploy mechanics staging already runs on, so production inherits the build/ship split, the architecture guard and the post-deploy commit assertion without duplicating any of it. Production ships from the same pool staging does, for the same reason: the host's IPv4 is RFC1918 and no GitHub-hosted runner can route to it.
Split from #84 deliberately, one variable per merge: #84 proved the ship path on staging, and this adds production now that the path is known good.
Related issues
None. Related work split out rather than folded in here:
deploy-native.ymlto commit SHAs. Open.shipjob checked outinputs.refrather than the commit the build produced, sostatic/andmonitoring/could skew from the binary. Merged.ship_runs_onatdind-small. Merged; this branch does the same for production.Changes
deploy-release.yml:release-*tag → production, with aworkflow_dispatchrefinput for rollback and adeploy-productionconcurrency group.validate-refjob so a manual dispatch can only name something immutable — arelease-*tag (bare orrefs/tags/-qualified) or a full 40-character commit SHA. Branches and abbreviated SHAs are rejected, because deploying one would break the reproducibility this workflow exists to provide. It runs onworkflow_dispatchonly; the tag trigger already constrains the push path.validate-refemits the accepted ref in normalized form anddeployconsumes that output rather than the raw input. Validating the text while checking outinputs.refanyway would only have made the input look acceptable: a barerelease-Xnames a tag and a branch equally well, so a branch of that name could have reached production having passed validation.git check-ref-formaton the qualified tag. Both are load-bearing rather than defensive: the input is free text that the REST API accepts newlines in, so an unvetted value injected extrakey=valuelines into$GITHUB_OUTPUTwhere a secondref=line wins — deploying a branch while the run's inputs still displayed the tag.check-ref-formatseparately rejectsrelease-../../heads/main, which passes any plausible character class and can path-normalize torefs/heads/main.dind-smallscale set by name for the production ship job. An earlier revision used'["self-hosted","linux","imcp-prod"]', which could never have matched: an ARC runner scale set is selected by its name alone and carries none of the defaultself-hosted/linux/x64labels, so no amount of labelling a pool makes a label list resolve. The call site records that, since it is the mistake someone would otherwise repeat.ship_runs_oninput description and the README's guidance for the same reason — both taught the label-list form as the way to select a self-hosted runner.deploy-release.ymlreferences in thedeploy.ymlanddeploy-native.ymlheaders. Ship staging from the on-prem runner over its private address #84 removed them so they would not dangle on a branch that does not add the file; this branch does, so they resolve here.deploy-release.ymlheader — the previous wording was wrong in a way that hid a precedence trap (see below).Testing
ship_runs_onparses as JSON to the bare stringdind-small, the same single-value shapebuild_runs_onalready uses.validate-refexercised end to end, asserting whatdeploywould check out rather than only accept/reject: the$GITHUB_OUTPUTinjection payload,release-../../heads/main,release-x.lock,release-a@{0},release-a b,release-,refs/heads/release-…,main,refs/heads/main,v1.2.3, an abbreviated SHA and an empty string are all refused; bare andrefs/tags/-qualifiedrelease-*tags both normalize torefs/tags/release-*; upper- and lower-case 40-char SHAs pass through unchanged.dind-smallselector, SSH to a private address, and the post-deploy/versionassertion.release-*tag, and the repository has none.cargo build/cargo test/clippy— no Rust source changed.npm test --prefix monitoring/mcp-status— no dashboard code changed; the workflow runs it anyway.Checklist
Required before a release tag will deploy
Merging is safe at any point — nothing deploys until a
release-*tag exists. This gates the tag, not the merge.PROD_DEPLOY_*secrets (SSH_KEY,HOST,DOMAIN,ACME_EMAIL, optionallyKNOWN_HOSTS), set at repository level. A job that calls a reusable workflow withuses:cannot declare anenvironment:, so${{ secrets.* }}in the caller resolves only repository and organization secrets — an environment-scoped secret referenced there arrives empty.The subtlety worth knowing: environment secrets are not unusable, and the name that can hijack these is the inner one.
shipreadssecrets.DEPLOY_SSH_KEYand it setsenvironment:, so a secret namedDEPLOY_SSH_KEYon thestagingorproductionenvironment overrides whatever the caller passed, in both pipelines. DefiningPROD_DEPLOY_SSH_KEYon an environment, by contrast, does nothing at all. Keep both environments free ofDEPLOY_*-named secrets and use them for protection rules only.PROD_DEPLOY_HOSTmust be the host's private address, not the public FQDN — see #102 for why, and #84 for what went wrong when staging got that wrong.Production public path — resolved
Recorded here because the arrangement is not obvious from the repo, and because the failure mode was silent.
The production host sits in a subnet whose route table sends
0.0.0.0/0to a NAT gateway. Its auto-assigned public IPv4 could therefore never receive traffic: the SYN arrives via the internet gateway and the reply is routed to the NAT gateway and dropped. Nothing in the console flags this. The same table routes::/0to a real internet gateway, so the host was reachable over IPv6 the whole time — which is why the endpoint looked healthy from any v6-capable vantage point while being invisible to IPv4-only clients.Fixed by attaching a second network interface in a public subnet (one whose route table sends
0.0.0.0/0to an internet gateway) with an Elastic IP on it, verified reachable from an IPv4-only network. IPv4 now arrives on a different interface than IPv6 previously did; Caddy binds*:80and*:443so it is indifferent. DNS is now a single DNS-onlyArecord pointing at that Elastic IP — proxying was removed because Cloudflare terminates 80 and 443, which prevents Caddy completing TLS-ALPN-01 or HTTP-01, and because its idle-connection timeout and buffering are a poor fit for the long-livedtext/event-streamresponses this transport depends on. Putting it back behind Cloudflare is tracked in #89.That two-interface arrangement later turned out to matter for a second reason: because security groups attach per-interface, the public-facing one could be given a group permitting
80/443only, which is what closed inbound SSH from the internet without touching the deploy path. See #91.Note that a deploy reports success independently of any of this:
Verify deployed versionreadshttp://127.0.0.1:8000/versionover SSH from the host, deliberately, so it proves the app is running and says nothing about public reachability. Verify withcurl -4against the public URL.Generated by Claude Code