@steve31415/baselib 3.75.0 → 3.76.0

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.
@@ -1,6 +1,8 @@
1
1
  import type { Runner, ServiceHealth } from './types.js';
2
2
  /** A gate's output shows its test browser process crashed (e.g. a segfault). */
3
3
  export declare function testBrowserCrashed(output: string): boolean;
4
+ /** A Cloud Build log shows a registry refused a pull for request quota. */
5
+ export declare function registryRateLimited(buildLog: string): boolean;
4
6
  /**
5
7
  * The `--startup-probe` value every `services update` asserts: Cloud Run
6
8
  * sends `GET <health path>` to each new instance and lets it take traffic
@@ -23,6 +23,19 @@ const BROWSER_CRASH = /^\s*\[pid=\d+\]\[err\] Received signal \d+ /m;
23
23
  export function testBrowserCrashed(output) {
24
24
  return BROWSER_CRASH.test(output);
25
25
  }
26
+ /** The Cloud Build id `gcloud builds submit` prints when it creates a build. */
27
+ const CLOUD_BUILD_ID = /\/builds\/([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})\b/;
28
+ /** A registry refusing a pull for request quota (Docker's error code). */
29
+ const REGISTRY_RATE_LIMIT = /\btoomanyrequests\b|429 Too Many Requests/i;
30
+ /**
31
+ * Pause before resubmitting a rate-limited build: the quota that refused it
32
+ * is counted per minute.
33
+ */
34
+ const RATE_LIMIT_PAUSE_MS = 60_000;
35
+ /** A Cloud Build log shows a registry refused a pull for request quota. */
36
+ export function registryRateLimited(buildLog) {
37
+ return REGISTRY_RATE_LIMIT.test(buildLog);
38
+ }
26
39
  /**
27
40
  * The `--startup-probe` value every `services update` asserts: Cloud Run
28
41
  * sends `GET <health path>` to each new instance and lets it take traffic
@@ -226,13 +239,35 @@ export async function runDeploy(options) {
226
239
  log('reusing existing immutable commit image');
227
240
  }
228
241
  else {
229
- const submit = await must(runner, 'gcloud', [
242
+ const submitArgs = [
230
243
  'builds', 'submit', contextDir,
231
244
  '--config', join(contextDir, 'cloudbuild.yaml'),
232
245
  '--region', config.region, ...gcloudBase,
233
246
  '--substitutions', `_IMAGE=${imageUri}`,
234
247
  '--suppress-logs', '--format=json',
235
- ], { timeoutMs: 15 * 60_000 });
248
+ ];
249
+ const submitBuild = () => runner('gcloud', submitArgs, { timeoutMs: 15 * 60_000 });
250
+ let submit = await submitBuild();
251
+ const buildId = CLOUD_BUILD_ID.exec(submit.stderr + submit.stdout)?.[1];
252
+ if (submit.code !== 0 && buildId) {
253
+ // The registry refusing a base-image pull for its per-minute request
254
+ // quota is outside anything the commit controls: resubmit once after
255
+ // a pause. Any other build failure fails at once. backup3 lost a
256
+ // deploy to mirror.gcr.io's "toomanyrequests" on 2026-11-30 (Cloud
257
+ // Build 6fb71ed9, Coder task 66468cf5) — 1 of ~1,140 builds since
258
+ // 2026-10-01.
259
+ const buildLog = await runner('gcloud', ['builds', 'log', buildId, '--region', config.region, ...gcloudBase]);
260
+ if (registryRateLimited(buildLog.stdout + buildLog.stderr)) {
261
+ await evidence.save('cloud-build-rate-limited.log', buildLog.stdout + buildLog.stderr);
262
+ log(`image build ${buildId} failed on a registry rate limit; resubmitting once in ${RATE_LIMIT_PAUSE_MS / 1000} s`);
263
+ await sleep(RATE_LIMIT_PAUSE_MS);
264
+ submit = await submitBuild();
265
+ }
266
+ }
267
+ if (submit.code !== 0) {
268
+ const tail = (submit.stderr.trim() || submit.stdout.trim()).slice(-2000);
269
+ throw new CommandFailure(`gcloud ${submitArgs.join(' ')} exited ${submit.code}\n${tail}`, submit);
270
+ }
236
271
  await evidence.save('cloud-build.json', submit.stdout);
237
272
  }
238
273
  const digest = (await describeImage()).image_summary?.fully_qualified_digest ?? '';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@steve31415/baselib",
3
- "version": "3.75.0",
3
+ "version": "3.76.0",
4
4
  "description": "Plasticine new-world shared platform library: logging, auth, service-to-service auth, db, HTTP, sync, app updates",
5
5
  "type": "module",
6
6
  "license": "MIT",