sandcovery 0.6.0 → 0.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  import { $ as CurrentRedactedNames, $n as merge$1, $t as timeoutOrElse, An as exitInterrupt$1, Ar as toJson, At as interrupt$1, B as makeFilter, Bn as TaggedError, Br as isString, Bt as provide, C as decodeUnknownEffect, Cn as hasInterrupts, Cr as makePrimitive, Ct as fail$2, D as encodeSync, Dn as andThen, Dr as BaseProto, Dt as forever, E as decodeUnknownSync, Er as setStackTraceLimit, Et as fnUntraced, Fn as succeed, Fr as symbol$1, Ft as onExit$1, G as CurrentRedactedNames$1, Gn as of, Gr as identity, Gt as runPromise, H as optionalKey, Hn as seconds, Hr as constTrue, Ht as provideService, In as suspend$2, Ir as hasProperty, It as onExitPrimitive, J as redactUrl, Jn as isSuccess, Jt as succeed$1, K as empty$2, Kn as getSuccess, Kr as pipeArguments, Kt as runSync, Ln as sync, Lr as isNotNull, Lt as onInterrupt, M as isGreaterThan, Mn as exitZipRight, Mr as redact, Mt as mapError, Nn as fiberInterrupt, Nr as symbol, Nt as matchCauseEffect, O as fromJsonString, On as callback, Or as Class, Ot as forkIn, P as isMaxCodePoints, Pn as makeLatchUnsafe, Pr as random, Pt as onError, Q as unwrap, Qn as getOrUndefined$1, R as isSchemaError, Rn as TracerTimingEnabled$1, Rr as isNotNullish, Rt as orElseSucceed, S as decodeTo, Sn as done, Sr as isExit, St as ensuring$2, T as decodeUnknownResult, Tn as squash, Tr as getStackTraceLimit, Tt as flatMap, Ur as constVoid, V as optional, Vr as constFalse, Vt as provideContext, W as makeFormatterStandardSchemaV1, Wn as toSeconds, Wr as dual, Wt as runFork, X as toString, Xn as Reference, Xt as sync$1, Y as setAll$1, Yn as try_, Yt as suspend$3, Z as fromBody, Zn as Service$1, Zt as tap$1, _ as String$1, _n as close, _r as args, _t as catchIf, an as void_, at as remove, b as Unknown, bn as fail$3, br as exitFailCause, bt as contextWith, c as Json, cn as withParentSpan, cr as isSome, ct as fromSetCookie, dn as catchDone, dr as match, dt as as$1, en as tryPromise, er as exists$1, et as empty$3, fn as doneExitFromCause, fr as none, ft as asVoid, g as Record, gn as addFinalizerExit, gr as PipeInspectableProto, hn as addFinalizer, hr as Done, ht as catchCause, in as useSpan, ir as getOrNull, it as merge$2, jn as exitVoid, jr as format, jt as map, k as is$1, kr as NodeInspectSymbol, kt as gen, l as Literal, lr as liftThrowable, m as NullOr, mn as effect, mr as toArray, mt as callback$1, nn as uninterruptibleMask, nr as fromNullishOr, nt as fromRecordUnsafe, o as FiniteFromString, on as whileLoop, or as getOrUndefined, ot as set, p as NonEmptyString, pn as isDoneCause, pr as some, pt as cached, q as fromInput, qn as isFailure, qt as sleep, r as DateFromString, rn as updateContext, rr as getOrElse, rt as isRedactedName, s as Int, sn as withFiber$1, sr as isNone, st as setAll, t as ArraySchema, tn as try_$1, tr as flatMap$1, tt as fromInput$1, u as Literals, ur as map$1, ut as andThen$1, v as Struct, vn as forkUnsafe, vr as evaluate, vt as catchTag, w as decodeUnknownOption, wn as isTimeoutError, wr as withFiber, wt as failCause$1, xn as TimeoutError, xr as exitSucceed, y as Union, yn as makeUnsafe$1, yr as exitFail, yt as context, zn as DisablePropagation, zr as isPropertyKey, zt as promise } from "./Schema-CoX0a2_o.mjs";
2
- import { C as enabledVariable, F as rerunArgv, I as valuesOf$1, O as flagOf, Q as CliFailure, R as ellipsis, S as writePrivateFile, U as escapeUnprintable, Y as isDigits, Z as isWordCharacter, _ as formatMoney, a as RELAY_PORT, at as holdCluster, c as onPath, ct as Clock, d as BIN, f as CLEARABLE, g as formatCount, h as counted, i as forwarderSocket, j as lastValue, m as PROBLEM_REPORT_MAX, n as attachForwarder, nt as Canceled, o as RELAY_SOURCE, q as consistsOf, rt as IDLE_MS, s as v7, st as noop, tt as usageFailure, u as shimsOf, v as formatPercent, x as withFileLock, y as version } from "./port-forwarder-Du1VlKxg.mjs";
3
- import { A as NO_MARKUP_TERMS, C as AUTO_TOP_UP_THRESHOLD_MIN_MICRO_USD, D as ENTERPRISE_PLAN, E as CREDIT_PURCHASE_MIN_MICRO_USD, G as CiJobId, J as KeySecret, K as CredentialId, L as CreateSandboxRequest, M as thresholdBelowTopUp, N as ApiError, O as FREE_PLAN, Q as UsageShareId, R as Port, S as AUTO_TOP_UP_THRESHOLD_MAX_MICRO_USD, T as CREDIT_PURCHASE_MAX_MICRO_USD, V as ProviderSort, W as ApiKeyId, X as Provider, Y as ProcessId, Z as SandboxId, _ as KeyKind, a as USAGE_SHARE_FIGURES, b as CredentialFields, c as EstimateRequest, d as UsagePeriod, f as API_PREFIX, g as CreateKeyRequest, i as ShareToken, j as creditsAfterFeeMicroUsd, k as MICRO_USD_PER_DOLLAR, l as MONTH_TEXT, m as SANDCOVERY_ORIGIN, n as CreateUsageShareRequest, o as UsageShareFigure, p as LocalPath, q as KeyId, r as DEFAULT_SHARED_FIGURES, s as CalendarDay, t as Sandcovery, u as MonthlyCostQuery, v as SpendLimit, x as GitHubId, y as UpdateKeyRequest, z as SandboxStatus } from "./src-lrpT0LG_.mjs";
2
+ import { C as enabledVariable, F as rerunArgv, I as valuesOf$1, O as flagOf, Q as CliFailure, R as ellipsis, S as writePrivateFile, U as escapeUnprintable, Y as isDigits, Z as isWordCharacter, _ as formatMoney, a as RELAY_PORT, at as holdCluster, c as onPath, ct as Clock, d as BIN, f as CLEARABLE, g as formatCount, h as counted, i as forwarderSocket, j as lastValue, m as PROBLEM_REPORT_MAX, n as attachForwarder, nt as Canceled, o as RELAY_SOURCE, q as consistsOf, rt as IDLE_MS, s as v7, st as noop, tt as usageFailure, u as shimsOf, v as formatPercent, x as withFileLock, y as version } from "./port-forwarder-DvSPr-Tg.mjs";
3
+ import { A as NO_MARKUP_TERMS, C as AUTO_TOP_UP_THRESHOLD_MIN_MICRO_USD, D as ENTERPRISE_PLAN, E as CREDIT_PURCHASE_MIN_MICRO_USD, G as CiJobId, J as KeySecret, K as CredentialId, L as CreateSandboxRequest, M as thresholdBelowTopUp, N as ApiError, O as FREE_PLAN, Q as UsageShareId, R as Port, S as AUTO_TOP_UP_THRESHOLD_MAX_MICRO_USD, T as CREDIT_PURCHASE_MAX_MICRO_USD, V as ProviderSort, W as ApiKeyId, X as Provider, Y as ProcessId, Z as SandboxId, _ as KeyKind, a as USAGE_SHARE_FIGURES, b as CredentialFields, c as EstimateRequest, d as UsagePeriod, f as API_PREFIX, g as CreateKeyRequest, i as ShareToken, j as creditsAfterFeeMicroUsd, k as MICRO_USD_PER_DOLLAR, l as MONTH_TEXT, m as SANDCOVERY_ORIGIN, n as CreateUsageShareRequest, o as UsageShareFigure, p as LocalPath, q as KeyId, r as DEFAULT_SHARED_FIGURES, s as CalendarDay, t as Sandcovery, u as MonthlyCostQuery, v as SpendLimit, x as GitHubId, y as UpdateKeyRequest, z as SandboxStatus } from "./src-BqfeIyqj.mjs";
4
4
  import { createRequire } from "node:module";
