everything-dev 2.0.0-rc.1 → 2.0.0-rc.5
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/dist/api-contract.cjs +3 -6
- package/dist/api-contract.cjs.map +1 -1
- package/dist/api-contract.mjs +3 -6
- package/dist/api-contract.mjs.map +1 -1
- package/dist/apps/upload/src/client.cjs +188 -0
- package/dist/apps/upload/src/client.cjs.map +1 -0
- package/dist/apps/upload/src/client.mjs +180 -0
- package/dist/apps/upload/src/client.mjs.map +1 -0
- package/dist/auth-login.cjs +1 -1
- package/dist/auth-login.mjs +1 -1
- package/dist/build.cjs +2 -2
- package/dist/build.mjs +2 -2
- package/dist/bundle-fs-resolve.cjs +9 -17
- package/dist/bundle-fs-resolve.cjs.map +1 -1
- package/dist/bundle-fs-resolve.d.cts +6 -0
- package/dist/bundle-fs-resolve.d.mts +6 -0
- package/dist/bundle-fs-resolve.mjs +9 -17
- package/dist/bundle-fs-resolve.mjs.map +1 -1
- package/dist/bundle-path.cjs +48 -0
- package/dist/bundle-path.cjs.map +1 -0
- package/dist/bundle-path.mjs +45 -0
- package/dist/bundle-path.mjs.map +1 -0
- package/dist/cdn-deploy.cjs +29 -11
- package/dist/cdn-deploy.cjs.map +1 -1
- package/dist/cdn-deploy.mjs +29 -11
- package/dist/cdn-deploy.mjs.map +1 -1
- package/dist/cli/init.cjs +4 -6
- package/dist/cli/init.cjs.map +1 -1
- package/dist/cli/init.d.cts +1 -1
- package/dist/cli/init.d.mts +1 -1
- package/dist/cli/init.mjs +4 -6
- package/dist/cli/init.mjs.map +1 -1
- package/dist/cli/status.cjs +69 -3
- package/dist/cli/status.cjs.map +1 -1
- package/dist/cli/status.mjs +67 -4
- package/dist/cli/status.mjs.map +1 -1
- package/dist/cli/sync.cjs +1 -2
- package/dist/cli/sync.cjs.map +1 -1
- package/dist/cli/sync.mjs +1 -2
- package/dist/cli/sync.mjs.map +1 -1
- package/dist/cli/upgrade.cjs +2 -2
- package/dist/cli/upgrade.cjs.map +1 -1
- package/dist/cli/upgrade.mjs +2 -2
- package/dist/cli/upgrade.mjs.map +1 -1
- package/dist/cli.cjs +5 -7
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.mjs +5 -7
- package/dist/cli.mjs.map +1 -1
- package/dist/commands/deploy.cjs +26 -18
- package/dist/commands/deploy.cjs.map +1 -1
- package/dist/commands/deploy.mjs +26 -18
- package/dist/commands/deploy.mjs.map +1 -1
- package/dist/commands/init.cjs +1 -1
- package/dist/commands/init.cjs.map +1 -1
- package/dist/commands/init.mjs +1 -1
- package/dist/commands/init.mjs.map +1 -1
- package/dist/commands/plugins.cjs +2 -2
- package/dist/commands/plugins.cjs.map +1 -1
- package/dist/commands/plugins.mjs +2 -2
- package/dist/commands/plugins.mjs.map +1 -1
- package/dist/commands/upgrade.cjs +31 -8
- package/dist/commands/upgrade.cjs.map +1 -1
- package/dist/commands/upgrade.mjs +31 -8
- package/dist/commands/upgrade.mjs.map +1 -1
- package/dist/components/dev-render.cjs +1 -1
- package/dist/components/dev-render.mjs +1 -1
- package/dist/config.cjs +3 -3
- package/dist/config.cjs.map +1 -1
- package/dist/config.mjs +3 -3
- package/dist/config.mjs.map +1 -1
- package/dist/contract.cjs +2 -0
- package/dist/contract.cjs.map +1 -1
- package/dist/contract.d.cts +3 -0
- package/dist/contract.d.mts +3 -0
- package/dist/contract.meta.cjs +2 -1
- package/dist/contract.meta.cjs.map +1 -1
- package/dist/contract.meta.d.cts +4 -1
- package/dist/contract.meta.d.mts +4 -1
- package/dist/contract.meta.mjs +2 -1
- package/dist/contract.meta.mjs.map +1 -1
- package/dist/contract.mjs +2 -0
- package/dist/contract.mjs.map +1 -1
- package/dist/db/driver.cjs +22 -2
- package/dist/db/driver.cjs.map +1 -1
- package/dist/db/driver.d.cts +13 -2
- package/dist/db/driver.d.mts +13 -2
- package/dist/db/driver.mjs +22 -3
- package/dist/db/driver.mjs.map +1 -1
- package/dist/db/index.cjs +1 -0
- package/dist/db/index.d.cts +2 -2
- package/dist/db/index.d.mts +2 -2
- package/dist/db/index.mjs +2 -2
- package/dist/deploy-diff.cjs +1 -1
- package/dist/deploy-diff.cjs.map +1 -1
- package/dist/deploy-diff.mjs +1 -1
- package/dist/deploy-diff.mjs.map +1 -1
- package/dist/dev-program.cjs +11 -2
- package/dist/dev-program.cjs.map +1 -1
- package/dist/dev-program.mjs +11 -3
- package/dist/dev-program.mjs.map +1 -1
- package/dist/image-deploy.cjs +103 -31
- package/dist/image-deploy.cjs.map +1 -1
- package/dist/image-deploy.mjs +103 -33
- package/dist/image-deploy.mjs.map +1 -1
- package/dist/internal/manifest-normalizer.cjs.map +1 -1
- package/dist/internal/manifest-normalizer.mjs.map +1 -1
- package/dist/plugin.d.cts +902 -1
- package/dist/plugin.d.mts +902 -1
- package/dist/publish.cjs +51 -2
- package/dist/publish.cjs.map +1 -1
- package/dist/publish.mjs +51 -4
- package/dist/publish.mjs.map +1 -1
- package/dist/resolution/session.cjs.map +1 -1
- package/dist/resolution/session.d.cts +5 -5
- package/dist/resolution/session.d.mts +5 -5
- package/dist/resolution/session.mjs.map +1 -1
- package/dist/storage-upload.cjs +7 -68
- package/dist/storage-upload.cjs.map +1 -1
- package/dist/storage-upload.mjs +7 -68
- package/dist/storage-upload.mjs.map +1 -1
- package/dist/types.d.cts +31 -1
- package/dist/types.d.mts +31 -1
- package/dist/ui/api.cjs +11 -69
- package/dist/ui/api.cjs.map +1 -1
- package/dist/ui/api.d.cts +2 -4
- package/dist/ui/api.d.mts +2 -4
- package/dist/ui/api.mjs +11 -69
- package/dist/ui/api.mjs.map +1 -1
- package/dist/ui/auth-guards.d.cts +78 -2
- package/dist/ui/auth-guards.d.mts +78 -2
- package/dist/ui/auth.cjs.map +1 -1
- package/dist/ui/auth.d.cts +4133 -7
- package/dist/ui/auth.d.mts +4133 -7
- package/dist/ui/auth.mjs.map +1 -1
- package/dist/ui/hydrate.cjs +2 -2
- package/dist/ui/hydrate.cjs.map +1 -1
- package/dist/ui/hydrate.mjs +2 -2
- package/dist/ui/hydrate.mjs.map +1 -1
- package/dist/utils/theme.cjs +2 -2
- package/dist/utils/theme.cjs.map +1 -1
- package/dist/utils/theme.mjs +2 -2
- package/dist/utils/theme.mjs.map +1 -1
- package/dist/version-manifest-resolve.cjs +55 -10
- package/dist/version-manifest-resolve.cjs.map +1 -1
- package/dist/version-manifest-resolve.mjs +53 -10
- package/dist/version-manifest-resolve.mjs.map +1 -1
- package/dist/workspace.cjs +26 -13
- package/dist/workspace.cjs.map +1 -1
- package/dist/workspace.mjs +26 -14
- package/dist/workspace.mjs.map +1 -1
- package/package.json +12 -10
package/dist/image-deploy.cjs
CHANGED
|
@@ -58,21 +58,26 @@ function readFrameworkVersion(configDir) {
|
|
|
58
58
|
* Tag scheme (ADR 0021): `sha-<short>` always; the exact `v<version>` tag; a
|
|
59
59
|
* floating major tag (`v2`) on stable releases only. `latest` is held during
|
|
60
60
|
* prereleases (npm's `rc` dist-tag analog) so existing deployments pinned to
|
|
61
|
-
* `:latest` keep serving the last stable image
|
|
61
|
+
* `:latest` keep serving the last stable image — and `:rc` is the floating
|
|
62
|
+
* ref for the prerelease train (npm's `rc` dist-tag mirror): it moves on
|
|
63
|
+
* every prerelease deploy and freezes at the last rc-train build once the
|
|
64
|
+
* workspace releases a stable version.
|
|
62
65
|
*/
|
|
63
66
|
function computeImageTags(input) {
|
|
64
67
|
const tags = [`sha-${input.shortSha}`];
|
|
65
68
|
const match = input.version?.trim().match(SEMVER_PATTERN);
|
|
66
69
|
if (!match) return {
|
|
67
70
|
tags,
|
|
68
|
-
pushLatest: true
|
|
71
|
+
pushLatest: true,
|
|
72
|
+
pushRc: false
|
|
69
73
|
};
|
|
70
74
|
const [, major, minor, patch, prerelease] = match;
|
|
71
75
|
const exact = prerelease ? `v${major}.${minor}.${patch}-${prerelease}` : `v${major}.${minor}.${patch}`;
|
|
72
76
|
if (prerelease) return {
|
|
73
77
|
tags: [...tags, exact],
|
|
74
78
|
pushLatest: false,
|
|
75
|
-
latestHoldReason: `${exact} is a prerelease — :latest still serves the last stable image
|
|
79
|
+
latestHoldReason: `${exact} is a prerelease — :latest still serves the last stable image`,
|
|
80
|
+
pushRc: true
|
|
76
81
|
};
|
|
77
82
|
return {
|
|
78
83
|
tags: [
|
|
@@ -80,14 +85,49 @@ function computeImageTags(input) {
|
|
|
80
85
|
exact,
|
|
81
86
|
`v${major}`
|
|
82
87
|
],
|
|
83
|
-
pushLatest: true
|
|
88
|
+
pushLatest: true,
|
|
89
|
+
pushRc: false
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
const DIGEST_PATTERN = /^sha256:[a-f0-9]{64}$/;
|
|
93
|
+
/** A Railway pin is `FROM image@<digest>` — anything else cannot resolve. */
|
|
94
|
+
function isValidImageDigest(digest) {
|
|
95
|
+
return DIGEST_PATTERN.test(digest);
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Decide the image leg's source: a digest handed over from a pre-pushed image
|
|
99
|
+
* (the CI image job) wins; otherwise the local docker build runs when the
|
|
100
|
+
* toolchain and Dockerfile are present (ADR 0021, as amended).
|
|
101
|
+
*/
|
|
102
|
+
function resolveDeployImagePlan(input) {
|
|
103
|
+
if (!input.imageRef) return {
|
|
104
|
+
kind: "skip",
|
|
105
|
+
reason: "set ci.image in bos.config.json (or BOS_IMAGE) to build and push the runtime image"
|
|
106
|
+
};
|
|
107
|
+
if (input.imageDigest) return {
|
|
108
|
+
kind: "prebuilt",
|
|
109
|
+
image: input.imageRef.image,
|
|
110
|
+
digest: input.imageDigest
|
|
111
|
+
};
|
|
112
|
+
if (!input.hasDocker) return {
|
|
113
|
+
kind: "skip",
|
|
114
|
+
reason: "docker is not available"
|
|
115
|
+
};
|
|
116
|
+
if (!input.hasDockerfile) return {
|
|
117
|
+
kind: "skip",
|
|
118
|
+
reason: "no Dockerfile at the config root"
|
|
119
|
+
};
|
|
120
|
+
return {
|
|
121
|
+
kind: "build",
|
|
122
|
+
image: input.imageRef.image
|
|
84
123
|
};
|
|
85
124
|
}
|
|
86
125
|
/**
|
|
87
126
|
* Image leg (ADR 0021): build the runtime stage, tag `sha-<short>` + version
|
|
88
|
-
* tags, push them, capture the digest,
|
|
89
|
-
* is a prerelease
|
|
90
|
-
* configured (child repos get
|
|
127
|
+
* tags, push them, capture the digest, then push the floating refs — `:latest`
|
|
128
|
+
* unless the version is a prerelease, and `:rc` when it is. Callers skip the
|
|
129
|
+
* leg with a notice when no image is configured (child repos get
|
|
130
|
+
* build+upload+publish only).
|
|
91
131
|
*/
|
|
92
132
|
async function buildAndPushImage(input) {
|
|
93
133
|
const shaResult = await require_run.run("git", [
|
|
@@ -103,13 +143,15 @@ async function buildAndPushImage(input) {
|
|
|
103
143
|
const detail = shaResult?.stderr.trim();
|
|
104
144
|
throw new Error(`Failed to resolve the current git SHA in ${input.configDir} (exit code ${shaResult?.exitCode ?? "unknown"}${detail ? `: ${detail}` : ""})`);
|
|
105
145
|
}
|
|
106
|
-
const { tags, pushLatest, latestHoldReason } = computeImageTags({
|
|
146
|
+
const { tags, pushLatest, latestHoldReason, pushRc } = computeImageTags({
|
|
107
147
|
shortSha,
|
|
108
148
|
version: readFrameworkVersion(input.configDir)
|
|
109
149
|
});
|
|
110
150
|
const refs = tags.map((tag) => `${input.image}:${tag}`);
|
|
111
151
|
const latestRef = `${input.image}:latest`;
|
|
112
|
-
const
|
|
152
|
+
const rcRef = `${input.image}:rc`;
|
|
153
|
+
const buildRefs = pushLatest ? [...refs, latestRef] : [...refs];
|
|
154
|
+
if (pushRc) buildRefs.push(rcRef);
|
|
113
155
|
console.log(` Building runtime image ${require_theme.colors.cyan(buildRefs.join(", "))}${pushLatest ? "" : require_theme.colors.yellow(" (latest held)")}`);
|
|
114
156
|
await require_run.run("docker", [
|
|
115
157
|
"build",
|
|
@@ -129,51 +171,79 @@ async function buildAndPushImage(input) {
|
|
|
129
171
|
digest ??= parseDigest(push.stdout);
|
|
130
172
|
if (input.verbose && push.stdout.trim()) console.log(require_theme.colors.dim(push.stdout.trim()));
|
|
131
173
|
}
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
const pushLatestRef = await require_run.run("docker", ["push", latestRef], {
|
|
174
|
+
const pushFloating = async (ref) => {
|
|
175
|
+
const push = await require_run.run("docker", ["push", ref], {
|
|
135
176
|
cwd: input.configDir,
|
|
136
177
|
capture: true
|
|
137
178
|
});
|
|
138
|
-
if (!
|
|
139
|
-
digest ??= parseDigest(
|
|
140
|
-
if (input.verbose &&
|
|
141
|
-
|
|
142
|
-
}
|
|
179
|
+
if (!push || push.exitCode !== 0) throw new Error(`docker push ${ref} failed with exit code ${push?.exitCode ?? "unknown"}`);
|
|
180
|
+
digest ??= parseDigest(push.stdout);
|
|
181
|
+
if (input.verbose && push.stdout.trim()) console.log(require_theme.colors.dim(push.stdout.trim()));
|
|
182
|
+
return true;
|
|
183
|
+
};
|
|
184
|
+
let latestPushed = false;
|
|
185
|
+
if (pushLatest) latestPushed = await pushFloating(latestRef);
|
|
186
|
+
else console.log(require_theme.colors.yellow(` latest held: ${latestHoldReason}`));
|
|
187
|
+
const rcPushed = pushRc ? await pushFloating(rcRef) : false;
|
|
143
188
|
if (!digest) console.log(require_theme.colors.yellow(" Could not capture the image digest from push output"));
|
|
144
189
|
return {
|
|
145
190
|
image: input.image,
|
|
146
191
|
tag: tags[0],
|
|
147
192
|
tags,
|
|
148
193
|
latestPushed,
|
|
194
|
+
rcPushed,
|
|
149
195
|
digest
|
|
150
196
|
};
|
|
151
197
|
}
|
|
152
198
|
/**
|
|
153
|
-
* Railway leg (ADR 0021):
|
|
154
|
-
*
|
|
155
|
-
*
|
|
199
|
+
* Railway leg (ADR 0021, amended): image-backed deploy. The service's source
|
|
200
|
+
* is a Docker image ref (connected once in the dashboard — `:rc` during the
|
|
201
|
+
* prerelease train), and `redeploy --from-source` pulls and deploys whatever
|
|
202
|
+
* that ref points at. The image leg pushes `:rc` (and the `sha-<short>` /
|
|
203
|
+
* version tags) immediately before this step, so the pulled bytes are exactly
|
|
204
|
+
* what this train validated. Railway skips the build entirely for
|
|
205
|
+
* Docker-image sources — nothing is uploaded, nothing is built on Railway,
|
|
206
|
+
* and the digest-pin Dockerfile mechanism this replaces is gone (the CLI v5
|
|
207
|
+
* dropped RAILWAY_DOCKERFILE_PATH, its snapshot respects .gitignore so
|
|
208
|
+
* generated Dockerfiles never shipped, and its Metal builder rejected the
|
|
209
|
+
* repo Dockerfile's cache-mount ids).
|
|
156
210
|
*/
|
|
157
211
|
async function deployImageToRailway(input) {
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
212
|
+
console.log(` Deploying to Railway service ${require_theme.colors.cyan(input.service)} (image-backed)...`);
|
|
213
|
+
let version;
|
|
214
|
+
try {
|
|
215
|
+
version = (await require_run.run("railway", ["--version"], {
|
|
216
|
+
cwd: input.configDir,
|
|
217
|
+
capture: true
|
|
218
|
+
}))?.stdout;
|
|
219
|
+
} catch {
|
|
220
|
+
version = void 0;
|
|
221
|
+
}
|
|
222
|
+
if (!version?.trim()) throw new Error("Railway CLI not found. Install it: npm i -g @railway/cli");
|
|
223
|
+
console.log(` ${require_theme.colors.dim(`railway ${version.trim()}`)}`);
|
|
224
|
+
const collected = {
|
|
225
|
+
stdout: "",
|
|
226
|
+
stderr: ""
|
|
227
|
+
};
|
|
163
228
|
const result = await require_run.run("railway", [
|
|
164
|
-
"
|
|
229
|
+
"redeploy",
|
|
165
230
|
"--service",
|
|
166
231
|
input.service,
|
|
167
|
-
"--
|
|
232
|
+
"--from-source",
|
|
233
|
+
"--yes"
|
|
168
234
|
], {
|
|
169
235
|
cwd: input.configDir,
|
|
170
236
|
capture: true,
|
|
171
|
-
|
|
237
|
+
onChunk: (stream, chunk) => {
|
|
238
|
+
collected[stream] += chunk.toString("utf-8");
|
|
239
|
+
for (const line of chunk.toString("utf-8").split("\n")) if (line.trim()) console.log(` ${require_theme.colors.dim(line.trim())}`);
|
|
240
|
+
}
|
|
172
241
|
});
|
|
173
|
-
if (result
|
|
174
|
-
|
|
242
|
+
if (!result || result.exitCode !== 0) {
|
|
243
|
+
const exitCode = result?.exitCode ?? "unknown";
|
|
244
|
+
const tail = (stream, text) => text.trim() ? `\nrailway ${stream} (tail):\n${text.trim().split("\n").slice(-20).join("\n")}` : "";
|
|
245
|
+
throw new Error(`railway redeploy failed with exit code ${exitCode}` + tail("stdout", collected.stdout) + tail("stderr", collected.stderr));
|
|
175
246
|
}
|
|
176
|
-
if (!result || result.exitCode !== 0) throw new Error(result?.stderr.trim() ? `railway up failed: ${result.stderr.trim().split("\n").slice(-3).join(" ")}` : `railway up failed with exit code ${result?.exitCode ?? "unknown"}`);
|
|
177
247
|
console.log(require_theme.colors.green(` ${require_theme.icons.ok} Railway deploy complete`));
|
|
178
248
|
}
|
|
179
249
|
|
|
@@ -182,5 +252,7 @@ exports.buildAndPushImage = buildAndPushImage;
|
|
|
182
252
|
exports.computeImageTags = computeImageTags;
|
|
183
253
|
exports.deployImageToRailway = deployImageToRailway;
|
|
184
254
|
exports.hasDocker = hasDocker;
|
|
255
|
+
exports.isValidImageDigest = isValidImageDigest;
|
|
256
|
+
exports.resolveDeployImagePlan = resolveDeployImagePlan;
|
|
185
257
|
exports.resolveImageRef = resolveImageRef;
|
|
186
258
|
//# sourceMappingURL=image-deploy.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"image-deploy.cjs","names":["run","readFileSync","join","colors","icons"],"sources":["../src/image-deploy.ts"],"sourcesContent":["import { mkdirSync, readFileSync, writeFileSync } from \"node:fs\";\nimport { join } from \"node:path\";\nimport { run } from \"./utils/run\";\nimport { colors, icons } from \"./utils/theme\";\n\nexport interface ResolvedImageRef {\n image: string;\n source: \"ci\" | \"env\" | \"repository\";\n}\n\n/**\n * Image reference resolution precedence (ADR 0021): `ci.image` in\n * bos.config.json → `BOS_IMAGE` env → derived from `repository`.\n */\nexport function resolveImageRef(input: {\n ciImage?: string;\n repository?: string;\n env?: Record<string, string | undefined>;\n}): ResolvedImageRef | undefined {\n const envImage = input.env?.BOS_IMAGE;\n if (input.ciImage) return { image: input.ciImage, source: \"ci\" };\n if (envImage) return { image: envImage, source: \"env\" };\n\n const repo = input.repository\n ?.replace(/^https?:\\/\\/(www\\.)?github\\.com\\//i, \"\")\n .replace(/\\.git$/i, \"\")\n .replace(/\\/+$/, \"\")\n .toLowerCase();\n if (!repo?.includes(\"/\") || repo.split(\"/\").length !== 2) return undefined;\n return { image: `ghcr.io/${repo}`, source: \"repository\" };\n}\n\nexport async function hasDocker(): Promise<boolean> {\n try {\n const result = await run(\"docker\", [\"info\", \"--format\", \"{{.ServerVersion}}\"], {\n capture: true,\n });\n return result?.exitCode === 0;\n } catch {\n return false;\n }\n}\n\nfunction parseDigest(pushOutput: string): string | undefined {\n const match = pushOutput.match(/digest:\\s*(sha256:[a-f0-9]+)/i);\n return match?.[1];\n}\n\nconst SEMVER_PATTERN = /^(\\d+)\\.(\\d+)\\.(\\d+)(?:-([0-9A-Za-z.-]+))?$/;\n\n/**\n * The runtime framework version baked into the image is the workspace source's\n * `everything-dev` package version — the image builds from `configDir`, so that\n * file is the truth. Missing (child repos without the workspace) → undefined.\n */\nfunction readFrameworkVersion(configDir: string): string | undefined {\n try {\n const raw = readFileSync(\n join(configDir, \"packages\", \"everything-dev\", \"package.json\"),\n \"utf-8\",\n );\n const pkg = JSON.parse(raw) as { version?: unknown };\n return typeof pkg.version === \"string\" && SEMVER_PATTERN.test(pkg.version)\n ? pkg.version\n : undefined;\n } catch {\n return undefined;\n }\n}\n\nexport interface ImageTags {\n /** Exact refs to build and push, in push order (latest excluded). */\n tags: string[];\n /** Push `:latest` after the pinned tags. */\n pushLatest: boolean;\n /** Human-readable reason when `latest` is held. */\n latestHoldReason?: string;\n}\n\n/**\n * Tag scheme (ADR 0021): `sha-<short>` always; the exact `v<version>` tag; a\n * floating major tag (`v2`) on stable releases only. `latest` is held during\n * prereleases (npm's `rc` dist-tag analog) so existing deployments pinned to\n * `:latest` keep serving the last stable image.\n */\nexport function computeImageTags(input: { shortSha: string; version?: string }): ImageTags {\n const tags = [`sha-${input.shortSha}`];\n const match = input.version?.trim().match(SEMVER_PATTERN);\n if (!match) {\n return { tags, pushLatest: true };\n }\n const [, major, minor, patch, prerelease] = match;\n const exact = prerelease\n ? `v${major}.${minor}.${patch}-${prerelease}`\n : `v${major}.${minor}.${patch}`;\n if (prerelease) {\n return {\n tags: [...tags, exact],\n pushLatest: false,\n latestHoldReason: `${exact} is a prerelease — :latest still serves the last stable image`,\n };\n }\n return { tags: [...tags, exact, `v${major}`], pushLatest: true };\n}\n\nexport interface ImageDeployResult {\n image: string;\n /** Primary pinned tag (the sha tag). */\n tag: string;\n /** All tags pushed, including the primary. */\n tags: string[];\n latestPushed: boolean;\n digest?: string;\n}\n\n/**\n * Image leg (ADR 0021): build the runtime stage, tag `sha-<short>` + version\n * tags, push them, capture the digest, and push `:latest` unless the version\n * is a prerelease. Callers skip the leg with a notice when no image is\n * configured (child repos get build+upload+publish only).\n */\nexport async function buildAndPushImage(input: {\n image: string;\n configDir: string;\n verbose?: boolean;\n}): Promise<ImageDeployResult> {\n const shaResult = await run(\"git\", [\"rev-parse\", \"--short=7\", \"HEAD\"], {\n cwd: input.configDir,\n capture: true,\n });\n const shortSha = shaResult?.stdout.trim();\n if (!shaResult || shaResult.exitCode !== 0 || !shortSha) {\n const detail = shaResult?.stderr.trim();\n throw new Error(\n `Failed to resolve the current git SHA in ${input.configDir} (exit code ${shaResult?.exitCode ?? \"unknown\"}${detail ? `: ${detail}` : \"\"})`,\n );\n }\n\n const version = readFrameworkVersion(input.configDir);\n const { tags, pushLatest, latestHoldReason } = computeImageTags({ shortSha, version });\n const refs = tags.map((tag) => `${input.image}:${tag}`);\n const latestRef = `${input.image}:latest`;\n const buildRefs = pushLatest ? [...refs, latestRef] : refs;\n\n console.log(\n ` Building runtime image ${colors.cyan(buildRefs.join(\", \"))}${pushLatest ? \"\" : colors.yellow(\" (latest held)\")}`,\n );\n await run(\n \"docker\",\n [\"build\", \"--target\", \"runtime\", ...buildRefs.flatMap((ref) => [\"-t\", ref]), \".\"],\n { cwd: input.configDir },\n );\n\n console.log(` Pushing ${colors.cyan(refs.join(\", \"))}...`);\n let digest: string | undefined;\n for (const ref of refs) {\n const push = await run(\"docker\", [\"push\", ref], {\n cwd: input.configDir,\n capture: true,\n });\n if (!push || push.exitCode !== 0) {\n throw new Error(`docker push ${ref} failed with exit code ${push?.exitCode ?? \"unknown\"}`);\n }\n digest ??= parseDigest(push.stdout);\n if (input.verbose && push.stdout.trim()) {\n console.log(colors.dim(push.stdout.trim()));\n }\n }\n\n let latestPushed = false;\n if (pushLatest) {\n const pushLatestRef = await run(\"docker\", [\"push\", latestRef], {\n cwd: input.configDir,\n capture: true,\n });\n if (!pushLatestRef || pushLatestRef.exitCode !== 0) {\n throw new Error(\n `docker push ${latestRef} failed with exit code ${pushLatestRef?.exitCode ?? \"unknown\"}`,\n );\n }\n digest ??= parseDigest(pushLatestRef.stdout);\n if (input.verbose && pushLatestRef.stdout.trim()) {\n console.log(colors.dim(pushLatestRef.stdout.trim()));\n }\n latestPushed = true;\n } else {\n console.log(colors.yellow(` latest held: ${latestHoldReason}`));\n }\n\n if (!digest) {\n console.log(colors.yellow(\" Could not capture the image digest from push output\"));\n }\n\n return { image: input.image, tag: tags[0], tags, latestPushed, digest };\n}\n\n/**\n * Railway leg (ADR 0021): pull-only deploy of the pushed image digest — a\n * thin `FROM image@digest` Dockerfile pins the digest so Railway never\n * rebuilds; `RAILWAY_DOCKERFILE_PATH` points at the generated file.\n */\nexport async function deployImageToRailway(input: {\n image: string;\n digest: string;\n service: string;\n configDir: string;\n}): Promise<void> {\n const deployDir = join(input.configDir, \".bos\", \"deploy\");\n mkdirSync(deployDir, { recursive: true });\n const dockerfilePath = join(deployDir, \"Dockerfile\");\n writeFileSync(dockerfilePath, `FROM ${input.image}@${input.digest}\\n`);\n\n console.log(` Deploying to Railway service ${colors.cyan(input.service)} (pull-only)...`);\n const result = await run(\"railway\", [\"up\", \"--service\", input.service, \"--ci\"], {\n cwd: input.configDir,\n capture: true,\n env: { RAILWAY_DOCKERFILE_PATH: \".bos/deploy/Dockerfile\" },\n });\n if (result?.stdout) {\n for (const line of result.stdout.split(\"\\n\")) {\n if (line.trim()) console.log(` ${colors.dim(line.trim())}`);\n }\n }\n if (!result || result.exitCode !== 0) {\n throw new Error(\n result?.stderr.trim()\n ? `railway up failed: ${result.stderr.trim().split(\"\\n\").slice(-3).join(\" \")}`\n : `railway up failed with exit code ${result?.exitCode ?? \"unknown\"}`,\n );\n }\n console.log(colors.green(` ${icons.ok} Railway deploy complete`));\n}\n"],"mappings":";;;;;;;;;;AAcA,SAAgB,gBAAgB,OAIC;CAC/B,MAAM,WAAW,MAAM,KAAK;CAC5B,IAAI,MAAM,SAAS,OAAO;EAAE,OAAO,MAAM;EAAS,QAAQ;CAAK;CAC/D,IAAI,UAAU,OAAO;EAAE,OAAO;EAAU,QAAQ;CAAM;CAEtD,MAAM,OAAO,MAAM,YACf,QAAQ,sCAAsC,EAAE,CAAC,CAClD,QAAQ,WAAW,EAAE,CAAC,CACtB,QAAQ,QAAQ,EAAE,CAAC,CACnB,YAAY;CACf,IAAI,CAAC,MAAM,SAAS,GAAG,KAAK,KAAK,MAAM,GAAG,CAAC,CAAC,WAAW,GAAG,OAAO;CACjE,OAAO;EAAE,OAAO,WAAW;EAAQ,QAAQ;CAAa;AAC1D;AAEA,eAAsB,YAA8B;CAClD,IAAI;EAIF,QAAO,MAHcA,gBAAI,UAAU;GAAC;GAAQ;GAAY;EAAoB,GAAG,EAC7E,SAAS,KACX,CAAC,EACY,EAAE,aAAa;CAC9B,QAAQ;EACN,OAAO;CACT;AACF;AAEA,SAAS,YAAY,YAAwC;CAE3D,OADc,WAAW,MAAM,+BACpB,CAAC,GAAG;AACjB;AAEA,MAAM,iBAAiB;;;;;;AAOvB,SAAS,qBAAqB,WAAuC;CACnE,IAAI;EACF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],"sourcesContent":["import { readFileSync } from \"node:fs\";\nimport { join } from \"node:path\";\nimport { run } from \"./utils/run\";\nimport { colors, icons } from \"./utils/theme\";\n\nexport interface ResolvedImageRef {\n image: string;\n source: \"ci\" | \"env\" | \"repository\";\n}\n\n/**\n * Image reference resolution precedence (ADR 0021): `ci.image` in\n * bos.config.json → `BOS_IMAGE` env → derived from `repository`.\n */\nexport function resolveImageRef(input: {\n ciImage?: string;\n repository?: string;\n env?: Record<string, string | undefined>;\n}): ResolvedImageRef | undefined {\n const envImage = input.env?.BOS_IMAGE;\n if (input.ciImage) return { image: input.ciImage, source: \"ci\" };\n if (envImage) return { image: envImage, source: \"env\" };\n\n const repo = input.repository\n ?.replace(/^https?:\\/\\/(www\\.)?github\\.com\\//i, \"\")\n .replace(/\\.git$/i, \"\")\n .replace(/\\/+$/, \"\")\n .toLowerCase();\n if (!repo?.includes(\"/\") || repo.split(\"/\").length !== 2) return undefined;\n return { image: `ghcr.io/${repo}`, source: \"repository\" };\n}\n\nexport async function hasDocker(): Promise<boolean> {\n try {\n const result = await run(\"docker\", [\"info\", \"--format\", \"{{.ServerVersion}}\"], {\n capture: true,\n });\n return result?.exitCode === 0;\n } catch {\n return false;\n }\n}\n\nfunction parseDigest(pushOutput: string): string | undefined {\n const match = pushOutput.match(/digest:\\s*(sha256:[a-f0-9]+)/i);\n return match?.[1];\n}\n\nconst SEMVER_PATTERN = /^(\\d+)\\.(\\d+)\\.(\\d+)(?:-([0-9A-Za-z.-]+))?$/;\n\n/**\n * The runtime framework version baked into the image is the workspace source's\n * `everything-dev` package version — the image builds from `configDir`, so that\n * file is the truth. Missing (child repos without the workspace) → undefined.\n */\nfunction readFrameworkVersion(configDir: string): string | undefined {\n try {\n const raw = readFileSync(\n join(configDir, \"packages\", \"everything-dev\", \"package.json\"),\n \"utf-8\",\n );\n const pkg = JSON.parse(raw) as { version?: unknown };\n return typeof pkg.version === \"string\" && SEMVER_PATTERN.test(pkg.version)\n ? pkg.version\n : undefined;\n } catch {\n return undefined;\n }\n}\n\nexport interface ImageTags {\n /** Exact refs to build and push, in push order (latest excluded). */\n tags: string[];\n /** Push `:latest` after the pinned tags. */\n pushLatest: boolean;\n /** Human-readable reason when `latest` is held. */\n latestHoldReason?: string;\n /** Push `:rc` after the pinned tags — the floating prerelease-train ref. */\n pushRc: boolean;\n}\n\n/**\n * Tag scheme (ADR 0021): `sha-<short>` always; the exact `v<version>` tag; a\n * floating major tag (`v2`) on stable releases only. `latest` is held during\n * prereleases (npm's `rc` dist-tag analog) so existing deployments pinned to\n * `:latest` keep serving the last stable image — and `:rc` is the floating\n * ref for the prerelease train (npm's `rc` dist-tag mirror): it moves on\n * every prerelease deploy and freezes at the last rc-train build once the\n * workspace releases a stable version.\n */\nexport function computeImageTags(input: { shortSha: string; version?: string }): ImageTags {\n const tags = [`sha-${input.shortSha}`];\n const match = input.version?.trim().match(SEMVER_PATTERN);\n if (!match) {\n return { tags, pushLatest: true, pushRc: false };\n }\n const [, major, minor, patch, prerelease] = match;\n const exact = prerelease\n ? `v${major}.${minor}.${patch}-${prerelease}`\n : `v${major}.${minor}.${patch}`;\n if (prerelease) {\n return {\n tags: [...tags, exact],\n pushLatest: false,\n latestHoldReason: `${exact} is a prerelease — :latest still serves the last stable image`,\n pushRc: true,\n };\n }\n return { tags: [...tags, exact, `v${major}`], pushLatest: true, pushRc: false };\n}\n\nexport interface ImageDeployResult {\n image: string;\n /** Primary pinned tag (the sha tag). */\n tag: string;\n /** All tags pushed, including the primary. */\n tags: string[];\n latestPushed: boolean;\n /** Whether the floating `:rc` prerelease-train ref was pushed. */\n rcPushed: boolean;\n digest?: string;\n}\n\nexport type DeployImagePlan =\n | { kind: \"prebuilt\"; image: string; digest: string }\n | { kind: \"build\"; image: string }\n | { kind: \"skip\"; reason: string };\n\nconst DIGEST_PATTERN = /^sha256:[a-f0-9]{64}$/;\n\n/** A Railway pin is `FROM image@<digest>` — anything else cannot resolve. */\nexport function isValidImageDigest(digest: string): boolean {\n return DIGEST_PATTERN.test(digest);\n}\n\n/**\n * Decide the image leg's source: a digest handed over from a pre-pushed image\n * (the CI image job) wins; otherwise the local docker build runs when the\n * toolchain and Dockerfile are present (ADR 0021, as amended).\n */\nexport function resolveDeployImagePlan(input: {\n imageRef: ResolvedImageRef | undefined;\n imageDigest?: string;\n hasDocker: boolean;\n hasDockerfile: boolean;\n}): DeployImagePlan {\n if (!input.imageRef) {\n return {\n kind: \"skip\",\n reason: \"set ci.image in bos.config.json (or BOS_IMAGE) to build and push the runtime image\",\n };\n }\n if (input.imageDigest) {\n return { kind: \"prebuilt\", image: input.imageRef.image, digest: input.imageDigest };\n }\n if (!input.hasDocker) {\n return { kind: \"skip\", reason: \"docker is not available\" };\n }\n if (!input.hasDockerfile) {\n return { kind: \"skip\", reason: \"no Dockerfile at the config root\" };\n }\n return { kind: \"build\", image: input.imageRef.image };\n}\n\n/**\n * Image leg (ADR 0021): build the runtime stage, tag `sha-<short>` + version\n * tags, push them, capture the digest, then push the floating refs — `:latest`\n * unless the version is a prerelease, and `:rc` when it is. Callers skip the\n * leg with a notice when no image is configured (child repos get\n * build+upload+publish only).\n */\nexport async function buildAndPushImage(input: {\n image: string;\n configDir: string;\n verbose?: boolean;\n}): Promise<ImageDeployResult> {\n const shaResult = await run(\"git\", [\"rev-parse\", \"--short=7\", \"HEAD\"], {\n cwd: input.configDir,\n capture: true,\n });\n const shortSha = shaResult?.stdout.trim();\n if (!shaResult || shaResult.exitCode !== 0 || !shortSha) {\n const detail = shaResult?.stderr.trim();\n throw new Error(\n `Failed to resolve the current git SHA in ${input.configDir} (exit code ${shaResult?.exitCode ?? \"unknown\"}${detail ? `: ${detail}` : \"\"})`,\n );\n }\n\n const version = readFrameworkVersion(input.configDir);\n const { tags, pushLatest, latestHoldReason, pushRc } = computeImageTags({\n shortSha,\n version,\n });\n const refs = tags.map((tag) => `${input.image}:${tag}`);\n const latestRef = `${input.image}:latest`;\n const rcRef = `${input.image}:rc`;\n const buildRefs = pushLatest ? [...refs, latestRef] : [...refs];\n if (pushRc) buildRefs.push(rcRef);\n\n console.log(\n ` Building runtime image ${colors.cyan(buildRefs.join(\", \"))}${pushLatest ? \"\" : colors.yellow(\" (latest held)\")}`,\n );\n await run(\n \"docker\",\n [\"build\", \"--target\", \"runtime\", ...buildRefs.flatMap((ref) => [\"-t\", ref]), \".\"],\n { cwd: input.configDir },\n );\n\n console.log(` Pushing ${colors.cyan(refs.join(\", \"))}...`);\n let digest: string | undefined;\n for (const ref of refs) {\n const push = await run(\"docker\", [\"push\", ref], {\n cwd: input.configDir,\n capture: true,\n });\n if (!push || push.exitCode !== 0) {\n throw new Error(`docker push ${ref} failed with exit code ${push?.exitCode ?? \"unknown\"}`);\n }\n digest ??= parseDigest(push.stdout);\n if (input.verbose && push.stdout.trim()) {\n console.log(colors.dim(push.stdout.trim()));\n }\n }\n\n const pushFloating = async (ref: string): Promise<boolean> => {\n const push = await run(\"docker\", [\"push\", ref], {\n cwd: input.configDir,\n capture: true,\n });\n if (!push || push.exitCode !== 0) {\n throw new Error(`docker push ${ref} failed with exit code ${push?.exitCode ?? \"unknown\"}`);\n }\n digest ??= parseDigest(push.stdout);\n if (input.verbose && push.stdout.trim()) {\n console.log(colors.dim(push.stdout.trim()));\n }\n return true;\n };\n\n let latestPushed = false;\n if (pushLatest) {\n latestPushed = await pushFloating(latestRef);\n } else {\n console.log(colors.yellow(` latest held: ${latestHoldReason}`));\n }\n const rcPushed = pushRc ? await pushFloating(rcRef) : false;\n\n if (!digest) {\n console.log(colors.yellow(\" Could not capture the image digest from push output\"));\n }\n\n return { image: input.image, tag: tags[0]!, tags, latestPushed, rcPushed, digest };\n}\n\n/**\n * Railway leg (ADR 0021, amended): image-backed deploy. The service's source\n * is a Docker image ref (connected once in the dashboard — `:rc` during the\n * prerelease train), and `redeploy --from-source` pulls and deploys whatever\n * that ref points at. The image leg pushes `:rc` (and the `sha-<short>` /\n * version tags) immediately before this step, so the pulled bytes are exactly\n * what this train validated. Railway skips the build entirely for\n * Docker-image sources — nothing is uploaded, nothing is built on Railway,\n * and the digest-pin Dockerfile mechanism this replaces is gone (the CLI v5\n * dropped RAILWAY_DOCKERFILE_PATH, its snapshot respects .gitignore so\n * generated Dockerfiles never shipped, and its Metal builder rejected the\n * repo Dockerfile's cache-mount ids).\n */\nexport async function deployImageToRailway(input: {\n service: string;\n configDir: string;\n}): Promise<void> {\n console.log(` Deploying to Railway service ${colors.cyan(input.service)} (image-backed)...`);\n // The probe is authoritative: runners don't ship the CLI, and a spawn\n // failure resolves (reject:false) as exitCode 1 with empty output — the\n // 2026-10-13 deploy surfaced exactly that as a silent instant failure.\n let version: string | undefined;\n try {\n version = (await run(\"railway\", [\"--version\"], { cwd: input.configDir, capture: true }))\n ?.stdout;\n } catch {\n version = undefined;\n }\n if (!version?.trim()) {\n throw new Error(\"Railway CLI not found. Install it: npm i -g @railway/cli\");\n }\n console.log(` ${colors.dim(`railway ${version.trim()}`)}`);\n\n // Stream the CLI's output live — a silent exit (empty stdout+stderr, seen\n // on the 2026-10-13 deploy) must still be diagnosable from the workflow log.\n const collected = { stdout: \"\", stderr: \"\" };\n const result = await run(\n \"railway\",\n [\"redeploy\", \"--service\", input.service, \"--from-source\", \"--yes\"],\n {\n cwd: input.configDir,\n capture: true,\n onChunk: (stream, chunk) => {\n collected[stream] += chunk.toString(\"utf-8\");\n for (const line of chunk.toString(\"utf-8\").split(\"\\n\")) {\n if (line.trim()) console.log(` ${colors.dim(line.trim())}`);\n }\n },\n },\n );\n if (!result || result.exitCode !== 0) {\n const exitCode = result?.exitCode ?? \"unknown\";\n const tail = (stream: string, text: string) =>\n text.trim()\n ? `\\nrailway ${stream} (tail):\\n${text.trim().split(\"\\n\").slice(-20).join(\"\\n\")}`\n : \"\";\n throw new Error(\n `railway redeploy failed with exit code ${exitCode}` +\n tail(\"stdout\", collected.stdout) +\n tail(\"stderr\", collected.stderr),\n );\n }\n console.log(colors.green(` ${icons.ok} Railway deploy complete`));\n}\n"],"mappings":";;;;;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AK,KAAK,GAAG,QAAQ,IAAI,KAAKG,qBAAO,IAAI,KAAK,KAAK,CAAC,GAAG;EAE/D;CACF,CACF;CACA,IAAI,CAAC,UAAU,OAAO,aAAa,GAAG;EACpC,MAAM,WAAW,QAAQ,YAAY;EACrC,MAAM,QAAQ,QAAgB,SAC5B,KAAK,KAAK,IACN,aAAa,OAAO,YAAY,KAAK,KAAK,CAAC,CAAC,MAAM,IAAI,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,KAAK,IAAI,MAC5E;EACN,MAAM,IAAI,MACR,0CAA0C,aACxC,KAAK,UAAU,UAAU,MAAM,IAC/B,KAAK,UAAU,UAAU,MAAM,CACnC;CACF;CACA,QAAQ,IAAIA,qBAAO,MAAM,KAAKC,oBAAM,GAAG,yBAAyB,CAAC;AACnE"}
|
package/dist/image-deploy.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { run } from "./utils/run.mjs";
|
|
2
2
|
import { colors, icons } from "./utils/theme.mjs";
|
|
3
|
-
import {
|
|
3
|
+
import { readFileSync } from "node:fs";
|
|
4
4
|
import { join } from "node:path";
|
|
5
5
|
|
|
6
6
|
//#region src/image-deploy.ts
|
|
@@ -58,21 +58,26 @@ function readFrameworkVersion(configDir) {
|
|
|
58
58
|
* Tag scheme (ADR 0021): `sha-<short>` always; the exact `v<version>` tag; a
|
|
59
59
|
* floating major tag (`v2`) on stable releases only. `latest` is held during
|
|
60
60
|
* prereleases (npm's `rc` dist-tag analog) so existing deployments pinned to
|
|
61
|
-
* `:latest` keep serving the last stable image
|
|
61
|
+
* `:latest` keep serving the last stable image — and `:rc` is the floating
|
|
62
|
+
* ref for the prerelease train (npm's `rc` dist-tag mirror): it moves on
|
|
63
|
+
* every prerelease deploy and freezes at the last rc-train build once the
|
|
64
|
+
* workspace releases a stable version.
|
|
62
65
|
*/
|
|
63
66
|
function computeImageTags(input) {
|
|
64
67
|
const tags = [`sha-${input.shortSha}`];
|
|
65
68
|
const match = input.version?.trim().match(SEMVER_PATTERN);
|
|
66
69
|
if (!match) return {
|
|
67
70
|
tags,
|
|
68
|
-
pushLatest: true
|
|
71
|
+
pushLatest: true,
|
|
72
|
+
pushRc: false
|
|
69
73
|
};
|
|
70
74
|
const [, major, minor, patch, prerelease] = match;
|
|
71
75
|
const exact = prerelease ? `v${major}.${minor}.${patch}-${prerelease}` : `v${major}.${minor}.${patch}`;
|
|
72
76
|
if (prerelease) return {
|
|
73
77
|
tags: [...tags, exact],
|
|
74
78
|
pushLatest: false,
|
|
75
|
-
latestHoldReason: `${exact} is a prerelease — :latest still serves the last stable image
|
|
79
|
+
latestHoldReason: `${exact} is a prerelease — :latest still serves the last stable image`,
|
|
80
|
+
pushRc: true
|
|
76
81
|
};
|
|
77
82
|
return {
|
|
78
83
|
tags: [
|
|
@@ -80,14 +85,49 @@ function computeImageTags(input) {
|
|
|
80
85
|
exact,
|
|
81
86
|
`v${major}`
|
|
82
87
|
],
|
|
83
|
-
pushLatest: true
|
|
88
|
+
pushLatest: true,
|
|
89
|
+
pushRc: false
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
const DIGEST_PATTERN = /^sha256:[a-f0-9]{64}$/;
|
|
93
|
+
/** A Railway pin is `FROM image@<digest>` — anything else cannot resolve. */
|
|
94
|
+
function isValidImageDigest(digest) {
|
|
95
|
+
return DIGEST_PATTERN.test(digest);
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Decide the image leg's source: a digest handed over from a pre-pushed image
|
|
99
|
+
* (the CI image job) wins; otherwise the local docker build runs when the
|
|
100
|
+
* toolchain and Dockerfile are present (ADR 0021, as amended).
|
|
101
|
+
*/
|
|
102
|
+
function resolveDeployImagePlan(input) {
|
|
103
|
+
if (!input.imageRef) return {
|
|
104
|
+
kind: "skip",
|
|
105
|
+
reason: "set ci.image in bos.config.json (or BOS_IMAGE) to build and push the runtime image"
|
|
106
|
+
};
|
|
107
|
+
if (input.imageDigest) return {
|
|
108
|
+
kind: "prebuilt",
|
|
109
|
+
image: input.imageRef.image,
|
|
110
|
+
digest: input.imageDigest
|
|
111
|
+
};
|
|
112
|
+
if (!input.hasDocker) return {
|
|
113
|
+
kind: "skip",
|
|
114
|
+
reason: "docker is not available"
|
|
115
|
+
};
|
|
116
|
+
if (!input.hasDockerfile) return {
|
|
117
|
+
kind: "skip",
|
|
118
|
+
reason: "no Dockerfile at the config root"
|
|
119
|
+
};
|
|
120
|
+
return {
|
|
121
|
+
kind: "build",
|
|
122
|
+
image: input.imageRef.image
|
|
84
123
|
};
|
|
85
124
|
}
|
|
86
125
|
/**
|
|
87
126
|
* Image leg (ADR 0021): build the runtime stage, tag `sha-<short>` + version
|
|
88
|
-
* tags, push them, capture the digest,
|
|
89
|
-
* is a prerelease
|
|
90
|
-
* configured (child repos get
|
|
127
|
+
* tags, push them, capture the digest, then push the floating refs — `:latest`
|
|
128
|
+
* unless the version is a prerelease, and `:rc` when it is. Callers skip the
|
|
129
|
+
* leg with a notice when no image is configured (child repos get
|
|
130
|
+
* build+upload+publish only).
|
|
91
131
|
*/
|
|
92
132
|
async function buildAndPushImage(input) {
|
|
93
133
|
const shaResult = await run("git", [
|
|
@@ -103,13 +143,15 @@ async function buildAndPushImage(input) {
|
|
|
103
143
|
const detail = shaResult?.stderr.trim();
|
|
104
144
|
throw new Error(`Failed to resolve the current git SHA in ${input.configDir} (exit code ${shaResult?.exitCode ?? "unknown"}${detail ? `: ${detail}` : ""})`);
|
|
105
145
|
}
|
|
106
|
-
const { tags, pushLatest, latestHoldReason } = computeImageTags({
|
|
146
|
+
const { tags, pushLatest, latestHoldReason, pushRc } = computeImageTags({
|
|
107
147
|
shortSha,
|
|
108
148
|
version: readFrameworkVersion(input.configDir)
|
|
109
149
|
});
|
|
110
150
|
const refs = tags.map((tag) => `${input.image}:${tag}`);
|
|
111
151
|
const latestRef = `${input.image}:latest`;
|
|
112
|
-
const
|
|
152
|
+
const rcRef = `${input.image}:rc`;
|
|
153
|
+
const buildRefs = pushLatest ? [...refs, latestRef] : [...refs];
|
|
154
|
+
if (pushRc) buildRefs.push(rcRef);
|
|
113
155
|
console.log(` Building runtime image ${colors.cyan(buildRefs.join(", "))}${pushLatest ? "" : colors.yellow(" (latest held)")}`);
|
|
114
156
|
await run("docker", [
|
|
115
157
|
"build",
|
|
@@ -129,54 +171,82 @@ async function buildAndPushImage(input) {
|
|
|
129
171
|
digest ??= parseDigest(push.stdout);
|
|
130
172
|
if (input.verbose && push.stdout.trim()) console.log(colors.dim(push.stdout.trim()));
|
|
131
173
|
}
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
const pushLatestRef = await run("docker", ["push", latestRef], {
|
|
174
|
+
const pushFloating = async (ref) => {
|
|
175
|
+
const push = await run("docker", ["push", ref], {
|
|
135
176
|
cwd: input.configDir,
|
|
136
177
|
capture: true
|
|
137
178
|
});
|
|
138
|
-
if (!
|
|
139
|
-
digest ??= parseDigest(
|
|
140
|
-
if (input.verbose &&
|
|
141
|
-
|
|
142
|
-
}
|
|
179
|
+
if (!push || push.exitCode !== 0) throw new Error(`docker push ${ref} failed with exit code ${push?.exitCode ?? "unknown"}`);
|
|
180
|
+
digest ??= parseDigest(push.stdout);
|
|
181
|
+
if (input.verbose && push.stdout.trim()) console.log(colors.dim(push.stdout.trim()));
|
|
182
|
+
return true;
|
|
183
|
+
};
|
|
184
|
+
let latestPushed = false;
|
|
185
|
+
if (pushLatest) latestPushed = await pushFloating(latestRef);
|
|
186
|
+
else console.log(colors.yellow(` latest held: ${latestHoldReason}`));
|
|
187
|
+
const rcPushed = pushRc ? await pushFloating(rcRef) : false;
|
|
143
188
|
if (!digest) console.log(colors.yellow(" Could not capture the image digest from push output"));
|
|
144
189
|
return {
|
|
145
190
|
image: input.image,
|
|
146
191
|
tag: tags[0],
|
|
147
192
|
tags,
|
|
148
193
|
latestPushed,
|
|
194
|
+
rcPushed,
|
|
149
195
|
digest
|
|
150
196
|
};
|
|
151
197
|
}
|
|
152
198
|
/**
|
|
153
|
-
* Railway leg (ADR 0021):
|
|
154
|
-
*
|
|
155
|
-
*
|
|
199
|
+
* Railway leg (ADR 0021, amended): image-backed deploy. The service's source
|
|
200
|
+
* is a Docker image ref (connected once in the dashboard — `:rc` during the
|
|
201
|
+
* prerelease train), and `redeploy --from-source` pulls and deploys whatever
|
|
202
|
+
* that ref points at. The image leg pushes `:rc` (and the `sha-<short>` /
|
|
203
|
+
* version tags) immediately before this step, so the pulled bytes are exactly
|
|
204
|
+
* what this train validated. Railway skips the build entirely for
|
|
205
|
+
* Docker-image sources — nothing is uploaded, nothing is built on Railway,
|
|
206
|
+
* and the digest-pin Dockerfile mechanism this replaces is gone (the CLI v5
|
|
207
|
+
* dropped RAILWAY_DOCKERFILE_PATH, its snapshot respects .gitignore so
|
|
208
|
+
* generated Dockerfiles never shipped, and its Metal builder rejected the
|
|
209
|
+
* repo Dockerfile's cache-mount ids).
|
|
156
210
|
*/
|
|
157
211
|
async function deployImageToRailway(input) {
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
212
|
+
console.log(` Deploying to Railway service ${colors.cyan(input.service)} (image-backed)...`);
|
|
213
|
+
let version;
|
|
214
|
+
try {
|
|
215
|
+
version = (await run("railway", ["--version"], {
|
|
216
|
+
cwd: input.configDir,
|
|
217
|
+
capture: true
|
|
218
|
+
}))?.stdout;
|
|
219
|
+
} catch {
|
|
220
|
+
version = void 0;
|
|
221
|
+
}
|
|
222
|
+
if (!version?.trim()) throw new Error("Railway CLI not found. Install it: npm i -g @railway/cli");
|
|
223
|
+
console.log(` ${colors.dim(`railway ${version.trim()}`)}`);
|
|
224
|
+
const collected = {
|
|
225
|
+
stdout: "",
|
|
226
|
+
stderr: ""
|
|
227
|
+
};
|
|
163
228
|
const result = await run("railway", [
|
|
164
|
-
"
|
|
229
|
+
"redeploy",
|
|
165
230
|
"--service",
|
|
166
231
|
input.service,
|
|
167
|
-
"--
|
|
232
|
+
"--from-source",
|
|
233
|
+
"--yes"
|
|
168
234
|
], {
|
|
169
235
|
cwd: input.configDir,
|
|
170
236
|
capture: true,
|
|
171
|
-
|
|
237
|
+
onChunk: (stream, chunk) => {
|
|
238
|
+
collected[stream] += chunk.toString("utf-8");
|
|
239
|
+
for (const line of chunk.toString("utf-8").split("\n")) if (line.trim()) console.log(` ${colors.dim(line.trim())}`);
|
|
240
|
+
}
|
|
172
241
|
});
|
|
173
|
-
if (result
|
|
174
|
-
|
|
242
|
+
if (!result || result.exitCode !== 0) {
|
|
243
|
+
const exitCode = result?.exitCode ?? "unknown";
|
|
244
|
+
const tail = (stream, text) => text.trim() ? `\nrailway ${stream} (tail):\n${text.trim().split("\n").slice(-20).join("\n")}` : "";
|
|
245
|
+
throw new Error(`railway redeploy failed with exit code ${exitCode}` + tail("stdout", collected.stdout) + tail("stderr", collected.stderr));
|
|
175
246
|
}
|
|
176
|
-
if (!result || result.exitCode !== 0) throw new Error(result?.stderr.trim() ? `railway up failed: ${result.stderr.trim().split("\n").slice(-3).join(" ")}` : `railway up failed with exit code ${result?.exitCode ?? "unknown"}`);
|
|
177
247
|
console.log(colors.green(` ${icons.ok} Railway deploy complete`));
|
|
178
248
|
}
|
|
179
249
|
|
|
180
250
|
//#endregion
|
|
181
|
-
export { buildAndPushImage, computeImageTags, deployImageToRailway, hasDocker, resolveImageRef };
|
|
251
|
+
export { buildAndPushImage, computeImageTags, deployImageToRailway, hasDocker, isValidImageDigest, resolveDeployImagePlan, resolveImageRef };
|
|
182
252
|
//# sourceMappingURL=image-deploy.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"image-deploy.mjs","names":[],"sources":["../src/image-deploy.ts"],"sourcesContent":["import { mkdirSync, readFileSync, writeFileSync } from \"node:fs\";\nimport { join } from \"node:path\";\nimport { run } from \"./utils/run\";\nimport { colors, icons } from \"./utils/theme\";\n\nexport interface ResolvedImageRef {\n image: string;\n source: \"ci\" | \"env\" | \"repository\";\n}\n\n/**\n * Image reference resolution precedence (ADR 0021): `ci.image` in\n * bos.config.json → `BOS_IMAGE` env → derived from `repository`.\n */\nexport function resolveImageRef(input: {\n ciImage?: string;\n repository?: string;\n env?: Record<string, string | undefined>;\n}): ResolvedImageRef | undefined {\n const envImage = input.env?.BOS_IMAGE;\n if (input.ciImage) return { image: input.ciImage, source: \"ci\" };\n if (envImage) return { image: envImage, source: \"env\" };\n\n const repo = input.repository\n ?.replace(/^https?:\\/\\/(www\\.)?github\\.com\\//i, \"\")\n .replace(/\\.git$/i, \"\")\n .replace(/\\/+$/, \"\")\n .toLowerCase();\n if (!repo?.includes(\"/\") || repo.split(\"/\").length !== 2) return undefined;\n return { image: `ghcr.io/${repo}`, source: \"repository\" };\n}\n\nexport async function hasDocker(): Promise<boolean> {\n try {\n const result = await run(\"docker\", [\"info\", \"--format\", \"{{.ServerVersion}}\"], {\n capture: true,\n });\n return result?.exitCode === 0;\n } catch {\n return false;\n }\n}\n\nfunction parseDigest(pushOutput: string): string | undefined {\n const match = pushOutput.match(/digest:\\s*(sha256:[a-f0-9]+)/i);\n return match?.[1];\n}\n\nconst SEMVER_PATTERN = /^(\\d+)\\.(\\d+)\\.(\\d+)(?:-([0-9A-Za-z.-]+))?$/;\n\n/**\n * The runtime framework version baked into the image is the workspace source's\n * `everything-dev` package version — the image builds from `configDir`, so that\n * file is the truth. Missing (child repos without the workspace) → undefined.\n */\nfunction readFrameworkVersion(configDir: string): string | undefined {\n try {\n const raw = readFileSync(\n join(configDir, \"packages\", \"everything-dev\", \"package.json\"),\n \"utf-8\",\n );\n const pkg = JSON.parse(raw) as { version?: unknown };\n return typeof pkg.version === \"string\" && SEMVER_PATTERN.test(pkg.version)\n ? pkg.version\n : undefined;\n } catch {\n return undefined;\n }\n}\n\nexport interface ImageTags {\n /** Exact refs to build and push, in push order (latest excluded). */\n tags: string[];\n /** Push `:latest` after the pinned tags. */\n pushLatest: boolean;\n /** Human-readable reason when `latest` is held. */\n latestHoldReason?: string;\n}\n\n/**\n * Tag scheme (ADR 0021): `sha-<short>` always; the exact `v<version>` tag; a\n * floating major tag (`v2`) on stable releases only. `latest` is held during\n * prereleases (npm's `rc` dist-tag analog) so existing deployments pinned to\n * `:latest` keep serving the last stable image.\n */\nexport function computeImageTags(input: { shortSha: string; version?: string }): ImageTags {\n const tags = [`sha-${input.shortSha}`];\n const match = input.version?.trim().match(SEMVER_PATTERN);\n if (!match) {\n return { tags, pushLatest: true };\n }\n const [, major, minor, patch, prerelease] = match;\n const exact = prerelease\n ? `v${major}.${minor}.${patch}-${prerelease}`\n : `v${major}.${minor}.${patch}`;\n if (prerelease) {\n return {\n tags: [...tags, exact],\n pushLatest: false,\n latestHoldReason: `${exact} is a prerelease — :latest still serves the last stable image`,\n };\n }\n return { tags: [...tags, exact, `v${major}`], pushLatest: true };\n}\n\nexport interface ImageDeployResult {\n image: string;\n /** Primary pinned tag (the sha tag). */\n tag: string;\n /** All tags pushed, including the primary. */\n tags: string[];\n latestPushed: boolean;\n digest?: string;\n}\n\n/**\n * Image leg (ADR 0021): build the runtime stage, tag `sha-<short>` + version\n * tags, push them, capture the digest, and push `:latest` unless the version\n * is a prerelease. Callers skip the leg with a notice when no image is\n * configured (child repos get build+upload+publish only).\n */\nexport async function buildAndPushImage(input: {\n image: string;\n configDir: string;\n verbose?: boolean;\n}): Promise<ImageDeployResult> {\n const shaResult = await run(\"git\", [\"rev-parse\", \"--short=7\", \"HEAD\"], {\n cwd: input.configDir,\n capture: true,\n });\n const shortSha = shaResult?.stdout.trim();\n if (!shaResult || shaResult.exitCode !== 0 || !shortSha) {\n const detail = shaResult?.stderr.trim();\n throw new Error(\n `Failed to resolve the current git SHA in ${input.configDir} (exit code ${shaResult?.exitCode ?? \"unknown\"}${detail ? `: ${detail}` : \"\"})`,\n );\n }\n\n const version = readFrameworkVersion(input.configDir);\n const { tags, pushLatest, latestHoldReason } = computeImageTags({ shortSha, version });\n const refs = tags.map((tag) => `${input.image}:${tag}`);\n const latestRef = `${input.image}:latest`;\n const buildRefs = pushLatest ? [...refs, latestRef] : refs;\n\n console.log(\n ` Building runtime image ${colors.cyan(buildRefs.join(\", \"))}${pushLatest ? \"\" : colors.yellow(\" (latest held)\")}`,\n );\n await run(\n \"docker\",\n [\"build\", \"--target\", \"runtime\", ...buildRefs.flatMap((ref) => [\"-t\", ref]), \".\"],\n { cwd: input.configDir },\n );\n\n console.log(` Pushing ${colors.cyan(refs.join(\", \"))}...`);\n let digest: string | undefined;\n for (const ref of refs) {\n const push = await run(\"docker\", [\"push\", ref], {\n cwd: input.configDir,\n capture: true,\n });\n if (!push || push.exitCode !== 0) {\n throw new Error(`docker push ${ref} failed with exit code ${push?.exitCode ?? \"unknown\"}`);\n }\n digest ??= parseDigest(push.stdout);\n if (input.verbose && push.stdout.trim()) {\n console.log(colors.dim(push.stdout.trim()));\n }\n }\n\n let latestPushed = false;\n if (pushLatest) {\n const pushLatestRef = await run(\"docker\", [\"push\", latestRef], {\n cwd: input.configDir,\n capture: true,\n });\n if (!pushLatestRef || pushLatestRef.exitCode !== 0) {\n throw new Error(\n `docker push ${latestRef} failed with exit code ${pushLatestRef?.exitCode ?? \"unknown\"}`,\n );\n }\n digest ??= parseDigest(pushLatestRef.stdout);\n if (input.verbose && pushLatestRef.stdout.trim()) {\n console.log(colors.dim(pushLatestRef.stdout.trim()));\n }\n latestPushed = true;\n } else {\n console.log(colors.yellow(` latest held: ${latestHoldReason}`));\n }\n\n if (!digest) {\n console.log(colors.yellow(\" Could not capture the image digest from push output\"));\n }\n\n return { image: input.image, tag: tags[0], tags, latestPushed, digest };\n}\n\n/**\n * Railway leg (ADR 0021): pull-only deploy of the pushed image digest — a\n * thin `FROM image@digest` Dockerfile pins the digest so Railway never\n * rebuilds; `RAILWAY_DOCKERFILE_PATH` points at the generated file.\n */\nexport async function deployImageToRailway(input: {\n image: string;\n digest: string;\n service: string;\n configDir: string;\n}): Promise<void> {\n const deployDir = join(input.configDir, \".bos\", \"deploy\");\n mkdirSync(deployDir, { recursive: true });\n const dockerfilePath = join(deployDir, \"Dockerfile\");\n writeFileSync(dockerfilePath, `FROM ${input.image}@${input.digest}\\n`);\n\n console.log(` Deploying to Railway service ${colors.cyan(input.service)} (pull-only)...`);\n const result = await run(\"railway\", [\"up\", \"--service\", input.service, \"--ci\"], {\n cwd: input.configDir,\n capture: true,\n env: { RAILWAY_DOCKERFILE_PATH: \".bos/deploy/Dockerfile\" },\n });\n if (result?.stdout) {\n for (const line of result.stdout.split(\"\\n\")) {\n if (line.trim()) console.log(` ${colors.dim(line.trim())}`);\n }\n }\n if (!result || result.exitCode !== 0) {\n throw new Error(\n result?.stderr.trim()\n ? `railway up failed: ${result.stderr.trim().split(\"\\n\").slice(-3).join(\" \")}`\n : `railway up failed with exit code ${result?.exitCode ?? \"unknown\"}`,\n );\n }\n console.log(colors.green(` ${icons.ok} Railway deploy complete`));\n}\n"],"mappings":";;;;;;;;;;AAcA,SAAgB,gBAAgB,OAIC;CAC/B,MAAM,WAAW,MAAM,KAAK;CAC5B,IAAI,MAAM,SAAS,OAAO;EAAE,OAAO,MAAM;EAAS,QAAQ;CAAK;CAC/D,IAAI,UAAU,OAAO;EAAE,OAAO;EAAU,QAAQ;CAAM;CAEtD,MAAM,OAAO,MAAM,YACf,QAAQ,sCAAsC,EAAE,CAAC,CAClD,QAAQ,WAAW,EAAE,CAAC,CACtB,QAAQ,QAAQ,EAAE,CAAC,CACnB,YAAY;CACf,IAAI,CAAC,MAAM,SAAS,GAAG,KAAK,KAAK,MAAM,GAAG,CAAC,CAAC,WAAW,GAAG,OAAO;CACjE,OAAO;EAAE,OAAO,WAAW;EAAQ,QAAQ;CAAa;AAC1D;AAEA,eAAsB,YAA8B;CAClD,IAAI;EAIF,QAAO,MAHc,IAAI,UAAU;GAAC;GAAQ;GAAY;EAAoB,GAAG,EAC7E,SAAS,KACX,CAAC,EACY,EAAE,aAAa;CAC9B,QAAQ;EACN,OAAO;CACT;AACF;AAEA,SAAS,YAAY,YAAwC;CAE3D,OADc,WAAW,MAAM,+BACpB,CA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["../src/image-deploy.ts"],"sourcesContent":["import { readFileSync } from \"node:fs\";\nimport { join } from \"node:path\";\nimport { run } from \"./utils/run\";\nimport { colors, icons } from \"./utils/theme\";\n\nexport interface ResolvedImageRef {\n image: string;\n source: \"ci\" | \"env\" | \"repository\";\n}\n\n/**\n * Image reference resolution precedence (ADR 0021): `ci.image` in\n * bos.config.json → `BOS_IMAGE` env → derived from `repository`.\n */\nexport function resolveImageRef(input: {\n ciImage?: string;\n repository?: string;\n env?: Record<string, string | undefined>;\n}): ResolvedImageRef | undefined {\n const envImage = input.env?.BOS_IMAGE;\n if (input.ciImage) return { image: input.ciImage, source: \"ci\" };\n if (envImage) return { image: envImage, source: \"env\" };\n\n const repo = input.repository\n ?.replace(/^https?:\\/\\/(www\\.)?github\\.com\\//i, \"\")\n .replace(/\\.git$/i, \"\")\n .replace(/\\/+$/, \"\")\n .toLowerCase();\n if (!repo?.includes(\"/\") || repo.split(\"/\").length !== 2) return undefined;\n return { image: `ghcr.io/${repo}`, source: \"repository\" };\n}\n\nexport async function hasDocker(): Promise<boolean> {\n try {\n const result = await run(\"docker\", [\"info\", \"--format\", \"{{.ServerVersion}}\"], {\n capture: true,\n });\n return result?.exitCode === 0;\n } catch {\n return false;\n }\n}\n\nfunction parseDigest(pushOutput: string): string | undefined {\n const match = pushOutput.match(/digest:\\s*(sha256:[a-f0-9]+)/i);\n return match?.[1];\n}\n\nconst SEMVER_PATTERN = /^(\\d+)\\.(\\d+)\\.(\\d+)(?:-([0-9A-Za-z.-]+))?$/;\n\n/**\n * The runtime framework version baked into the image is the workspace source's\n * `everything-dev` package version — the image builds from `configDir`, so that\n * file is the truth. Missing (child repos without the workspace) → undefined.\n */\nfunction readFrameworkVersion(configDir: string): string | undefined {\n try {\n const raw = readFileSync(\n join(configDir, \"packages\", \"everything-dev\", \"package.json\"),\n \"utf-8\",\n );\n const pkg = JSON.parse(raw) as { version?: unknown };\n return typeof pkg.version === \"string\" && SEMVER_PATTERN.test(pkg.version)\n ? pkg.version\n : undefined;\n } catch {\n return undefined;\n }\n}\n\nexport interface ImageTags {\n /** Exact refs to build and push, in push order (latest excluded). */\n tags: string[];\n /** Push `:latest` after the pinned tags. */\n pushLatest: boolean;\n /** Human-readable reason when `latest` is held. */\n latestHoldReason?: string;\n /** Push `:rc` after the pinned tags — the floating prerelease-train ref. */\n pushRc: boolean;\n}\n\n/**\n * Tag scheme (ADR 0021): `sha-<short>` always; the exact `v<version>` tag; a\n * floating major tag (`v2`) on stable releases only. `latest` is held during\n * prereleases (npm's `rc` dist-tag analog) so existing deployments pinned to\n * `:latest` keep serving the last stable image — and `:rc` is the floating\n * ref for the prerelease train (npm's `rc` dist-tag mirror): it moves on\n * every prerelease deploy and freezes at the last rc-train build once the\n * workspace releases a stable version.\n */\nexport function computeImageTags(input: { shortSha: string; version?: string }): ImageTags {\n const tags = [`sha-${input.shortSha}`];\n const match = input.version?.trim().match(SEMVER_PATTERN);\n if (!match) {\n return { tags, pushLatest: true, pushRc: false };\n }\n const [, major, minor, patch, prerelease] = match;\n const exact = prerelease\n ? `v${major}.${minor}.${patch}-${prerelease}`\n : `v${major}.${minor}.${patch}`;\n if (prerelease) {\n return {\n tags: [...tags, exact],\n pushLatest: false,\n latestHoldReason: `${exact} is a prerelease — :latest still serves the last stable image`,\n pushRc: true,\n };\n }\n return { tags: [...tags, exact, `v${major}`], pushLatest: true, pushRc: false };\n}\n\nexport interface ImageDeployResult {\n image: string;\n /** Primary pinned tag (the sha tag). */\n tag: string;\n /** All tags pushed, including the primary. */\n tags: string[];\n latestPushed: boolean;\n /** Whether the floating `:rc` prerelease-train ref was pushed. */\n rcPushed: boolean;\n digest?: string;\n}\n\nexport type DeployImagePlan =\n | { kind: \"prebuilt\"; image: string; digest: string }\n | { kind: \"build\"; image: string }\n | { kind: \"skip\"; reason: string };\n\nconst DIGEST_PATTERN = /^sha256:[a-f0-9]{64}$/;\n\n/** A Railway pin is `FROM image@<digest>` — anything else cannot resolve. */\nexport function isValidImageDigest(digest: string): boolean {\n return DIGEST_PATTERN.test(digest);\n}\n\n/**\n * Decide the image leg's source: a digest handed over from a pre-pushed image\n * (the CI image job) wins; otherwise the local docker build runs when the\n * toolchain and Dockerfile are present (ADR 0021, as amended).\n */\nexport function resolveDeployImagePlan(input: {\n imageRef: ResolvedImageRef | undefined;\n imageDigest?: string;\n hasDocker: boolean;\n hasDockerfile: boolean;\n}): DeployImagePlan {\n if (!input.imageRef) {\n return {\n kind: \"skip\",\n reason: \"set ci.image in bos.config.json (or BOS_IMAGE) to build and push the runtime image\",\n };\n }\n if (input.imageDigest) {\n return { kind: \"prebuilt\", image: input.imageRef.image, digest: input.imageDigest };\n }\n if (!input.hasDocker) {\n return { kind: \"skip\", reason: \"docker is not available\" };\n }\n if (!input.hasDockerfile) {\n return { kind: \"skip\", reason: \"no Dockerfile at the config root\" };\n }\n return { kind: \"build\", image: input.imageRef.image };\n}\n\n/**\n * Image leg (ADR 0021): build the runtime stage, tag `sha-<short>` + version\n * tags, push them, capture the digest, then push the floating refs — `:latest`\n * unless the version is a prerelease, and `:rc` when it is. Callers skip the\n * leg with a notice when no image is configured (child repos get\n * build+upload+publish only).\n */\nexport async function buildAndPushImage(input: {\n image: string;\n configDir: string;\n verbose?: boolean;\n}): Promise<ImageDeployResult> {\n const shaResult = await run(\"git\", [\"rev-parse\", \"--short=7\", \"HEAD\"], {\n cwd: input.configDir,\n capture: true,\n });\n const shortSha = shaResult?.stdout.trim();\n if (!shaResult || shaResult.exitCode !== 0 || !shortSha) {\n const detail = shaResult?.stderr.trim();\n throw new Error(\n `Failed to resolve the current git SHA in ${input.configDir} (exit code ${shaResult?.exitCode ?? \"unknown\"}${detail ? `: ${detail}` : \"\"})`,\n );\n }\n\n const version = readFrameworkVersion(input.configDir);\n const { tags, pushLatest, latestHoldReason, pushRc } = computeImageTags({\n shortSha,\n version,\n });\n const refs = tags.map((tag) => `${input.image}:${tag}`);\n const latestRef = `${input.image}:latest`;\n const rcRef = `${input.image}:rc`;\n const buildRefs = pushLatest ? [...refs, latestRef] : [...refs];\n if (pushRc) buildRefs.push(rcRef);\n\n console.log(\n ` Building runtime image ${colors.cyan(buildRefs.join(\", \"))}${pushLatest ? \"\" : colors.yellow(\" (latest held)\")}`,\n );\n await run(\n \"docker\",\n [\"build\", \"--target\", \"runtime\", ...buildRefs.flatMap((ref) => [\"-t\", ref]), \".\"],\n { cwd: input.configDir },\n );\n\n console.log(` Pushing ${colors.cyan(refs.join(\", \"))}...`);\n let digest: string | undefined;\n for (const ref of refs) {\n const push = await run(\"docker\", [\"push\", ref], {\n cwd: input.configDir,\n capture: true,\n });\n if (!push || push.exitCode !== 0) {\n throw new Error(`docker push ${ref} failed with exit code ${push?.exitCode ?? \"unknown\"}`);\n }\n digest ??= parseDigest(push.stdout);\n if (input.verbose && push.stdout.trim()) {\n console.log(colors.dim(push.stdout.trim()));\n }\n }\n\n const pushFloating = async (ref: string): Promise<boolean> => {\n const push = await run(\"docker\", [\"push\", ref], {\n cwd: input.configDir,\n capture: true,\n });\n if (!push || push.exitCode !== 0) {\n throw new Error(`docker push ${ref} failed with exit code ${push?.exitCode ?? \"unknown\"}`);\n }\n digest ??= parseDigest(push.stdout);\n if (input.verbose && push.stdout.trim()) {\n console.log(colors.dim(push.stdout.trim()));\n }\n return true;\n };\n\n let latestPushed = false;\n if (pushLatest) {\n latestPushed = await pushFloating(latestRef);\n } else {\n console.log(colors.yellow(` latest held: ${latestHoldReason}`));\n }\n const rcPushed = pushRc ? await pushFloating(rcRef) : false;\n\n if (!digest) {\n console.log(colors.yellow(\" Could not capture the image digest from push output\"));\n }\n\n return { image: input.image, tag: tags[0]!, tags, latestPushed, rcPushed, digest };\n}\n\n/**\n * Railway leg (ADR 0021, amended): image-backed deploy. The service's source\n * is a Docker image ref (connected once in the dashboard — `:rc` during the\n * prerelease train), and `redeploy --from-source` pulls and deploys whatever\n * that ref points at. The image leg pushes `:rc` (and the `sha-<short>` /\n * version tags) immediately before this step, so the pulled bytes are exactly\n * what this train validated. Railway skips the build entirely for\n * Docker-image sources — nothing is uploaded, nothing is built on Railway,\n * and the digest-pin Dockerfile mechanism this replaces is gone (the CLI v5\n * dropped RAILWAY_DOCKERFILE_PATH, its snapshot respects .gitignore so\n * generated Dockerfiles never shipped, and its Metal builder rejected the\n * repo Dockerfile's cache-mount ids).\n */\nexport async function deployImageToRailway(input: {\n service: string;\n configDir: string;\n}): Promise<void> {\n console.log(` Deploying to Railway service ${colors.cyan(input.service)} (image-backed)...`);\n // The probe is authoritative: runners don't ship the CLI, and a spawn\n // failure resolves (reject:false) as exitCode 1 with empty output — the\n // 2026-10-13 deploy surfaced exactly that as a silent instant failure.\n let version: string | undefined;\n try {\n version = (await run(\"railway\", [\"--version\"], { cwd: input.configDir, capture: true }))\n ?.stdout;\n } catch {\n version = undefined;\n }\n if (!version?.trim()) {\n throw new Error(\"Railway CLI not found. Install it: npm i -g @railway/cli\");\n }\n console.log(` ${colors.dim(`railway ${version.trim()}`)}`);\n\n // Stream the CLI's output live — a silent exit (empty stdout+stderr, seen\n // on the 2026-10-13 deploy) must still be diagnosable from the workflow log.\n const collected = { stdout: \"\", stderr: \"\" };\n const result = await run(\n \"railway\",\n [\"redeploy\", \"--service\", input.service, \"--from-source\", \"--yes\"],\n {\n cwd: input.configDir,\n capture: true,\n onChunk: (stream, chunk) => {\n collected[stream] += chunk.toString(\"utf-8\");\n for (const line of chunk.toString(\"utf-8\").split(\"\\n\")) {\n if (line.trim()) console.log(` ${colors.dim(line.trim())}`);\n }\n },\n },\n );\n if (!result || result.exitCode !== 0) {\n const exitCode = result?.exitCode ?? \"unknown\";\n const tail = (stream: string, text: string) =>\n text.trim()\n ? `\\nrailway ${stream} (tail):\\n${text.trim().split(\"\\n\").slice(-20).join(\"\\n\")}`\n : \"\";\n throw new Error(\n `railway redeploy failed with exit code ${exitCode}` +\n tail(\"stdout\", collected.stdout) +\n tail(\"stderr\", collected.stderr),\n );\n }\n console.log(colors.green(` ${icons.ok} Railway deploy complete`));\n}\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