diff --git a/pkgs/queue-transport-alert/worker/README.md b/pkgs/queue-transport-alert/worker/README.md index ca9711eb57..b7c3537ee6 100644 --- a/pkgs/queue-transport-alert/worker/README.md +++ b/pkgs/queue-transport-alert/worker/README.md @@ -82,7 +82,7 @@ keeps the two in step). The app stages the flake package the Nix store, then: 1. `cf workers versions create --tag git-` uploads a version - with its secrets read from stdin (`--secrets-file /dev/stdin`); + with its secrets passed through a pipe (`--secrets-file <(cat)`); nothing goes live yet. 2. `cf workers deployments create` puts that version at 100%. 3. `cf workers triggers deploy` applies the cron schedule. diff --git a/pkgs/queue-transport-alert/worker/deploy.mjs b/pkgs/queue-transport-alert/worker/deploy.mjs index d29979eb10..2802979000 100644 --- a/pkgs/queue-transport-alert/worker/deploy.mjs +++ b/pkgs/queue-transport-alert/worker/deploy.mjs @@ -3,7 +3,7 @@ // // cf workers versions create upload a version stamped with the git // SHA (--tag git-), its secrets -// read from stdin; nothing goes live yet +// through a pipe; nothing goes live yet // cf workers deployments create put that version at 100% // cf workers triggers deploy apply the cron schedule from the config // @@ -33,6 +33,7 @@ // the previous version's value. No secret is printed or written to disk. import { execFileSync } from "node:child_process"; import { cpSync, existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, symlinkSync } from "node:fs"; +import { setDefaultAutoSelectFamilyAttemptTimeout } from "node:net"; import { homedir, tmpdir } from "node:os"; import { dirname, join } from "node:path"; import { fileURLToPath } from "node:url"; @@ -95,13 +96,25 @@ for (const [name, variable] of [["cf", "QTA_CF_MODULE"], ["wrangler", "QTA_WRANG symlinkSync(target, join(stage, "node_modules", name)); } -function runCf(args, { capture = false, input } = {}) { +function runCf(args, { capture = false } = {}) { return execFileSync("cf", ["-q", ...args], { cwd: stage, env, encoding: "utf8", - input, - stdio: [input === undefined ? "inherit" : "pipe", capture ? "pipe" : "inherit", "inherit"], + stdio: ["inherit", capture ? "pipe" : "inherit", "inherit"], + }); +} + +// cf reads --secrets-file with a plain file read, which fails on this +// process's stdin pipe. Hand it a fresh pipe instead: bash's process +// substitution copies our stdin (the secrets JSON) into /dev/fd/N, and +// cf itself gets /dev/null, so the values never touch disk or argv. +function runCfWithSecrets(args, secrets) { + execFileSync("bash", ["-c", 'cf -q "$@" --secrets-file <(cat) = 3) { + throw new Error(`version ${versionId} is deployed, but ${url} did not answer: ${error.cause?.message ?? error.message}`); + } + await new Promise((resolve) => setTimeout(resolve, 3_000)); + } + } console.log(`verified: version ${versionId} serves 100%; ${url} reports the broker ${status.status ?? "unknown"}`); } @@ -163,10 +190,7 @@ if (brokerToken) { } console.log(`uploading version (tag ${tag}; secrets ${Object.keys(workerSecrets).join(", ")})`); -runCf( - ["workers", "versions", "create", "--worker", WORKER, "--tag", tag, "--message", message, "--secrets-file", "/dev/stdin"], - { input: JSON.stringify(workerSecrets) }, -); +runCfWithSecrets(["workers", "versions", "create", "--worker", WORKER, "--tag", tag, "--message", message], workerSecrets); const versions = listItems( parseJsonOutput(runCf(["workers", "versions", "list", "--worker-id", WORKER], { capture: true })), "versions", diff --git a/pkgs/queue-transport-alert/worker/deploy.nix b/pkgs/queue-transport-alert/worker/deploy.nix index b59bb69888..c1bfb942e2 100644 --- a/pkgs/queue-transport-alert/worker/deploy.nix +++ b/pkgs/queue-transport-alert/worker/deploy.nix @@ -1,5 +1,6 @@ { writeShellApplication, + bash, bws, cf, git, @@ -16,6 +17,7 @@ writeShellApplication { name = "queue-transport-alert-deploy"; runtimeInputs = [ + bash bws cf git