@zabaca/zbc 0.18.0 → 0.19.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/templates/apps/walgit/CONTEXT.md +5 -1
- package/templates/apps/walgit/shared/container-env.ts +81 -0
- package/templates/apps/walgit/shared/landing.ts +575 -168
- package/templates/apps/walgit/shared/llms.ts +25 -3
- package/templates/apps/walgit/src/proposals.ts +47 -11
- package/templates/apps/walgit/src/signers.ts +44 -3
- package/templates/apps/walgit/worker/index.ts +43 -37
- package/templates/infra/modules/cloudflare/index.ts +106 -6
|
@@ -600,10 +600,32 @@ landed — and leaves the field out when it landed none.
|
|
|
600
600
|
|
|
601
601
|
`
|
|
602
602
|
: ''
|
|
603
|
-
}
|
|
603
|
+
}### Ask to be added to a name
|
|
604
|
+
|
|
605
|
+
The Signer List is a target like a branch, and it is the only way to ask for a
|
|
606
|
+
name you are not listed on. Propose the list itself, with your fingerprint line
|
|
607
|
+
added to its \`signers\` file:
|
|
608
|
+
|
|
609
|
+
\`\`\`sh
|
|
610
|
+
git fetch -q https://${host}/$NAME.git refs/walgit/signers
|
|
611
|
+
git checkout -q -B ask FETCH_HEAD
|
|
612
|
+
ssh-keygen -lf $HOME/.ssh/id_ed25519.pub | awk '{print $2}' >> signers
|
|
613
|
+
git add signers && git -c user.email=agent@localhost -c user.name=agent commit -qm ask
|
|
614
|
+
git push --signed=yes https://${host}/$NAME.git HEAD:refs/walgit/proposals/walgit/signers/add-me
|
|
615
|
+
\`\`\`
|
|
616
|
+
|
|
617
|
+
\`walgit/signers\` is the target — the ref with \`refs/\` dropped — and \`add-me\` is
|
|
618
|
+
your own word for the request, as an id always is. It is the one target that is
|
|
619
|
+
not a branch, and every other rule above is unchanged: it is held under
|
|
620
|
+
\`refs/walgit/proposals/\` and moves nothing. \`refs/walgit/signers\` is still
|
|
621
|
+
written only by a key the list already names, so the list changes when a Signer
|
|
622
|
+
accepts your Proposal and not before — and once it has, your next push is judged
|
|
623
|
+
by the list it installed.
|
|
624
|
+
|
|
625
|
+
A Proposal is a push like any other: it is signed, it is append-only, it counts
|
|
604
626
|
against the name's size caps, and it cannot be deleted or withdrawn. A target
|
|
605
|
-
that does not exist, a target that is
|
|
606
|
-
commit are refused before anything is stored.
|
|
627
|
+
that does not exist, a target that is neither a branch nor the Signer List, and
|
|
628
|
+
a tip that is not a commit are refused before anything is stored.
|
|
607
629
|
`
|
|
608
630
|
: ''
|
|
609
631
|
|
|
@@ -3,8 +3,9 @@
|
|
|
3
3
|
* List (docs/adr/0018).
|
|
4
4
|
*
|
|
5
5
|
* A Proposal is a ref under `refs/walgit/proposals/<target>/<id>` naming a
|
|
6
|
-
* commit its pusher wants in `refs/heads/<target
|
|
7
|
-
*
|
|
6
|
+
* commit its pusher wants in `refs/heads/<target>` — or in `refs/walgit/signers`,
|
|
7
|
+
* the one non-branch target, which is how a stranger asks to be listed — plus
|
|
8
|
+
* the Push Certificate behind it, and nothing else. There is no record, no row and no file: whether
|
|
8
9
|
* it is Merged is `merge-base --is-ancestor` against the target, computed on
|
|
9
10
|
* read from the Cache and never written down.
|
|
10
11
|
*
|
|
@@ -36,7 +37,7 @@
|
|
|
36
37
|
*/
|
|
37
38
|
|
|
38
39
|
import { flagEnabled } from '../shared/policy'
|
|
39
|
-
import { ZERO_OID } from '../shared/protocol'
|
|
40
|
+
import { SIGNERS_REF, ZERO_OID } from '../shared/protocol'
|
|
40
41
|
import { git } from './git'
|
|
41
42
|
import type { Provenance, RefChange } from './wal-index'
|
|
42
43
|
|
|
@@ -51,11 +52,40 @@ export function proposalsEnabled(env: Record<string, string | undefined> = proce
|
|
|
51
52
|
*/
|
|
52
53
|
export const PROPOSALS_PREFIX = 'refs/walgit/proposals/'
|
|
53
54
|
|
|
54
|
-
/**
|
|
55
|
-
|
|
55
|
+
/**
|
|
56
|
+
* The one target that is not a branch: the Signer List itself (docs/adr/0018).
|
|
57
|
+
*
|
|
58
|
+
* A stranger who may read a claimed name has nothing it can DO about not being
|
|
59
|
+
* listed — the refusal could only tell it what somebody else must push. So the
|
|
60
|
+
* list is proposable like a branch: the stranger pushes the `signers` file with
|
|
61
|
+
* its own fingerprint line added, and a Signer accepts it. The invariant is
|
|
62
|
+
* untouched, because a Proposal moves nothing: `refs/walgit/signers` is still
|
|
63
|
+
* only ever written by a listed key's push.
|
|
64
|
+
*
|
|
65
|
+
* The spelling is the ref with `refs/` dropped, which is the cheapest thing it
|
|
66
|
+
* could be: the id is still the last segment, the "no target begins with
|
|
67
|
+
* `refs/`" refusal is untouched, and `ls-remote` still shows the target without
|
|
68
|
+
* anything being fetched.
|
|
69
|
+
*/
|
|
70
|
+
export const SIGNERS_TARGET = 'walgit/signers'
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* The ref a Proposal wants its commit in.
|
|
74
|
+
*
|
|
75
|
+
* `refs/heads/<target>` for every target but one, and the exception is exact:
|
|
76
|
+
* `walgit/signers/deeper` is an ordinary branch name and is resolved as one, so
|
|
77
|
+
* the Signer List cannot be reached by a target that merely starts with its
|
|
78
|
+
* spelling.
|
|
79
|
+
*/
|
|
80
|
+
export const targetRef = (target: string): string =>
|
|
81
|
+
target === SIGNERS_TARGET ? SIGNERS_REF : `refs/heads/${target}`
|
|
56
82
|
|
|
57
83
|
export interface Proposal {
|
|
58
|
-
/**
|
|
84
|
+
/**
|
|
85
|
+
* What this Proposal is for: a branch WITHOUT its `refs/heads/` prefix, or
|
|
86
|
+
* `walgit/signers` for the Signer List. `targetRef` is the one place that
|
|
87
|
+
* knows which.
|
|
88
|
+
*/
|
|
59
89
|
target: string
|
|
60
90
|
/** The pusher's word. The host assigns nothing and collisions are refused. */
|
|
61
91
|
id: string
|
|
@@ -121,9 +151,11 @@ export function gitObjectType(gitDir: string): (oid: string) => string | null {
|
|
|
121
151
|
export type ProposalRefusal =
|
|
122
152
|
/** The ref is in the namespace and names no `<target>/<id>`. */
|
|
123
153
|
| 'grammar'
|
|
124
|
-
/** `refs/heads/<target
|
|
154
|
+
/** The target's ref — `refs/heads/<target>`, or the Signer List — is not one
|
|
155
|
+
* this repository holds. */
|
|
125
156
|
| 'missing-target'
|
|
126
|
-
/** The target is
|
|
157
|
+
/** The target is neither a branch nor `walgit/signers`: it names something
|
|
158
|
+
* outside `refs/heads/`. */
|
|
127
159
|
| 'not-a-branch'
|
|
128
160
|
/** The tip is a tree, a blob, a tag, or an object the host cannot see. */
|
|
129
161
|
| 'not-a-commit'
|
|
@@ -162,7 +194,7 @@ export function checkProposalRefs(
|
|
|
162
194
|
repoId,
|
|
163
195
|
'not-a-branch',
|
|
164
196
|
change.ref,
|
|
165
|
-
`its target \`${proposal.target}\` is not a branch — a Proposal names one under refs/heads
|
|
197
|
+
`its target \`${proposal.target}\` is not a branch — a Proposal names one under refs/heads/, or \`${SIGNERS_TARGET}\` for the Signer List`,
|
|
166
198
|
)
|
|
167
199
|
}
|
|
168
200
|
|
|
@@ -206,13 +238,17 @@ function rejectionMessage(repoId: string, ref: string, why: string): string {
|
|
|
206
238
|
return [
|
|
207
239
|
`walgit: refused — ${ref} is not a Proposal ${repoId} can hold: ${why}.`,
|
|
208
240
|
'',
|
|
209
|
-
'A Proposal is a ref naming the commit you want in
|
|
241
|
+
'A Proposal is a ref naming the commit you want in a branch that already',
|
|
242
|
+
"exists here — or in this name's Signer List:",
|
|
210
243
|
'',
|
|
211
244
|
` git push --signed=yes origin HEAD:${PROPOSALS_PREFIX}<branch>/<your-id>`,
|
|
212
245
|
'',
|
|
213
246
|
'The branch is the one you want it merged into and must already exist here;',
|
|
214
247
|
'the id is your own word for this change, and a taken one is refused as a',
|
|
215
|
-
'non-fast-forward, so pick another.
|
|
248
|
+
'non-fast-forward, so pick another. To ask to be added to this name instead,',
|
|
249
|
+
`propose its Signer List: the same push with \`${SIGNERS_TARGET}\` where the branch`,
|
|
250
|
+
`goes, carrying ${SIGNERS_REF}'s \`signers\` file with your fingerprint added.`,
|
|
251
|
+
'Refs here are append-only like every',
|
|
216
252
|
'other, which is why a Proposal is judged before it is stored rather than',
|
|
217
253
|
'after.',
|
|
218
254
|
'',
|
|
@@ -51,7 +51,7 @@ import { SIGNERS_REF, ZERO_OID } from '../shared/protocol'
|
|
|
51
51
|
import { suggestName } from './append-only'
|
|
52
52
|
import { git } from './git'
|
|
53
53
|
import { readAllowed } from './private'
|
|
54
|
-
import { isProposalRef } from './proposals'
|
|
54
|
+
import { PROPOSALS_PREFIX, SIGNERS_TARGET, isProposalRef } from './proposals'
|
|
55
55
|
import { certificatePresented, signedPushEnabled, type PushCertEnv } from './push-cert'
|
|
56
56
|
import type { RefChange } from './wal-index'
|
|
57
57
|
|
|
@@ -602,10 +602,26 @@ function mayPropose(
|
|
|
602
602
|
claimed: readonly string[],
|
|
603
603
|
changes: readonly RefChange[],
|
|
604
604
|
proposals: ProposalGate,
|
|
605
|
+
): boolean {
|
|
606
|
+
if (changes.length === 0 || !changes.every((c) => isProposalRef(c.ref))) return false
|
|
607
|
+
return proposalsOpenTo(signer, claimed, proposals)
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
/**
|
|
611
|
+
* The same three conditions minus the refs, so the refusal can ask whether this
|
|
612
|
+
* pusher has the Proposal door at all before offering it one.
|
|
613
|
+
*
|
|
614
|
+
* Split rather than duplicated: a remedy naming a door this deployment does not
|
|
615
|
+
* open, or one this key would be refused at, is worse than the terse remedy it
|
|
616
|
+
* replaces — an agent acts on it and is refused a second time.
|
|
617
|
+
*/
|
|
618
|
+
function proposalsOpenTo(
|
|
619
|
+
signer: PushSigner,
|
|
620
|
+
claimed: readonly string[],
|
|
621
|
+
proposals: ProposalGate,
|
|
605
622
|
): boolean {
|
|
606
623
|
if (!proposals.enabled) return false
|
|
607
624
|
if (signer.kind !== 'signed') return false
|
|
608
|
-
if (changes.length === 0 || !changes.every((c) => isProposalRef(c.ref))) return false
|
|
609
625
|
return readAllowed({
|
|
610
626
|
enabled: proposals.privateRepos,
|
|
611
627
|
claim: {
|
|
@@ -676,7 +692,13 @@ export function checkSignerAllowed(
|
|
|
676
692
|
return {
|
|
677
693
|
ok: false,
|
|
678
694
|
kind: signer.kind === 'signed' ? 'not-listed' : signer.kind,
|
|
679
|
-
message: heldMessage(
|
|
695
|
+
message: heldMessage(
|
|
696
|
+
repoId,
|
|
697
|
+
signer,
|
|
698
|
+
changes,
|
|
699
|
+
stage,
|
|
700
|
+
proposalsOpenTo(signer, claimed, proposals),
|
|
701
|
+
),
|
|
680
702
|
}
|
|
681
703
|
}
|
|
682
704
|
|
|
@@ -689,12 +711,20 @@ export function checkSignerAllowed(
|
|
|
689
711
|
* (docs/adr/0012). So this says three things and an agent can act on each: the
|
|
690
712
|
* name is held, here is a free one to use instead, and here is how to be added
|
|
691
713
|
* to this one.
|
|
714
|
+
*
|
|
715
|
+
* `canPropose` decides whether the third of those is something the READER can
|
|
716
|
+
* do or only something somebody else can. Where Proposals are open to this key
|
|
717
|
+
* (docs/adr/0018), the remedy leads with proposing the Signer List — the one
|
|
718
|
+
* remedy a stranger can act on alone — and keeps the grant recipe under it,
|
|
719
|
+
* because the grant is still what lands. Where they are not, the line is left
|
|
720
|
+
* out entirely: a door that 404s is worse than the terse remedy it replaces.
|
|
692
721
|
*/
|
|
693
722
|
function heldMessage(
|
|
694
723
|
repoId: string,
|
|
695
724
|
signer: PushSigner,
|
|
696
725
|
changes: readonly RefChange[],
|
|
697
726
|
stage: GateStage,
|
|
727
|
+
canPropose: boolean,
|
|
698
728
|
): string {
|
|
699
729
|
const why =
|
|
700
730
|
signer.kind === 'signed'
|
|
@@ -755,6 +785,17 @@ function heldMessage(
|
|
|
755
785
|
'',
|
|
756
786
|
'What you can do instead:',
|
|
757
787
|
` - push to a free name: git remote set-url origin <same-host>/${suggestName(repoId)}.git`,
|
|
788
|
+
...(canPropose
|
|
789
|
+
? [
|
|
790
|
+
" - or ask to be added, yourself: propose this name's Signer List — commit",
|
|
791
|
+
` ${SIGNERS_REF}'s \`signers\` file with the line \`ssh-keygen -lf <your-key>\``,
|
|
792
|
+
' prints added, and push it as a Proposal:',
|
|
793
|
+
'',
|
|
794
|
+
` git push --signed=yes origin HEAD:${PROPOSALS_PREFIX}${SIGNERS_TARGET}/<your-id>`,
|
|
795
|
+
'',
|
|
796
|
+
' That moves nothing: it is held until a listed key merges it.',
|
|
797
|
+
]
|
|
798
|
+
: []),
|
|
758
799
|
` - or be added to this one: a listed key pushes a commit on ${SIGNERS_REF}`,
|
|
759
800
|
' whose `signers` file gains the line `ssh-keygen -lf <your-key>` prints.',
|
|
760
801
|
' A grant governs the NEXT push, so retry once theirs has landed.',
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
import { Container, getContainer } from '@cloudflare/containers'
|
|
29
29
|
|
|
30
30
|
import { capabilitiesFrom, type Capabilities } from '../shared/capabilities'
|
|
31
|
-
import { containerEnv, fingerprintEnv } from '../shared/container-env'
|
|
31
|
+
import { containerEnv, fingerprintEnv, reconcileContainerEnv } from '../shared/container-env'
|
|
32
32
|
import { parseTokens } from '../shared/credentials'
|
|
33
33
|
import { authorizeAnnounce, authorizeSubscribe } from '../shared/events'
|
|
34
34
|
import { renderLanding, wantsLanding } from '../shared/landing'
|
|
@@ -54,6 +54,15 @@ import { BROADCAST_PATH, EVENTS_OBJECT_NAME, WalgitEvents } from './events-do'
|
|
|
54
54
|
|
|
55
55
|
export interface Env {
|
|
56
56
|
WALGIT_CONTAINER: DurableObjectNamespace<WalgitContainer>
|
|
57
|
+
/**
|
|
58
|
+
* The commit this Worker was deployed from, set by the cloudflare module's
|
|
59
|
+
* `deployIdVar`. Nothing reads it: it exists so that a deploy which changes
|
|
60
|
+
* only the container image still changes the environment the container is
|
|
61
|
+
* fingerprinted on, and `reconcileEnv` below replaces the running container
|
|
62
|
+
* (shared/container-env.ts). Absent on a deployment that does not set
|
|
63
|
+
* `deployIdVar`, which then behaves exactly as before.
|
|
64
|
+
*/
|
|
65
|
+
WALGIT_BUILD_ID?: string
|
|
57
66
|
/** Comma-separated bearer tokens; git sends one as the Basic-auth password. */
|
|
58
67
|
WALGIT_HTTP_TOKENS?: string
|
|
59
68
|
/** The write-ahead log's home — see src/store-env.ts. */
|
|
@@ -190,51 +199,48 @@ export class WalgitContainer extends Container<Env> {
|
|
|
190
199
|
}
|
|
191
200
|
|
|
192
201
|
/**
|
|
193
|
-
*
|
|
202
|
+
* Bind this Durable Object to `reconcileContainerEnv`'s rules.
|
|
194
203
|
*
|
|
195
|
-
*
|
|
196
|
-
*
|
|
197
|
-
* container
|
|
198
|
-
*
|
|
199
|
-
*
|
|
200
|
-
* takes effect whenever the container next happens to idle out, which under
|
|
201
|
-
* sustained traffic is never.
|
|
202
|
-
*
|
|
203
|
-
* The fingerprint is persisted in Durable Object storage because that is the
|
|
204
|
-
* only state that survives the very event being detected — a redeploy
|
|
205
|
-
* discards every in-memory field, so an in-memory copy would compare the new
|
|
206
|
-
* environment against itself and always agree.
|
|
204
|
+
* The decision — and the two orderings that matter, no-record-is-a-mismatch
|
|
205
|
+
* and record-only-after-a-successful-destroy — lives in
|
|
206
|
+
* `shared/container-env.ts`, where it can be tested without a Workers
|
|
207
|
+
* runtime. What is left here is exactly the three things only this side can
|
|
208
|
+
* do: reach the container, reach Durable Object storage, and log.
|
|
207
209
|
*/
|
|
208
210
|
private async reconcileEnv(): Promise<void> {
|
|
209
211
|
const current = fingerprintEnv(this.envVars ?? {})
|
|
210
|
-
|
|
211
|
-
|
|
212
|
+
let booted: string | undefined
|
|
213
|
+
// Captured so the port's getter below reads `this` Durable Object's state
|
|
214
|
+
// rather than the object literal's.
|
|
215
|
+
const state = this.ctx
|
|
216
|
+
|
|
217
|
+
const outcome = await reconcileContainerEnv(
|
|
218
|
+
{
|
|
219
|
+
// A getter, not a snapshot: it is read after the storage lookup above
|
|
220
|
+
// it, exactly where the original code read it.
|
|
221
|
+
get running() {
|
|
222
|
+
return state.container?.running ?? false
|
|
223
|
+
},
|
|
224
|
+
read: async () => {
|
|
225
|
+
booted = await state.storage.get<string>(ENV_FINGERPRINT_KEY)
|
|
226
|
+
return booted
|
|
227
|
+
},
|
|
228
|
+
// SIGKILL rather than a graceful stop: the container serves git over
|
|
229
|
+
// HTTP and holds nothing worth draining — every durable effect of a
|
|
230
|
+
// push is in the log before it is acknowledged (docs/adr/0007) — and
|
|
231
|
+
// `sleepAfter` already covers the polite path. `destroy` triggers
|
|
232
|
+
// `onStop`; the next `containerFetch` starts a fresh one.
|
|
233
|
+
destroy: () => this.destroy(),
|
|
234
|
+
write: (fingerprint) => state.storage.put(ENV_FINGERPRINT_KEY, fingerprint),
|
|
235
|
+
},
|
|
236
|
+
current,
|
|
237
|
+
)
|
|
212
238
|
|
|
213
|
-
|
|
214
|
-
// replace: its next start reads `envVars` as it now is, which is already
|
|
215
|
-
// the new environment.
|
|
216
|
-
//
|
|
217
|
-
// No recorded fingerprint counts as a mismatch rather than as a fresh
|
|
218
|
-
// start, deliberately. A running container with no record predates this
|
|
219
|
-
// code, so what it booted with is unknowable — and on the deploy that
|
|
220
|
-
// ships this, that container is exactly the one already serving a
|
|
221
|
-
// superseded policy. Assuming it is current would leave the bug live
|
|
222
|
-
// until the next idle. A DO that has never started a container reaches
|
|
223
|
-
// here with `running` false and simply records.
|
|
224
|
-
if (this.ctx.container?.running) {
|
|
225
|
-
// SIGKILL rather than a graceful stop: the container serves git over
|
|
226
|
-
// HTTP and holds nothing worth draining — every durable effect of a push
|
|
227
|
-
// is in the log before it is acknowledged (docs/adr/0007) — and
|
|
228
|
-
// `sleepAfter` already covers the polite path. `destroy` triggers
|
|
229
|
-
// `onStop`; the next `containerFetch` starts a fresh one.
|
|
230
|
-
await this.destroy()
|
|
239
|
+
if (outcome === 'replaced') {
|
|
231
240
|
console.log(
|
|
232
241
|
`walgit container env changed (${booted ?? 'unrecorded'} -> ${current}); container replaced`,
|
|
233
242
|
)
|
|
234
243
|
}
|
|
235
|
-
// Written last, and only after a successful destroy: recording first would
|
|
236
|
-
// make a failed replacement look reconciled forever.
|
|
237
|
-
await this.ctx.storage.put(ENV_FINGERPRINT_KEY, current)
|
|
238
244
|
}
|
|
239
245
|
|
|
240
246
|
async fetch(request: Request): Promise<Response> {
|
|
@@ -86,6 +86,52 @@ function wrangler(workdir: string, args: string[], env: NodeJS.ProcessEnv, input
|
|
|
86
86
|
return combined
|
|
87
87
|
}
|
|
88
88
|
|
|
89
|
+
/**
|
|
90
|
+
* Which deploy this is, as a value the deployed code can be told.
|
|
91
|
+
*
|
|
92
|
+
* `GITHUB_SHA` in CI, `git rev-parse HEAD` locally. A dirty working tree gets a
|
|
93
|
+
* distinct id rather than the bare commit: a local apply builds the image from
|
|
94
|
+
* the working tree, so the same commit with edits is a different image, and
|
|
95
|
+
* handing it the commit's id would be the staleness this exists to prevent. The
|
|
96
|
+
* timestamp makes each such apply its own deploy, which is the honest answer
|
|
97
|
+
* when the content is whatever happened to be on disk.
|
|
98
|
+
*
|
|
99
|
+
* Absence is a hard error rather than a silent skip — see `deployIdVar`.
|
|
100
|
+
*/
|
|
101
|
+
function resolveDeployId(projectRoot: string, varName: string): string {
|
|
102
|
+
const fromCi = process.env.GITHUB_SHA?.trim()
|
|
103
|
+
if (fromCi) return fromCi
|
|
104
|
+
|
|
105
|
+
let head: string
|
|
106
|
+
try {
|
|
107
|
+
head = execSync('git rev-parse HEAD', {
|
|
108
|
+
cwd: projectRoot,
|
|
109
|
+
encoding: 'utf8',
|
|
110
|
+
stdio: ['ignore', 'pipe', 'ignore'],
|
|
111
|
+
}).trim()
|
|
112
|
+
} catch {
|
|
113
|
+
throw new Error(
|
|
114
|
+
`deployIdVar is set (${varName}) but this deploy has no id: GITHUB_SHA is unset and \`git rev-parse HEAD\` failed in ${projectRoot}. ` +
|
|
115
|
+
`Deploy from CI, from a git checkout, or drop deployIdVar.`,
|
|
116
|
+
)
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
let dirty = false
|
|
120
|
+
try {
|
|
121
|
+
dirty =
|
|
122
|
+
execSync('git status --porcelain', {
|
|
123
|
+
cwd: projectRoot,
|
|
124
|
+
encoding: 'utf8',
|
|
125
|
+
stdio: ['ignore', 'pipe', 'ignore'],
|
|
126
|
+
}).trim() !== ''
|
|
127
|
+
} catch {
|
|
128
|
+
// A repository whose status cannot be read still has a HEAD worth
|
|
129
|
+
// reporting; treating that as clean is the same answer as before this
|
|
130
|
+
// check existed.
|
|
131
|
+
}
|
|
132
|
+
return dirty ? `${head}-dirty-${Date.now()}` : head
|
|
133
|
+
}
|
|
134
|
+
|
|
89
135
|
const buildSchema = z.object({
|
|
90
136
|
command: z.string(),
|
|
91
137
|
cwd: z.string().optional(),
|
|
@@ -475,12 +521,55 @@ export const cloudflareModule = defineModule({
|
|
|
475
521
|
*/
|
|
476
522
|
bindings: z.array(bindingSchema).default([]),
|
|
477
523
|
/**
|
|
478
|
-
*
|
|
479
|
-
*
|
|
480
|
-
*
|
|
481
|
-
*
|
|
482
|
-
*
|
|
483
|
-
*
|
|
524
|
+
* Name a Worker var after the deploy itself: the deployed commit
|
|
525
|
+
* (`GITHUB_SHA` in CI, `git rev-parse HEAD` locally, `<sha>-dirty-<ms>` on
|
|
526
|
+
* a working tree with changes), passed as `--var <name>:<id>` like any
|
|
527
|
+
* other var. Unset — the default — injects nothing.
|
|
528
|
+
*
|
|
529
|
+
* It is worth a key of its own because a var is the ONLY channel a Worker
|
|
530
|
+
* has for telling a container-backed payload that a deploy happened at all.
|
|
531
|
+
* `immediateContainerRollout` below rolls the container application to the
|
|
532
|
+
* new image and does not replace a running instance; a payload that reacts
|
|
533
|
+
* to its environment (walgit fingerprints it in a Durable Object and
|
|
534
|
+
* destroys the container when it moves) has nothing to react to when a
|
|
535
|
+
* deploy changed only code. This gives it something: every deploy from a
|
|
536
|
+
* new commit changes this value, and no deploy from the same commit does.
|
|
537
|
+
*
|
|
538
|
+
* Also the only place the deployed commit is written down — Cloudflare
|
|
539
|
+
* numbers container versions itself (v50, v51) and nothing else in a deploy
|
|
540
|
+
* names the code inside one.
|
|
541
|
+
*
|
|
542
|
+
* A var, so never a secret: it is a commit id, visible in the dashboard
|
|
543
|
+
* beside every other var, which is half the point.
|
|
544
|
+
*
|
|
545
|
+
* A HARD ERROR when no id can be resolved (not CI, not a git checkout).
|
|
546
|
+
* Silently omitting it would deploy the payload with no deploy marker,
|
|
547
|
+
* which is exactly the invisible staleness the key exists to prevent. An
|
|
548
|
+
* entry of the same name in `workerVars` takes precedence — the instance
|
|
549
|
+
* pinning a value outranks the module deriving one.
|
|
550
|
+
*/
|
|
551
|
+
deployIdVar: z.string().optional(),
|
|
552
|
+
/**
|
|
553
|
+
* For container-backed Workers: roll the CONTAINER APPLICATION to the new
|
|
554
|
+
* image on deploy (`--containers-rollout immediate`) instead of wrangler's
|
|
555
|
+
* gradual default. Set true whenever the image matters at deploy time.
|
|
556
|
+
* No-op for asset-only Workers.
|
|
557
|
+
*
|
|
558
|
+
* WHAT IT DOES NOT DO — and the reason this paragraph exists — is replace a
|
|
559
|
+
* RUNNING instance. It rolls the application to a new version; a single
|
|
560
|
+
* always-warm, DO-bound instance is not drained by that rollout, and keeps
|
|
561
|
+
* serving the old image until it idle-sleeps, which under sustained traffic
|
|
562
|
+
* is never. Observed on walgit's 0.16.1 deploy (2026-09-14): the
|
|
563
|
+
* application moved to v51 with a new image, the rollout reported
|
|
564
|
+
* `completed`, and the instance answering git was the one started an hour
|
|
565
|
+
* earlier — the fix in that release was not live.
|
|
566
|
+
*
|
|
567
|
+
* It also has nothing to roll for a deploy that changes only vars: no new
|
|
568
|
+
* image, no new container version.
|
|
569
|
+
*
|
|
570
|
+
* So it is necessary and not sufficient. Replacing a running instance is
|
|
571
|
+
* the payload's own job, and `deployIdVar` above is what lets it know it
|
|
572
|
+
* has one to do.
|
|
484
573
|
*/
|
|
485
574
|
immediateContainerRollout: z.boolean().default(false),
|
|
486
575
|
/**
|
|
@@ -572,6 +661,17 @@ export const cloudflareModule = defineModule({
|
|
|
572
661
|
const resolvedVars = config.workerVars.map((entry) =>
|
|
573
662
|
resolveWorkerValue(entry, ctx, 'workerVars'),
|
|
574
663
|
)
|
|
664
|
+
// The deploy's own id, resolved here so a deploy with no id fails with
|
|
665
|
+
// every other unresolvable reference rather than at wrangler. Last,
|
|
666
|
+
// and skipped when `workerVars` already names it: a `--var` repeated
|
|
667
|
+
// twice is a value wrangler picks between, and the instance's own entry
|
|
668
|
+
// is the one that should win.
|
|
669
|
+
if (config.deployIdVar && !resolvedVars.some((v) => v.name === config.deployIdVar)) {
|
|
670
|
+
resolvedVars.push({
|
|
671
|
+
name: config.deployIdVar,
|
|
672
|
+
value: resolveDeployId(ctx.projectRoot, config.deployIdVar),
|
|
673
|
+
})
|
|
674
|
+
}
|
|
575
675
|
const resolvedSecrets = config.workerSecrets.map((entry) =>
|
|
576
676
|
resolveWorkerValue(entry, ctx, 'workerSecrets'),
|
|
577
677
|
)
|