GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Merge pull request #12025 from developing-today/claude/qta-cf-secrets… · developing-today/code@b3de6c1

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • pkgs/queue-transport-alert/worker
    • README.md
    • deploy.mjs
    • deploy.nix
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎pkgs/queue-transport-alert/worker/README.md‎

Copy file name to clipboardExpand all lines: pkgs/queue-transport-alert/worker/README.md
+1-1Lines changed: 1 addition & 1 deletion
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ keeps the two in step). The app stages the flake package
8282
the Nix store, then:
8383

8484
1. `cf workers versions create --tag git-<sha12>` uploads a version
85-
with its secrets read from stdin (`--secrets-file /dev/stdin`);
85+
with its secrets passed through a pipe (`--secrets-file <(cat)`);
8686
nothing goes live yet.
8787
2. `cf workers deployments create` puts that version at 100%.
8888
3. `cf workers triggers deploy` applies the cron schedule.
Collapse file

‎pkgs/queue-transport-alert/worker/deploy.mjs‎

Copy file name to clipboardExpand all lines: pkgs/queue-transport-alert/worker/deploy.mjs
+35-11Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
//
44
// cf workers versions create upload a version stamped with the git
55
// SHA (--tag git-<sha12>), its secrets
6-
// read from stdin; nothing goes live yet
6+
// through a pipe; nothing goes live yet
77
// cf workers deployments create put that version at 100%
88
// cf workers triggers deploy apply the cron schedule from the config
99
//
@@ -33,6 +33,7 @@
3333
// the previous version's value. No secret is printed or written to disk.
3434
import { execFileSync } from "node:child_process";
3535
import { cpSync, existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, symlinkSync } from "node:fs";
36+
import { setDefaultAutoSelectFamilyAttemptTimeout } from "node:net";
3637
import { homedir, tmpdir } from "node:os";
3738
import { dirname, join } from "node:path";
3839
import { fileURLToPath } from "node:url";
@@ -95,13 +96,25 @@ for (const [name, variable] of [["cf", "QTA_CF_MODULE"], ["wrangler", "QTA_WRANG
9596
symlinkSync(target, join(stage, "node_modules", name));
9697
}
9798

98-
function runCf(args, { capture = false, input } = {}) {
99+
function runCf(args, { capture = false } = {}) {
99100
return execFileSync("cf", ["-q", ...args], {
100101
cwd: stage,
101102
env,
102103
encoding: "utf8",
103-
input,
104-
stdio: [input === undefined ? "inherit" : "pipe", capture ? "pipe" : "inherit", "inherit"],
104+
stdio: ["inherit", capture ? "pipe" : "inherit", "inherit"],
105+
});
106+
}
107+
108+
// cf reads --secrets-file with a plain file read, which fails on this
109+
// process's stdin pipe. Hand it a fresh pipe instead: bash's process
110+
// substitution copies our stdin (the secrets JSON) into /dev/fd/N, and
111+
// cf itself gets /dev/null, so the values never touch disk or argv.
112+
function runCfWithSecrets(args, secrets) {
113+
execFileSync("bash", ["-c", 'cf -q "$@" --secrets-file <(cat) </dev/null', "cf", ...args], {
114+
cwd: stage,
115+
env,
116+
input: JSON.stringify(secrets),
117+
stdio: ["pipe", "inherit", "inherit"],
105118
});
106119
}
107120

@@ -121,9 +134,23 @@ async function verify(versionId) {
121134
throw new Error(`post-deploy check failed: expected version ${versionId} at 100%, latest deployment serves ${serving.serving}`);
122135
}
123136
const url = `${WORKER_URL}/status.json`;
124-
const response = await fetch(url, { headers: { "user-agent": BROWSER_UA }, signal: AbortSignal.timeout(15_000) });
125-
if (!response.ok) throw new Error(`post-deploy check failed: ${url} answered HTTP ${response.status}`);
126-
const status = await response.json();
137+
// Node tries each address for only 250 ms by default; on the laptop's
138+
// network that timed out every address while curl got through.
139+
setDefaultAutoSelectFamilyAttemptTimeout(5_000);
140+
let status;
141+
for (let attempt = 1; ; attempt += 1) {
142+
try {
143+
const response = await fetch(url, { headers: { "user-agent": BROWSER_UA }, signal: AbortSignal.timeout(20_000) });
144+
if (!response.ok) throw new Error(`HTTP ${response.status}`);
145+
status = await response.json();
146+
break;
147+
} catch (error) {
148+
if (attempt >= 3) {
149+
throw new Error(`version ${versionId} is deployed, but ${url} did not answer: ${error.cause?.message ?? error.message}`);
150+
}
151+
await new Promise((resolve) => setTimeout(resolve, 3_000));
152+
}
153+
}
127154
console.log(`verified: version ${versionId} serves 100%; ${url} reports the broker ${status.status ?? "unknown"}`);
128155
}
129156

@@ -163,10 +190,7 @@ if (brokerToken) {
163190
}
164191

165192
console.log(`uploading version (tag ${tag}; secrets ${Object.keys(workerSecrets).join(", ")})`);
166-
runCf(
167-
["workers", "versions", "create", "--worker", WORKER, "--tag", tag, "--message", message, "--secrets-file", "/dev/stdin"],
168-
{ input: JSON.stringify(workerSecrets) },
169-
);
193+
runCfWithSecrets(["workers", "versions", "create", "--worker", WORKER, "--tag", tag, "--message", message], workerSecrets);
170194
const versions = listItems(
171195
parseJsonOutput(runCf(["workers", "versions", "list", "--worker-id", WORKER], { capture: true })),
172196
"versions",
Collapse file

‎pkgs/queue-transport-alert/worker/deploy.nix‎

Copy file name to clipboardExpand all lines: pkgs/queue-transport-alert/worker/deploy.nix
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
writeShellApplication,
3+
bash,
34
bws,
45
cf,
56
git,
@@ -16,6 +17,7 @@
1617
writeShellApplication {
1718
name = "queue-transport-alert-deploy";
1819
runtimeInputs = [
20+
bash
1921
bws
2022
cf
2123
git

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.