@vercel/container 29.0.0 → 29.1.0-snapshot-3c48721091f5

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/index.js CHANGED
@@ -106,8 +106,8 @@ async function generateProjectManifest({
106
106
  var diagnostics = (options) => (0, import_build_utils.createDiagnostics)(manifestSlot(options.config?.daemon?.name))(options);
107
107
 
108
108
  // src/index.ts
109
- var import_promises14 = require("fs/promises");
110
- var import_node_path30 = __toESM(require("path"));
109
+ var import_promises15 = require("fs/promises");
110
+ var import_node_path31 = __toESM(require("path"));
111
111
 
112
112
  // src/util.ts
113
113
  var import_build_utils2 = require("@vercel/build-utils");
@@ -670,9 +670,6 @@ function buildArgFlags(params) {
670
670
  function buildTargetFlags(params) {
671
671
  return params.buildTarget ? ["--target", params.buildTarget] : [];
672
672
  }
673
- function exportsLayouts(engine) {
674
- return engine.exportLayout !== void 0;
675
- }
676
673
 
677
674
  // src/registry.ts
678
675
  async function resolveRegistryTarget(params) {
@@ -1111,20 +1108,37 @@ function readDigestFile(path4) {
1111
1108
 
1112
1109
  // src/engines/docker.ts
1113
1110
  var import_node_child_process2 = require("child_process");
1111
+ var import_promises6 = require("fs/promises");
1112
+ var import_node_path7 = require("path");
1113
+ var import_tar = require("tar");
1114
1114
  function runDocker(args, opts = {}) {
1115
1115
  debug(`exec: docker ${args.join(" ")}`);
1116
1116
  return run("docker", args, opts);
1117
1117
  }
1118
+ async function getDockerDaemonVersion() {
1119
+ const { stdout } = await run(
1120
+ "docker",
1121
+ ["version", "--format", "{{.Server.Version}}"],
1122
+ { quiet: true }
1123
+ );
1124
+ return stdout.trim();
1125
+ }
1118
1126
  async function isDockerDaemonReachable() {
1119
1127
  try {
1120
- await run("docker", ["version", "--format", "{{.Server.Version}}"], {
1121
- quiet: true
1122
- });
1128
+ await getDockerDaemonVersion();
1123
1129
  return true;
1124
1130
  } catch {
1125
1131
  return false;
1126
1132
  }
1127
1133
  }
1134
+ var MIN_LAYOUT_EXPORT_VERSION = [25, 0, 1];
1135
+ function parseVersion(version2) {
1136
+ return /^(\d+)\.(\d+)\.(\d+)/.exec(version2)?.slice(1).map(Number);
1137
+ }
1138
+ function isOlderThan(version2, minimum) {
1139
+ const differs = version2.findIndex((part, index) => part !== minimum[index]);
1140
+ return differs !== -1 && version2[differs] < minimum[differs];
1141
+ }
1128
1142
  function tail(text, n = 12) {
1129
1143
  return text.trim().split("\n").slice(-n).join("\n");
1130
1144
  }
@@ -1262,12 +1276,8 @@ var dockerEngine = {
1262
1276
  name: "docker",
1263
1277
  async ensureReady(span) {
1264
1278
  try {
1265
- const { stdout } = await run(
1266
- "docker",
1267
- ["version", "--format", "{{.Server.Version}}"],
1268
- { quiet: true }
1269
- );
1270
- span?.setAttributes({ "docker.server_version": stdout.trim() });
1279
+ const serverVersion = await getDockerDaemonVersion();
1280
+ span?.setAttributes({ "docker.server_version": serverVersion });
1271
1281
  } catch (err) {
1272
1282
  const message = err.message;
1273
1283
  const onVercel = isBuildContainer();
@@ -1336,6 +1346,36 @@ ${version2.trim()}`);
1336
1346
  ]);
1337
1347
  return params.imageRef;
1338
1348
  },
1349
+ async verifyLayoutExport() {
1350
+ const version2 = parseVersion(await getDockerDaemonVersion());
1351
+ if (!version2 || isOlderThan(version2, MIN_LAYOUT_EXPORT_VERSION)) {
1352
+ throw new Error(
1353
+ `Docker Engine ${MIN_LAYOUT_EXPORT_VERSION.join(".")} or later is required, but the Docker daemon reports ${version2 ? version2.join(".") : "an unrecognized version"}. Use a supported version, then re-run the build.`
1354
+ );
1355
+ }
1356
+ },
1357
+ async exportLayout(params, directory) {
1358
+ const archive = (0, import_node_path7.join)(directory, "docker-image.tar");
1359
+ try {
1360
+ await runDocker(["image", "save", "--output", archive, params.imageRef]);
1361
+ await (0, import_tar.extract)({
1362
+ file: archive,
1363
+ cwd: directory,
1364
+ strict: true,
1365
+ filter: (path4, entry) => {
1366
+ if (!("type" in entry) || entry.type !== "File")
1367
+ return false;
1368
+ const name = path4.replace(/^\.\//, "");
1369
+ return name === "oci-layout" || name === "index.json" || /^blobs\/sha256\/[a-f0-9]{64}$/.test(name);
1370
+ }
1371
+ });
1372
+ if (!await lstatIfPresent((0, import_node_path7.join)(directory, "oci-layout"))) {
1373
+ throw new Error("Docker didn't save the image as an OCI image layout.");
1374
+ }
1375
+ } finally {
1376
+ await (0, import_promises6.rm)(archive, { force: true });
1377
+ }
1378
+ },
1339
1379
  async onBuildTriggers(imageRef) {
1340
1380
  const { stdout } = await runDocker([
1341
1381
  "image",
@@ -1543,27 +1583,27 @@ Continuing (set VERCEL_VCR_STRICT_STORAGE=1 to fail builds).`
1543
1583
  // src/buildpacks/build.ts
1544
1584
  var import_node_fs14 = require("fs");
1545
1585
  var import_node_os10 = require("os");
1546
- var import_node_path19 = require("path");
1586
+ var import_node_path20 = require("path");
1547
1587
 
1548
1588
  // src/buildpacks/cache.ts
1549
1589
  var import_node_crypto4 = require("crypto");
1550
1590
  var import_node_fs4 = require("fs");
1551
- var import_promises6 = require("fs/promises");
1552
- var import_node_path7 = require("path");
1591
+ var import_promises7 = require("fs/promises");
1592
+ var import_node_path8 = require("path");
1553
1593
  var BUILDPACK_CACHE_DIR = ".vercel/cache/buildpacks";
1554
1594
  var CNB_COMMITTED_DIR = "committed";
1555
1595
  var CNB_CACHE_METADATA_FILE = "io.buildpacks.lifecycle.cache.metadata";
1556
1596
  var IMAGE_ID_FILE = "image-id";
1557
1597
  function buildpackCacheDir(options) {
1558
- const root = (0, import_node_path7.resolve)(options.repoRootPath || options.workPath);
1559
- const app = (0, import_node_path7.relative)(root, (0, import_node_path7.resolve)(options.workPath)).split(import_node_path7.sep).join("/") || ".";
1598
+ const root = (0, import_node_path8.resolve)(options.repoRootPath || options.workPath);
1599
+ const app = (0, import_node_path8.relative)(root, (0, import_node_path8.resolve)(options.workPath)).split(import_node_path8.sep).join("/") || ".";
1560
1600
  const daemon = options.config?.daemon;
1561
1601
  const owner = daemon ? { daemon: daemon.name } : options.service?.name ?? null;
1562
1602
  const key = (0, import_node_crypto4.createHash)("sha256").update(JSON.stringify([app, owner])).digest("hex").slice(0, 32);
1563
- return (0, import_node_path7.join)(root, BUILDPACK_CACHE_DIR, key);
1603
+ return (0, import_node_path8.join)(root, BUILDPACK_CACHE_DIR, key);
1564
1604
  }
1565
1605
  async function restoreBuildpackCache(dir, cacheKey, cacheDir) {
1566
- const committed = (0, import_node_path7.join)(cacheDir, CNB_COMMITTED_DIR);
1606
+ const committed = (0, import_node_path8.join)(cacheDir, CNB_COMMITTED_DIR);
1567
1607
  const [copy, key] = await Promise.allSettled([
1568
1608
  copyCommitted(dir, cacheDir),
1569
1609
  cacheKey
@@ -1573,7 +1613,7 @@ async function restoreBuildpackCache(dir, cacheKey, cacheDir) {
1573
1613
  throw copy.reason;
1574
1614
  if (key.status === "rejected")
1575
1615
  throw key.reason;
1576
- if (readRegularFile((0, import_node_path7.join)(dir, IMAGE_ID_FILE)) !== key.value) {
1616
+ if (readRegularFile((0, import_node_path8.join)(dir, IMAGE_ID_FILE)) !== key.value) {
1577
1617
  (0, import_node_fs4.rmSync)(committed, { recursive: true, force: true });
1578
1618
  return { status: "miss", reason: "base_image_changed" };
1579
1619
  }
@@ -1588,11 +1628,11 @@ async function restoreBuildpackCache(dir, cacheKey, cacheDir) {
1588
1628
  }
1589
1629
  }
1590
1630
  async function saveBuildpackCache(dir, cacheKey, cacheDir) {
1591
- const committed = (0, import_node_path7.join)(cacheDir, CNB_COMMITTED_DIR);
1631
+ const committed = (0, import_node_path8.join)(cacheDir, CNB_COMMITTED_DIR);
1592
1632
  let metadata;
1593
1633
  try {
1594
1634
  assertDirectory(committed);
1595
- metadata = readRegularFile((0, import_node_path7.join)(committed, CNB_CACHE_METADATA_FILE));
1635
+ metadata = readRegularFile((0, import_node_path8.join)(committed, CNB_CACHE_METADATA_FILE));
1596
1636
  } catch (error) {
1597
1637
  const missing = error.code === "ENOENT";
1598
1638
  return {
@@ -1606,7 +1646,7 @@ async function saveBuildpackCache(dir, cacheKey, cacheDir) {
1606
1646
  const bytes = sizeOf(committed);
1607
1647
  (0, import_node_fs4.rmSync)(dir, { recursive: true, force: true });
1608
1648
  await copyCommitted(cacheDir, dir);
1609
- (0, import_node_fs4.writeFileSync)((0, import_node_path7.join)(dir, IMAGE_ID_FILE), cacheKey);
1649
+ (0, import_node_fs4.writeFileSync)((0, import_node_path8.join)(dir, IMAGE_ID_FILE), cacheKey);
1610
1650
  return { status: "saved", bytes };
1611
1651
  } catch (error) {
1612
1652
  try {
@@ -1618,16 +1658,16 @@ async function saveBuildpackCache(dir, cacheKey, cacheDir) {
1618
1658
  }
1619
1659
  function isSaved(dir, cacheKey, metadata) {
1620
1660
  try {
1621
- const committed = (0, import_node_path7.join)(dir, CNB_COMMITTED_DIR);
1661
+ const committed = (0, import_node_path8.join)(dir, CNB_COMMITTED_DIR);
1622
1662
  assertDirectory(committed);
1623
- return readRegularFile((0, import_node_path7.join)(dir, IMAGE_ID_FILE)) === cacheKey && readRegularFile((0, import_node_path7.join)(committed, CNB_CACHE_METADATA_FILE)) === metadata;
1663
+ return readRegularFile((0, import_node_path8.join)(dir, IMAGE_ID_FILE)) === cacheKey && readRegularFile((0, import_node_path8.join)(committed, CNB_CACHE_METADATA_FILE)) === metadata;
1624
1664
  } catch {
1625
1665
  return false;
1626
1666
  }
1627
1667
  }
1628
1668
  async function copyCommitted(from, to) {
1629
- const source = (0, import_node_path7.join)(from, CNB_COMMITTED_DIR);
1630
- const target = (0, import_node_path7.join)(to, CNB_COMMITTED_DIR);
1669
+ const source = (0, import_node_path8.join)(from, CNB_COMMITTED_DIR);
1670
+ const target = (0, import_node_path8.join)(to, CNB_COMMITTED_DIR);
1631
1671
  assertDirectory(source);
1632
1672
  (0, import_node_fs4.mkdirSync)(target, { recursive: true });
1633
1673
  const entries = (0, import_node_fs4.readdirSync)(source, { withFileTypes: true });
@@ -1637,9 +1677,9 @@ async function copyCommitted(from, to) {
1637
1677
  }
1638
1678
  const copies = await Promise.allSettled(
1639
1679
  entries.map(
1640
- (entry) => (0, import_promises6.copyFile)(
1641
- (0, import_node_path7.join)(source, entry.name),
1642
- (0, import_node_path7.join)(target, entry.name),
1680
+ (entry) => (0, import_promises7.copyFile)(
1681
+ (0, import_node_path8.join)(source, entry.name),
1682
+ (0, import_node_path8.join)(target, entry.name),
1643
1683
  import_node_fs4.constants.COPYFILE_FICLONE
1644
1684
  )
1645
1685
  )
@@ -1650,12 +1690,12 @@ async function copyCommitted(from, to) {
1650
1690
  }
1651
1691
  function assertDirectory(path4) {
1652
1692
  if (!(0, import_node_fs4.lstatSync)(path4).isDirectory()) {
1653
- throw new Error(`${(0, import_node_path7.basename)(path4)} is not a directory`);
1693
+ throw new Error(`${(0, import_node_path8.basename)(path4)} is not a directory`);
1654
1694
  }
1655
1695
  }
1656
1696
  function readRegularFile(path4) {
1657
1697
  if (!(0, import_node_fs4.lstatSync)(path4).isFile())
1658
- throw notRegularFile((0, import_node_path7.basename)(path4));
1698
+ throw notRegularFile((0, import_node_path8.basename)(path4));
1659
1699
  return (0, import_node_fs4.readFileSync)(path4, "utf8");
1660
1700
  }
1661
1701
  function notRegularFile(name) {
@@ -1663,7 +1703,7 @@ function notRegularFile(name) {
1663
1703
  }
1664
1704
  function sizeOf(dir) {
1665
1705
  return (0, import_node_fs4.readdirSync)(dir).reduce(
1666
- (bytes, name) => bytes + (0, import_node_fs4.lstatSync)((0, import_node_path7.join)(dir, name)).size,
1706
+ (bytes, name) => bytes + (0, import_node_fs4.lstatSync)((0, import_node_path8.join)(dir, name)).size,
1667
1707
  0
1668
1708
  );
1669
1709
  }
@@ -1704,9 +1744,9 @@ var import_build_utils4 = require("@vercel/build-utils");
1704
1744
  var import_node_crypto5 = require("crypto");
1705
1745
  var import_node_fs5 = require("fs");
1706
1746
  var import_node_os6 = require("os");
1707
- var import_node_path8 = require("path");
1747
+ var import_node_path9 = require("path");
1708
1748
  var import_smol_toml = require("smol-toml");
1709
- var import_tar = require("tar");
1749
+ var import_tar2 = require("tar");
1710
1750
 
1711
1751
  // src/buildpacks/distribution.json
1712
1752
  var distribution_default = {
@@ -1889,20 +1929,20 @@ async function stageWorkspace({
1889
1929
  workPath,
1890
1930
  repoRootPath
1891
1931
  }, destinationDir) {
1892
- const repoRoot = (0, import_node_path8.resolve)(repoRootPath ?? workPath);
1893
- const serviceRoot = (0, import_node_path8.resolve)(workPath);
1894
- const serviceRelative = (0, import_node_path8.relative)(repoRoot, serviceRoot);
1932
+ const repoRoot = (0, import_node_path9.resolve)(repoRootPath ?? workPath);
1933
+ const serviceRoot = (0, import_node_path9.resolve)(workPath);
1934
+ const serviceRelative = (0, import_node_path9.relative)(repoRoot, serviceRoot);
1895
1935
  if ((0, import_node_fs5.lstatSync)(serviceRoot).isSymbolicLink()) {
1896
1936
  throw new Error(
1897
1937
  "Buildpack service root must not be reached through a symbolic link."
1898
1938
  );
1899
1939
  }
1900
- if (serviceRelative && serviceRelative !== "." && serviceRelative !== ".." && !serviceRelative.startsWith(`..${import_node_path8.sep}`) && !(0, import_node_path8.isAbsolute)(serviceRelative)) {
1940
+ if (serviceRelative && serviceRelative !== "." && serviceRelative !== ".." && !serviceRelative.startsWith(`..${import_node_path9.sep}`) && !(0, import_node_path9.isAbsolute)(serviceRelative)) {
1901
1941
  let current = repoRoot;
1902
- for (const part of serviceRelative.split(import_node_path8.sep)) {
1942
+ for (const part of serviceRelative.split(import_node_path9.sep)) {
1903
1943
  if (!part || part === ".")
1904
1944
  continue;
1905
- current = (0, import_node_path8.join)(current, part);
1945
+ current = (0, import_node_path9.join)(current, part);
1906
1946
  if ((0, import_node_fs5.lstatSync)(current).isSymbolicLink()) {
1907
1947
  throw new Error(
1908
1948
  "Buildpack service root must not be reached through a symbolic link."
@@ -1913,8 +1953,8 @@ async function stageWorkspace({
1913
1953
  const staged = /* @__PURE__ */ Object.create(null);
1914
1954
  const symlinks = /* @__PURE__ */ new Set();
1915
1955
  for (const [name, file] of Object.entries(files)) {
1916
- const normalized = import_node_path8.posix.normalize(name).replace(/\/$/, "");
1917
- if (!normalized || normalized === "." || name.includes("\\") || import_node_path8.win32.isAbsolute(name) || import_node_path8.posix.isAbsolute(name) || name.split("/").includes("..") || normalized in staged) {
1956
+ const normalized = import_node_path9.posix.normalize(name).replace(/\/$/, "");
1957
+ if (!normalized || normalized === "." || name.includes("\\") || import_node_path9.win32.isAbsolute(name) || import_node_path9.posix.isAbsolute(name) || name.split("/").includes("..") || normalized in staged) {
1918
1958
  throw new Error(`Invalid buildpack source path ${JSON.stringify(name)}.`);
1919
1959
  }
1920
1960
  staged[normalized] = file;
@@ -1927,21 +1967,21 @@ async function stageWorkspace({
1927
1967
  if (!target) {
1928
1968
  throw new Error(`Cannot read buildpack source symlink ${name}.`);
1929
1969
  }
1930
- if ((0, import_node_path8.isAbsolute)(target)) {
1931
- target = (0, import_node_path8.relative)((0, import_node_path8.resolve)(workPath, import_node_path8.posix.dirname(normalized)), target) || ".";
1932
- } else if (import_node_path8.win32.isAbsolute(target)) {
1970
+ if ((0, import_node_path9.isAbsolute)(target)) {
1971
+ target = (0, import_node_path9.relative)((0, import_node_path9.resolve)(workPath, import_node_path9.posix.dirname(normalized)), target) || ".";
1972
+ } else if (import_node_path9.win32.isAbsolute(target)) {
1933
1973
  throw new Error(
1934
1974
  `Buildpack source symlink ${name} has an absolute target.`
1935
1975
  );
1936
1976
  }
1937
- if (import_node_path8.sep === "\\") {
1977
+ if (import_node_path9.sep === "\\") {
1938
1978
  target = target.replace(/\\/g, "/");
1939
1979
  } else if (target.includes("\\")) {
1940
1980
  throw new Error(
1941
1981
  `Buildpack source symlink ${name} has a target staging would reinterpret.`
1942
1982
  );
1943
1983
  }
1944
- const resolved = import_node_path8.posix.join(import_node_path8.posix.dirname(normalized), target);
1984
+ const resolved = import_node_path9.posix.join(import_node_path9.posix.dirname(normalized), target);
1945
1985
  if (resolved === ".." || resolved.startsWith("../")) {
1946
1986
  throw new Error(
1947
1987
  `Buildpack source symlink ${name} escapes the service root. Buildpack services must be self-contained.`
@@ -1951,7 +1991,7 @@ async function stageWorkspace({
1951
1991
  symlinks.add(normalized);
1952
1992
  }
1953
1993
  for (const name of Object.keys(staged)) {
1954
- for (let parent = import_node_path8.posix.dirname(name); parent !== "."; parent = import_node_path8.posix.dirname(parent)) {
1994
+ for (let parent = import_node_path9.posix.dirname(name); parent !== "."; parent = import_node_path9.posix.dirname(parent)) {
1955
1995
  if (symlinks.has(parent)) {
1956
1996
  throw new Error(
1957
1997
  `Buildpack source ${name} is inside symlink ${parent}.`
@@ -1960,16 +2000,16 @@ async function stageWorkspace({
1960
2000
  }
1961
2001
  const file = staged[name];
1962
2002
  if (file.type === "FileFsRef" && !(0, import_build_utils4.isSymbolicLink)(file.mode)) {
1963
- const sourcePath = (0, import_node_path8.resolve)(file.fsPath);
1964
- const sourceRelative = (0, import_node_path8.relative)((0, import_node_path8.resolve)(workPath), sourcePath);
1965
- if (sourceRelative.startsWith(`..${import_node_path8.sep}`) || sourceRelative === ".." || (0, import_node_path8.isAbsolute)(sourceRelative)) {
2003
+ const sourcePath = (0, import_node_path9.resolve)(file.fsPath);
2004
+ const sourceRelative = (0, import_node_path9.relative)((0, import_node_path9.resolve)(workPath), sourcePath);
2005
+ if (sourceRelative.startsWith(`..${import_node_path9.sep}`) || sourceRelative === ".." || (0, import_node_path9.isAbsolute)(sourceRelative)) {
1966
2006
  continue;
1967
2007
  }
1968
2008
  const sourceRoot = import_node_fs5.realpathSync.native(workPath);
1969
2009
  const sourceTarget = import_node_fs5.realpathSync.native(sourcePath);
1970
- if (sourceTarget !== (0, import_node_path8.resolve)(sourceRoot, sourceRelative)) {
1971
- const target = (0, import_node_path8.relative)(sourceRoot, sourceTarget).split(import_node_path8.sep).join("/");
1972
- if (target === ".." || target.startsWith("../") || (0, import_node_path8.isAbsolute)(target) || !(target in staged)) {
2010
+ if (sourceTarget !== (0, import_node_path9.resolve)(sourceRoot, sourceRelative)) {
2011
+ const target = (0, import_node_path9.relative)(sourceRoot, sourceTarget).split(import_node_path9.sep).join("/");
2012
+ if (target === ".." || target.startsWith("../") || (0, import_node_path9.isAbsolute)(target) || !(target in staged)) {
1973
2013
  throw new Error(
1974
2014
  `Buildpack source ${name} follows a symlink to an excluded or outside-root file. Buildpack services must be self-contained.`
1975
2015
  );
@@ -1982,13 +2022,13 @@ async function stageWorkspace({
1982
2022
  for (const name of symlinks) {
1983
2023
  let target;
1984
2024
  try {
1985
- target = (0, import_node_path8.relative)(root, import_node_fs5.realpathSync.native((0, import_node_path8.join)(destinationDir, name)));
2025
+ target = (0, import_node_path9.relative)(root, import_node_fs5.realpathSync.native((0, import_node_path9.join)(destinationDir, name)));
1986
2026
  } catch {
1987
2027
  throw new Error(
1988
2028
  `Buildpack source symlink ${name} has no target in the staged service.`
1989
2029
  );
1990
2030
  }
1991
- if (target === ".." || target.startsWith(`..${import_node_path8.sep}`) || (0, import_node_path8.isAbsolute)(target)) {
2031
+ if (target === ".." || target.startsWith(`..${import_node_path9.sep}`) || (0, import_node_path9.isAbsolute)(target)) {
1992
2032
  throw new Error(
1993
2033
  `Buildpack source symlink ${name} escapes the staged service.`
1994
2034
  );
@@ -2018,14 +2058,14 @@ function writePlatformEnvDir(buildEnv, config, parentDir = (0, import_node_os6.t
2018
2058
  if (config.buildCommand) {
2019
2059
  environment.VERCEL_BUILD_COMMAND = config.buildCommand;
2020
2060
  }
2021
- const dir = (0, import_node_fs5.mkdtempSync)((0, import_node_path8.join)(parentDir, "vercel-cnb-env-"));
2061
+ const dir = (0, import_node_fs5.mkdtempSync)((0, import_node_path9.join)(parentDir, "vercel-cnb-env-"));
2022
2062
  (0, import_node_fs5.chmodSync)(dir, 493);
2023
2063
  for (const [key, value] of Object.entries(environment)) {
2024
2064
  if (!ENV_NAME_RE.test(key)) {
2025
2065
  debug(`skipping build env var with an unsupported name: ${key}`);
2026
2066
  continue;
2027
2067
  }
2028
- const file = (0, import_node_path8.join)(dir, key);
2068
+ const file = (0, import_node_path9.join)(dir, key);
2029
2069
  (0, import_node_fs5.writeFileSync)(file, value);
2030
2070
  (0, import_node_fs5.chmodSync)(file, 420);
2031
2071
  }
@@ -2101,9 +2141,9 @@ function writeOrderDir(buildpack, parentDir = (0, import_node_os6.tmpdir)()) {
2101
2141
  }
2102
2142
  ]
2103
2143
  };
2104
- const dir = (0, import_node_fs5.mkdtempSync)((0, import_node_path8.join)(parentDir, "vercel-cnb-order-"));
2144
+ const dir = (0, import_node_fs5.mkdtempSync)((0, import_node_path9.join)(parentDir, "vercel-cnb-order-"));
2105
2145
  (0, import_node_fs5.chmodSync)(dir, 493);
2106
- const file = (0, import_node_path8.join)(dir, "order.toml");
2146
+ const file = (0, import_node_path9.join)(dir, "order.toml");
2107
2147
  (0, import_node_fs5.writeFileSync)(file, (0, import_smol_toml.stringify)(order));
2108
2148
  (0, import_node_fs5.chmodSync)(file, 420);
2109
2149
  return dir;
@@ -2159,10 +2199,10 @@ async function downloadPinnedArchive(archive, destinationPath) {
2159
2199
  (0, import_node_fs5.writeFileSync)(destinationPath, contents);
2160
2200
  }
2161
2201
  async function fetchPinnedArchive(archive, destinationDir) {
2162
- const archivePath = (0, import_node_path8.join)(destinationDir, `${archive.sha256}.tgz`);
2202
+ const archivePath = (0, import_node_path9.join)(destinationDir, `${archive.sha256}.tgz`);
2163
2203
  try {
2164
2204
  await downloadPinnedArchive(archive, archivePath);
2165
- (0, import_tar.extract)({ file: archivePath, cwd: destinationDir, sync: true });
2205
+ (0, import_tar2.extract)({ file: archivePath, cwd: destinationDir, sync: true });
2166
2206
  } finally {
2167
2207
  (0, import_node_fs5.rmSync)(archivePath, { force: true });
2168
2208
  }
@@ -2176,16 +2216,16 @@ function blobPath(layoutDir, digest) {
2176
2216
  if (!match) {
2177
2217
  throw new Error(`Unsupported OCI digest ${JSON.stringify(digest)}.`);
2178
2218
  }
2179
- return (0, import_node_path8.join)(layoutDir, "blobs", "sha256", match[1]);
2219
+ return (0, import_node_path9.join)(layoutDir, "blobs", "sha256", match[1]);
2180
2220
  }
2181
2221
  async function fetchBuildpackage(archive, cnbDir) {
2182
- const layoutDir = (0, import_node_fs5.mkdtempSync)((0, import_node_path8.join)((0, import_node_os6.tmpdir)(), "vercel-cnb-buildpackage-"));
2183
- const archivePath = (0, import_node_path8.join)(layoutDir, "buildpackage.cnb");
2222
+ const layoutDir = (0, import_node_fs5.mkdtempSync)((0, import_node_path9.join)((0, import_node_os6.tmpdir)(), "vercel-cnb-buildpackage-"));
2223
+ const archivePath = (0, import_node_path9.join)(layoutDir, "buildpackage.cnb");
2184
2224
  try {
2185
2225
  await downloadPinnedArchive(archive, archivePath);
2186
- await (0, import_tar.extract)({ file: archivePath, cwd: layoutDir });
2226
+ await (0, import_tar2.extract)({ file: archivePath, cwd: layoutDir });
2187
2227
  const index = readOciJson(
2188
- (0, import_node_path8.join)(layoutDir, "index.json")
2228
+ (0, import_node_path9.join)(layoutDir, "index.json")
2189
2229
  );
2190
2230
  const name = archiveName(archive);
2191
2231
  const manifestDigest = index.manifests?.[0]?.digest;
@@ -2213,7 +2253,7 @@ async function fetchBuildpackage(archive, cnbDir) {
2213
2253
  `${name} layer ${layer.digest} hashes to sha256:${actual}.`
2214
2254
  );
2215
2255
  }
2216
- await (0, import_tar.extract)({
2256
+ await (0, import_tar2.extract)({
2217
2257
  file: layerPath,
2218
2258
  cwd: cnbDir,
2219
2259
  strict: true,
@@ -2244,14 +2284,14 @@ async function fetchDistribution(buildpack, cnbDir) {
2244
2284
  )
2245
2285
  ]);
2246
2286
  for (const entry of buildpack.buildpacks) {
2247
- const directory = (0, import_node_path8.join)(
2287
+ const directory = (0, import_node_path9.join)(
2248
2288
  cnbDir,
2249
2289
  "buildpacks",
2250
2290
  entry.id.replace("/", "_"),
2251
2291
  entry.version
2252
2292
  );
2253
2293
  for (const file of ["buildpack.toml", "bin/detect", "bin/build"]) {
2254
- if (!(0, import_node_fs5.statSync)((0, import_node_path8.join)(directory, file), { throwIfNoEntry: false })?.isFile()) {
2294
+ if (!(0, import_node_fs5.statSync)((0, import_node_path9.join)(directory, file), { throwIfNoEntry: false })?.isFile()) {
2255
2295
  throw new Error(
2256
2296
  `Buildpack ${entry.id}@${entry.version} is missing ${file}.`
2257
2297
  );
@@ -2278,15 +2318,15 @@ function creatorArgs(image, imageRef, options = {}) {
2278
2318
  var import_node_fs7 = require("fs");
2279
2319
  var import_node_crypto6 = require("crypto");
2280
2320
  var import_node_os8 = require("os");
2281
- var import_node_path12 = require("path");
2321
+ var import_node_path13 = require("path");
2282
2322
 
2283
2323
  // src/buildah-store-cache/cleanup.ts
2284
2324
  var import_node_child_process3 = require("child_process");
2285
2325
 
2286
2326
  // src/buildah-store-cache/command/index.ts
2287
2327
  var import_build_utils5 = require("@vercel/build-utils");
2288
- var import_node_path9 = require("path");
2289
- var STORE_COMMAND_SCRIPT = (0, import_node_path9.join)(__dirname, "buildah-store-command.js");
2328
+ var import_node_path10 = require("path");
2329
+ var STORE_COMMAND_SCRIPT = (0, import_node_path10.join)(__dirname, "buildah-store-command.js");
2290
2330
  function storeCommand(request, script = STORE_COMMAND_SCRIPT) {
2291
2331
  return [(0, import_build_utils5.getNodeExecPath)(), script, JSON.stringify(request)];
2292
2332
  }
@@ -2298,7 +2338,7 @@ async function runStoreCommand(request, lock) {
2298
2338
 
2299
2339
  // src/buildah-store-cache/lock.ts
2300
2340
  var import_node_os7 = require("os");
2301
- var import_node_path10 = require("path");
2341
+ var import_node_path11 = require("path");
2302
2342
  var FileLock = class {
2303
2343
  constructor(path4) {
2304
2344
  this.path = path4;
@@ -2319,7 +2359,7 @@ async function buildahStoreLock() {
2319
2359
  return void 0;
2320
2360
  }
2321
2361
  flockAvailable ??= hasCommand("flock");
2322
- return await flockAvailable ? new FileLock((0, import_node_path10.join)((0, import_node_os7.tmpdir)(), "vercel-buildah-store.lock")) : void 0;
2362
+ return await flockAvailable ? new FileLock((0, import_node_path11.join)((0, import_node_os7.tmpdir)(), "vercel-buildah-store.lock")) : void 0;
2323
2363
  }
2324
2364
  var sharedBuildahStoreLock = {
2325
2365
  async wrap(command) {
@@ -2374,7 +2414,7 @@ async function recordPendingCleanup(container) {
2374
2414
 
2375
2415
  // src/buildpacks/lifecycle/build-user.ts
2376
2416
  var import_node_fs6 = require("fs");
2377
- var import_node_path11 = require("path");
2417
+ var import_node_path12 = require("path");
2378
2418
  var BUILD_USER_NAME = "cnb";
2379
2419
  var BUILD_USER_DIRECTORIES = ["layers", "platform", "workspace", "home/cnb"];
2380
2420
  var BUILD_GROUP_ENTRY = {
@@ -2400,7 +2440,7 @@ var BUILD_USER_ENTRY = {
2400
2440
  var MountedRootfs = class {
2401
2441
  constructor(root) {
2402
2442
  this.root = root;
2403
- if (!(0, import_node_path11.isAbsolute)(root)) {
2443
+ if (!(0, import_node_path12.isAbsolute)(root)) {
2404
2444
  throw new Error(`Expected the build image's mount point, got "${root}".`);
2405
2445
  }
2406
2446
  }
@@ -2429,7 +2469,7 @@ var MountedRootfs = class {
2429
2469
  directory(relativePath, create) {
2430
2470
  let path4 = this.root;
2431
2471
  for (const component of relativePath.split("/")) {
2432
- path4 = (0, import_node_path11.join)(path4, component);
2472
+ path4 = (0, import_node_path12.join)(path4, component);
2433
2473
  const stat = lstatIfPresent2(path4);
2434
2474
  if (!stat && create) {
2435
2475
  (0, import_node_fs6.mkdirSync)(path4, { mode: 493 });
@@ -2445,7 +2485,7 @@ var MountedRootfs = class {
2445
2485
  const separator = relativePath.lastIndexOf("/");
2446
2486
  const parent = this.directory(relativePath.slice(0, separator), false);
2447
2487
  const fd = (0, import_node_fs6.openSync)(
2448
- (0, import_node_path11.join)(parent, relativePath.slice(separator + 1)),
2488
+ (0, import_node_path12.join)(parent, relativePath.slice(separator + 1)),
2449
2489
  flags | import_node_fs6.constants.O_NOFOLLOW
2450
2490
  );
2451
2491
  if (!(0, import_node_fs6.fstatSync)(fd).isFile()) {
@@ -2542,7 +2582,7 @@ function chownTree(root, uid, gid) {
2542
2582
  if (stat.isDirectory()) {
2543
2583
  (0, import_node_fs7.chmodSync)(root, 493);
2544
2584
  for (const entry of (0, import_node_fs7.readdirSync)(root)) {
2545
- chownTree((0, import_node_path12.join)(root, entry), uid, gid);
2585
+ chownTree((0, import_node_path13.join)(root, entry), uid, gid);
2546
2586
  }
2547
2587
  } else if (stat.isFile()) {
2548
2588
  (0, import_node_fs7.chmodSync)(root, 420);
@@ -2611,9 +2651,9 @@ async function copySavedCache(dir, buildContainer, containerReady, client) {
2611
2651
  step("Restoring the buildpack cache");
2612
2652
  let scratch;
2613
2653
  try {
2614
- scratch = (0, import_node_fs7.mkdtempSync)((0, import_node_path12.join)(cacheScratchParent(), "vercel-cnb-cache-"));
2654
+ scratch = (0, import_node_fs7.mkdtempSync)((0, import_node_path13.join)(cacheScratchParent(), "vercel-cnb-cache-"));
2615
2655
  (0, import_node_fs7.chmodSync)(scratch, 493);
2616
- const cacheDir = (0, import_node_path12.join)(scratch, "cache");
2656
+ const cacheDir = (0, import_node_path13.join)(scratch, "cache");
2617
2657
  (0, import_node_fs7.mkdirSync)(cacheDir, { mode: 493 });
2618
2658
  const imageId = containerReady.then(
2619
2659
  () => inspectBaseImageId(buildContainer, client)
@@ -2667,11 +2707,11 @@ async function buildAndPushWithLifecycle(buildpack, params, client, span) {
2667
2707
  let cacheScratch;
2668
2708
  let containerCleanup;
2669
2709
  try {
2670
- reportDir = (0, import_node_fs7.mkdtempSync)((0, import_node_path12.join)((0, import_node_os8.tmpdir)(), "vercel-cnb-report-"));
2671
- const reportPath = (0, import_node_path12.join)(reportDir, "report.toml");
2710
+ reportDir = (0, import_node_fs7.mkdtempSync)((0, import_node_path13.join)((0, import_node_os8.tmpdir)(), "vercel-cnb-report-"));
2711
+ const reportPath = (0, import_node_path13.join)(reportDir, "report.toml");
2672
2712
  (0, import_node_fs7.chownSync)(reportDir, BUILD_USER_ID, BUILD_GROUP_ID);
2673
2713
  (0, import_node_fs7.chmodSync)(reportDir, 493);
2674
- cnbDir = (0, import_node_fs7.mkdtempSync)((0, import_node_path12.join)((0, import_node_os8.tmpdir)(), "vercel-cnb-"));
2714
+ cnbDir = (0, import_node_fs7.mkdtempSync)((0, import_node_path13.join)((0, import_node_os8.tmpdir)(), "vercel-cnb-"));
2675
2715
  (0, import_node_fs7.chmodSync)(cnbDir, 493);
2676
2716
  orderDir = writeOrderDir(buildpack);
2677
2717
  platformEnvDir = writePlatformEnvDir(params.buildEnv, {
@@ -2838,7 +2878,7 @@ async function buildAndPushWithLifecycle(buildpack, params, client, span) {
2838
2878
  var import_node_crypto7 = require("crypto");
2839
2879
  var import_node_fs8 = require("fs");
2840
2880
  var import_node_os9 = require("os");
2841
- var import_node_path13 = require("path");
2881
+ var import_node_path14 = require("path");
2842
2882
  function localBuildImageDockerfile(buildImage2, nodeMajor) {
2843
2883
  const lines = [];
2844
2884
  if (nodeMajor !== void 0) {
@@ -2884,8 +2924,8 @@ var buildAndPushWithLifecycleDocker = async (buildpack, params, span) => {
2884
2924
  let stageDir;
2885
2925
  const containers = [];
2886
2926
  try {
2887
- stageDir = (0, import_node_fs8.mkdtempSync)((0, import_node_path13.join)((0, import_node_os9.tmpdir)(), "vercel-cnb-"));
2888
- const cnbDir = (0, import_node_path13.join)(stageDir, "cnb");
2927
+ stageDir = (0, import_node_fs8.mkdtempSync)((0, import_node_path14.join)((0, import_node_os9.tmpdir)(), "vercel-cnb-"));
2928
+ const cnbDir = (0, import_node_path14.join)(stageDir, "cnb");
2889
2929
  (0, import_node_fs8.mkdirSync)(cnbDir, { mode: 493 });
2890
2930
  const orderDir = writeOrderDir(buildpack, stageDir);
2891
2931
  const platformEnvDir = writePlatformEnvDir(
@@ -2907,7 +2947,7 @@ var buildAndPushWithLifecycleDocker = async (buildpack, params, span) => {
2907
2947
  params.nodeToolchain?.major
2908
2948
  );
2909
2949
  const buildImageTag = localBuildImageTag(dockerfile);
2910
- const buildImageIdPath = (0, import_node_path13.join)(stageDir, "build-image.id");
2950
+ const buildImageIdPath = (0, import_node_path14.join)(stageDir, "build-image.id");
2911
2951
  step(
2912
2952
  `Preparing ${buildpack.runtime} ${params.image.version} build image` + (params.nodeToolchain ? ` with Node.js ${params.nodeToolchain.major}` : "")
2913
2953
  );
@@ -3014,7 +3054,7 @@ var buildAndPushWithLifecycleDocker = async (buildpack, params, span) => {
3014
3054
  `Building and publishing ${params.imageRef} via Vercel ${buildpack.runtime} buildpacks`
3015
3055
  );
3016
3056
  await runDocker2(["start", "--attach", containerName]);
3017
- const reportPath = (0, import_node_path13.join)(stageDir, "report.toml");
3057
+ const reportPath = (0, import_node_path14.join)(stageDir, "report.toml");
3018
3058
  await runDocker2([
3019
3059
  "cp",
3020
3060
  `${containerName}:/platform-output/report.toml`,
@@ -3070,9 +3110,9 @@ var buildAndPushWithLifecycleDocker = async (buildpack, params, span) => {
3070
3110
  // src/buildpacks/node-toolchain.ts
3071
3111
  var import_build_utils6 = require("@vercel/build-utils");
3072
3112
  var import_node_fs9 = require("fs");
3073
- var import_node_path14 = require("path");
3113
+ var import_node_path15 = require("path");
3074
3114
  async function selectNodeMajor(workPath, config, meta) {
3075
- if (!(0, import_node_fs9.existsSync)((0, import_node_path14.join)(workPath, "package.json"))) {
3115
+ if (!(0, import_node_fs9.existsSync)((0, import_node_path15.join)(workPath, "package.json"))) {
3076
3116
  return void 0;
3077
3117
  }
3078
3118
  const version2 = await (0, import_build_utils6.getNodeVersion)(workPath, void 0, config, meta);
@@ -3093,7 +3133,7 @@ async function resolveNodeToolchain(workPath, config, meta) {
3093
3133
  return void 0;
3094
3134
  }
3095
3135
  for (const executable of ["node", "npm"]) {
3096
- if (!(0, import_node_fs9.existsSync)((0, import_node_path14.join)(toolchain.home, "bin", executable))) {
3136
+ if (!(0, import_node_fs9.existsSync)((0, import_node_path15.join)(toolchain.home, "bin", executable))) {
3097
3137
  throw new Error(
3098
3138
  `The selected Node.js ${toolchain.version} installation is missing ${toolchain.home}/bin/${executable} in the build environment.`
3099
3139
  );
@@ -3107,11 +3147,11 @@ async function resolveLocalNodeToolchain(workPath, config, meta) {
3107
3147
 
3108
3148
  // src/buildpacks/registry.ts
3109
3149
  var import_node_fs13 = require("fs");
3110
- var import_node_path18 = require("path");
3150
+ var import_node_path19 = require("path");
3111
3151
 
3112
3152
  // src/buildpacks/go.ts
3113
3153
  var import_node_fs10 = require("fs");
3114
- var import_node_path15 = require("path");
3154
+ var import_node_path16 = require("path");
3115
3155
  var DEFAULT_GO_VERSION = "1";
3116
3156
  var OLDEST_TOOLCHAIN_MINOR = 21;
3117
3157
  var GO_CANDIDATE_ENTRYPOINTS = [
@@ -3137,7 +3177,7 @@ function compareImageVersions(a, b) {
3137
3177
  return a.parts[0] - b.parts[0] || a.parts[1] - b.parts[1] || a.parts[2] - b.parts[2];
3138
3178
  }
3139
3179
  function selectGoVersion(workPath) {
3140
- const goMod = (0, import_node_path15.join)(workPath, "go.mod");
3180
+ const goMod = (0, import_node_path16.join)(workPath, "go.mod");
3141
3181
  if (!(0, import_node_fs10.existsSync)(goMod))
3142
3182
  return DEFAULT_GO_VERSION;
3143
3183
  const contents = (0, import_node_fs10.readFileSync)(goMod, "utf8");
@@ -3162,10 +3202,10 @@ var go = {
3162
3202
  },
3163
3203
  defaultEntrypoint({ workPath, zeroConfig }) {
3164
3204
  const candidate = GO_CANDIDATE_ENTRYPOINTS.find(
3165
- (name) => (0, import_node_fs10.existsSync)((0, import_node_path15.join)(workPath, name))
3205
+ (name) => (0, import_node_fs10.existsSync)((0, import_node_path16.join)(workPath, name))
3166
3206
  );
3167
3207
  if (candidate)
3168
- return import_node_path15.posix.dirname(candidate);
3208
+ return import_node_path16.posix.dirname(candidate);
3169
3209
  if (zeroConfig) {
3170
3210
  const last = GO_CANDIDATE_ENTRYPOINTS.length - 1;
3171
3211
  throw new Error(
@@ -3178,7 +3218,7 @@ var go = {
3178
3218
 
3179
3219
  // src/buildpacks/ruby.ts
3180
3220
  var import_node_fs11 = require("fs");
3181
- var import_node_path16 = require("path");
3221
+ var import_node_path17 = require("path");
3182
3222
  var import_smol_toml2 = require("smol-toml");
3183
3223
 
3184
3224
  // src/buildpacks/version.ts
@@ -3210,7 +3250,7 @@ var ruby = {
3210
3250
  return { version: version2, buildImage: image, runImage: image };
3211
3251
  },
3212
3252
  validate({ workPath, buildEnv }) {
3213
- const gemfile = (0, import_node_path16.join)(workPath, "Gemfile");
3253
+ const gemfile = (0, import_node_path17.join)(workPath, "Gemfile");
3214
3254
  if (!(0, import_node_fs11.existsSync)(gemfile))
3215
3255
  return;
3216
3256
  if (!GEMFILE_RAILS_GEM_RE.test((0, import_node_fs11.readFileSync)(gemfile, "utf8")))
@@ -3224,12 +3264,12 @@ var ruby = {
3224
3264
  };
3225
3265
  function selectRubyVersion(workPath) {
3226
3266
  for (const name of RUBY_VERSION_FILES) {
3227
- const file = (0, import_node_path16.join)(workPath, name);
3267
+ const file = (0, import_node_path17.join)(workPath, name);
3228
3268
  if ((0, import_node_fs11.existsSync)(file)) {
3229
3269
  return parseVersionFile(name, (0, import_node_fs11.readFileSync)(file, "utf8"));
3230
3270
  }
3231
3271
  }
3232
- const gemfile = (0, import_node_path16.join)(workPath, "Gemfile");
3272
+ const gemfile = (0, import_node_path17.join)(workPath, "Gemfile");
3233
3273
  return (0, import_node_fs11.existsSync)(gemfile) ? parseGemfileRubyVersion((0, import_node_fs11.readFileSync)(gemfile, "utf8")) : void 0;
3234
3274
  }
3235
3275
  function parseVersionFile(name, contents) {
@@ -3268,7 +3308,7 @@ function parseGemfileRubyVersion(contents) {
3268
3308
 
3269
3309
  // src/buildpacks/rust.ts
3270
3310
  var import_node_fs12 = require("fs");
3271
- var import_node_path17 = require("path");
3311
+ var import_node_path18 = require("path");
3272
3312
  var import_smol_toml3 = require("smol-toml");
3273
3313
  var DEFAULT_RUST_VERSION = "1";
3274
3314
  var RUST_TOOLCHAIN_FILES = ["rust-toolchain", "rust-toolchain.toml"];
@@ -3285,12 +3325,12 @@ var rust = {
3285
3325
  };
3286
3326
  },
3287
3327
  defaultEntrypoint({ workPath, zeroConfig }) {
3288
- return zeroConfig && (0, import_node_fs12.existsSync)((0, import_node_path17.join)(workPath, "src/main.rs")) ? "src/main.rs" : void 0;
3328
+ return zeroConfig && (0, import_node_fs12.existsSync)((0, import_node_path18.join)(workPath, "src/main.rs")) ? "src/main.rs" : void 0;
3289
3329
  }
3290
3330
  };
3291
3331
  function selectRustVersion(workPath) {
3292
3332
  for (const name of RUST_TOOLCHAIN_FILES) {
3293
- const file = (0, import_node_path17.join)(workPath, name);
3333
+ const file = (0, import_node_path18.join)(workPath, name);
3294
3334
  if ((0, import_node_fs12.existsSync)(file)) {
3295
3335
  const channel = parseToolchainFile(name, (0, import_node_fs12.readFileSync)(file, "utf8"));
3296
3336
  return channel !== void 0 && isValidVersion(channel) ? channel : void 0;
@@ -3336,7 +3376,7 @@ function requestedBuildpack(config) {
3336
3376
  }
3337
3377
  function hasProjectMarkers(buildpack, workPath) {
3338
3378
  return buildpack.projectMarkers.some(
3339
- (name) => (0, import_node_fs13.existsSync)((0, import_node_path18.join)(workPath, name))
3379
+ (name) => (0, import_node_fs13.existsSync)((0, import_node_path19.join)(workPath, name))
3340
3380
  );
3341
3381
  }
3342
3382
 
@@ -3365,7 +3405,7 @@ function selectCommands(params) {
3365
3405
  return commands;
3366
3406
  }
3367
3407
  async function buildAndPushBuildpack(params) {
3368
- const sourceDir = (0, import_node_fs14.mkdtempSync)((0, import_node_path19.join)((0, import_node_os10.tmpdir)(), "vercel-cnb-source-"));
3408
+ const sourceDir = (0, import_node_fs14.mkdtempSync)((0, import_node_path20.join)((0, import_node_os10.tmpdir)(), "vercel-cnb-source-"));
3369
3409
  try {
3370
3410
  step("Staging buildpack source files");
3371
3411
  await stageWorkspace(params, sourceDir);
@@ -3515,7 +3555,7 @@ async function buildAndPushBuildpack(params) {
3515
3555
 
3516
3556
  // src/image-source.ts
3517
3557
  var import_node_fs15 = require("fs");
3518
- var import_node_path20 = __toESM(require("path"));
3558
+ var import_node_path21 = __toESM(require("path"));
3519
3559
  var DETECT_SENTINEL = "<detect>";
3520
3560
  var IMAGE_REFERENCE_PATTERN = /^(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?)*(?::[0-9]+)?\/)?[a-z0-9]+(?:(?:\.|_|__|-+)[a-z0-9]+)*(?:\/[a-z0-9]+(?:(?:\.|_|__|-+)[a-z0-9]+)*)*(?::[a-zA-Z0-9_][a-zA-Z0-9._-]{0,127})?(?:@[a-zA-Z][a-zA-Z0-9]*(?:[-_.+][a-zA-Z][a-zA-Z0-9]*)*:[0-9a-fA-F]{32,})?$/;
3521
3561
  function assertValidImageReference(imageRef) {
@@ -3548,7 +3588,7 @@ function resolveImageSource(options, context) {
3548
3588
  }
3549
3589
  const dockerfileConfigured = entrypointRef && isDockerfileRef(entrypointRef) ? entrypointRef : findDockerfile(workPath);
3550
3590
  const dockerfileRel = dockerfileConfigured ?? "Dockerfile";
3551
- const dockerfilePath = import_node_path20.default.join(workPath, dockerfileRel);
3591
+ const dockerfilePath = import_node_path21.default.join(workPath, dockerfileRel);
3552
3592
  const hasDockerfile = dockerfileConfigured !== void 0 || !buildpack && (0, import_node_fs15.existsSync)(dockerfilePath);
3553
3593
  if (hasDockerfile) {
3554
3594
  return { kind: "dockerfile", dockerfileRel, dockerfilePath };
@@ -3570,8 +3610,8 @@ function resolveImageSource(options, context) {
3570
3610
 
3571
3611
  // src/build-context.ts
3572
3612
  var import_build_utils7 = require("@vercel/build-utils");
3573
- var import_promises7 = require("fs/promises");
3574
- var import_node_path21 = require("path");
3613
+ var import_promises8 = require("fs/promises");
3614
+ var import_node_path22 = require("path");
3575
3615
  async function resolveBuildContext({
3576
3616
  repoRootPath,
3577
3617
  workPath,
@@ -3587,8 +3627,8 @@ async function resolveBuildContext({
3587
3627
  ["Container build context", context],
3588
3628
  ["Dockerfile", dockerfile]
3589
3629
  ]) {
3590
- const rel = (0, import_node_path21.relative)(root, target);
3591
- if (rel === ".." || rel.startsWith(`..${import_node_path21.sep}`) || (0, import_node_path21.isAbsolute)(rel)) {
3630
+ const rel = (0, import_node_path22.relative)(root, target);
3631
+ if (rel === ".." || rel.startsWith(`..${import_node_path22.sep}`) || (0, import_node_path22.isAbsolute)(rel)) {
3592
3632
  throw new import_build_utils7.NowBuildError({
3593
3633
  code: "INVALID_CONTAINER_BUILD_CONTEXT",
3594
3634
  message: `${label} resolves outside the repository. Keep the build context and Dockerfile inside the repository, including symbolic link targets.`
@@ -3599,7 +3639,7 @@ async function resolveBuildContext({
3599
3639
  }
3600
3640
  async function resolvePath(path4, label) {
3601
3641
  try {
3602
- return await (0, import_promises7.realpath)(path4);
3642
+ return await (0, import_promises8.realpath)(path4);
3603
3643
  } catch (error) {
3604
3644
  const code = error.code;
3605
3645
  throw new import_build_utils7.NowBuildError({
@@ -3612,9 +3652,9 @@ async function resolvePath(path4, label) {
3612
3652
  // src/buildah-store-cache/cache.ts
3613
3653
  var import_build_utils8 = require("@vercel/build-utils");
3614
3654
  var import_node_crypto8 = require("crypto");
3615
- var import_promises8 = require("fs/promises");
3655
+ var import_promises9 = require("fs/promises");
3616
3656
  var import_node_os11 = require("os");
3617
- var import_node_path22 = require("path");
3657
+ var import_node_path23 = require("path");
3618
3658
  var BUILDAH_STORE_CACHE_DIR = ".vercel/cache/buildah-store";
3619
3659
  var STORE_PATHS = {
3620
3660
  graphRoot: BUILDAH_GRAPH_ROOT,
@@ -3628,7 +3668,7 @@ var BuildahStoreCache = class _BuildahStoreCache {
3628
3668
  }
3629
3669
  static forProject(options, client) {
3630
3670
  return new _BuildahStoreCache(
3631
- (0, import_node_path22.resolve)(options.repoRootPath || options.workPath),
3671
+ (0, import_node_path23.resolve)(options.repoRootPath || options.workPath),
3632
3672
  client
3633
3673
  );
3634
3674
  }
@@ -3705,7 +3745,7 @@ var BuildahStoreCache = class _BuildahStoreCache {
3705
3745
  return {};
3706
3746
  }
3707
3747
  return await (0, import_build_utils8.glob)(
3708
- `${BUILDAH_STORE_CACHE_DIR}/${(0, import_node_path22.basename)(archive)}`,
3748
+ `${BUILDAH_STORE_CACHE_DIR}/${(0, import_node_path23.basename)(archive)}`,
3709
3749
  this.repositoryRoot
3710
3750
  );
3711
3751
  } catch (error) {
@@ -3715,7 +3755,7 @@ var BuildahStoreCache = class _BuildahStoreCache {
3715
3755
  }
3716
3756
  async removeSnapshots() {
3717
3757
  try {
3718
- await (0, import_promises8.rm)(await this.snapshotDirectory({ create: false }), {
3758
+ await (0, import_promises9.rm)(await this.snapshotDirectory({ create: false }), {
3719
3759
  recursive: true,
3720
3760
  force: true
3721
3761
  });
@@ -3727,24 +3767,24 @@ var BuildahStoreCache = class _BuildahStoreCache {
3727
3767
  }
3728
3768
  async archivePath(options) {
3729
3769
  const key = await snapshotKey(this.client);
3730
- return (0, import_node_path22.join)(await this.snapshotDirectory(options), `store-${key}.tar.zst`);
3770
+ return (0, import_node_path23.join)(await this.snapshotDirectory(options), `store-${key}.tar.zst`);
3731
3771
  }
3732
3772
  async snapshotDirectory({
3733
3773
  create
3734
3774
  }) {
3735
- const root = await (0, import_promises8.realpath)(this.repositoryRoot);
3775
+ const root = await (0, import_promises9.realpath)(this.repositoryRoot);
3736
3776
  let directory = root;
3737
3777
  for (const part of BUILDAH_STORE_CACHE_DIR.split("/")) {
3738
- directory = (0, import_node_path22.join)(directory, part);
3778
+ directory = (0, import_node_path23.join)(directory, part);
3739
3779
  if (create) {
3740
- await (0, import_promises8.mkdir)(directory, { mode: 448 }).catch((error) => {
3780
+ await (0, import_promises9.mkdir)(directory, { mode: 448 }).catch((error) => {
3741
3781
  if (error.code !== "EEXIST")
3742
3782
  throw error;
3743
3783
  });
3744
3784
  }
3745
3785
  const stats = await lstatIfPresent(directory);
3746
3786
  if (!stats) {
3747
- return (0, import_node_path22.join)(root, BUILDAH_STORE_CACHE_DIR);
3787
+ return (0, import_node_path23.join)(root, BUILDAH_STORE_CACHE_DIR);
3748
3788
  }
3749
3789
  if (!stats.isDirectory()) {
3750
3790
  throw new Error(`${directory} is not a directory`);
@@ -3756,7 +3796,7 @@ var BuildahStoreCache = class _BuildahStoreCache {
3756
3796
  async function restoreStore(archive) {
3757
3797
  const storeLock = await requireStoreLock();
3758
3798
  const state = await createBuildahStoreStateDirectory();
3759
- const gate = new FileLock((0, import_node_path22.join)(state, "restore.lock"));
3799
+ const gate = new FileLock((0, import_node_path23.join)(state, "restore.lock"));
3760
3800
  return runStoreCommand(
3761
3801
  {
3762
3802
  action: "restore",
@@ -3764,7 +3804,7 @@ async function restoreStore(archive) {
3764
3804
  ...STORE_PATHS,
3765
3805
  archive,
3766
3806
  storeLock: storeLock.path,
3767
- marker: (0, import_node_path22.join)(state, "restored")
3807
+ marker: (0, import_node_path23.join)(state, "restored")
3768
3808
  }
3769
3809
  },
3770
3810
  gate
@@ -3795,7 +3835,7 @@ async function requireStoreLock() {
3795
3835
  }
3796
3836
  async function describeSave2(result, archive, start) {
3797
3837
  if (result.status === "saved") {
3798
- return `saved the Buildah store cache (${formatBytes((await (0, import_promises8.lstat)(archive)).size)}) in ${elapsed(start)}`;
3838
+ return `saved the Buildah store cache (${formatBytes((await (0, import_promises9.lstat)(archive)).size)}) in ${elapsed(start)}`;
3799
3839
  }
3800
3840
  if (result.status === "unused") {
3801
3841
  return await isRegularFile(archive) ? "kept the previous Buildah store cache: no service built with Buildah" : "no Buildah store cache to keep: no service recorded Buildah image usage";
@@ -3810,8 +3850,8 @@ async function snapshotKey(client) {
3810
3850
  [
3811
3851
  "/usr/share/containers/storage.conf",
3812
3852
  "/etc/containers/storage.conf",
3813
- (0, import_node_path22.join)(
3814
- process.env.XDG_CONFIG_HOME || (0, import_node_path22.join)((0, import_node_os11.homedir)(), ".config"),
3853
+ (0, import_node_path23.join)(
3854
+ process.env.XDG_CONFIG_HOME || (0, import_node_path23.join)((0, import_node_os11.homedir)(), ".config"),
3815
3855
  "containers/storage.conf"
3816
3856
  ),
3817
3857
  process.env.CONTAINERS_STORAGE_CONF,
@@ -3836,7 +3876,7 @@ async function readOptionalFile(path4) {
3836
3876
  return "";
3837
3877
  }
3838
3878
  try {
3839
- return await (0, import_promises8.readFile)(path4, "utf8");
3879
+ return await (0, import_promises9.readFile)(path4, "utf8");
3840
3880
  } catch (error) {
3841
3881
  if (error.code === "ENOENT")
3842
3882
  return "";
@@ -3852,8 +3892,8 @@ function failureReason(error) {
3852
3892
 
3853
3893
  // src/oci-layout/layout.ts
3854
3894
  var import_node_crypto9 = require("crypto");
3855
- var import_promises9 = require("fs/promises");
3856
- var import_node_path23 = require("path");
3895
+ var import_promises10 = require("fs/promises");
3896
+ var import_node_path24 = require("path");
3857
3897
  var OCI_LAYOUT_VERSION = "1.0.0";
3858
3898
  var OCI_INDEX_MEDIA_TYPE = "application/vnd.oci.image.index.v1+json";
3859
3899
  var OCI_MANIFEST_MEDIA_TYPE = "application/vnd.oci.image.manifest.v1+json";
@@ -3887,7 +3927,7 @@ function parseSha256Hex(digest) {
3887
3927
  return digest.slice("sha256:".length);
3888
3928
  }
3889
3929
  function blobPath2(layoutDir, digest) {
3890
- return (0, import_node_path23.join)(layoutDir, "blobs", "sha256", parseSha256Hex(digest));
3930
+ return (0, import_node_path24.join)(layoutDir, "blobs", "sha256", parseSha256Hex(digest));
3891
3931
  }
3892
3932
  function assertSafePathSegment(segment, imageRef) {
3893
3933
  if (!segment || segment === "." || segment === ".." || segment.includes("/") || segment.includes("\\")) {
@@ -3911,7 +3951,7 @@ function layoutRefPath(layoutDir, imageRef) {
3911
3951
  assertSafePathSegment(part, imageRef);
3912
3952
  }
3913
3953
  const hex = parseSha256Hex(digest);
3914
- return (0, import_node_path23.join)(layoutDir, registry, ...repoParts2, "sha256", hex);
3954
+ return (0, import_node_path24.join)(layoutDir, registry, ...repoParts2, "sha256", hex);
3915
3955
  }
3916
3956
  const colonIndex = remainder.lastIndexOf(":");
3917
3957
  if (colonIndex <= remainder.lastIndexOf("/") || colonIndex === remainder.length - 1) {
@@ -3924,7 +3964,7 @@ function layoutRefPath(layoutDir, imageRef) {
3924
3964
  assertSafePathSegment(part, imageRef);
3925
3965
  }
3926
3966
  assertSafePathSegment(tag, imageRef);
3927
- return (0, import_node_path23.join)(layoutDir, registry, ...repoParts, tag);
3967
+ return (0, import_node_path24.join)(layoutDir, registry, ...repoParts, tag);
3928
3968
  }
3929
3969
  function parseDescriptor(value, label) {
3930
3970
  if (!isRecord(value)) {
@@ -3950,7 +3990,7 @@ function parseJson(text, label) {
3950
3990
  }
3951
3991
  }
3952
3992
  async function readRegularJson(path4, label) {
3953
- const stats = await (0, import_promises9.lstat)(path4).catch((error) => {
3993
+ const stats = await (0, import_promises10.lstat)(path4).catch((error) => {
3954
3994
  if (error.code === "ENOENT") {
3955
3995
  throw new Error(`OCI layout is missing ${label}.`);
3956
3996
  }
@@ -3959,11 +3999,11 @@ async function readRegularJson(path4, label) {
3959
3999
  if (!stats.isFile()) {
3960
4000
  throw new Error(`OCI layout ${label} must be a regular file.`);
3961
4001
  }
3962
- return parseJson(await (0, import_promises9.readFile)(path4, "utf8"), label);
4002
+ return parseJson(await (0, import_promises10.readFile)(path4, "utf8"), label);
3963
4003
  }
3964
4004
  async function readVerifiedBlob(layoutDir, descriptor, label) {
3965
4005
  const path4 = blobPath2(layoutDir, descriptor.digest);
3966
- const stats = await (0, import_promises9.lstat)(path4).catch((error) => {
4006
+ const stats = await (0, import_promises10.lstat)(path4).catch((error) => {
3967
4007
  if (error.code === "ENOENT") {
3968
4008
  throw new Error(
3969
4009
  `OCI layout is missing ${label} blob ${descriptor.digest}.`
@@ -3981,7 +4021,7 @@ async function readVerifiedBlob(layoutDir, descriptor, label) {
3981
4021
  `OCI layout ${label} blob ${descriptor.digest} has size ${stats.size}, expected ${descriptor.size}.`
3982
4022
  );
3983
4023
  }
3984
- const content = await (0, import_promises9.readFile)(path4);
4024
+ const content = await (0, import_promises10.readFile)(path4);
3985
4025
  if (content.length !== descriptor.size) {
3986
4026
  throw new Error(
3987
4027
  `OCI layout ${label} blob ${descriptor.digest} has size ${content.length}, expected ${descriptor.size}.`
@@ -3997,7 +4037,7 @@ async function readVerifiedBlob(layoutDir, descriptor, label) {
3997
4037
  }
3998
4038
  async function verifyBlobSize(layoutDir, descriptor, label) {
3999
4039
  const path4 = blobPath2(layoutDir, descriptor.digest);
4000
- const stats = await (0, import_promises9.lstat)(path4).catch((error) => {
4040
+ const stats = await (0, import_promises10.lstat)(path4).catch((error) => {
4001
4041
  if (error.code === "ENOENT") {
4002
4042
  throw new Error(
4003
4043
  `OCI layout is missing ${label} blob ${descriptor.digest}.`
@@ -4089,7 +4129,7 @@ async function collectTargetImage(search, descriptor) {
4089
4129
  }
4090
4130
  async function verifyOciLayout(layoutDir) {
4091
4131
  const marker = await readRegularJson(
4092
- (0, import_node_path23.join)(layoutDir, "oci-layout"),
4132
+ (0, import_node_path24.join)(layoutDir, "oci-layout"),
4093
4133
  "oci-layout"
4094
4134
  );
4095
4135
  if (!isRecord(marker) || marker.imageLayoutVersion !== OCI_LAYOUT_VERSION) {
@@ -4098,7 +4138,7 @@ async function verifyOciLayout(layoutDir) {
4098
4138
  );
4099
4139
  }
4100
4140
  const index = await readRegularJson(
4101
- (0, import_node_path23.join)(layoutDir, "index.json"),
4141
+ (0, import_node_path24.join)(layoutDir, "index.json"),
4102
4142
  "index.json"
4103
4143
  );
4104
4144
  const search = {
@@ -4132,31 +4172,31 @@ async function verifyOciLayout(layoutDir) {
4132
4172
  return { manifestDigest: descriptor.digest };
4133
4173
  }
4134
4174
  async function moveDirectory(sourceDir, destinationDir) {
4135
- const parentDir = (0, import_node_path23.dirname)(destinationDir);
4136
- await (0, import_promises9.mkdir)(parentDir, { recursive: true });
4175
+ const parentDir = (0, import_node_path24.dirname)(destinationDir);
4176
+ await (0, import_promises10.mkdir)(parentDir, { recursive: true });
4137
4177
  try {
4138
- await (0, import_promises9.rename)(sourceDir, destinationDir);
4178
+ await (0, import_promises10.rename)(sourceDir, destinationDir);
4139
4179
  return;
4140
4180
  } catch (error) {
4141
4181
  if (error.code !== "EXDEV") {
4142
4182
  throw error;
4143
4183
  }
4144
4184
  }
4145
- const tempDir = await (0, import_promises9.mkdtemp)((0, import_node_path23.join)(parentDir, ".oci-layout-"));
4185
+ const tempDir = await (0, import_promises10.mkdtemp)((0, import_node_path24.join)(parentDir, ".oci-layout-"));
4146
4186
  try {
4147
- await (0, import_promises9.cp)(sourceDir, tempDir, { recursive: true });
4148
- await (0, import_promises9.rename)(tempDir, destinationDir);
4187
+ await (0, import_promises10.cp)(sourceDir, tempDir, { recursive: true });
4188
+ await (0, import_promises10.rename)(tempDir, destinationDir);
4149
4189
  } catch (error) {
4150
- await (0, import_promises9.rm)(tempDir, { recursive: true, force: true });
4190
+ await (0, import_promises10.rm)(tempDir, { recursive: true, force: true });
4151
4191
  throw error;
4152
4192
  }
4153
- await (0, import_promises9.rm)(sourceDir, { recursive: true, force: true });
4193
+ await (0, import_promises10.rm)(sourceDir, { recursive: true, force: true });
4154
4194
  }
4155
4195
 
4156
4196
  // src/oci-layout/pull.ts
4157
4197
  var import_node_crypto10 = require("crypto");
4158
- var import_promises10 = require("fs/promises");
4159
- var import_node_path24 = require("path");
4198
+ var import_promises11 = require("fs/promises");
4199
+ var import_node_path25 = require("path");
4160
4200
  var MANIFEST_ACCEPT_HEADER = [
4161
4201
  OCI_MANIFEST_MEDIA_TYPE,
4162
4202
  DOCKER_MANIFEST_MEDIA_TYPE,
@@ -4254,11 +4294,11 @@ var OciRegistryPuller = class {
4254
4294
  const layerDescriptors = manifest.layers.map(
4255
4295
  (layer, index) => parseDescriptor(layer, `layer[${index}]`)
4256
4296
  );
4257
- const blobsDir = (0, import_node_path24.join)(destinationDir, "blobs", "sha256");
4258
- await (0, import_promises10.mkdir)(blobsDir, { recursive: true, mode: 493 });
4297
+ const blobsDir = (0, import_node_path25.join)(destinationDir, "blobs", "sha256");
4298
+ await (0, import_promises11.mkdir)(blobsDir, { recursive: true, mode: 493 });
4259
4299
  try {
4260
- await (0, import_promises10.writeFile)(
4261
- (0, import_node_path24.join)(blobsDir, parseSha256Hex(parsed.digest)),
4300
+ await (0, import_promises11.writeFile)(
4301
+ (0, import_node_path25.join)(blobsDir, parseSha256Hex(parsed.digest)),
4262
4302
  manifestBytes
4263
4303
  );
4264
4304
  const fetchBlob = async (descriptor, label) => {
@@ -4299,7 +4339,7 @@ var OciRegistryPuller = class {
4299
4339
  let config;
4300
4340
  try {
4301
4341
  config = JSON.parse(
4302
- await (0, import_promises10.readFile)(
4342
+ await (0, import_promises11.readFile)(
4303
4343
  blobPath2(destinationDir, configDescriptor.digest),
4304
4344
  "utf8"
4305
4345
  )
@@ -4315,12 +4355,12 @@ var OciRegistryPuller = class {
4315
4355
  );
4316
4356
  }
4317
4357
  const manifestMediaType = typeof manifest.mediaType === "string" ? manifest.mediaType : OCI_MANIFEST_MEDIA_TYPE;
4318
- await (0, import_promises10.writeFile)(
4319
- (0, import_node_path24.join)(destinationDir, "oci-layout"),
4358
+ await (0, import_promises11.writeFile)(
4359
+ (0, import_node_path25.join)(destinationDir, "oci-layout"),
4320
4360
  JSON.stringify({ imageLayoutVersion: OCI_LAYOUT_VERSION })
4321
4361
  );
4322
- await (0, import_promises10.writeFile)(
4323
- (0, import_node_path24.join)(destinationDir, "index.json"),
4362
+ await (0, import_promises11.writeFile)(
4363
+ (0, import_node_path25.join)(destinationDir, "index.json"),
4324
4364
  JSON.stringify({
4325
4365
  schemaVersion: 2,
4326
4366
  mediaType: OCI_INDEX_MEDIA_TYPE,
@@ -4335,7 +4375,7 @@ var OciRegistryPuller = class {
4335
4375
  );
4336
4376
  return { manifestDigest: parsed.digest };
4337
4377
  } catch (error) {
4338
- await (0, import_promises10.rm)(destinationDir, { recursive: true, force: true });
4378
+ await (0, import_promises11.rm)(destinationDir, { recursive: true, force: true });
4339
4379
  throw error;
4340
4380
  }
4341
4381
  }
@@ -4350,7 +4390,7 @@ var OciRegistryPuller = class {
4350
4390
  return this.fetchWithRetries(request, async (response) => {
4351
4391
  const hash = (0, import_node_crypto10.createHash)("sha256");
4352
4392
  let size = 0;
4353
- const file = await (0, import_promises10.open)(path4, "w");
4393
+ const file = await (0, import_promises11.open)(path4, "w");
4354
4394
  try {
4355
4395
  if (response.body) {
4356
4396
  for await (const chunk of response.body) {
@@ -4461,20 +4501,13 @@ function ociLayoutRequested(env = process.env) {
4461
4501
  }
4462
4502
 
4463
4503
  // src/publish.ts
4464
- var import_promises11 = require("fs/promises");
4504
+ var import_node_crypto11 = require("crypto");
4505
+ var import_promises12 = require("fs/promises");
4465
4506
  var import_node_os12 = require("os");
4466
- var import_node_path25 = require("path");
4507
+ var import_node_path26 = require("path");
4467
4508
  function createImagePublisher(params) {
4468
4509
  const { build: build2, engine, exportLayout } = params;
4469
- if (!exportLayout) {
4470
- return new VcrPublisher(engine, build2);
4471
- }
4472
- if (!exportsLayouts(engine)) {
4473
- throw new Error(
4474
- `${CONTAINER_OCI_LAYOUT_ENV}=1 needs Buildah to write the image as an OCI image layout, but this build uses ${engine.name}.`
4475
- );
4476
- }
4477
- return new OciLayoutPublisher(engine, build2);
4510
+ return exportLayout ? new OciLayoutPublisher(engine, build2) : new VcrPublisher(engine, build2);
4478
4511
  }
4479
4512
  var VcrPublisher = class {
4480
4513
  constructor(engine, build2) {
@@ -4546,10 +4579,13 @@ var OciLayoutPublisher = class {
4546
4579
  this.spanAttributes = {};
4547
4580
  }
4548
4581
  async resolve(span) {
4549
- const imageRef = `localhost/${this.build.repository}:${this.build.tag}`;
4582
+ const imageRef = `localhost/${this.build.repository}:${this.build.tag}-${(0, import_node_crypto11.randomBytes)(4).toString("hex")}`;
4550
4583
  span?.setAttributes({ "image.tag": this.build.tag, "image.ref": imageRef });
4551
4584
  return {
4552
4585
  imageRef,
4586
+ connect: async () => {
4587
+ await this.engine.verifyLayoutExport?.();
4588
+ },
4553
4589
  publish: (params, exportSpan) => this.exportLayout(params, exportSpan)
4554
4590
  };
4555
4591
  }
@@ -4573,15 +4609,15 @@ var OciLayoutPublisher = class {
4573
4609
  span?.setAttributes({ "image.digest": manifestDigest });
4574
4610
  return { kind: "oci-layout", directory, manifestDigest };
4575
4611
  } catch (error) {
4576
- await (0, import_promises11.rm)(directory, { recursive: true, force: true });
4612
+ await (0, import_promises12.rm)(directory, { recursive: true, force: true });
4577
4613
  throw error;
4578
4614
  }
4579
4615
  }
4580
4616
  };
4581
4617
  async function createStagingDirectory() {
4582
- const parent = isBuildContainer() ? (0, import_node_path25.join)((0, import_node_path25.dirname)(BUILDAH_GRAPH_ROOT), "oci-layouts") : (0, import_node_os12.tmpdir)();
4583
- await (0, import_promises11.mkdir)(parent, { recursive: true });
4584
- return (0, import_promises11.mkdtemp)((0, import_node_path25.join)(parent, "vercel-container-layout-"));
4618
+ const parent = isBuildContainer() ? (0, import_node_path26.join)((0, import_node_path26.dirname)(BUILDAH_GRAPH_ROOT), "oci-layouts") : (0, import_node_os12.tmpdir)();
4619
+ await (0, import_promises12.mkdir)(parent, { recursive: true });
4620
+ return (0, import_promises12.mkdtemp)((0, import_node_path26.join)(parent, "vercel-container-layout-"));
4585
4621
  }
4586
4622
  async function authenticateRegistry(engine, credentials, span) {
4587
4623
  const forceLogin = readString(process.env.VERCEL_VCR_FORCE_LOGIN) === "1";
@@ -4616,7 +4652,7 @@ var import_build_utils9 = require("@vercel/build-utils");
4616
4652
  var import_node_child_process4 = require("child_process");
4617
4653
  var import_node_fs16 = require("fs");
4618
4654
  var import_node_os13 = require("os");
4619
- var import_node_path26 = __toESM(require("path"));
4655
+ var import_node_path27 = __toESM(require("path"));
4620
4656
  var HOST_ONLY_ENV = /* @__PURE__ */ new Set([
4621
4657
  "TMPDIR",
4622
4658
  "TMP",
@@ -4646,8 +4682,8 @@ function isHostOnlyEnvVar(key) {
4646
4682
  return HOST_ONLY_ENV.has(key) || key.startsWith("__") || key.startsWith("XPC_") || key.startsWith("SSH_") || key.startsWith("Apple");
4647
4683
  }
4648
4684
  function writeEnvFile(env) {
4649
- const dir = (0, import_node_fs16.mkdtempSync)(import_node_path26.default.join((0, import_node_os13.tmpdir)(), "vercel-container-dev-env-"));
4650
- const file = import_node_path26.default.join(dir, "env");
4685
+ const dir = (0, import_node_fs16.mkdtempSync)(import_node_path27.default.join((0, import_node_os13.tmpdir)(), "vercel-container-dev-env-"));
4686
+ const file = import_node_path27.default.join(dir, "env");
4651
4687
  const lines = [];
4652
4688
  for (const [key, value] of Object.entries(env)) {
4653
4689
  if (value.includes("\n")) {
@@ -4799,7 +4835,7 @@ async function resolveDevImage(options, out, span) {
4799
4835
  const contextDir = await resolveBuildContext({
4800
4836
  repoRootPath: options.repoRootPath,
4801
4837
  workPath: options.workPath,
4802
- contextDir: options.service ? options.workPath : import_node_path26.default.dirname(dockerfilePath),
4838
+ contextDir: options.service ? options.workPath : import_node_path27.default.dirname(dockerfilePath),
4803
4839
  dockerfilePath
4804
4840
  });
4805
4841
  await assertDockerAvailable(out);
@@ -5022,7 +5058,7 @@ async function startContainer(options, reuseKey) {
5022
5058
  }
5023
5059
  });
5024
5060
  const cleanupEnvFile = () => {
5025
- (0, import_node_fs16.rmSync)(import_node_path26.default.dirname(envFilePath), { recursive: true, force: true });
5061
+ (0, import_node_fs16.rmSync)(import_node_path27.default.dirname(envFilePath), { recursive: true, force: true });
5026
5062
  };
5027
5063
  const shutdown = async () => {
5028
5064
  runningContainers.delete(reuseKey);
@@ -5099,9 +5135,9 @@ async function startContainer(options, reuseKey) {
5099
5135
 
5100
5136
  // src/prepare-cache.ts
5101
5137
  var import_build_utils10 = require("@vercel/build-utils");
5102
- var import_node_path27 = require("path");
5138
+ var import_node_path28 = require("path");
5103
5139
  async function prepareCache(options) {
5104
- const root = (0, import_node_path27.resolve)(options.repoRootPath || options.workPath);
5140
+ const root = (0, import_node_path28.resolve)(options.repoRootPath || options.workPath);
5105
5141
  const buildpackFiles = await collectBuildpackCache(root);
5106
5142
  const buildahStoreFiles = await BuildahStoreCache.forProject(
5107
5143
  options,
@@ -5124,14 +5160,14 @@ async function collectBuildpackCache(root) {
5124
5160
  }
5125
5161
 
5126
5162
  // src/executable-image/index.ts
5127
- var import_node_crypto11 = require("crypto");
5128
- var import_promises13 = require("fs/promises");
5129
- var import_node_path29 = require("path");
5163
+ var import_node_crypto12 = require("crypto");
5164
+ var import_promises14 = require("fs/promises");
5165
+ var import_node_path30 = require("path");
5130
5166
 
5131
5167
  // src/buildpacks/lifecycle/native.ts
5132
5168
  var import_node_fs17 = require("fs");
5133
- var import_promises12 = require("fs/promises");
5134
- var import_node_path28 = require("path");
5169
+ var import_promises13 = require("fs/promises");
5170
+ var import_node_path29 = require("path");
5135
5171
  var import_smol_toml4 = require("smol-toml");
5136
5172
  var PREBUILT_STATIC_GROUP = {
5137
5173
  runtime: "prebuilt-static",
@@ -5157,7 +5193,7 @@ async function resolveNativeBuildUser(deps = {}) {
5157
5193
  if (uid !== 0) {
5158
5194
  throw new Error("The native CNB lifecycle cannot run with the root group.");
5159
5195
  }
5160
- const passwd = await (deps.readPasswd ?? (() => (0, import_promises12.readFile)("/etc/passwd", "utf8")))();
5196
+ const passwd = await (deps.readPasswd ?? (() => (0, import_promises13.readFile)("/etc/passwd", "utf8")))();
5161
5197
  const nobody = passwd.split("\n").map((line) => line.split(":")).find(([name]) => name === "nobody");
5162
5198
  const unprivilegedUid = Number(nobody?.[2]);
5163
5199
  const unprivilegedGid = Number(nobody?.[3]);
@@ -5168,7 +5204,7 @@ async function resolveNativeBuildUser(deps = {}) {
5168
5204
  }
5169
5205
  return { uid: unprivilegedUid, gid: unprivilegedGid, switchUser: true };
5170
5206
  }
5171
- async function resolveStagingParent(resolveRealpath = import_promises12.realpath) {
5207
+ async function resolveStagingParent(resolveRealpath = import_promises13.realpath) {
5172
5208
  const parent = await resolveRealpath("/var/tmp");
5173
5209
  if (HIVE_RUNTIME_MOUNTS.some(
5174
5210
  (mount) => parent === mount || parent.startsWith(`${mount}/`)
@@ -5180,17 +5216,17 @@ async function resolveStagingParent(resolveRealpath = import_promises12.realpath
5180
5216
  return parent;
5181
5217
  }
5182
5218
  async function chownRecursive(rootPath, uid, gid) {
5183
- const stats = await (0, import_promises12.lstat)(rootPath);
5219
+ const stats = await (0, import_promises13.lstat)(rootPath);
5184
5220
  if (stats.isDirectory()) {
5185
- for (const entry of await (0, import_promises12.readdir)(rootPath)) {
5186
- await chownRecursive((0, import_node_path28.join)(rootPath, entry), uid, gid);
5221
+ for (const entry of await (0, import_promises13.readdir)(rootPath)) {
5222
+ await chownRecursive((0, import_node_path29.join)(rootPath, entry), uid, gid);
5187
5223
  }
5188
5224
  }
5189
- await (0, import_promises12.lchown)(rootPath, uid, gid);
5225
+ await (0, import_promises13.lchown)(rootPath, uid, gid);
5190
5226
  }
5191
5227
  async function verifyLaunchCommand(layersDir, executablePath) {
5192
5228
  const metadata = (0, import_smol_toml4.parse)(
5193
- await (0, import_promises12.readFile)((0, import_node_path28.join)(layersDir, "config", "metadata.toml"), "utf8")
5229
+ await (0, import_promises13.readFile)((0, import_node_path29.join)(layersDir, "config", "metadata.toml"), "utf8")
5194
5230
  );
5195
5231
  const valid = metadata.processes?.some(
5196
5232
  (proc) => proc.type === "web" && proc.direct === true && proc.command?.length === 1 && (proc.command[0] === executablePath || proc.command[0] === "./user-server")
@@ -5215,7 +5251,7 @@ var NativeLifecycleRunner = class {
5215
5251
  credentials: params.credentials
5216
5252
  },
5217
5253
  async (reportFile) => {
5218
- const digest = readReportDigest(await (0, import_promises12.readFile)(reportFile, "utf8"));
5254
+ const digest = readReportDigest(await (0, import_promises13.readFile)(reportFile, "utf8"));
5219
5255
  if (!digest) {
5220
5256
  throw new Error("The CNB lifecycle did not report an image digest.");
5221
5257
  }
@@ -5241,30 +5277,30 @@ var NativeLifecycleRunner = class {
5241
5277
  * exists, so a failure in either is reported as a lifecycle failure.
5242
5278
  */
5243
5279
  async execute(executablePath, target, readResult, span) {
5244
- const executableStats = await (0, import_promises12.lstat)(executablePath);
5280
+ const executableStats = await (0, import_promises13.lstat)(executablePath);
5245
5281
  if (!executableStats.isFile() || executableStats.size === 0) {
5246
5282
  throw new Error(
5247
5283
  "The prebuilt executable must be a nonempty regular file."
5248
5284
  );
5249
5285
  }
5250
5286
  const { user, stagingParent, cnbDir, platformDir, orderFile, runImage } = this.options;
5251
- const runRoot = await (0, import_promises12.mkdtemp)((0, import_node_path28.join)(stagingParent, "vercel-cnb-native-"));
5287
+ const runRoot = await (0, import_promises13.mkdtemp)((0, import_node_path29.join)(stagingParent, "vercel-cnb-native-"));
5252
5288
  try {
5253
5289
  if (user.switchUser) {
5254
- await (0, import_promises12.chmod)(runRoot, 493);
5290
+ await (0, import_promises13.chmod)(runRoot, 493);
5255
5291
  }
5256
- const workPath = (0, import_node_path28.join)(runRoot, "workspace");
5257
- const layers = (0, import_node_path28.join)(runRoot, "layers");
5258
- const reportDir = (0, import_node_path28.join)(runRoot, "report");
5259
- const home = (0, import_node_path28.join)(runRoot, "home");
5260
- const temp = (0, import_node_path28.join)(runRoot, "tmp");
5292
+ const workPath = (0, import_node_path29.join)(runRoot, "workspace");
5293
+ const layers = (0, import_node_path29.join)(runRoot, "layers");
5294
+ const reportDir = (0, import_node_path29.join)(runRoot, "report");
5295
+ const home = (0, import_node_path29.join)(runRoot, "home");
5296
+ const temp = (0, import_node_path29.join)(runRoot, "tmp");
5261
5297
  const dirs = [workPath, layers, reportDir, home, temp];
5262
5298
  for (const dir of dirs) {
5263
- await (0, import_promises12.mkdir)(dir, { mode: 448 });
5299
+ await (0, import_promises13.mkdir)(dir, { mode: 448 });
5264
5300
  }
5265
- const executable = (0, import_node_path28.join)(workPath, "user-server");
5266
- await (0, import_promises12.copyFile)(executablePath, executable, import_node_fs17.constants.COPYFILE_EXCL);
5267
- const handle = await (0, import_promises12.open)(
5301
+ const executable = (0, import_node_path29.join)(workPath, "user-server");
5302
+ await (0, import_promises13.copyFile)(executablePath, executable, import_node_fs17.constants.COPYFILE_EXCL);
5303
+ const handle = await (0, import_promises13.open)(
5268
5304
  executable,
5269
5305
  import_node_fs17.constants.O_RDONLY | import_node_fs17.constants.O_NOFOLLOW
5270
5306
  );
@@ -5278,19 +5314,19 @@ var NativeLifecycleRunner = class {
5278
5314
  }
5279
5315
  if (user.switchUser) {
5280
5316
  for (const dir of dirs) {
5281
- await (0, import_promises12.chown)(dir, user.uid, user.gid);
5317
+ await (0, import_promises13.chown)(dir, user.uid, user.gid);
5282
5318
  }
5283
5319
  }
5284
- const lifecycleDir = (0, import_node_path28.join)(cnbDir, "lifecycle");
5285
- const reportFile = (0, import_node_path28.join)(reportDir, "report.toml");
5320
+ const lifecycleDir = (0, import_node_path29.join)(cnbDir, "lifecycle");
5321
+ const reportFile = (0, import_node_path29.join)(reportDir, "report.toml");
5286
5322
  const { args: exportArgs, env: exportEnv } = creatorExport(target);
5287
5323
  const args = [
5288
5324
  `-app=${workPath}`,
5289
5325
  `-layers=${layers}`,
5290
- `-buildpacks=${(0, import_node_path28.join)(cnbDir, "buildpacks")}`,
5326
+ `-buildpacks=${(0, import_node_path29.join)(cnbDir, "buildpacks")}`,
5291
5327
  `-platform=${platformDir}`,
5292
5328
  `-order=${orderFile}`,
5293
- `-launcher=${(0, import_node_path28.join)(lifecycleDir, "launcher")}`,
5329
+ `-launcher=${(0, import_node_path29.join)(lifecycleDir, "launcher")}`,
5294
5330
  `-launcher-sbom=${lifecycleDir}`,
5295
5331
  `-uid=${user.uid}`,
5296
5332
  `-gid=${user.gid}`,
@@ -5308,7 +5344,7 @@ var NativeLifecycleRunner = class {
5308
5344
  ...exportEnv
5309
5345
  };
5310
5346
  try {
5311
- await this.runCommand((0, import_node_path28.join)(lifecycleDir, "creator"), args, {
5347
+ await this.runCommand((0, import_node_path29.join)(lifecycleDir, "creator"), args, {
5312
5348
  cwd: workPath,
5313
5349
  ...user.switchUser && { uid: user.uid, gid: user.gid },
5314
5350
  env
@@ -5324,7 +5360,7 @@ var NativeLifecycleRunner = class {
5324
5360
  });
5325
5361
  }
5326
5362
  } finally {
5327
- await (0, import_promises12.rm)(runRoot, { recursive: true, force: true });
5363
+ await (0, import_promises13.rm)(runRoot, { recursive: true, force: true });
5328
5364
  }
5329
5365
  }
5330
5366
  };
@@ -5350,22 +5386,22 @@ var ExecutableImageBuilder = class _ExecutableImageBuilder {
5350
5386
  const fetchDist = deps.fetchDistribution ?? fetchDistribution;
5351
5387
  const resolveTarget = deps.resolveRegistryTarget ?? resolveRegistryTarget;
5352
5388
  const ensureRepo = deps.ensureRepository ?? ensureRepository;
5353
- const sharedRoot = await (0, import_promises13.mkdtemp)(
5354
- (0, import_node_path29.join)(stagingParent, "vercel-cnb-executable-")
5389
+ const sharedRoot = await (0, import_promises14.mkdtemp)(
5390
+ (0, import_node_path30.join)(stagingParent, "vercel-cnb-executable-")
5355
5391
  );
5356
5392
  try {
5357
5393
  if (user.switchUser) {
5358
- await (0, import_promises13.chmod)(sharedRoot, 493);
5394
+ await (0, import_promises14.chmod)(sharedRoot, 493);
5359
5395
  }
5360
- const cnbDir = (0, import_node_path29.join)(sharedRoot, "cnb");
5361
- const platformDir = (0, import_node_path29.join)(sharedRoot, "platform");
5362
- await (0, import_promises13.mkdir)(cnbDir, { mode: 493 });
5363
- await (0, import_promises13.mkdir)(platformDir, { mode: 493 });
5396
+ const cnbDir = (0, import_node_path30.join)(sharedRoot, "cnb");
5397
+ const platformDir = (0, import_node_path30.join)(sharedRoot, "platform");
5398
+ await (0, import_promises14.mkdir)(cnbDir, { mode: 493 });
5399
+ await (0, import_promises14.mkdir)(platformDir, { mode: 493 });
5364
5400
  if (user.switchUser) {
5365
- await (0, import_promises13.chmod)(cnbDir, 493);
5366
- await (0, import_promises13.chmod)(platformDir, 493);
5401
+ await (0, import_promises14.chmod)(cnbDir, 493);
5402
+ await (0, import_promises14.chmod)(platformDir, 493);
5367
5403
  }
5368
- const orderFile = (0, import_node_path29.join)(
5404
+ const orderFile = (0, import_node_path30.join)(
5369
5405
  writeOrderDir(PREBUILT_STATIC_GROUP, sharedRoot),
5370
5406
  "order.toml"
5371
5407
  );
@@ -5385,8 +5421,8 @@ var ExecutableImageBuilder = class _ExecutableImageBuilder {
5385
5421
  runCommand: deps.runCommand
5386
5422
  });
5387
5423
  if (layoutMode) {
5388
- const layoutRoot = (0, import_node_path29.join)(sharedRoot, "layout");
5389
- await (0, import_promises13.mkdir)(layoutRoot, { mode: 448 });
5424
+ const layoutRoot = (0, import_node_path30.join)(sharedRoot, "layout");
5425
+ await (0, import_promises14.mkdir)(layoutRoot, { mode: 448 });
5390
5426
  const runImageLayoutDir = layoutRefPath(layoutRoot, runImage);
5391
5427
  const puller = new OciRegistryPuller({
5392
5428
  credentials: {
@@ -5437,7 +5473,7 @@ var ExecutableImageBuilder = class _ExecutableImageBuilder {
5437
5473
  options.span
5438
5474
  );
5439
5475
  } catch (error) {
5440
- await (0, import_promises13.rm)(sharedRoot, { recursive: true, force: true });
5476
+ await (0, import_promises14.rm)(sharedRoot, { recursive: true, force: true });
5441
5477
  throw error;
5442
5478
  }
5443
5479
  }
@@ -5446,7 +5482,7 @@ var ExecutableImageBuilder = class _ExecutableImageBuilder {
5446
5482
  if (this.closed) {
5447
5483
  throw new Error("ExecutableImageBuilder has already been closed.");
5448
5484
  }
5449
- const tag = `build-${(0, import_node_crypto11.randomUUID)()}`;
5485
+ const tag = `build-${(0, import_node_crypto12.randomUUID)()}`;
5450
5486
  const mode = this.mode;
5451
5487
  return withSpan(
5452
5488
  this.span,
@@ -5463,7 +5499,7 @@ var ExecutableImageBuilder = class _ExecutableImageBuilder {
5463
5499
  if (this.closed)
5464
5500
  return;
5465
5501
  this.closed = true;
5466
- await (0, import_promises13.rm)(this.sharedRoot, { recursive: true, force: true });
5502
+ await (0, import_promises14.rm)(this.sharedRoot, { recursive: true, force: true });
5467
5503
  }
5468
5504
  async exportLayout(mode, tag, executable, span) {
5469
5505
  const outputImageRef = `oci.local/executable:${tag}`;
@@ -5486,7 +5522,7 @@ var ExecutableImageBuilder = class _ExecutableImageBuilder {
5486
5522
  manifestDigest
5487
5523
  };
5488
5524
  } finally {
5489
- await (0, import_promises13.rm)(exportedDir, { recursive: true, force: true });
5525
+ await (0, import_promises14.rm)(exportedDir, { recursive: true, force: true });
5490
5526
  }
5491
5527
  }
5492
5528
  async push(mode, tag, executable, span) {
@@ -5714,22 +5750,22 @@ async function resolveImageOutput(options, source, buildahClient, span, schedule
5714
5750
  if (meta?.isDev) {
5715
5751
  const serviceName = options.service?.name;
5716
5752
  const tag2 = devImageTag(
5717
- serviceName ?? import_node_path30.default.basename(dockerfileRel).split(".")[0]
5753
+ serviceName ?? import_node_path31.default.basename(dockerfileRel).split(".")[0]
5718
5754
  );
5719
5755
  span?.setAttributes({ "container.mode": "dev", "image.tag": tag2 });
5720
5756
  return { kind: "registry", reference: tag2 };
5721
5757
  }
5722
5758
  const repository = daemon ? (0, import_build_utils11.getDaemonImageRepository)(daemon.name) : sanitizeRepository(
5723
- options.service?.name ?? import_node_path30.default.basename(dockerfileRel).split(".")[0]
5759
+ options.service?.name ?? import_node_path31.default.basename(dockerfileRel).split(".")[0]
5724
5760
  );
5725
5761
  const tag = resolveImageTag();
5726
5762
  const contextDir = await resolveBuildContext({
5727
5763
  repoRootPath: options.repoRootPath,
5728
5764
  workPath: options.workPath,
5729
- contextDir: daemon || schedulesCommand || options.service ? options.workPath : import_node_path30.default.dirname(dockerfilePath),
5765
+ contextDir: daemon || schedulesCommand || options.service ? options.workPath : import_node_path31.default.dirname(dockerfilePath),
5730
5766
  dockerfilePath
5731
5767
  });
5732
- const contextIsRoot = Boolean(daemon || schedulesCommand || options.service) || import_node_path30.default.dirname(import_node_path30.default.normalize(dockerfileRel)) === ".";
5768
+ const contextIsRoot = Boolean(daemon || schedulesCommand || options.service) || import_node_path31.default.dirname(import_node_path31.default.normalize(dockerfileRel)) === ".";
5733
5769
  const buildArgs = buildArgsFromEnv(meta?.buildEnv);
5734
5770
  const shouldExportLayout = ociLayoutRequested() && !daemon;
5735
5771
  span?.setAttributes({
@@ -5784,7 +5820,7 @@ async function build(options) {
5784
5820
  return await createBuildResult(options, source, schedulesCommand, image);
5785
5821
  } catch (error) {
5786
5822
  if (image.kind === "oci-layout") {
5787
- await (0, import_promises14.rm)(image.directory, { recursive: true, force: true });
5823
+ await (0, import_promises15.rm)(image.directory, { recursive: true, force: true });
5788
5824
  }
5789
5825
  throw error;
5790
5826
  }