@vercel/container 29.1.0 → 30.0.0-snapshot-4bb5562899c1

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.
@@ -8,6 +8,11 @@ export declare class StoreOperations {
8
8
  private finishPendingCleanup;
9
9
  private pruneImages;
10
10
  private archiveStore;
11
+ /**
12
+ * Buildah's first open in a run root flushes the graph root's filesystem,
13
+ * which is cheap only before the snapshot is extracted.
14
+ */
15
+ private prewarmStorage;
11
16
  private restoreBlobInfoCache;
12
17
  private stageBlobInfoCache;
13
18
  }
@@ -2,14 +2,20 @@ export interface BuildahStorePaths {
2
2
  graphRoot: string;
3
3
  blobInfoCache: string;
4
4
  }
5
+ export interface PrewarmOptions {
6
+ graphRoot: string;
7
+ buildahArgs: string[];
8
+ }
5
9
  export interface ExtractOptions extends BuildahStorePaths {
6
10
  archive: string;
11
+ prewarm: PrewarmOptions;
7
12
  }
8
13
  export interface RestoreOptions extends ExtractOptions {
9
14
  storeLock: string;
10
15
  marker: string;
11
16
  }
12
- export interface SaveOptions extends ExtractOptions {
17
+ export interface SaveOptions extends BuildahStorePaths {
18
+ archive: string;
13
19
  stateDirectory: string;
14
20
  threads: number;
15
21
  buildahArgs: string[];
@@ -18,9 +24,14 @@ export interface CleanupOptions {
18
24
  record: string;
19
25
  buildahArgs: string[];
20
26
  }
27
+ export interface PrewarmResult {
28
+ durationMs: number;
29
+ error?: string;
30
+ }
21
31
  export type RestoreResult = {
22
32
  status: 'hit';
23
33
  bytes: number;
34
+ prewarm: PrewarmResult;
24
35
  } | {
25
36
  status: 'miss';
26
37
  reason: string;
@@ -132,7 +132,8 @@ var StoreOperations = class {
132
132
  options: {
133
133
  graphRoot: options.graphRoot,
134
134
  archive: options.archive,
135
- blobInfoCache: options.blobInfoCache
135
+ blobInfoCache: options.blobInfoCache,
136
+ prewarm: options.prewarm
136
137
  }
137
138
  },
138
139
  new FileLock(options.storeLock)
@@ -148,6 +149,7 @@ var StoreOperations = class {
148
149
  }
149
150
  const archive = await requireRegularFile(options.archive);
150
151
  await (0, import_promises3.mkdir)((0, import_node_path3.dirname)(options.graphRoot), { recursive: true });
152
+ const prewarm = await this.prewarmStorage(options.prewarm);
151
153
  const staging = await (0, import_promises3.mkdtemp)(`${options.graphRoot}.restore.`);
152
154
  try {
153
155
  await run(
@@ -174,7 +176,7 @@ var StoreOperations = class {
174
176
  (0, import_node_path3.join)(options.graphRoot, STAGED_BLOB_INFO_CACHE),
175
177
  options.blobInfoCache
176
178
  );
177
- return { status: "hit", bytes: archive.size };
179
+ return { status: "hit", bytes: archive.size, prewarm };
178
180
  } finally {
179
181
  await (0, import_promises3.rm)(staging, { recursive: true, force: true });
180
182
  }
@@ -331,6 +333,24 @@ var StoreOperations = class {
331
333
  await (0, import_promises3.rm)(temporary, { force: true });
332
334
  }
333
335
  }
336
+ /**
337
+ * Buildah's first open in a run root flushes the graph root's filesystem,
338
+ * which is cheap only before the snapshot is extracted.
339
+ */
340
+ async prewarmStorage(options) {
341
+ const start = Date.now();
342
+ let error;
343
+ try {
344
+ await run("buildah", [...options.buildahArgs, "info"], { quiet: true });
345
+ } catch (cause) {
346
+ error = cause.message;
347
+ }
348
+ await (0, import_promises3.rm)(options.graphRoot, { recursive: true, force: true }).catch(
349
+ () => {
350
+ }
351
+ );
352
+ return { durationMs: Date.now() - start, error };
353
+ }
334
354
  async restoreBlobInfoCache(staged, destination) {
335
355
  try {
336
356
  if (!(await lstatIfPresent(staged))?.isFile())
package/dist/index.js CHANGED
@@ -476,9 +476,9 @@ function buildahRegistriesConfPath() {
476
476
  }
477
477
  return cachedRegistriesConfPath;
478
478
  }
479
- async function buildahStorageArgs() {
479
+ async function buildahStorageArgs(graphRoot = BUILDAH_GRAPH_ROOT) {
480
480
  const driver = await selectStorageDriver();
481
- const rootArgs = isBuildContainer() ? ["--root", BUILDAH_GRAPH_ROOT, "--runroot", BUILDAH_RUN_ROOT] : [];
481
+ const rootArgs = isBuildContainer() ? ["--root", graphRoot, "--runroot", BUILDAH_RUN_ROOT] : [];
482
482
  const registriesArgs = [
483
483
  "--registries-conf",
484
484
  buildahRegistriesConfPath()
@@ -3661,6 +3661,7 @@ var STORE_PATHS = {
3661
3661
  // Buildah's default when running as root, as it does in the build container.
3662
3662
  blobInfoCache: "/var/lib/containers/cache/blob-info-cache-v1.sqlite"
3663
3663
  };
3664
+ var PREWARM_GRAPH_ROOT = `${BUILDAH_GRAPH_ROOT}.prewarm`;
3664
3665
  var BuildahStoreCache = class _BuildahStoreCache {
3665
3666
  constructor(repositoryRoot, client) {
3666
3667
  this.repositoryRoot = repositoryRoot;
@@ -3709,12 +3710,15 @@ var BuildahStoreCache = class _BuildahStoreCache {
3709
3710
  let result = "miss";
3710
3711
  let reason;
3711
3712
  let bytes = 0;
3713
+ let prewarm;
3712
3714
  try {
3713
3715
  const archive = await this.archivePath({ create: false });
3714
3716
  const restored = await restoreStore(archive);
3715
3717
  result = restored.status;
3716
- if (restored.status === "hit")
3718
+ if (restored.status === "hit") {
3717
3719
  bytes = restored.bytes;
3720
+ prewarm = restored.prewarm;
3721
+ }
3718
3722
  if (restored.status === "miss")
3719
3723
  reason = restored.reason;
3720
3724
  } catch (error) {
@@ -3724,6 +3728,12 @@ var BuildahStoreCache = class _BuildahStoreCache {
3724
3728
  await this.removeSnapshots();
3725
3729
  const restoredBytes = result === "hit" ? bytes : 0;
3726
3730
  const detail = reason ?? (result === "hit" ? formatBytes(restoredBytes) : void 0);
3731
+ const prewarmError = prewarm?.error ? failureReason(prewarm.error) : void 0;
3732
+ if (prewarm) {
3733
+ debug(
3734
+ prewarmError ? `could not prewarm Buildah storage: ${prewarmError}` : `prewarmed Buildah storage in ${prewarm.durationMs}ms`
3735
+ );
3736
+ }
3727
3737
  done(
3728
3738
  `Buildah store cache: ${result}${detail ? ` (${detail})` : ""} in ${elapsed(start)}`
3729
3739
  );
@@ -3731,7 +3741,9 @@ var BuildahStoreCache = class _BuildahStoreCache {
3731
3741
  "container.buildah_store.restore": result,
3732
3742
  "container.buildah_store.restore_ms": String(Date.now() - start),
3733
3743
  "container.buildah_store.restore_bytes": String(restoredBytes),
3734
- "container.buildah_store.miss_reason": reason
3744
+ "container.buildah_store.miss_reason": reason,
3745
+ "container.buildah_store.prewarm_ms": prewarm && String(prewarm.durationMs),
3746
+ "container.buildah_store.prewarm_error": prewarmError
3735
3747
  });
3736
3748
  }
3737
3749
  async save() {
@@ -3804,7 +3816,11 @@ async function restoreStore(archive) {
3804
3816
  ...STORE_PATHS,
3805
3817
  archive,
3806
3818
  storeLock: storeLock.path,
3807
- marker: (0, import_node_path23.join)(state, "restored")
3819
+ marker: (0, import_node_path23.join)(state, "restored"),
3820
+ prewarm: {
3821
+ graphRoot: PREWARM_GRAPH_ROOT,
3822
+ buildahArgs: await buildahStorageArgs(PREWARM_GRAPH_ROOT)
3823
+ }
3808
3824
  }
3809
3825
  },
3810
3826
  gate
@@ -5767,7 +5783,7 @@ async function resolveImageOutput(options, source, buildahClient, span, schedule
5767
5783
  });
5768
5784
  const contextIsRoot = Boolean(daemon || schedulesCommand || options.service) || import_node_path31.default.dirname(import_node_path31.default.normalize(dockerfileRel)) === ".";
5769
5785
  const buildArgs = buildArgsFromEnv(meta?.buildEnv);
5770
- const shouldExportLayout = ociLayoutRequested() && !daemon;
5786
+ const shouldExportLayout = ociLayoutRequested() && !daemon && config.publishContainerImages !== true;
5771
5787
  span?.setAttributes({
5772
5788
  "container.repository": repository,
5773
5789
  "container.context_is_root": toTag(contextIsRoot),
Binary file
@@ -12,4 +12,4 @@ export declare const DOCKER_HUB_MIRROR_FLAG = "VERCEL_BUILDAH_DOCKER_HUB_MIRROR"
12
12
  /** Test-only: forget the written registries.conf so env changes take effect. */
13
13
  export declare function __resetRegistriesConfCache(): void;
14
14
  /** Global Buildah flags for native storage and registry resolution. */
15
- export declare function buildahStorageArgs(): Promise<string[]>;
15
+ export declare function buildahStorageArgs(graphRoot?: string): Promise<string[]>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vercel/container",
3
- "version": "29.1.0",
3
+ "version": "30.0.0-snapshot-4bb5562899c1",
4
4
  "license": "Apache-2.0",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -18,13 +18,13 @@
18
18
  "tar": "7.5.11"
19
19
  },
20
20
  "peerDependencies": {
21
- "@vercel/build-utils": "15.7.0"
21
+ "@vercel/build-utils": "15.8.0-snapshot-4bb5562899c1"
22
22
  },
23
23
  "devDependencies": {
24
24
  "@types/node": "20.11.0",
25
25
  "vitest": "4.1.10",
26
- "@vercel-internals/ipc-proxy": "1.1.4",
27
- "@vercel/build-utils": "15.7.0"
26
+ "@vercel-internals/ipc-proxy": "1.1.5",
27
+ "@vercel/build-utils": "15.8.0-snapshot-4bb5562899c1"
28
28
  },
29
29
  "publishConfig": {
30
30
  "access": "public"