@vercel/container 3.0.0 → 4.0.1

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.
Files changed (2) hide show
  1. package/dist/index.js +18 -0
  2. package/package.json +3 -3
package/dist/index.js CHANGED
@@ -1124,6 +1124,17 @@ function writeEnvFile(env) {
1124
1124
  `);
1125
1125
  return file;
1126
1126
  }
1127
+ function useContainerHost(endpoint) {
1128
+ try {
1129
+ const url = new URL(endpoint);
1130
+ if (url.hostname === "localhost" || url.hostname === "127.0.0.1" || url.hostname === "[::1]") {
1131
+ url.hostname = "host.docker.internal";
1132
+ return url.toString();
1133
+ }
1134
+ } catch {
1135
+ }
1136
+ return endpoint;
1137
+ }
1127
1138
  function emit(out, line) {
1128
1139
  if (out.onStderr) {
1129
1140
  out.onStderr(Buffer.from(`${line}
@@ -1366,6 +1377,12 @@ async function startContainer(options, reuseKey) {
1366
1377
  mergedEnv[key] = value;
1367
1378
  }
1368
1379
  }
1380
+ const runtimeCacheEndpoint = mergedEnv.RUNTIME_CACHE_ENDPOINT;
1381
+ const containerRuntimeCacheEndpoint = runtimeCacheEndpoint ? useContainerHost(runtimeCacheEndpoint) : void 0;
1382
+ const needsHostGateway = containerRuntimeCacheEndpoint !== void 0 && containerRuntimeCacheEndpoint !== runtimeCacheEndpoint;
1383
+ if (containerRuntimeCacheEndpoint) {
1384
+ mergedEnv.RUNTIME_CACHE_ENDPOINT = containerRuntimeCacheEndpoint;
1385
+ }
1369
1386
  mergedEnv.PORT = String(containerPort);
1370
1387
  const envFilePath = writeEnvFile(mergedEnv);
1371
1388
  const command = normalizeCommand(
@@ -1381,6 +1398,7 @@ async function startContainer(options, reuseKey) {
1381
1398
  // an ephemeral host port chosen by Docker when none was requested.
1382
1399
  "-p",
1383
1400
  `127.0.0.1:${requestedHostPort}:${containerPort}`,
1401
+ ...needsHostGateway ? ["--add-host", "host.docker.internal:host-gateway"] : [],
1384
1402
  "--env-file",
1385
1403
  envFilePath,
1386
1404
  image,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vercel/container",
3
- "version": "3.0.0",
3
+ "version": "4.0.1",
4
4
  "license": "Apache-2.0",
5
5
  "main": "./dist/index.js",
6
6
  "homepage": "https://vercel.com/docs",
@@ -14,12 +14,12 @@
14
14
  ],
15
15
  "dependencies": {},
16
16
  "peerDependencies": {
17
- "@vercel/build-utils": "14.5.0"
17
+ "@vercel/build-utils": "14.6.1"
18
18
  },
19
19
  "devDependencies": {
20
20
  "@types/node": "20.11.0",
21
21
  "vitest": "4.1.10",
22
- "@vercel/build-utils": "14.5.0"
22
+ "@vercel/build-utils": "14.6.1"
23
23
  },
24
24
  "publishConfig": {
25
25
  "access": "public"