@vercel/container 15.0.0 → 16.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +261 -138
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -214,6 +214,7 @@ var import_node_os3 = require("os");
|
|
|
214
214
|
var import_node_path3 = require("path");
|
|
215
215
|
|
|
216
216
|
// src/storage-driver.ts
|
|
217
|
+
var import_node_child_process2 = require("child_process");
|
|
217
218
|
var import_node_fs2 = require("fs");
|
|
218
219
|
var import_node_os2 = require("os");
|
|
219
220
|
var import_node_path2 = require("path");
|
|
@@ -281,9 +282,41 @@ async function buildahStorageArgs() {
|
|
|
281
282
|
}
|
|
282
283
|
return [...rootArgs, ...registriesArgs, "--storage-driver", driver];
|
|
283
284
|
}
|
|
285
|
+
async function runBuildah(args, opts = {}) {
|
|
286
|
+
const fullArgs = [...await buildahStorageArgs(), ...args];
|
|
287
|
+
debug(`exec: buildah ${fullArgs.join(" ")}`);
|
|
288
|
+
const start = Date.now();
|
|
289
|
+
try {
|
|
290
|
+
const result = await run("buildah", fullArgs, opts);
|
|
291
|
+
debug(`buildah ${args[0]} finished in ${Date.now() - start}ms`);
|
|
292
|
+
return result;
|
|
293
|
+
} catch (error) {
|
|
294
|
+
debug(`buildah ${args[0]} failed after ${Date.now() - start}ms`);
|
|
295
|
+
throw error;
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
async function startBuildahInBackground(args) {
|
|
299
|
+
const fullArgs = [...await buildahStorageArgs(), ...args];
|
|
300
|
+
debug(`exec in the background: buildah ${fullArgs.join(" ")}`);
|
|
301
|
+
const start = Date.now();
|
|
302
|
+
const child = (0, import_node_child_process2.spawn)("buildah", fullArgs, {
|
|
303
|
+
detached: true,
|
|
304
|
+
stdio: "ignore"
|
|
305
|
+
});
|
|
306
|
+
child.on(
|
|
307
|
+
"error",
|
|
308
|
+
(error) => debug(`background buildah ${args[0]} failed: ${error.message}`)
|
|
309
|
+
);
|
|
310
|
+
child.on(
|
|
311
|
+
"exit",
|
|
312
|
+
(code) => debug(
|
|
313
|
+
`background buildah ${args[0]} exited with code ${code} after ${Date.now() - start}ms`
|
|
314
|
+
)
|
|
315
|
+
);
|
|
316
|
+
child.unref();
|
|
317
|
+
}
|
|
284
318
|
async function readBuildahStoreInfo() {
|
|
285
|
-
const
|
|
286
|
-
const { stdout } = await run("buildah", [...args, "info"], { quiet: true });
|
|
319
|
+
const { stdout } = await runBuildah(["info"], { quiet: true });
|
|
287
320
|
const store = JSON.parse(stdout).store;
|
|
288
321
|
if (!store) {
|
|
289
322
|
return void 0;
|
|
@@ -688,12 +721,6 @@ async function ensureRepository(repository, token, claims, span) {
|
|
|
688
721
|
}
|
|
689
722
|
|
|
690
723
|
// src/engines/buildah.ts
|
|
691
|
-
async function runBuildah(args, opts = {}) {
|
|
692
|
-
const storageArgs = await buildahStorageArgs();
|
|
693
|
-
const fullArgs = [...storageArgs, ...args];
|
|
694
|
-
debug(`exec: buildah ${fullArgs.join(" ")}`);
|
|
695
|
-
return run("buildah", fullArgs, opts);
|
|
696
|
-
}
|
|
697
724
|
function logLayerCacheSummary(output) {
|
|
698
725
|
const steps = (output.match(/^STEP\s+\d+\/\d+:/gm) || []).length;
|
|
699
726
|
const cached = (output.match(/-->\s+Using cache\b/gi) || []).length;
|
|
@@ -904,7 +931,7 @@ function readDigestFile(path4) {
|
|
|
904
931
|
}
|
|
905
932
|
|
|
906
933
|
// src/engines/docker.ts
|
|
907
|
-
var
|
|
934
|
+
var import_node_child_process3 = require("child_process");
|
|
908
935
|
function runDocker(args, opts = {}) {
|
|
909
936
|
debug(`exec: docker ${args.join(" ")}`);
|
|
910
937
|
return run("docker", args, opts);
|
|
@@ -940,7 +967,7 @@ async function startDockerDaemon(span) {
|
|
|
940
967
|
span?.setAttributes({ "docker.storage_driver": driver });
|
|
941
968
|
step(`Starting Docker daemon (storage-driver=${driver})`);
|
|
942
969
|
debug(`exec: dockerd ${args.join(" ")}`);
|
|
943
|
-
const child = (0,
|
|
970
|
+
const child = (0, import_node_child_process3.spawn)("dockerd", args, {
|
|
944
971
|
stdio: ["ignore", "pipe", "pipe"]
|
|
945
972
|
});
|
|
946
973
|
let log = "";
|
|
@@ -1216,6 +1243,7 @@ var import_node_path13 = require("path");
|
|
|
1216
1243
|
// src/buildpacks/cache.ts
|
|
1217
1244
|
var import_node_crypto2 = require("crypto");
|
|
1218
1245
|
var import_node_fs4 = require("fs");
|
|
1246
|
+
var import_promises = require("fs/promises");
|
|
1219
1247
|
var import_node_path4 = require("path");
|
|
1220
1248
|
var BUILDPACK_CACHE_DIR = ".vercel/cache/buildpacks";
|
|
1221
1249
|
var CNB_COMMITTED_DIR = "committed";
|
|
@@ -1230,20 +1258,32 @@ function buildpackCacheDir(options) {
|
|
|
1230
1258
|
const key = (0, import_node_crypto2.createHash)("sha256").update(JSON.stringify([app, options.service?.name ?? null])).digest("hex").slice(0, 32);
|
|
1231
1259
|
return (0, import_node_path4.join)(root, BUILDPACK_CACHE_DIR, key);
|
|
1232
1260
|
}
|
|
1233
|
-
function restoreBuildpackCache(dir, imageId, cacheDir) {
|
|
1261
|
+
async function restoreBuildpackCache(dir, imageId, cacheDir) {
|
|
1262
|
+
const committed = (0, import_node_path4.join)(cacheDir, CNB_COMMITTED_DIR);
|
|
1263
|
+
const [copy, image] = await Promise.allSettled([
|
|
1264
|
+
copyCommitted(dir, cacheDir),
|
|
1265
|
+
imageId
|
|
1266
|
+
]);
|
|
1234
1267
|
try {
|
|
1235
|
-
if (
|
|
1268
|
+
if (copy.status === "rejected")
|
|
1269
|
+
throw copy.reason;
|
|
1270
|
+
if (image.status === "rejected")
|
|
1271
|
+
throw image.reason;
|
|
1272
|
+
if (readRegularFile((0, import_node_path4.join)(dir, IMAGE_ID_FILE)) !== image.value) {
|
|
1273
|
+
(0, import_node_fs4.rmSync)(committed, { recursive: true, force: true });
|
|
1236
1274
|
return { status: "miss", reason: "base_image_changed" };
|
|
1237
1275
|
}
|
|
1238
|
-
|
|
1239
|
-
return { status: "hit", bytes: sizeOf((0, import_node_path4.join)(cacheDir, CNB_COMMITTED_DIR)) };
|
|
1276
|
+
return { status: "hit", bytes: sizeOf(committed) };
|
|
1240
1277
|
} catch (error) {
|
|
1241
|
-
(0, import_node_fs4.rmSync)(
|
|
1278
|
+
(0, import_node_fs4.rmSync)(committed, { recursive: true, force: true });
|
|
1242
1279
|
const cold = error.code === "ENOENT";
|
|
1243
|
-
return {
|
|
1280
|
+
return {
|
|
1281
|
+
status: "miss",
|
|
1282
|
+
reason: cold ? "no_cache" : firstLine(error)
|
|
1283
|
+
};
|
|
1244
1284
|
}
|
|
1245
1285
|
}
|
|
1246
|
-
function saveBuildpackCache(dir, imageId, cacheDir) {
|
|
1286
|
+
async function saveBuildpackCache(dir, imageId, cacheDir) {
|
|
1247
1287
|
const committed = (0, import_node_path4.join)(cacheDir, CNB_COMMITTED_DIR);
|
|
1248
1288
|
let metadata;
|
|
1249
1289
|
try {
|
|
@@ -1261,11 +1301,14 @@ function saveBuildpackCache(dir, imageId, cacheDir) {
|
|
|
1261
1301
|
return { status: "unchanged" };
|
|
1262
1302
|
const bytes = sizeOf(committed);
|
|
1263
1303
|
(0, import_node_fs4.rmSync)(dir, { recursive: true, force: true });
|
|
1264
|
-
copyCommitted(cacheDir, dir);
|
|
1304
|
+
await copyCommitted(cacheDir, dir);
|
|
1265
1305
|
(0, import_node_fs4.writeFileSync)((0, import_node_path4.join)(dir, IMAGE_ID_FILE), imageId);
|
|
1266
1306
|
return { status: "saved", bytes };
|
|
1267
1307
|
} catch (error) {
|
|
1268
|
-
|
|
1308
|
+
try {
|
|
1309
|
+
(0, import_node_fs4.rmSync)(dir, { recursive: true, force: true });
|
|
1310
|
+
} catch {
|
|
1311
|
+
}
|
|
1269
1312
|
return { status: "skipped", reason: firstLine(error) };
|
|
1270
1313
|
}
|
|
1271
1314
|
}
|
|
@@ -1278,16 +1321,28 @@ function isSaved(dir, imageId, metadata) {
|
|
|
1278
1321
|
return false;
|
|
1279
1322
|
}
|
|
1280
1323
|
}
|
|
1281
|
-
function copyCommitted(from, to) {
|
|
1324
|
+
async function copyCommitted(from, to) {
|
|
1282
1325
|
const source = (0, import_node_path4.join)(from, CNB_COMMITTED_DIR);
|
|
1283
1326
|
const target = (0, import_node_path4.join)(to, CNB_COMMITTED_DIR);
|
|
1284
1327
|
assertDirectory(source);
|
|
1285
1328
|
(0, import_node_fs4.mkdirSync)(target, { recursive: true });
|
|
1286
|
-
|
|
1329
|
+
const entries = (0, import_node_fs4.readdirSync)(source, { withFileTypes: true });
|
|
1330
|
+
for (const entry of entries) {
|
|
1287
1331
|
if (!entry.isFile())
|
|
1288
1332
|
throw notRegularFile(entry.name);
|
|
1289
|
-
(0, import_node_fs4.copyFileSync)((0, import_node_path4.join)(source, entry.name), (0, import_node_path4.join)(target, entry.name));
|
|
1290
1333
|
}
|
|
1334
|
+
const copies = await Promise.allSettled(
|
|
1335
|
+
entries.map(
|
|
1336
|
+
(entry) => (0, import_promises.copyFile)(
|
|
1337
|
+
(0, import_node_path4.join)(source, entry.name),
|
|
1338
|
+
(0, import_node_path4.join)(target, entry.name),
|
|
1339
|
+
import_node_fs4.constants.COPYFILE_FICLONE
|
|
1340
|
+
)
|
|
1341
|
+
)
|
|
1342
|
+
);
|
|
1343
|
+
const failed = copies.find((copy) => copy.status === "rejected");
|
|
1344
|
+
if (failed)
|
|
1345
|
+
throw failed.reason;
|
|
1291
1346
|
}
|
|
1292
1347
|
function assertDirectory(path4) {
|
|
1293
1348
|
if (!(0, import_node_fs4.lstatSync)(path4).isDirectory()) {
|
|
@@ -1796,7 +1851,11 @@ function creatorArgs(image, imageRef, options = {}) {
|
|
|
1796
1851
|
return [
|
|
1797
1852
|
"-app=/workspace",
|
|
1798
1853
|
`-order=${ORDER_FILE}`,
|
|
1799
|
-
...options.
|
|
1854
|
+
...options.debug ? ["-log-level=debug"] : [],
|
|
1855
|
+
...options.cacheDir ? [
|
|
1856
|
+
`-cache-dir=${options.cacheDir}`,
|
|
1857
|
+
...options.parallelExport ? ["-parallel"] : []
|
|
1858
|
+
] : ["-skip-restore"],
|
|
1800
1859
|
`-run-image=${image.runImage}`,
|
|
1801
1860
|
"-report=/platform-output/report.toml",
|
|
1802
1861
|
imageRef
|
|
@@ -1808,13 +1867,9 @@ var import_node_fs6 = require("fs");
|
|
|
1808
1867
|
var import_node_crypto4 = require("crypto");
|
|
1809
1868
|
var import_node_os5 = require("os");
|
|
1810
1869
|
var import_node_path6 = require("path");
|
|
1811
|
-
async function
|
|
1812
|
-
const storageArgs = await buildahStorageArgs();
|
|
1813
|
-
return run("buildah", [...storageArgs, ...args], { env, quiet });
|
|
1814
|
-
}
|
|
1815
|
-
async function removeContainer(name) {
|
|
1870
|
+
async function removeContainerInBackground(name) {
|
|
1816
1871
|
try {
|
|
1817
|
-
await
|
|
1872
|
+
await startBuildahInBackground(["rm", name]);
|
|
1818
1873
|
} catch (error) {
|
|
1819
1874
|
debug(
|
|
1820
1875
|
`could not remove Buildah CNB container ${name}: ${error.message}`
|
|
@@ -1822,10 +1877,9 @@ async function removeContainer(name) {
|
|
|
1822
1877
|
}
|
|
1823
1878
|
}
|
|
1824
1879
|
async function inspectBaseImageId(container) {
|
|
1825
|
-
const { stdout } = await
|
|
1880
|
+
const { stdout } = await runBuildah(
|
|
1826
1881
|
["inspect", "--type", "container", container],
|
|
1827
|
-
|
|
1828
|
-
true
|
|
1882
|
+
{ quiet: true }
|
|
1829
1883
|
);
|
|
1830
1884
|
const inspected = JSON.parse(stdout);
|
|
1831
1885
|
const id = inspected.FromImageID || inspected.FromImageDigest;
|
|
@@ -1862,7 +1916,89 @@ function chownTree(root, uid, gid) {
|
|
|
1862
1916
|
}
|
|
1863
1917
|
(0, import_node_fs6.lchownSync)(root, uid, gid);
|
|
1864
1918
|
}
|
|
1865
|
-
var
|
|
1919
|
+
var RegistrySetupFailure = class extends Error {
|
|
1920
|
+
constructor(reason) {
|
|
1921
|
+
super("registry setup failed");
|
|
1922
|
+
this.reason = reason;
|
|
1923
|
+
}
|
|
1924
|
+
};
|
|
1925
|
+
async function prepareBuildContainer(buildContainer, buildpack, params) {
|
|
1926
|
+
const start = Date.now();
|
|
1927
|
+
step(
|
|
1928
|
+
`Preparing ${buildpack.runtime} ${params.image.version} stock image and Vercel buildpacks`
|
|
1929
|
+
);
|
|
1930
|
+
await runBuildah([
|
|
1931
|
+
"from",
|
|
1932
|
+
"--pull=always",
|
|
1933
|
+
"--platform",
|
|
1934
|
+
TARGET_PLATFORM,
|
|
1935
|
+
"--name",
|
|
1936
|
+
buildContainer,
|
|
1937
|
+
params.image.buildImage
|
|
1938
|
+
]);
|
|
1939
|
+
await runBuildah([
|
|
1940
|
+
"run",
|
|
1941
|
+
"--network",
|
|
1942
|
+
"host",
|
|
1943
|
+
buildContainer,
|
|
1944
|
+
"--",
|
|
1945
|
+
"sh",
|
|
1946
|
+
"-c",
|
|
1947
|
+
`groupadd -g ${BUILD_GROUP_ID} cnb && useradd -m -u ${BUILD_USER_ID} -g ${BUILD_GROUP_ID} cnb && mkdir -p /layers /platform /workspace && chown -R ${BUILD_USER} /layers /platform /workspace /home/cnb`
|
|
1948
|
+
]);
|
|
1949
|
+
await runBuildah([
|
|
1950
|
+
"copy",
|
|
1951
|
+
"--chown",
|
|
1952
|
+
BUILD_USER,
|
|
1953
|
+
buildContainer,
|
|
1954
|
+
params.workPath,
|
|
1955
|
+
"/workspace"
|
|
1956
|
+
]);
|
|
1957
|
+
done(`prepared the ${buildpack.runtime} build image in ${elapsed(start)}`);
|
|
1958
|
+
}
|
|
1959
|
+
async function fetchDistributionTimed(buildpack, cnbDir) {
|
|
1960
|
+
const start = Date.now();
|
|
1961
|
+
step("Fetching the CNB lifecycle and buildpacks...");
|
|
1962
|
+
await fetchDistribution(buildpack, cnbDir);
|
|
1963
|
+
done(`fetched the CNB lifecycle and buildpacks in ${elapsed(start)}`);
|
|
1964
|
+
}
|
|
1965
|
+
async function copySavedCache(dir, buildContainer, containerReady) {
|
|
1966
|
+
const start = Date.now();
|
|
1967
|
+
step("Restoring the buildpack cache");
|
|
1968
|
+
let scratch;
|
|
1969
|
+
try {
|
|
1970
|
+
scratch = (0, import_node_fs6.mkdtempSync)((0, import_node_path6.join)(cacheScratchParent(), "vercel-cnb-cache-"));
|
|
1971
|
+
(0, import_node_fs6.chmodSync)(scratch, 493);
|
|
1972
|
+
const cacheDir = (0, import_node_path6.join)(scratch, "cache");
|
|
1973
|
+
(0, import_node_fs6.mkdirSync)(cacheDir, { mode: 493 });
|
|
1974
|
+
const imageId = containerReady.then(
|
|
1975
|
+
() => inspectBaseImageId(buildContainer)
|
|
1976
|
+
);
|
|
1977
|
+
const restored = await restoreBuildpackCache(dir, imageId, cacheDir);
|
|
1978
|
+
const baseImageId = await imageId;
|
|
1979
|
+
debug(`buildpack cache restore took ${Date.now() - start}ms`);
|
|
1980
|
+
const chownStart = Date.now();
|
|
1981
|
+
chownTree(cacheDir, BUILD_USER_ID, BUILD_GROUP_ID);
|
|
1982
|
+
debug(`buildpack cache chown took ${Date.now() - chownStart}ms`);
|
|
1983
|
+
return {
|
|
1984
|
+
scratch,
|
|
1985
|
+
cacheDir,
|
|
1986
|
+
imageId: baseImageId,
|
|
1987
|
+
restored,
|
|
1988
|
+
durationMs: Date.now() - start
|
|
1989
|
+
};
|
|
1990
|
+
} catch (error) {
|
|
1991
|
+
return {
|
|
1992
|
+
scratch,
|
|
1993
|
+
restored: {
|
|
1994
|
+
status: "miss",
|
|
1995
|
+
reason: `setup_failed:${error.message.split("\n")[0]}`
|
|
1996
|
+
},
|
|
1997
|
+
durationMs: Date.now() - start
|
|
1998
|
+
};
|
|
1999
|
+
}
|
|
2000
|
+
}
|
|
2001
|
+
async function buildAndPushWithLifecycle(buildpack, params, span) {
|
|
1866
2002
|
const urls = distributionUrls(buildpack);
|
|
1867
2003
|
return withSpan(
|
|
1868
2004
|
span,
|
|
@@ -1885,6 +2021,7 @@ var buildAndPushWithLifecycle = async (buildpack, params, span) => {
|
|
|
1885
2021
|
let orderDir;
|
|
1886
2022
|
let platformEnvDir;
|
|
1887
2023
|
let cacheScratch;
|
|
2024
|
+
let containerRemoval;
|
|
1888
2025
|
try {
|
|
1889
2026
|
reportDir = (0, import_node_fs6.mkdtempSync)((0, import_node_path6.join)((0, import_node_os5.tmpdir)(), "vercel-cnb-report-"));
|
|
1890
2027
|
const reportPath = (0, import_node_path6.join)(reportDir, "report.toml");
|
|
@@ -1896,68 +2033,32 @@ var buildAndPushWithLifecycle = async (buildpack, params, span) => {
|
|
|
1896
2033
|
platformEnvDir = writePlatformEnvDir(params.buildEnv, {
|
|
1897
2034
|
nodeHome: params.nodeToolchain?.home
|
|
1898
2035
|
});
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
done("fetched the CNB lifecycle and buildpacks");
|
|
1902
|
-
step(
|
|
1903
|
-
`Preparing ${buildpack.runtime} ${params.image.version} stock image and Vercel buildpacks`
|
|
1904
|
-
);
|
|
1905
|
-
await runBuildah2([
|
|
1906
|
-
"from",
|
|
1907
|
-
"--pull=always",
|
|
1908
|
-
"--platform",
|
|
1909
|
-
TARGET_PLATFORM,
|
|
1910
|
-
"--name",
|
|
1911
|
-
buildContainer,
|
|
1912
|
-
params.image.buildImage
|
|
1913
|
-
]);
|
|
1914
|
-
await runBuildah2([
|
|
1915
|
-
"run",
|
|
1916
|
-
"--network",
|
|
1917
|
-
"host",
|
|
2036
|
+
const registrySetup = params.prepareRegistry?.();
|
|
2037
|
+
const containerReady = prepareBuildContainer(
|
|
1918
2038
|
buildContainer,
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
BUILD_USER,
|
|
1928
|
-
buildContainer,
|
|
1929
|
-
params.workPath,
|
|
1930
|
-
"/workspace"
|
|
2039
|
+
buildpack,
|
|
2040
|
+
params
|
|
2041
|
+
);
|
|
2042
|
+
const [registry, container, distribution2, cacheCopy] = await Promise.allSettled([
|
|
2043
|
+
registrySetup,
|
|
2044
|
+
containerReady,
|
|
2045
|
+
fetchDistributionTimed(buildpack, cnbDir),
|
|
2046
|
+
params.cache ? copySavedCache(params.cache.dir, buildContainer, containerReady) : void 0
|
|
1931
2047
|
]);
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
if (
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
restored = restoreBuildpackCache(
|
|
1947
|
-
params.cache.dir,
|
|
1948
|
-
imageId,
|
|
1949
|
-
cacheDir
|
|
1950
|
-
);
|
|
1951
|
-
chownTree(cacheDir, BUILD_USER_ID, BUILD_GROUP_ID);
|
|
1952
|
-
} catch (error) {
|
|
1953
|
-
cacheDir = void 0;
|
|
1954
|
-
restored = {
|
|
1955
|
-
status: "miss",
|
|
1956
|
-
reason: `setup_failed:${error.message.split("\n")[0]}`
|
|
1957
|
-
};
|
|
1958
|
-
}
|
|
1959
|
-
done(describeRestore(restored));
|
|
1960
|
-
recordRestore(lifecycleSpan, restored, Date.now() - restoreStart);
|
|
2048
|
+
const copy = cacheCopy.status === "fulfilled" ? cacheCopy.value : void 0;
|
|
2049
|
+
cacheScratch = copy?.scratch;
|
|
2050
|
+
if (registry.status === "rejected") {
|
|
2051
|
+
throw new RegistrySetupFailure(registry.reason);
|
|
2052
|
+
}
|
|
2053
|
+
if (container.status === "rejected")
|
|
2054
|
+
throw container.reason;
|
|
2055
|
+
if (distribution2.status === "rejected")
|
|
2056
|
+
throw distribution2.reason;
|
|
2057
|
+
const imageId = copy?.imageId;
|
|
2058
|
+
const cacheDir = copy?.cacheDir;
|
|
2059
|
+
if (copy) {
|
|
2060
|
+
done(describeRestore(copy.restored));
|
|
2061
|
+
recordRestore(lifecycleSpan, copy.restored, copy.durationMs);
|
|
1961
2062
|
}
|
|
1962
2063
|
const platformEnvMount = [
|
|
1963
2064
|
"--volume",
|
|
@@ -1975,7 +2076,7 @@ var buildAndPushWithLifecycle = async (buildpack, params, span) => {
|
|
|
1975
2076
|
step(
|
|
1976
2077
|
`Building and publishing ${params.imageRef} via Vercel ${buildpack.runtime} buildpacks`
|
|
1977
2078
|
);
|
|
1978
|
-
await
|
|
2079
|
+
await runBuildah(
|
|
1979
2080
|
[
|
|
1980
2081
|
"run",
|
|
1981
2082
|
"--network",
|
|
@@ -2005,11 +2106,14 @@ var buildAndPushWithLifecycle = async (buildpack, params, span) => {
|
|
|
2005
2106
|
"--",
|
|
2006
2107
|
"/cnb/lifecycle/creator",
|
|
2007
2108
|
...creatorArgs(params.image, params.imageRef, {
|
|
2008
|
-
cacheDir: cacheDir ? CACHE_MOUNT_DIR : void 0
|
|
2109
|
+
cacheDir: cacheDir ? CACHE_MOUNT_DIR : void 0,
|
|
2110
|
+
debug: DEBUG,
|
|
2111
|
+
parallelExport: true
|
|
2009
2112
|
})
|
|
2010
2113
|
],
|
|
2011
|
-
lifecycleEnv
|
|
2114
|
+
{ env: lifecycleEnv }
|
|
2012
2115
|
);
|
|
2116
|
+
containerRemoval = removeContainerInBackground(buildContainer);
|
|
2013
2117
|
const digest = readReportDigest((0, import_node_fs6.readFileSync)(reportPath, "utf8"));
|
|
2014
2118
|
if (!digest) {
|
|
2015
2119
|
throw new Error(
|
|
@@ -2020,7 +2124,11 @@ var buildAndPushWithLifecycle = async (buildpack, params, span) => {
|
|
|
2020
2124
|
lifecycleSpan?.setAttributes({ "image.digest": digest });
|
|
2021
2125
|
if (params.cache && imageId && cacheDir) {
|
|
2022
2126
|
const saveStart = Date.now();
|
|
2023
|
-
const save = saveBuildpackCache(
|
|
2127
|
+
const save = await saveBuildpackCache(
|
|
2128
|
+
params.cache.dir,
|
|
2129
|
+
imageId,
|
|
2130
|
+
cacheDir
|
|
2131
|
+
);
|
|
2024
2132
|
done(`${describeSave(save)} in ${elapsed(saveStart)}`);
|
|
2025
2133
|
recordSave(lifecycleSpan, save, Date.now() - saveStart);
|
|
2026
2134
|
}
|
|
@@ -2032,6 +2140,8 @@ var buildAndPushWithLifecycle = async (buildpack, params, span) => {
|
|
|
2032
2140
|
runtimeVersion: params.image.version
|
|
2033
2141
|
};
|
|
2034
2142
|
} catch (error) {
|
|
2143
|
+
if (error instanceof RegistrySetupFailure)
|
|
2144
|
+
throw error.reason;
|
|
2035
2145
|
const exitCode = error.exitCode;
|
|
2036
2146
|
const hint = describeCreatorExitCode(exitCode);
|
|
2037
2147
|
lifecycleSpan?.setAttributes({
|
|
@@ -2049,7 +2159,7 @@ var buildAndPushWithLifecycle = async (buildpack, params, span) => {
|
|
|
2049
2159
|
].join("\n")
|
|
2050
2160
|
);
|
|
2051
2161
|
} finally {
|
|
2052
|
-
|
|
2162
|
+
containerRemoval ??= removeContainerInBackground(buildContainer);
|
|
2053
2163
|
for (const dir of [
|
|
2054
2164
|
cnbDir,
|
|
2055
2165
|
reportDir,
|
|
@@ -2065,10 +2175,11 @@ var buildAndPushWithLifecycle = async (buildpack, params, span) => {
|
|
|
2065
2175
|
}
|
|
2066
2176
|
}
|
|
2067
2177
|
}
|
|
2178
|
+
await containerRemoval;
|
|
2068
2179
|
}
|
|
2069
2180
|
}
|
|
2070
2181
|
);
|
|
2071
|
-
}
|
|
2182
|
+
}
|
|
2072
2183
|
|
|
2073
2184
|
// src/buildpacks/lifecycle/docker.ts
|
|
2074
2185
|
var import_node_crypto5 = require("crypto");
|
|
@@ -2683,42 +2794,54 @@ async function buildAndPushBuildpack(params) {
|
|
|
2683
2794
|
username: target.username,
|
|
2684
2795
|
token: target.token
|
|
2685
2796
|
};
|
|
2686
|
-
|
|
2687
|
-
|
|
2688
|
-
|
|
2689
|
-
|
|
2690
|
-
|
|
2691
|
-
|
|
2692
|
-
|
|
2693
|
-
|
|
2694
|
-
|
|
2695
|
-
|
|
2696
|
-
|
|
2697
|
-
|
|
2698
|
-
|
|
2699
|
-
|
|
2700
|
-
|
|
2701
|
-
|
|
2702
|
-
|
|
2703
|
-
|
|
2704
|
-
|
|
2705
|
-
|
|
2706
|
-
|
|
2707
|
-
|
|
2708
|
-
|
|
2709
|
-
|
|
2710
|
-
|
|
2711
|
-
|
|
2712
|
-
|
|
2713
|
-
|
|
2714
|
-
|
|
2715
|
-
|
|
2716
|
-
|
|
2717
|
-
|
|
2718
|
-
|
|
2719
|
-
|
|
2720
|
-
|
|
2721
|
-
|
|
2797
|
+
const prepareRegistry = async () => {
|
|
2798
|
+
step(`Authenticating to ${VCR_REGISTRY} as ${target.username}`);
|
|
2799
|
+
await withSpan(
|
|
2800
|
+
buildSpan,
|
|
2801
|
+
"container.registry_login",
|
|
2802
|
+
{
|
|
2803
|
+
"container.registry": VCR_REGISTRY,
|
|
2804
|
+
"registry.username": target.username
|
|
2805
|
+
},
|
|
2806
|
+
() => engine.login(credentials)
|
|
2807
|
+
);
|
|
2808
|
+
done("authenticated");
|
|
2809
|
+
await withSpan(
|
|
2810
|
+
buildSpan,
|
|
2811
|
+
"container.ensure_repository",
|
|
2812
|
+
{ "container.repository": params.repository },
|
|
2813
|
+
(s) => ensureRepository(
|
|
2814
|
+
params.repository,
|
|
2815
|
+
target.token,
|
|
2816
|
+
target.claims,
|
|
2817
|
+
s
|
|
2818
|
+
)
|
|
2819
|
+
);
|
|
2820
|
+
};
|
|
2821
|
+
const lifecycleParams = {
|
|
2822
|
+
workPath: sourceDir,
|
|
2823
|
+
image,
|
|
2824
|
+
imageRef: target.imageRef,
|
|
2825
|
+
credentials,
|
|
2826
|
+
buildEnv,
|
|
2827
|
+
nodeToolchain,
|
|
2828
|
+
cache
|
|
2829
|
+
};
|
|
2830
|
+
let result;
|
|
2831
|
+
if (engine.name === "buildah") {
|
|
2832
|
+
result = await buildAndPushWithLifecycle(
|
|
2833
|
+
buildpack,
|
|
2834
|
+
{ ...lifecycleParams, prepareRegistry },
|
|
2835
|
+
buildSpan
|
|
2836
|
+
);
|
|
2837
|
+
} else {
|
|
2838
|
+
await prepareRegistry();
|
|
2839
|
+
result = await buildAndPushWithLifecycleDocker(
|
|
2840
|
+
buildpack,
|
|
2841
|
+
lifecycleParams,
|
|
2842
|
+
buildSpan
|
|
2843
|
+
);
|
|
2844
|
+
}
|
|
2722
2845
|
const resolvedRef = `${VCR_REGISTRY}/${target.fullRepository}@${result.digest}`;
|
|
2723
2846
|
buildSpan?.setAttributes({
|
|
2724
2847
|
"image.digest": result.digest,
|
|
@@ -2772,7 +2895,7 @@ function resolveImageSource(options, context) {
|
|
|
2772
2895
|
}
|
|
2773
2896
|
|
|
2774
2897
|
// src/dev.ts
|
|
2775
|
-
var
|
|
2898
|
+
var import_node_child_process4 = require("child_process");
|
|
2776
2899
|
var import_node_fs15 = require("fs");
|
|
2777
2900
|
var import_node_os8 = require("os");
|
|
2778
2901
|
var import_node_path15 = __toESM(require("path"));
|
|
@@ -2840,7 +2963,7 @@ function emit(out, line) {
|
|
|
2840
2963
|
}
|
|
2841
2964
|
function runForwarded(cmd, args, out, opts = {}) {
|
|
2842
2965
|
return new Promise((resolve4, reject) => {
|
|
2843
|
-
const child = (0,
|
|
2966
|
+
const child = (0, import_node_child_process4.spawn)(cmd, args, { stdio: ["ignore", "pipe", "pipe"] });
|
|
2844
2967
|
let stdout = "";
|
|
2845
2968
|
let stderr = "";
|
|
2846
2969
|
child.stdout?.on("data", (chunk) => {
|
|
@@ -3102,7 +3225,7 @@ async function startContainer(options, reuseKey) {
|
|
|
3102
3225
|
];
|
|
3103
3226
|
emit(out, `\u25B2 container vercel dev: starting container ${image}`);
|
|
3104
3227
|
debug(`docker ${args.join(" ")}`);
|
|
3105
|
-
const child = (0,
|
|
3228
|
+
const child = (0, import_node_child_process4.spawn)("docker", args, {
|
|
3106
3229
|
stdio: ["ignore", "pipe", "pipe"]
|
|
3107
3230
|
});
|
|
3108
3231
|
let runStderr = "";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vercel/container",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "16.0.0",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"homepage": "https://vercel.com/docs",
|
|
@@ -17,12 +17,12 @@
|
|
|
17
17
|
"tar": "7.5.11"
|
|
18
18
|
},
|
|
19
19
|
"peerDependencies": {
|
|
20
|
-
"@vercel/build-utils": "14.
|
|
20
|
+
"@vercel/build-utils": "14.18.0"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"@types/node": "20.11.0",
|
|
24
24
|
"vitest": "4.1.10",
|
|
25
|
-
"@vercel/build-utils": "14.
|
|
25
|
+
"@vercel/build-utils": "14.18.0"
|
|
26
26
|
},
|
|
27
27
|
"publishConfig": {
|
|
28
28
|
"access": "public"
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"build": "node ../../utils/build-builder.mjs",
|
|
32
32
|
"type-check": "tsc --noEmit",
|
|
33
33
|
"test": "vitest run --config ../../vitest.config.mts",
|
|
34
|
-
"test-unit": "vitest run --config ../../vitest.config.mts test/unit.test.ts test/diagnostics.test.ts test/workspace.test.ts test/lifecycle-docker.test.ts test/ruby-version.test.ts test/go-version.test.ts test/rust-version.test.ts test/docker-push.test.ts test/cache.test.ts",
|
|
34
|
+
"test-unit": "vitest run --config ../../vitest.config.mts test/unit.test.ts test/diagnostics.test.ts test/workspace.test.ts test/lifecycle-docker.test.ts test/ruby-version.test.ts test/go-version.test.ts test/rust-version.test.ts test/docker-push.test.ts test/cache.test.ts test/buildah-debug.test.ts",
|
|
35
35
|
"test-e2e": "vitest run --config ../../vitest.config.mts test/e2e.test.ts"
|
|
36
36
|
}
|
|
37
37
|
}
|