5
5
  import { spawn } from "node:child_process";
6
6
  import { createHash, randomBytes } from "node:crypto";
@@ -11992,7 +11992,7 @@ var require_public_api = /* @__PURE__ */ __commonJSMin(((exports) => {
11992
11992
  exports.parseDocument = parseDocument;
11993
11993
  exports.stringify = stringify;
11994
11994
  }));
11995
- // src/cli/commands/compose.ts
11995
+ // src/cli/commands/environment.ts
11996
11996
  var import_dist = (/* @__PURE__ */ __commonJSMin(((exports) => {
11997
11997
  var composer = require_composer();
11998
11998
  var Document = require_Document();
@@ -12039,6 +12039,102 @@ var import_dist = (/* @__PURE__ */ __commonJSMin(((exports) => {
12039
12039
  exports.visit = visit.visit;
12040
12040
  exports.visitAsync = visit.visitAsync;
12041
12041
  })))();
12042
+ const ASSIGNED = "SANDCOVERY_DOCKER_ENV_";
12043
+ const UNSET = "SANDCOVERY_DOCKER_UNSET_";
12044
+ const DOLLAR$1 = "$";
12045
+ const DOCKER_CONFIG = `DOCKER_CONFIG="${DOLLAR$1}{DOCKER_CONFIG:-$HOME/.docker}"`;
12046
+ const CLIENT_VARIABLES = [
12047
+ "BUILDKIT_COLORS",
12048
+ "BUILDKIT_PROGRESS",
12049
+ "BUILDKIT_TTY_LOG_LINES",
12050
+ "BUILDX_BAKE_DISABLE_VARS_ENV_LOOKUP",
12051
+ "BUILDX_BAKE_FILE",
12052
+ "BUILDX_BAKE_FILE_RELATIVE_PATHS",
12053
+ "BUILDX_BAKE_FILE_SEPARATOR",
12054
+ "BUILDX_BAKE_GIT_ADVICE",
12055
+ "BUILDX_BAKE_GIT_AUTH_HEADER",
12056
+ "BUILDX_BAKE_GIT_AUTH_TOKEN",
12057
+ "BUILDX_CPU_PROFILE",
12058
+ "BUILDX_EXPERIMENTAL",
12059
+ "BUILDX_GIT_CHECK_DIRTY",
12060
+ "BUILDX_GIT_INFO",
12061
+ "BUILDX_GIT_LABELS",
12062
+ "BUILDX_MEM_PROFILE",
12063
+ "BUILDX_METADATA_PROVENANCE",
12064
+ "BUILDX_METADATA_WARNINGS",
12065
+ "BUILDX_NO_DEFAULT_ATTESTATIONS",
12066
+ "BUILDX_NO_DEFAULT_LOAD",
12067
+ "BUILDX_NO_DEFAULT_OCI_ARTIFACT",
12068
+ "BUILDX_SEND_GIT_QUERY_AS_INPUT",
12069
+ "COMPOSE_ANSI",
12070
+ "COMPOSE_CONVERT_WINDOWS_PATHS",
12071
+ "COMPOSE_DISABLE_ENV_FILE",
12072
+ "COMPOSE_ENV_FILES",
12073
+ "COMPOSE_EXPERIMENTAL",
12074
+ "COMPOSE_FILE",
12075
+ "COMPOSE_IGNORE_ORPHANS",
12076
+ "COMPOSE_MENU",
12077
+ "COMPOSE_PARALLEL_LIMIT",
12078
+ "COMPOSE_PATH_SEPARATOR",
12079
+ "COMPOSE_PROFILES",
12080
+ "COMPOSE_PROGRESS",
12081
+ "COMPOSE_PROJECT_NAME",
12082
+ "COMPOSE_REMOVE_ORPHANS",
12083
+ "COMPOSE_STATUS_STDOUT",
12084
+ "DOCKER_API_VERSION",
12085
+ "DOCKER_CUSTOM_HEADERS",
12086
+ "DOCKER_DEFAULT_PLATFORM",
12087
+ "DOCKER_HIDE_LEGACY_COMMANDS",
12088
+ "EXPERIMENTAL_BUILDKIT_SOURCE_POLICY",
12089
+ "NO_COLOR"
12090
+ ];
12091
+ const LOCAL_ONLY = /* @__PURE__ */ new Set([
12092
+ "BUILDKIT_HOST",
12093
+ "BUILDX_BAKE_GIT_SSH",
12094
+ "BUILDX_BUILDER",
12095
+ "BUILDX_CONFIG",
12096
+ "DOCKER_CERT_PATH",
12097
+ "DOCKER_CONFIG",
12098
+ "DOCKER_CONTEXT",
12099
+ "DOCKER_HOST",
12100
+ "DOCKER_TLS",
12101
+ "DOCKER_TLS_VERIFY",
12102
+ "HTTPS_PROXY",
12103
+ "HTTP_PROXY",
12104
+ "NO_PROXY"
12105
+ ]);
12106
+ const listOf = ({ separator, value }) => value === void 0 || value === "" ? [] : value.split(separator);
12107
+ const carriedEnv = ({ named, shell }) => {
12108
+ const client = CLIENT_VARIABLES.filter((name) => shell[name] !== void 0);
12109
+ const names = [.../* @__PURE__ */ new Set([...client, ...named])].filter((name) => name !== "" && !name.includes("=") && !LOCAL_ONLY.has(name));
12110
+ const assigned = names.flatMap((name) => {
12111
+ const value = shell[name];
12112
+ return value === void 0 ? [] : [`${name}=${value}`];
12113
+ });
12114
+ const unset = names.filter((name) => shell[name] === void 0);
12115
+ return Object.fromEntries([...assigned.map((entry, index) => [`${ASSIGNED}${String(index)}`, entry]), ...unset.map((name, index) => [`${UNSET}${String(index)}`, name])]);
12116
+ };
12117
+ const reference = (carrier) => `"${DOLLAR$1}${carrier}"`;
12118
+ const sudoCall = (env) => {
12119
+ const carriers = Object.keys(env);
12120
+ return carriers.length === 0 ? "sudo -n" : `sudo -n --preserve-env=${carriers.join(",")}`;
12121
+ };
12122
+ const dockerCall = (env) => {
12123
+ const carriers = Object.keys(env);
12124
+ if (carriers.length === 0) return "docker";
12125
+ const unset = carriers.flatMap((carrier) => carrier.startsWith(UNSET) ? [`-u ${reference(carrier)}`] : []);
12126
+ const assigned = carriers.flatMap((carrier) => carrier.startsWith(ASSIGNED) ? [reference(carrier)] : []);
12127
+ return [
12128
+ "env",
12129
+ ...carriers.map((carrier) => `-u ${carrier}`),
12130
+ ...unset,
12131
+ "--",
12132
+ DOCKER_CONFIG,
12133
+ ...assigned,
12134
+ "\"$(command -v docker)\""
12135
+ ].join(" ");
12136
+ };
12137
+ // src/cli/commands/compose.ts
12042
12138
  const COMPOSE_FILES = [
12043
12139
  "compose.yaml",
12044
12140
  "compose.yml",
@@ -12066,7 +12162,7 @@ const VALUE_FLAGS = /* @__PURE__ */ new Set([
12066
12162
  ]);
12067
12163
  const FILE_FLAGS$1 = /* @__PURE__ */ new Set(["--file", "-f"]);
12068
12164
  const DIRECTORY_FLAGS = /* @__PURE__ */ new Set(["--project-directory", "--workdir"]);
12069
- const ENV_FILE_FLAGS = /* @__PURE__ */ new Set(["--env-file"]);
12165
+ const ENV_FILE_FLAGS$1 = /* @__PURE__ */ new Set(["--env-file"]);
12070
12166
  const READING_SUBCOMMANDS = /* @__PURE__ */ new Set([
12071
12167
  "attach",
12072
12168
  "config",
@@ -12096,6 +12192,8 @@ const READING_SUBCOMMANDS = /* @__PURE__ */ new Set([
12096
12192
  ]);
12097
12193
  const COMPOSE_FILE_VARIABLE = "COMPOSE_FILE";
12098
12194
  const PATH_SEPARATOR_VARIABLE = "COMPOSE_PATH_SEPARATOR";
12195
+ const ENV_FILES_VARIABLE = "COMPOSE_ENV_FILES";
12196
+ const ENV_FILES_SEPARATOR = ",";
12099
12197
  const DOT_ENV = ".env";
12100
12198
  const DOCKERFILE$1 = "Dockerfile";
12101
12199
  const EXPORT_PREFIX = "export ";
@@ -12106,8 +12204,11 @@ const Texts = Union([String$1, ArraySchema(String$1)]);
12106
12204
  const Paths = Union([String$1, ArraySchema(Union([String$1, Struct({ path: String$1 })]))]);
12107
12205
  const ContextList = ArraySchema(String$1);
12108
12206
  const AdditionalContexts = Union([ContextList, Record(String$1, String$1)]);
12207
+ const MappingList = ArraySchema(Unknown);
12208
+ const Mapping = Union([MappingList, Record(String$1, Unknown)]);
12109
12209
  const Build = Union([String$1, Struct({
12110
12210
  additional_contexts: optionalKey(AdditionalContexts),
12211
+ args: optionalKey(Mapping),
12111
12212
  context: optionalKey(String$1),
12112
12213
  dockerfile: optionalKey(String$1),
12113
12214
  dockerfile_inline: optionalKey(String$1)
@@ -12116,10 +12217,14 @@ const Volume = Union([String$1, Struct({
12116
12217
  source: optionalKey(String$1),
12117
12218
  type: optionalKey(String$1)
12118
12219
  })]);
12119
- const FileSource = Struct({ file: optionalKey(String$1) });
12220
+ const FileSource = Struct({
12221
+ environment: optionalKey(String$1),
12222
+ file: optionalKey(String$1)
12223
+ });
12120
12224
  const Service = Struct({
12121
12225
  build: optionalKey(Build),
12122
12226
  env_file: optionalKey(Paths),
12227
+ environment: optionalKey(Mapping),
12123
12228
  extends: optionalKey(Union([String$1, FileSource])),
12124
12229
  label_file: optionalKey(Texts),
12125
12230
  volumes: optionalKey(ArraySchema(Volume))
@@ -12137,6 +12242,7 @@ const Model = Struct({
12137
12242
  });
12138
12243
  const decodeModel = decodeUnknownSync(Model);
12139
12244
  const isContextList = is$1(ContextList);
12245
+ const isMappingList = is$1(MappingList);
12140
12246
  const readText$2 = liftThrowable((file) => fs.readFileSync(file, "utf-8"));
12141
12247
  const statOf = liftThrowable((file) => fs.statSync(file));
12142
12248
  const isFile$1 = (file) => exists$1(statOf(file), (stat) => stat.isFile());
@@ -12152,6 +12258,26 @@ const nameAt = (text, start) => {
12152
12258
  })) end += 1;
12153
12259
  return text.slice(start, end);
12154
12260
  };
12261
+ const referencedNames = (text) => {
12262
+ const names = [];
12263
+ let index = text.indexOf("$");
12264
+ while (index !== -1) {
12265
+ const next = text.charAt(index + 1);
12266
+ const start = next === "{" ? index + 2 : index + 1;
12267
+ const name = next === "$" ? "" : nameAt(text, start);
12268
+ if (name !== "") names.push(name);
12269
+ index = text.indexOf("$", next === "$" ? index + 2 : start);
12270
+ }
12271
+ return names;
12272
+ };
12273
+ const namesIn = (document) => {
12274
+ const names = [];
12275
+ const scalarNames = (key, node) => {
12276
+ if (key !== "key" && isString(node.value)) names.push(...referencedNames(node.value));
12277
+ };
12278
+ (0, import_dist.visit)(document, { Scalar: scalarNames });
12279
+ return names;
12280
+ };
12155
12281
  const closingBrace = (text, start) => {
12156
12282
  let depth = 0;
12157
12283
  let index = start;
@@ -12231,34 +12357,45 @@ const withoutComment = (value) => {
12231
12357
  const starts = [value.indexOf(" #"), value.indexOf(" #")].filter((index) => index >= 0);
12232
12358
  return starts.length === 0 ? value : value.slice(0, Math.min(...starts));
12233
12359
  };
12360
+ const interpolatedText = (raw) => {
12361
+ if (raw.startsWith("'")) return;
12362
+ return (raw.startsWith("\"") ? doubleQuoted(raw) : withoutComment(raw)).trimEnd();
12363
+ };
12234
12364
  const dotenvValue = ({ env, raw }) => {
12235
- if (raw.startsWith("'")) {
12236
- const end = raw.indexOf("'", 1);
12237
- return end === -1 ? raw.slice(1) : raw.slice(1, end);
12238
- }
12239
- const text = raw.startsWith("\"") ? doubleQuoted(raw) : withoutComment(raw);
12240
- return interpolated({
12365
+ const text = interpolatedText(raw);
12366
+ if (text !== void 0) return interpolated({
12241
12367
  env,
12242
- text: text.trimEnd()
12368
+ text
12243
12369
  });
12244
- };
12370
+ const end = raw.indexOf("'", 1);
12371
+ return end === -1 ? raw.slice(1) : raw.slice(1, end);
12372
+ };
12373
+ const dotenvLines = (text) => text.split("\n").flatMap((line) => {
12374
+ const trimmed = line.trim();
12375
+ const assignment = trimmed.startsWith(EXPORT_PREFIX) ? trimmed.slice(7).trimStart() : trimmed;
12376
+ const equals = assignment.indexOf("=");
12377
+ if (assignment === "" || equals === 0 || assignment.startsWith("#")) return [];
12378
+ return equals === -1 ? [{
12379
+ key: assignment,
12380
+ raw: null
12381
+ }] : [{
12382
+ key: assignment.slice(0, equals).trim(),
12383
+ raw: assignment.slice(equals + 1).trim()
12384
+ }];
12385
+ });
12245
12386
  const dotenvEntries = ({ env, text }) => {
12246
12387
  const entries = /* @__PURE__ */ new Map();
12247
- for (const line of text.split("\n")) {
12248
- const trimmed = line.trim();
12249
- const assignment = trimmed.startsWith(EXPORT_PREFIX) ? trimmed.slice(7).trimStart() : trimmed;
12250
- const equals = assignment.indexOf("=");
12251
- if (equals > 0 && !assignment.startsWith("#")) {
12252
- const key = assignment.slice(0, equals).trim();
12253
- const raw = assignment.slice(equals + 1).trim();
12254
- entries.set(key, dotenvValue({
12255
- env: new Map([...entries, ...env]),
12256
- raw
12257
- }));
12258
- }
12259
- }
12388
+ for (const { key, raw } of dotenvLines(text)) if (raw !== null) entries.set(key, dotenvValue({
12389
+ env: new Map([...entries, ...env]),
12390
+ raw
12391
+ }));
12260
12392
  return entries;
12261
12393
  };
12394
+ const dotenvNames = (text) => dotenvLines(text).flatMap(({ key, raw }) => {
12395
+ if (raw === null) return [key];
12396
+ const interpolates = interpolatedText(raw);
12397
+ return interpolates === void 0 ? [] : referencedNames(interpolates);
12398
+ });
12262
12399
  const withDotenv = ({ env, files }) => {
12263
12400
  let current = env;
12264
12401
  for (const file of files) for (const text of toArray(readText$2(file))) current = new Map([...dotenvEntries({
@@ -12272,7 +12409,7 @@ const fromCwd = (cwd, texts) => texts.flatMap((text) => resolved({
12272
12409
  directory: cwd,
12273
12410
  text
12274
12411
  }));
12275
- const localPaths$1 = ({ location, values }) => values.flatMap((value) => resolved({
12412
+ const localPaths = ({ location, values }) => values.flatMap((value) => resolved({
12276
12413
  directory: location.directory,
12277
12414
  text: interpolated({
12278
12415
  env: location.env,
@@ -12299,12 +12436,20 @@ const additionalContexts = (contexts) => {
12299
12436
  if (contexts === void 0) return [];
12300
12437
  return isContextList(contexts) ? contexts.map(afterEquals$1) : Object.values(contexts);
12301
12438
  };
12439
+ const bareNames$1 = (mapping) => {
12440
+ if (mapping === void 0) return [];
12441
+ if (isMappingList(mapping)) return mapping.filter((entry) => isString(entry) && !entry.includes("="));
12442
+ return Object.entries(mapping).flatMap(([name, value]) => value === null ? [name] : []);
12443
+ };
12444
+ const addNames = (found, names) => {
12445
+ for (const name of names) found.names.add(name);
12446
+ };
12302
12447
  const addContext = ({ context, dockerfile, found, location }) => {
12303
12448
  for (const directory of localContexts({
12304
12449
  location,
12305
12450
  values: [context]
12306
12451
  })) {
12307
- const [file] = localPaths$1({
12452
+ const [file] = localPaths({
12308
12453
  location: {
12309
12454
  ...location,
12310
12455
  directory
@@ -12333,6 +12478,7 @@ const addBuild = ({ build, found, location }) => {
12333
12478
  location,
12334
12479
  values: extras
12335
12480
  })) found.mounted.add(directory);
12481
+ addNames(found, bareNames$1(build.args));
12336
12482
  const inline = build.dockerfile_inline !== void 0;
12337
12483
  addContext({
12338
12484
  context: build.context ?? ".",
@@ -12366,15 +12512,21 @@ const addService = ({ found, load, location, service }) => {
12366
12512
  directory: location.directory,
12367
12513
  text
12368
12514
  })) found.mounted.add(source);
12369
- const read = [...pathsOf(service.env_file), ...textsOf(service.label_file)];
12370
- for (const file of localPaths$1({
12515
+ addNames(found, bareNames$1(service.environment));
12516
+ const envFiles = localPaths({
12517
+ location,
12518
+ values: pathsOf(service.env_file)
12519
+ });
12520
+ const labelFiles = localPaths({
12371
12521
  location,
12372
- values: read
12373
- })) found.read.add(file);
12522
+ values: textsOf(service.label_file)
12523
+ });
12524
+ for (const file of envFiles) found.envFiles.add(file);
12525
+ for (const file of [...envFiles, ...labelFiles]) found.read.add(file);
12374
12526
  const parent = service.extends;
12375
12527
  if (parent === void 0 || isString(parent)) return;
12376
12528
  const values = parent.file === void 0 ? [] : [parent.file];
12377
- for (const file of localPaths$1({
12529
+ for (const file of localPaths({
12378
12530
  location,
12379
12531
  values
12380
12532
  })) load({
@@ -12388,22 +12540,25 @@ const addService = ({ found, load, location, service }) => {
12388
12540
  };
12389
12541
  const addInclude = ({ found, include, load, location }) => {
12390
12542
  const named = isString(include) ? include : include.path;
12391
- const files = localPaths$1({
12543
+ const files = localPaths({
12392
12544
  location,
12393
12545
  values: textsOf(named)
12394
12546
  });
12395
12547
  const [first] = files;
12396
12548
  if (first === void 0) return;
12397
12549
  const options = isString(include) ? void 0 : include;
12398
- const [directory = path.dirname(first)] = localPaths$1({
12550
+ const [directory = path.dirname(first)] = localPaths({
12399
12551
  location,
12400
12552
  values: textsOf(options?.project_directory)
12401
12553
  });
12402
- const envFiles = options?.env_file === void 0 ? [path.join(directory, DOT_ENV)] : localPaths$1({
12554
+ const envFiles = options?.env_file === void 0 ? [path.join(directory, DOT_ENV)] : localPaths({
12403
12555
  location,
12404
12556
  values: pathsOf(options.env_file)
12405
12557
  });
12406
- for (const file of envFiles) found.read.add(file);
12558
+ for (const file of envFiles) {
12559
+ found.envFiles.add(file);
12560
+ found.read.add(file);
12561
+ }
12407
12562
  const env = withDotenv({
12408
12563
  env: location.env,
12409
12564
  files: envFiles
@@ -12417,18 +12572,16 @@ const addInclude = ({ found, include, load, location }) => {
12417
12572
  }
12418
12573
  });
12419
12574
  };
12420
- const modelsIn = (text) => {
12421
- return (0, import_dist.parseAllDocuments)(text, { merge: true }).filter((parsed) => parsed.errors.length === 0).flatMap((parsed) => toArray(liftThrowable(() => decodeModel(parsed.toJS()))()));
12422
- };
12575
+ const documentsIn = (text) => (0, import_dist.parseAllDocuments)(text, { merge: true }).filter((parsed) => parsed.errors.length === 0);
12576
+ const decodedModel = liftThrowable(decodeModel);
12577
+ const modelsOf = (document) => toArray(decodedModel(document.toJS()));
12423
12578
  const loadFile = ({ file, found, location }) => {
12424
12579
  if (found.loaded.has(file)) return;
12425
12580
  found.loaded.add(file);
12426
12581
  found.read.add(file);
12427
- const models = match(readText$2(file), {
12428
- onNone: () => [],
12429
- onSome: modelsIn
12430
- });
12431
- for (const model of models) {
12582
+ const documents = toArray(readText$2(file)).flatMap(documentsIn);
12583
+ addNames(found, documents.flatMap(namesIn));
12584
+ for (const model of documents.flatMap(modelsOf)) {
12432
12585
  const services = Object.values(model.services ?? {});
12433
12586
  const sources = [...Object.values(model.configs ?? {}), ...Object.values(model.secrets ?? {})];
12434
12587
  for (const include of model.include ?? []) addInclude({
@@ -12443,8 +12596,9 @@ const loadFile = ({ file, found, location }) => {
12443
12596
  location,
12444
12597
  service
12445
12598
  });
12599
+ addNames(found, sources.flatMap((source) => textsOf(source.environment)));
12446
12600
  const values = sources.flatMap((source) => textsOf(source.file));
12447
- for (const source of localPaths$1({
12601
+ for (const source of localPaths({
12448
12602
  location,
12449
12603
  values
12450
12604
  })) found.mounted.add(source);
@@ -12478,7 +12632,7 @@ const optionsOf = (words) => {
12478
12632
  }
12479
12633
  const valuesOf = (names) => flags.flatMap(({ flag, value }) => names.has(flag) ? [value] : []);
12480
12634
  return {
12481
- envFiles: valuesOf(ENV_FILE_FLAGS),
12635
+ envFiles: valuesOf(ENV_FILE_FLAGS$1),
12482
12636
  files: valuesOf(FILE_FLAGS$1),
12483
12637
  projectDirectories: valuesOf(DIRECTORY_FLAGS),
12484
12638
  subcommand
@@ -12495,15 +12649,16 @@ const defaultFiles = (directory) => {
12495
12649
  return parent === directory ? [] : defaultFiles(parent);
12496
12650
  };
12497
12651
  const fromVariable = ({ cwd, env }) => {
12498
- const value = env.get(COMPOSE_FILE_VARIABLE);
12499
- if (value === void 0 || value === "") return;
12500
- const separator = env.get(PATH_SEPARATOR_VARIABLE) ?? path.delimiter;
12501
- return fromCwd(cwd, value.split(separator));
12652
+ const files = listOf({
12653
+ separator: env.get(PATH_SEPARATOR_VARIABLE) ?? path.delimiter,
12654
+ value: env.get(COMPOSE_FILE_VARIABLE)
12655
+ });
12656
+ return files.length === 0 ? void 0 : fromCwd(cwd, files);
12502
12657
  };
12503
- const composeFiles = ({ base, cwd, envFiles, files }) => {
12658
+ const composeFiles = ({ base, cwd, envFiles, files, shell }) => {
12504
12659
  if (files.length > 0) return fromCwd(cwd, files.filter((file) => file !== "-"));
12505
12660
  const env = withDotenv({
12506
- env: /* @__PURE__ */ new Map(),
12661
+ env: shell,
12507
12662
  files: envFiles
12508
12663
  });
12509
12664
  return fromVariable({
@@ -12520,17 +12675,23 @@ const wholePath = (file) => ({
12520
12675
  kind: "whole",
12521
12676
  path: file
12522
12677
  });
12523
- const composePaths = ({ cwd, words }) => {
12678
+ const composeReads = ({ cwd, shell, words }) => {
12524
12679
  const options = optionsOf(words);
12525
12680
  const [base = cwd] = fromCwd(cwd, options.projectDirectories.slice(-1));
12526
- const named = fromCwd(cwd, options.envFiles);
12527
- const explicit = options.envFiles.length > 0;
12681
+ const listed = options.envFiles.length > 0 ? options.envFiles : listOf({
12682
+ separator: ENV_FILES_SEPARATOR,
12683
+ value: shell[ENV_FILES_VARIABLE]
12684
+ });
12685
+ const named = fromCwd(cwd, listed);
12686
+ const explicit = listed.length > 0;
12528
12687
  const firstEnvFiles = explicit ? named : [path.join(base, DOT_ENV)];
12688
+ const variables = new Map(Object.entries(shell).flatMap(([name, value]) => value === void 0 ? [] : [[name, value]]));
12529
12689
  const files = composeFiles({
12530
12690
  base,
12531
12691
  cwd,
12532
12692
  envFiles: firstEnvFiles,
12533
- files: options.files
12693
+ files: options.files,
12694
+ shell: variables
12534
12695
  });
12535
12696
  const [first] = files;
12536
12697
  const fileDirectory = first === void 0 ? base : path.dirname(first);
@@ -12538,13 +12699,15 @@ const composePaths = ({ cwd, words }) => {
12538
12699
  const projectEnv = path.join(directory, DOT_ENV);
12539
12700
  const envFiles = explicit ? named : [...firstEnvFiles, projectEnv];
12540
12701
  const env = withDotenv({
12541
- env: /* @__PURE__ */ new Map(),
12702
+ env: variables,
12542
12703
  files: envFiles
12543
12704
  });
12544
12705
  const found = {
12545
12706
  contexts: [],
12707
+ envFiles: new Set(envFiles),
12546
12708
  loaded: /* @__PURE__ */ new Set(),
12547
12709
  mounted: /* @__PURE__ */ new Set(),
12710
+ names: /* @__PURE__ */ new Set(),
12548
12711
  read: new Set(envFiles)
12549
12712
  };
12550
12713
  for (const file of files) loadFile({
@@ -12555,16 +12718,24 @@ const composePaths = ({ cwd, words }) => {
12555
12718
  env
12556
12719
  }
12557
12720
  });
12721
+ const fromEnvFiles = [...found.envFiles].flatMap((file) => toArray(readText$2(file)).flatMap(dotenvNames));
12722
+ const names = [...found.names, ...fromEnvFiles];
12558
12723
  const { subcommand } = options;
12559
12724
  const sends = subcommand !== void 0 && !READING_SUBCOMMANDS.has(subcommand);
12560
12725
  const read = [...found.read].map(wholePath);
12561
- if (!sends) return read;
12726
+ if (!sends) return {
12727
+ names,
12728
+ paths: read
12729
+ };
12562
12730
  const mounted = [...found.mounted].map(wholePath);
12563
- return [
12564
- ...read,
12565
- ...mounted,
12566
- ...found.contexts.map(contextPath)
12567
- ];
12731
+ return {
12732
+ names,
12733
+ paths: [
12734
+ ...read,
12735
+ ...mounted,
12736
+ ...found.contexts.map(contextPath)
12737
+ ]
12738
+ };
12568
12739
  };
12569
12740
  // src/cli/commands/processes.ts
12570
12741
  const START_ACTION$1 = "start the process";
@@ -16568,7 +16739,13 @@ const BUILD_CONTEXT_FLAGS = /* @__PURE__ */ new Set(["--build-context"]);
16568
16739
  const SECRET_FLAGS = /* @__PURE__ */ new Set(["--secret"]);
16569
16740
  const VOLUME_FLAGS = /* @__PURE__ */ new Set(["--volume", "-v"]);
16570
16741
  const MOUNT_FLAGS = /* @__PURE__ */ new Set(["--mount"]);
16571
- const RUN_FILE_FLAGS = /* @__PURE__ */ new Set(["--env-file", "--label-file"]);
16742
+ const ENV_FILE_FLAGS = /* @__PURE__ */ new Set(["--env-file"]);
16743
+ const RUN_FILE_FLAGS = /* @__PURE__ */ new Set([...ENV_FILE_FLAGS, "--label-file"]);
16744
+ const ENV_FLAGS = /* @__PURE__ */ new Set(["--env", "-e"]);
16745
+ const BUILD_ARG_FLAGS = /* @__PURE__ */ new Set(["--build-arg"]);
16746
+ const SOURCE_POLICY_VARIABLE = "EXPERIMENTAL_BUILDKIT_SOURCE_POLICY";
16747
+ const BAKE_FILE_VARIABLE = "BUILDX_BAKE_FILE";
16748
+ const BAKE_FILE_SEPARATOR_VARIABLE = "BUILDX_BAKE_FILE_SEPARATOR";
16572
16749
  const INPUT_FLAGS = /* @__PURE__ */ new Set(["--input", "-i"]);
16573
16750
  const decodeSandboxes = decodeUnknownOption(fromJsonString(Record(String$1, SandboxId)));
16574
16751
  const decodeDockerSandboxes = decodeUnknownOption(fromJsonString(Record(String$1, Struct({
@@ -16607,7 +16784,9 @@ const relayCommand = (tokenFile) => {
16607
16784
  `$s python3 -c ${quoted(RELAY_SOURCE)} ${String(RELAY_PORT)} ${file}`
16608
16785
  ].join(" && ");
16609
16786
  };
16610
- const shownAddress = ({ host, port }) => host.includes(":") ? `[${host}]:${String(port)}` : `${host}:${String(port)}`;
16787
+ const shownAddress = ({ host, port, protocol }) => {
16788
+ return `${host.includes(":") ? `[${host}]` : host}:${String(port)}/${protocol}`;
16789
+ };
16611
16790
  const unforwardedMessage = (entry) => entry.reason === "busy" ? `Can't forward ${shownAddress(entry)} to this computer. Another program here listens on it, so the port stays in the sandbox.` : `Can't forward ${shownAddress(entry)} to this computer. Only an administrator may listen on it here, so the port stays in the sandbox.`;
16612
16791
  const forwarded = async ({ context, sandbox, sync }) => {
16613
16792
  const { entry } = context;
@@ -16841,14 +17020,28 @@ const dockerfileOf = ({ cwd, directory, file }) => {
16841
17020
  if (file === void 0) return path.join(directory, DOCKERFILE);
16842
17021
  return file === "-" ? void 0 : path.resolve(cwd, file);
16843
17022
  };
16844
- const buildPaths = ({ cwd, words }) => {
17023
+ const secretVariable = (secret) => {
17024
+ const fields = csvFields(secret);
17025
+ const type = fields.get("type");
17026
+ const source = fields.get("src") ?? fields.get("source");
17027
+ const typed = type === "env" ? source : void 0;
17028
+ const name = fields.get("env") ?? typed ?? fields.get("id");
17029
+ return type === "file" || name === void 0 ? [] : [name];
17030
+ };
17031
+ const bareNames = (values) => values.filter((value) => !value.includes("="));
17032
+ const policyPaths = ({ cwd, shell }) => wholePaths({
17033
+ cwd,
17034
+ values: [shell[SOURCE_POLICY_VARIABLE] ?? ""]
17035
+ });
17036
+ const buildPaths = (input) => {
17037
+ const { cwd, words } = input;
16845
17038
  const { flags, operands } = parsedWords({
16846
17039
  stopAtOperand: false,
16847
17040
  switches: BUILD_SWITCHES,
16848
17041
  words
16849
17042
  });
16850
17043
  const context = operands.at(-1);
16851
- if (context === void 0 || context === "-" || isRemote(context)) return [];
17044
+ if (context === void 0 || context === "-" || isRemote(context)) return policyPaths(input);
16852
17045
  const directory = path.resolve(cwd, context);
16853
17046
  const file = valuesOf(flags, FILE_FLAGS).at(-1);
16854
17047
  const dockerfile = dockerfileOf({
@@ -16858,14 +17051,38 @@ const buildPaths = ({ cwd, words }) => {
16858
17051
  });
16859
17052
  const extras = valuesOf(flags, BUILD_CONTEXT_FLAGS).map(afterEquals);
16860
17053
  const secrets = valuesOf(flags, SECRET_FLAGS).flatMap(secretSource);
16861
- return [{
16862
- dockerfile,
16863
- kind: "context",
16864
- path: directory
16865
- }, ...wholePaths({
16866
- cwd,
16867
- values: [...extras, ...secrets]
16868
- })];
17054
+ return [
17055
+ {
17056
+ dockerfile,
17057
+ kind: "context",
17058
+ path: directory
17059
+ },
17060
+ ...wholePaths({
17061
+ cwd,
17062
+ values: [...extras, ...secrets]
17063
+ }),
17064
+ ...policyPaths(input)
17065
+ ];
17066
+ };
17067
+ const buildNames = ({ words }) => {
17068
+ const { flags } = parsedWords({
17069
+ stopAtOperand: false,
17070
+ switches: BUILD_SWITCHES,
17071
+ words
17072
+ });
17073
+ return [...bareNames(valuesOf(flags, BUILD_ARG_FLAGS)), ...valuesOf(flags, SECRET_FLAGS).flatMap(secretVariable)];
17074
+ };
17075
+ const envFileNames = (text) => text.split("\n").flatMap((line) => {
17076
+ const entry = (line.endsWith("\r") ? line.slice(0, -1) : line).trimStart();
17077
+ return entry === "" || entry.startsWith("#") || entry.includes("=") ? [] : [entry];
17078
+ });
17079
+ const runNames = ({ cwd, words }) => {
17080
+ const { flags } = parsedWords({
17081
+ stopAtOperand: true,
17082
+ switches: RUN_SWITCHES,
17083
+ words
17084
+ });
17085
+ return [...valuesOf(flags, ENV_FILE_FLAGS).flatMap((file) => toArray(readText(path.resolve(cwd, file)))).flatMap(envFileNames), ...bareNames(valuesOf(flags, ENV_FLAGS))];
16869
17086
  };
16870
17087
  const runPaths = ({ cwd, words }) => {
16871
17088
  const { flags } = parsedWords({
@@ -16921,31 +17138,59 @@ const importPaths = ({ cwd, words }) => {
16921
17138
  values: operands.slice(0, 1)
16922
17139
  });
16923
17140
  };
16924
- const bakePaths = ({ cwd }) => [{
16925
- dockerfile: path.join(cwd, DOCKERFILE),
16926
- kind: "context",
16927
- path: cwd
16928
- }];
17141
+ const bakePaths = (input) => {
17142
+ const { cwd, shell } = input;
17143
+ const separator = shell[BAKE_FILE_SEPARATOR_VARIABLE] ?? "";
17144
+ const files = listOf({
17145
+ separator: separator === "" ? path.delimiter : separator,
17146
+ value: shell[BAKE_FILE_VARIABLE]
17147
+ });
17148
+ return [
17149
+ {
17150
+ dockerfile: path.join(cwd, DOCKERFILE),
17151
+ kind: "context",
17152
+ path: cwd
17153
+ },
17154
+ ...wholePaths({
17155
+ cwd,
17156
+ values: files
17157
+ }),
17158
+ ...policyPaths(input)
17159
+ ];
17160
+ };
16929
17161
  const PATH_COLLECTORS = /* @__PURE__ */ new Map([
16930
17162
  ["bake", bakePaths],
16931
17163
  ["build", buildPaths],
16932
17164
  ["cp", cpPaths],
16933
17165
  ["create", runPaths],
17166
+ ["exec", runPaths],
16934
17167
  ["import", importPaths],
16935
17168
  ["load", loadPaths],
16936
17169
  ["run", runPaths]
16937
17170
  ]);
16938
- const localPaths = ({ args, cwd }) => {
17171
+ const NAME_COLLECTORS = /* @__PURE__ */ new Map([
17172
+ ["build", buildNames],
17173
+ ["create", runNames],
17174
+ ["exec", runNames],
17175
+ ["run", runNames]
17176
+ ]);
17177
+ const localReads = ({ args, cwd, shell }) => {
16939
17178
  const [command, ...rest] = commandWords(args);
16940
- if (command === COMPOSE) return composePaths({
17179
+ if (command === COMPOSE) return composeReads({
16941
17180
  cwd,
17181
+ shell,
16942
17182
  words: rest
16943
17183
  });
16944
17184
  const { name, words } = dockerCommand(args);
16945
- return PATH_COLLECTORS.get(name)?.({
17185
+ const input = {
16946
17186
  cwd,
17187
+ shell,
16947
17188
  words
16948
- }) ?? [];
17189
+ };
17190
+ return {
17191
+ names: NAME_COLLECTORS.get(name)?.(input) ?? [],
17192
+ paths: PATH_COLLECTORS.get(name)?.(input) ?? []
17193
+ };
16949
17194
  };
16950
17195
  const runningSandbox = async ({ action, context, id }) => {
16951
17196
  try {
@@ -17130,9 +17375,10 @@ const dockerSandbox = async (context) => {
17130
17375
  });
17131
17376
  return sandbox;
17132
17377
  };
17133
- const remoteCommand = ({ args, prefix }) => {
17134
- const script = `${prefix} && exec docker ${args.map(quoted).join(" ")}`;
17135
- return `s= && [ "$(id -u)" -eq 0 ] || s='sudo -n' && exec $s sh -c ${quoted(script)}`;
17378
+ const remoteCommand = ({ args, env, prefix }) => {
17379
+ const words = args.map(quoted).join(" ");
17380
+ const script = `${prefix} && exec ${dockerCall(env)} ${words}`;
17381
+ return `s= && [ "$(id -u)" -eq 0 ] || s='${sudoCall(env)}' && exec $s sh -c ${quoted(script)}`;
17136
17382
  };
17137
17383
  const terminalLike = (context) => {
17138
17384
  const streams = {
@@ -17161,9 +17407,11 @@ const dockerRun = async (context) => {
17161
17407
  sync: false
17162
17408
  });
17163
17409
  const live = new Set(Object.values(savedDockerSandboxes(sandboxesFile(context))).map((saved) => saved.id));
17164
- const paths = localPaths({
17410
+ const shell = process.env;
17411
+ const { names, paths } = localReads({
17165
17412
  args,
17166
- cwd
17413
+ cwd,
17414
+ shell
17167
17415
  });
17168
17416
  const prefix = await syncCommand({
17169
17417
  context,
@@ -17172,11 +17420,20 @@ const dockerRun = async (context) => {
17172
17420
  live,
17173
17421
  paths
17174
17422
  });
17423
+ const env = carriedEnv({
17424
+ named: names,
17425
+ shell
17426
+ });
17175
17427
  const terminal = terminalLike(context);
17176
- const run = { command: remoteCommand({
17428
+ const script = remoteCommand({
17177
17429
  args,
17430
+ env,
17178
17431
  prefix
17179
- }) };
17432
+ });
17433
+ const run = Object.keys(env).length === 0 ? { command: script } : {
17434
+ command: script,
17435
+ env
17436
+ };
17180
17437
  const exitCode = await runAttached({
17181
17438
  context,
17182
17439
  forwards: context.mode.stdin.tty || readsStdin(command),