ppio-sandbox 2.1.1-a7 → 2.1.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.
package/dist/desktop.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  Sandbox
3
- } from "./chunk-5OUOMKUS.mjs";
3
+ } from "./chunk-3OWF5GCM.mjs";
4
4
  import {
5
5
  ALL_TRAFFIC,
6
6
  ApiClient,
@@ -49,7 +49,7 @@ import {
49
49
  waitForProcess,
50
50
  waitForTimeout,
51
51
  waitForURL
52
- } from "./chunk-3FDSHOTR.mjs";
52
+ } from "./chunk-PQGBLWKQ.mjs";
53
53
  export {
54
54
  ALL_TRAFFIC,
55
55
  ApiClient,
@@ -4211,7 +4211,9 @@ interface TemplateBuilder {
4211
4211
  depth?: number;
4212
4212
  user?: string;
4213
4213
  }): TemplateBuilder;
4214
- setEnvs(envs: Record<string, string>): TemplateBuilder;
4214
+ setEnvs(envs: Record<string, string>, options?: {
4215
+ runtime?: boolean;
4216
+ }): TemplateBuilder;
4215
4217
  skipCache(): this;
4216
4218
  setStartCmd(startCommand: string, readyCommand: string | ReadyCmd): TemplateFinal;
4217
4219
  setReadyCmd(readyCommand: string | ReadyCmd): TemplateFinal;
@@ -4250,6 +4252,11 @@ declare class TemplateBase implements TemplateFromImage, TemplateBuilder, Templa
4250
4252
  private forceNextLayer;
4251
4253
  private instructions;
4252
4254
  private envs;
4255
+ private envDeclarations;
4256
+ private imageEnvs;
4257
+ private imageWorkdir?;
4258
+ private imageStartCmd?;
4259
+ private imageReadyCmd?;
4253
4260
  private inheritImageConfig;
4254
4261
  private imageCredentials;
4255
4262
  private imageConfigError;
@@ -4372,10 +4379,13 @@ declare class TemplateBase implements TemplateFromImage, TemplateBuilder, Templa
4372
4379
  setStartCmd(startCommand: string, readyCommand: string | ReadyCmd): TemplateFinal;
4373
4380
  setReadyCmd(readyCommand: string | ReadyCmd): TemplateFinal;
4374
4381
  setPatchCmd(cmd: string): TemplateBuilder;
4375
- setEnvs(envs: Record<string, string>): TemplateBuilder;
4382
+ setEnvs(envs: Record<string, string>, options?: {
4383
+ runtime?: boolean;
4384
+ }): TemplateBuilder;
4376
4385
  private runtimeEnvInstruction;
4377
4386
  private withRuntimeEnv;
4378
4387
  private configFailureMessage;
4388
+ private resetInheritedConfig;
4379
4389
  private resolveInheritedConfig;
4380
4390
  static imageConfigFailure(template: TemplateClass): {
4381
4391
  error: string;
@@ -4211,7 +4211,9 @@ interface TemplateBuilder {
4211
4211
  depth?: number;
4212
4212
  user?: string;
4213
4213
  }): TemplateBuilder;
4214
- setEnvs(envs: Record<string, string>): TemplateBuilder;
4214
+ setEnvs(envs: Record<string, string>, options?: {
4215
+ runtime?: boolean;
4216
+ }): TemplateBuilder;
4215
4217
  skipCache(): this;
4216
4218
  setStartCmd(startCommand: string, readyCommand: string | ReadyCmd): TemplateFinal;
4217
4219
  setReadyCmd(readyCommand: string | ReadyCmd): TemplateFinal;
@@ -4250,6 +4252,11 @@ declare class TemplateBase implements TemplateFromImage, TemplateBuilder, Templa
4250
4252
  private forceNextLayer;
4251
4253
  private instructions;
4252
4254
  private envs;
4255
+ private envDeclarations;
4256
+ private imageEnvs;
4257
+ private imageWorkdir?;
4258
+ private imageStartCmd?;
4259
+ private imageReadyCmd?;
4253
4260
  private inheritImageConfig;
4254
4261
  private imageCredentials;
4255
4262
  private imageConfigError;
@@ -4372,10 +4379,13 @@ declare class TemplateBase implements TemplateFromImage, TemplateBuilder, Templa
4372
4379
  setStartCmd(startCommand: string, readyCommand: string | ReadyCmd): TemplateFinal;
4373
4380
  setReadyCmd(readyCommand: string | ReadyCmd): TemplateFinal;
4374
4381
  setPatchCmd(cmd: string): TemplateBuilder;
4375
- setEnvs(envs: Record<string, string>): TemplateBuilder;
4382
+ setEnvs(envs: Record<string, string>, options?: {
4383
+ runtime?: boolean;
4384
+ }): TemplateBuilder;
4376
4385
  private runtimeEnvInstruction;
4377
4386
  private withRuntimeEnv;
4378
4387
  private configFailureMessage;
4388
+ private resetInheritedConfig;
4379
4389
  private resolveInheritedConfig;
4380
4390
  static imageConfigFailure(template: TemplateClass): {
4381
4391
  error: string;
package/dist/index.d.mts CHANGED
@@ -1,5 +1,5 @@
1
- import { S as Sandbox } from './index-C1XbKLkc.mjs';
2
- export { ai as ALL_TRAFFIC, A as ApiClient, b as AuthenticationError, B as BuildError, b5 as BuildInfo, b6 as BuildOptions, b7 as BuildStatusReason, al as CommandConnectOpts, u as CommandExitError, z as CommandHandle, ak as CommandRequestOpts, v as CommandResult, am as CommandStartOpts, an as Commands, C as ConnectionConfig, a as ConnectionOpts, b8 as CopyItem, E as EntryInfo, F as FileNotFoundError, m as FileType, i as FileUploadError, n as Filesystem, s as FilesystemEvent, r as FilesystemEventType, q as FilesystemReadOpts, o as FilesystemWriteOpts, b9 as GetBuildStatusOptions, ap as Git, av as GitAddOpts, G as GitAuthError, aC as GitBranches, ar as GitCloneOpts, au as GitCommitOpts, aA as GitConfigOpts, aB as GitConfigScope, az as GitDangerouslyAuthenticateOpts, aw as GitDeleteBranchOpts, aD as GitFileStatus, as as GitInitOpts, ay as GitPullOpts, ax as GitPushOpts, at as GitRemoteAddOpts, aq as GitRequestOpts, aE as GitStatus, d as GitUpstreamError, aW as ImageConfig, j as ImageConfigError, bn as ImageConfigFailureMode, I as InvalidArgumentError, aR as LogEntry, aT as LogEntryEnd, aU as LogEntryLevel, aS as LogEntryStart, L as Logger, ah as McpServer, ba as McpServerName, N as NotEnoughSpaceError, e as NotFoundError, P as PPIO, aj as ProcessInfo, ao as Pty, y as PtyOutput, R as RateLimitError, aL as ReadyCmd, aX as RegistryCredentials, bo as RegistryDispatcher, K as SandboxApiOpts, O as SandboxBetaCreateOpts, X as SandboxCloneOpts, Y as SandboxCloneResult, Z as SandboxCommitOpts, _ as SandboxCommitResult, M as SandboxConnectOpts, f as SandboxError, ae as SandboxEventItem, af as SandboxEventsOpts, ag as SandboxEventsResult, D as SandboxInfo, a6 as SandboxInfoLifecycle, a5 as SandboxLifecycle, a1 as SandboxListOpts, H as SandboxMetrics, Q as SandboxMetricsOpts, a3 as SandboxNetworkOpts, a4 as SandboxNetworkUpdateOpts, g as SandboxNotFoundError, J as SandboxOpts, a2 as SandboxPaginator, aa as SandboxQuota, ab as SandboxQuotaLimit, ad as SandboxQuotaOpts, ac as SandboxQuotaUsage, $ as SandboxResetOpts, a0 as SandboxState, aI as Secret, aJ as SecretBinding, k as SecretError, aK as SecretWriteParams, a7 as SnapshotInfo, a8 as SnapshotListOpts, a9 as SnapshotPaginator, x as Stderr, w as Stdout, b4 as Template, b1 as TemplateApi, b3 as TemplateBase, bc as TemplateBuildStatus, bd as TemplateBuildStatusResponse, bb as TemplateBuilder, be as TemplateClass, bf as TemplateDeleteOpts, T as TemplateError, bg as TemplateInfo, bi as TemplateListOptions, bh as TemplateListOpts, bj as TemplateListResponse, b2 as TemplatePaginator, bk as TemplateTag, bl as TemplateTagInfo, bm as TemplateType, h as TimeoutError, U as Username, aF as Volume, aH as VolumeAndToken, V as VolumeError, aG as VolumeInfo, t as WatchHandle, W as WriteInfo, aY as clearImageConfigCache, c as components, aV as defaultBuildLogger, aZ as effectiveStartCmd, a_ as fetchImageConfig, l as getSignature, a$ as parseImageRef, p as paths, b0 as unsupportedBase, aP as waitForFile, aM as waitForPort, aO as waitForProcess, aQ as waitForTimeout, aN as waitForURL } from './index-C1XbKLkc.mjs';
1
+ import { S as Sandbox } from './index-CAD08VLb.mjs';
2
+ export { ai as ALL_TRAFFIC, A as ApiClient, b as AuthenticationError, B as BuildError, b5 as BuildInfo, b6 as BuildOptions, b7 as BuildStatusReason, al as CommandConnectOpts, u as CommandExitError, z as CommandHandle, ak as CommandRequestOpts, v as CommandResult, am as CommandStartOpts, an as Commands, C as ConnectionConfig, a as ConnectionOpts, b8 as CopyItem, E as EntryInfo, F as FileNotFoundError, m as FileType, i as FileUploadError, n as Filesystem, s as FilesystemEvent, r as FilesystemEventType, q as FilesystemReadOpts, o as FilesystemWriteOpts, b9 as GetBuildStatusOptions, ap as Git, av as GitAddOpts, G as GitAuthError, aC as GitBranches, ar as GitCloneOpts, au as GitCommitOpts, aA as GitConfigOpts, aB as GitConfigScope, az as GitDangerouslyAuthenticateOpts, aw as GitDeleteBranchOpts, aD as GitFileStatus, as as GitInitOpts, ay as GitPullOpts, ax as GitPushOpts, at as GitRemoteAddOpts, aq as GitRequestOpts, aE as GitStatus, d as GitUpstreamError, aW as ImageConfig, j as ImageConfigError, bn as ImageConfigFailureMode, I as InvalidArgumentError, aR as LogEntry, aT as LogEntryEnd, aU as LogEntryLevel, aS as LogEntryStart, L as Logger, ah as McpServer, ba as McpServerName, N as NotEnoughSpaceError, e as NotFoundError, P as PPIO, aj as ProcessInfo, ao as Pty, y as PtyOutput, R as RateLimitError, aL as ReadyCmd, aX as RegistryCredentials, bo as RegistryDispatcher, K as SandboxApiOpts, O as SandboxBetaCreateOpts, X as SandboxCloneOpts, Y as SandboxCloneResult, Z as SandboxCommitOpts, _ as SandboxCommitResult, M as SandboxConnectOpts, f as SandboxError, ae as SandboxEventItem, af as SandboxEventsOpts, ag as SandboxEventsResult, D as SandboxInfo, a6 as SandboxInfoLifecycle, a5 as SandboxLifecycle, a1 as SandboxListOpts, H as SandboxMetrics, Q as SandboxMetricsOpts, a3 as SandboxNetworkOpts, a4 as SandboxNetworkUpdateOpts, g as SandboxNotFoundError, J as SandboxOpts, a2 as SandboxPaginator, aa as SandboxQuota, ab as SandboxQuotaLimit, ad as SandboxQuotaOpts, ac as SandboxQuotaUsage, $ as SandboxResetOpts, a0 as SandboxState, aI as Secret, aJ as SecretBinding, k as SecretError, aK as SecretWriteParams, a7 as SnapshotInfo, a8 as SnapshotListOpts, a9 as SnapshotPaginator, x as Stderr, w as Stdout, b4 as Template, b1 as TemplateApi, b3 as TemplateBase, bc as TemplateBuildStatus, bd as TemplateBuildStatusResponse, bb as TemplateBuilder, be as TemplateClass, bf as TemplateDeleteOpts, T as TemplateError, bg as TemplateInfo, bi as TemplateListOptions, bh as TemplateListOpts, bj as TemplateListResponse, b2 as TemplatePaginator, bk as TemplateTag, bl as TemplateTagInfo, bm as TemplateType, h as TimeoutError, U as Username, aF as Volume, aH as VolumeAndToken, V as VolumeError, aG as VolumeInfo, t as WatchHandle, W as WriteInfo, aY as clearImageConfigCache, c as components, aV as defaultBuildLogger, aZ as effectiveStartCmd, a_ as fetchImageConfig, l as getSignature, a$ as parseImageRef, p as paths, b0 as unsupportedBase, aP as waitForFile, aM as waitForPort, aO as waitForProcess, aQ as waitForTimeout, aN as waitForURL } from './index-CAD08VLb.mjs';
3
3
  import 'openapi-fetch';
4
4
  import 'node:fs';
5
5
  import '@connectrpc/connect';
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { S as Sandbox } from './index-C1XbKLkc.js';
2
- export { ai as ALL_TRAFFIC, A as ApiClient, b as AuthenticationError, B as BuildError, b5 as BuildInfo, b6 as BuildOptions, b7 as BuildStatusReason, al as CommandConnectOpts, u as CommandExitError, z as CommandHandle, ak as CommandRequestOpts, v as CommandResult, am as CommandStartOpts, an as Commands, C as ConnectionConfig, a as ConnectionOpts, b8 as CopyItem, E as EntryInfo, F as FileNotFoundError, m as FileType, i as FileUploadError, n as Filesystem, s as FilesystemEvent, r as FilesystemEventType, q as FilesystemReadOpts, o as FilesystemWriteOpts, b9 as GetBuildStatusOptions, ap as Git, av as GitAddOpts, G as GitAuthError, aC as GitBranches, ar as GitCloneOpts, au as GitCommitOpts, aA as GitConfigOpts, aB as GitConfigScope, az as GitDangerouslyAuthenticateOpts, aw as GitDeleteBranchOpts, aD as GitFileStatus, as as GitInitOpts, ay as GitPullOpts, ax as GitPushOpts, at as GitRemoteAddOpts, aq as GitRequestOpts, aE as GitStatus, d as GitUpstreamError, aW as ImageConfig, j as ImageConfigError, bn as ImageConfigFailureMode, I as InvalidArgumentError, aR as LogEntry, aT as LogEntryEnd, aU as LogEntryLevel, aS as LogEntryStart, L as Logger, ah as McpServer, ba as McpServerName, N as NotEnoughSpaceError, e as NotFoundError, P as PPIO, aj as ProcessInfo, ao as Pty, y as PtyOutput, R as RateLimitError, aL as ReadyCmd, aX as RegistryCredentials, bo as RegistryDispatcher, K as SandboxApiOpts, O as SandboxBetaCreateOpts, X as SandboxCloneOpts, Y as SandboxCloneResult, Z as SandboxCommitOpts, _ as SandboxCommitResult, M as SandboxConnectOpts, f as SandboxError, ae as SandboxEventItem, af as SandboxEventsOpts, ag as SandboxEventsResult, D as SandboxInfo, a6 as SandboxInfoLifecycle, a5 as SandboxLifecycle, a1 as SandboxListOpts, H as SandboxMetrics, Q as SandboxMetricsOpts, a3 as SandboxNetworkOpts, a4 as SandboxNetworkUpdateOpts, g as SandboxNotFoundError, J as SandboxOpts, a2 as SandboxPaginator, aa as SandboxQuota, ab as SandboxQuotaLimit, ad as SandboxQuotaOpts, ac as SandboxQuotaUsage, $ as SandboxResetOpts, a0 as SandboxState, aI as Secret, aJ as SecretBinding, k as SecretError, aK as SecretWriteParams, a7 as SnapshotInfo, a8 as SnapshotListOpts, a9 as SnapshotPaginator, x as Stderr, w as Stdout, b4 as Template, b1 as TemplateApi, b3 as TemplateBase, bc as TemplateBuildStatus, bd as TemplateBuildStatusResponse, bb as TemplateBuilder, be as TemplateClass, bf as TemplateDeleteOpts, T as TemplateError, bg as TemplateInfo, bi as TemplateListOptions, bh as TemplateListOpts, bj as TemplateListResponse, b2 as TemplatePaginator, bk as TemplateTag, bl as TemplateTagInfo, bm as TemplateType, h as TimeoutError, U as Username, aF as Volume, aH as VolumeAndToken, V as VolumeError, aG as VolumeInfo, t as WatchHandle, W as WriteInfo, aY as clearImageConfigCache, c as components, aV as defaultBuildLogger, aZ as effectiveStartCmd, a_ as fetchImageConfig, l as getSignature, a$ as parseImageRef, p as paths, b0 as unsupportedBase, aP as waitForFile, aM as waitForPort, aO as waitForProcess, aQ as waitForTimeout, aN as waitForURL } from './index-C1XbKLkc.js';
1
+ import { S as Sandbox } from './index-CAD08VLb.js';
2
+ export { ai as ALL_TRAFFIC, A as ApiClient, b as AuthenticationError, B as BuildError, b5 as BuildInfo, b6 as BuildOptions, b7 as BuildStatusReason, al as CommandConnectOpts, u as CommandExitError, z as CommandHandle, ak as CommandRequestOpts, v as CommandResult, am as CommandStartOpts, an as Commands, C as ConnectionConfig, a as ConnectionOpts, b8 as CopyItem, E as EntryInfo, F as FileNotFoundError, m as FileType, i as FileUploadError, n as Filesystem, s as FilesystemEvent, r as FilesystemEventType, q as FilesystemReadOpts, o as FilesystemWriteOpts, b9 as GetBuildStatusOptions, ap as Git, av as GitAddOpts, G as GitAuthError, aC as GitBranches, ar as GitCloneOpts, au as GitCommitOpts, aA as GitConfigOpts, aB as GitConfigScope, az as GitDangerouslyAuthenticateOpts, aw as GitDeleteBranchOpts, aD as GitFileStatus, as as GitInitOpts, ay as GitPullOpts, ax as GitPushOpts, at as GitRemoteAddOpts, aq as GitRequestOpts, aE as GitStatus, d as GitUpstreamError, aW as ImageConfig, j as ImageConfigError, bn as ImageConfigFailureMode, I as InvalidArgumentError, aR as LogEntry, aT as LogEntryEnd, aU as LogEntryLevel, aS as LogEntryStart, L as Logger, ah as McpServer, ba as McpServerName, N as NotEnoughSpaceError, e as NotFoundError, P as PPIO, aj as ProcessInfo, ao as Pty, y as PtyOutput, R as RateLimitError, aL as ReadyCmd, aX as RegistryCredentials, bo as RegistryDispatcher, K as SandboxApiOpts, O as SandboxBetaCreateOpts, X as SandboxCloneOpts, Y as SandboxCloneResult, Z as SandboxCommitOpts, _ as SandboxCommitResult, M as SandboxConnectOpts, f as SandboxError, ae as SandboxEventItem, af as SandboxEventsOpts, ag as SandboxEventsResult, D as SandboxInfo, a6 as SandboxInfoLifecycle, a5 as SandboxLifecycle, a1 as SandboxListOpts, H as SandboxMetrics, Q as SandboxMetricsOpts, a3 as SandboxNetworkOpts, a4 as SandboxNetworkUpdateOpts, g as SandboxNotFoundError, J as SandboxOpts, a2 as SandboxPaginator, aa as SandboxQuota, ab as SandboxQuotaLimit, ad as SandboxQuotaOpts, ac as SandboxQuotaUsage, $ as SandboxResetOpts, a0 as SandboxState, aI as Secret, aJ as SecretBinding, k as SecretError, aK as SecretWriteParams, a7 as SnapshotInfo, a8 as SnapshotListOpts, a9 as SnapshotPaginator, x as Stderr, w as Stdout, b4 as Template, b1 as TemplateApi, b3 as TemplateBase, bc as TemplateBuildStatus, bd as TemplateBuildStatusResponse, bb as TemplateBuilder, be as TemplateClass, bf as TemplateDeleteOpts, T as TemplateError, bg as TemplateInfo, bi as TemplateListOptions, bh as TemplateListOpts, bj as TemplateListResponse, b2 as TemplatePaginator, bk as TemplateTag, bl as TemplateTagInfo, bm as TemplateType, h as TimeoutError, U as Username, aF as Volume, aH as VolumeAndToken, V as VolumeError, aG as VolumeInfo, t as WatchHandle, W as WriteInfo, aY as clearImageConfigCache, c as components, aV as defaultBuildLogger, aZ as effectiveStartCmd, a_ as fetchImageConfig, l as getSignature, a$ as parseImageRef, p as paths, b0 as unsupportedBase, aP as waitForFile, aM as waitForPort, aO as waitForProcess, aQ as waitForTimeout, aN as waitForURL } from './index-CAD08VLb.js';
3
3
  import 'openapi-fetch';
4
4
  import 'node:fs';
5
5
  import '@connectrpc/connect';
package/dist/index.js CHANGED
@@ -80,7 +80,7 @@ var __forAwait = (obj, it, method) => (it = obj[__knownSymbol("asyncIterator")])
80
80
  var version;
81
81
  var init_package = __esm({
82
82
  "package.json"() {
83
- version = "2.1.1-a7";
83
+ version = "2.1.2";
84
84
  }
85
85
  });
86
86
 
@@ -5702,54 +5702,15 @@ function handleUserInstruction(instruction, templateBuilder) {
5702
5702
  }
5703
5703
  }
5704
5704
  function handleEnvInstruction(instruction, templateBuilder) {
5705
- const argumentsData = instruction.getArguments();
5706
- const keyword = instruction.getKeyword();
5707
- if (argumentsData && argumentsData.length >= 1) {
5708
- const envVars = {};
5709
- if (argumentsData.length === 2) {
5710
- const firstArg = argumentsData[0].getValue();
5711
- const secondArg = argumentsData[1].getValue();
5712
- if (firstArg.includes("=") && secondArg.includes("=")) {
5713
- for (const arg of argumentsData) {
5714
- const envString = arg.getValue();
5715
- const equalIndex = envString.indexOf("=");
5716
- if (equalIndex > 0) {
5717
- const key = envString.substring(0, equalIndex);
5718
- const value = envString.substring(equalIndex + 1);
5719
- envVars[key] = value;
5720
- }
5721
- }
5722
- } else {
5723
- envVars[firstArg] = secondArg;
5724
- }
5725
- } else if (argumentsData.length === 1) {
5726
- const envString = argumentsData[0].getValue();
5727
- const equalIndex = envString.indexOf("=");
5728
- if (equalIndex > 0) {
5729
- const key = envString.substring(0, equalIndex);
5730
- const value = envString.substring(equalIndex + 1);
5731
- envVars[key] = value;
5732
- } else if (keyword === "ARG" && envString.trim()) {
5733
- const key = envString.trim();
5734
- envVars[key] = "";
5735
- }
5736
- } else {
5737
- for (const arg of argumentsData) {
5738
- const envString = arg.getValue();
5739
- const equalIndex = envString.indexOf("=");
5740
- if (equalIndex > 0) {
5741
- const key = envString.substring(0, equalIndex);
5742
- const value = envString.substring(equalIndex + 1);
5743
- envVars[key] = value;
5744
- } else if (keyword === "ARG") {
5745
- const key = envString;
5746
- envVars[key] = "";
5747
- }
5748
- }
5749
- }
5750
- if (Object.keys(envVars).length > 0) {
5751
- templateBuilder.setEnvs(envVars);
5752
- }
5705
+ var _a3;
5706
+ const envVars = {};
5707
+ for (const property of instruction.getProperties()) {
5708
+ envVars[property.getName()] = (_a3 = property.getValue()) != null ? _a3 : "";
5709
+ }
5710
+ if (Object.keys(envVars).length) {
5711
+ templateBuilder.setEnvs(envVars, {
5712
+ runtime: instruction.getKeyword() === "ENV"
5713
+ });
5753
5714
  }
5754
5715
  }
5755
5716
  function handleCmdEntrypointInstruction(instruction, templateBuilder) {
@@ -5796,61 +5757,120 @@ function expandableDoubleQuote(value) {
5796
5757
  const escaped = value.split("\\").join("\\\\").split('"').join('\\"').split("`").join("\\`").replace(/\$\(/g, "\\$(");
5797
5758
  return `"${escaped}"`;
5798
5759
  }
5799
- function envFilesScript(envs) {
5800
- const lines = [
5801
- "set -e",
5802
- `: > ${PROFILE_PATH}`,
5803
- `: > ${ENVIRONMENT_PATH}`
5804
- ];
5805
- for (const [name, declared] of Object.entries(envs)) {
5760
+ function envFilesScript(envs, literalEnvs = {}, envGroups, baseEnvPath) {
5761
+ const groups = envGroups != null ? envGroups : Object.entries(envs).map(([name, value]) => ({
5762
+ values: { [name]: value },
5763
+ runtime: true
5764
+ }));
5765
+ const lines = String.raw`set -e
5766
+ ${baseEnvPath ? ". " + shellQuote2(baseEnvPath) : ":"}
5767
+ ${baseEnvPath ? "command -p rm -f " + shellQuote2(baseEnvPath) : ":"}
5768
+ if [ -f "${PROFILE_PATH}" ]; then . "${PROFILE_PATH}"; fi
5769
+ command -p touch "${PROFILE_PATH}" "${ENVIRONMENT_PATH}"
5770
+ __ppio_build_env() {
5771
+ while [ "$#" -gt 0 ]; do export "$1=$2"; shift 2; done
5772
+ }
5773
+ __ppio_runtime_env() {
5774
+ while [ "$#" -gt 0 ]; do
5775
+ export "$1=$2"
5776
+ printf "export %s='" "$1" >> ${PROFILE_PATH}
5777
+ printf '%s' "$2" | command -p sed "s/'/'\\\\''/g" >> ${PROFILE_PATH}
5778
+ printf "'\n" >> ${PROFILE_PATH}
5779
+ command -p sed "/^$1=/d" ${ENVIRONMENT_PATH} > ${ENVIRONMENT_PATH}.tmp
5780
+ command -p cat ${ENVIRONMENT_PATH}.tmp > ${ENVIRONMENT_PATH}
5781
+ command -p rm -f ${ENVIRONMENT_PATH}.tmp
5782
+ case "$2" in
5783
+ *'"'*) ;;
5784
+ *) if [ "$(printf '%s' "$2" | command -p wc -l)" -eq 0 ]; then printf '%s=%s\n' "$1" "$2" >> ${ENVIRONMENT_PATH}; fi ;;
5785
+ esac
5786
+ shift 2
5787
+ done
5788
+ }`.split("\n");
5789
+ const quote = (value) => "'" + value.replace(/'/g, "'\\''") + "'";
5790
+ if (Object.keys(literalEnvs).length) {
5791
+ lines.push(
5792
+ "__ppio_runtime_env " + Object.entries(literalEnvs).map(([name, value]) => `${name} ${quote(value)}`).join(" ")
5793
+ );
5794
+ }
5795
+ for (const group of groups) {
5796
+ if (!Object.keys(group.values).length) continue;
5797
+ const fn = group.runtime ? "__ppio_runtime_env" : "__ppio_build_env";
5806
5798
  lines.push(
5807
- // Expand the declared value here, against the build's own environment.
5808
- `v=${expandableDoubleQuote(declared)}`,
5809
- // Export it before moving on, so a later value can reference this one --
5810
- // `ENV VIRTUAL_ENV=/opt/venv PYTHONPATH=$VIRTUAL_ENV/lib` is ordinary, and
5811
- // the platform's own ENV handling cannot be relied on for it (it ignores
5812
- // PATH entirely). Without this the reference expanded to empty.
5813
- `export ${name}="$v"`,
5814
- // profile.d: single-quoted, with any embedded quote closed and reopened.
5815
- `printf "export ${name}='%s'\\n" "$(printf '%s' "$v" | sed "s/'/'\\\\\\\\''/g")" >> ${PROFILE_PATH}`,
5816
- // pam_env: bare, and only when it can represent the value at all.
5817
- 'case "$v" in',
5818
- ` *'"'*) v= ;;`,
5819
- "esac",
5820
- `[ -n "$v" ] && [ "$(printf '%s' "$v" | wc -l)" -eq 0 ] && printf '${name}=%s\\n' "$v" >> ${ENVIRONMENT_PATH}`,
5821
- // `[ ... ] &&` above exits non-zero when the value is skipped, which would
5822
- // abort the script under `set -e`.
5823
- "true"
5799
+ fn + " " + Object.entries(group.values).map(([name, value]) => `${name} ${expandableDoubleQuote(value)}`).join(" ")
5824
5800
  );
5825
5801
  }
5826
- lines.push(`chmod 0644 ${PROFILE_PATH} ${ENVIRONMENT_PATH}`);
5802
+ lines.push(`command -p chmod 0644 ${PROFILE_PATH} ${ENVIRONMENT_PATH}`);
5827
5803
  return lines.join("\n");
5828
5804
  }
5829
- function envFilesCommand(envs) {
5830
- const { usable, skipped } = partitionEnvNames(Object.keys(envs));
5831
- if (usable.length === 0) {
5832
- return { command: null, skipped };
5833
- }
5834
- const script = envFilesScript(
5835
- Object.fromEntries(usable.map((name) => [name, envs[name]]))
5805
+ function envFilesCommand(envs, literalEnvs = {}, envGroups, baseEnvPath) {
5806
+ const groups = envGroups != null ? envGroups : Object.entries(envs).map(([name, value]) => ({
5807
+ values: { [name]: value },
5808
+ runtime: true
5809
+ }));
5810
+ const names = [
5811
+ .../* @__PURE__ */ new Set([
5812
+ ...Object.keys(literalEnvs),
5813
+ ...groups.flatMap((group) => Object.keys(group.values))
5814
+ ])
5815
+ ];
5816
+ const { usable, skipped } = partitionEnvNames(names);
5817
+ const allowed = new Set(usable);
5818
+ const filter = (values) => Object.fromEntries(
5819
+ Object.entries(values).filter(([name]) => allowed.has(name))
5836
5820
  );
5837
- const b64 = Buffer.from(script, "utf8").toString("base64");
5821
+ const literals = filter(literalEnvs);
5822
+ const filtered = groups.map((group) => ({
5823
+ values: filter(group.values),
5824
+ runtime: group.runtime
5825
+ }));
5826
+ if (!Object.keys(literals).length && !filtered.some((group) => group.runtime && Object.keys(group.values).length))
5827
+ return { command: null, skipped };
5828
+ const b64 = Buffer.from(
5829
+ envFilesScript({}, literals, filtered, baseEnvPath),
5830
+ "utf8"
5831
+ ).toString("base64");
5838
5832
  return {
5839
5833
  command: [
5840
- `echo ${b64} | base64 -d > ${SCRIPT_PATH}`,
5841
- `sh ${SCRIPT_PATH}`,
5842
- `rm -f ${SCRIPT_PATH}`
5834
+ `echo ${b64} | command -p base64 -d > ${SCRIPT_PATH}`,
5835
+ `command -p sh ${SCRIPT_PATH}`,
5836
+ `command -p rm -f ${SCRIPT_PATH}`
5843
5837
  ].join(" && "),
5844
5838
  skipped
5845
5839
  };
5846
5840
  }
5847
- var PROFILE_PATH, ENVIRONMENT_PATH, SCRIPT_PATH;
5841
+ function shellQuote2(value) {
5842
+ return "'" + value.replace(/'/g, "'\\''") + "'";
5843
+ }
5844
+ function envSnapshotCommand(groups) {
5845
+ const { usable } = partitionEnvNames([
5846
+ ...new Set(groups.flatMap((group) => Object.keys(group.values)))
5847
+ ]);
5848
+ if (!usable.length) return null;
5849
+ const lines = [
5850
+ "set -e",
5851
+ "umask 077",
5852
+ `: > ${BASE_ENV_PATH}`,
5853
+ `command -p chmod 0600 ${BASE_ENV_PATH}`
5854
+ ];
5855
+ for (const name of usable) {
5856
+ lines.push(String.raw`if [ "${"${" + name + "+x}"}" = x ]; then
5857
+ printf "export ${name}='" >> ${BASE_ENV_PATH}
5858
+ printf '%s' "${"${" + name + "}"}" | command -p sed "s/'/'\\\\''/g" >> ${BASE_ENV_PATH}
5859
+ printf "'\n" >> ${BASE_ENV_PATH}
5860
+ else
5861
+ printf 'unset ${name}\n' >> ${BASE_ENV_PATH}
5862
+ fi`);
5863
+ }
5864
+ return "command -p sh -c " + shellQuote2(lines.join("\n"));
5865
+ }
5866
+ var PROFILE_PATH, ENVIRONMENT_PATH, SCRIPT_PATH, BASE_ENV_PATH;
5848
5867
  var init_envFiles = __esm({
5849
5868
  "src/core/template/envFiles.ts"() {
5850
5869
  "use strict";
5851
5870
  PROFILE_PATH = "/etc/profile.d/99-image-env.sh";
5852
5871
  ENVIRONMENT_PATH = "/etc/environment";
5853
5872
  SCRIPT_PATH = "/tmp/.ppio-image-env.sh";
5873
+ BASE_ENV_PATH = "/etc/.ppio-image-env-base.sh";
5854
5874
  }
5855
5875
  });
5856
5876
 
@@ -5867,9 +5887,15 @@ function unsupportedBase(blob) {
5867
5887
  return null;
5868
5888
  }
5869
5889
  const families = [
5870
- [/alpine-minirootfs|etc\/alpine-release|apk add|apk --no-cache/i, "Alpine (musl)"],
5890
+ [
5891
+ /alpine-minirootfs|etc\/alpine-release|apk add|apk --no-cache/i,
5892
+ "Alpine (musl)"
5893
+ ],
5871
5894
  [/^BusyBox /im, "BusyBox"],
5872
- [/microdnf|dnf install|yum install|rpm -i/i, "RPM-based (Fedora/RHEL/Rocky)"],
5895
+ [
5896
+ /microdnf|dnf install|yum install|rpm -i/i,
5897
+ "RPM-based (Fedora/RHEL/Rocky)"
5898
+ ],
5873
5899
  [/pacman -S/i, "Arch"],
5874
5900
  [/zypper|KIWI /i, "SUSE"]
5875
5901
  ];
@@ -5911,7 +5937,7 @@ function parseImageRef(image) {
5911
5937
  let reference;
5912
5938
  const at = ref.indexOf("@");
5913
5939
  if (at !== -1) {
5914
- repository = ref.slice(0, at);
5940
+ repository = ref.slice(0, at).replace(/:[^/]*$/, "");
5915
5941
  reference = ref.slice(at + 1);
5916
5942
  } else {
5917
5943
  const colon = ref.lastIndexOf(":");
@@ -6017,7 +6043,10 @@ async function registryGet(url, headers, options) {
6017
6043
  for (let attempt = 0; attempt < attempts; attempt++) {
6018
6044
  if (attempt > 0) {
6019
6045
  await new Promise(
6020
- (resolve) => setTimeout(resolve, retryDelayMs(last, 2 ** (attempt - 1) * backoffBaseMs))
6046
+ (resolve) => setTimeout(
6047
+ resolve,
6048
+ retryDelayMs(last, 2 ** (attempt - 1) * backoffBaseMs)
6049
+ )
6021
6050
  );
6022
6051
  }
6023
6052
  try {
@@ -6142,7 +6171,7 @@ function describeFailure(error, image, host, repository, authenticated) {
6142
6171
  async function fetchImageConfig(image, credentials, options) {
6143
6172
  var _a3, _b, _c, _d, _e, _f, _g;
6144
6173
  const dispatcher = options == null ? void 0 : options.dispatcher;
6145
- const cacheable = dispatcher === void 0;
6174
+ const cacheable = dispatcher === void 0 && image.includes("@");
6146
6175
  const key = JSON.stringify([
6147
6176
  image,
6148
6177
  (_a3 = credentials == null ? void 0 : credentials.username) != null ? _a3 : null,
@@ -6208,7 +6237,7 @@ async function fetchImageConfig(image, credentials, options) {
6208
6237
  Boolean((credentials == null ? void 0 : credentials.username) && (credentials == null ? void 0 : credentials.password))
6209
6238
  );
6210
6239
  }
6211
- if (cacheable) {
6240
+ if (cacheable && !result.error) {
6212
6241
  CACHE.set(key, result);
6213
6242
  }
6214
6243
  return copyConfig(result);
@@ -6218,7 +6247,7 @@ function effectiveStartCmd(entrypoint, cmd) {
6218
6247
  return parts.length > 0 ? parts.map(shellQuoteArg).join(" ") : null;
6219
6248
  }
6220
6249
  function shellQuoteArg(value) {
6221
- return /^[A-Za-z0-9_./:@%+=,-]+$/.test(value) ? value : `'${value.replace(/'/g, `'\\''`)}'`;
6250
+ return /^[A-Za-z0-9_./:@%+=,-]+$/.test(value) ? value : `'${value.replace(/'/g, "'\\''")}'`;
6222
6251
  }
6223
6252
  function clearImageConfigCache() {
6224
6253
  CACHE.clear();
@@ -6316,7 +6345,10 @@ var init_imageConfig = __esm({
6316
6345
  if (params.service) {
6317
6346
  url.searchParams.set("service", params.service);
6318
6347
  }
6319
- url.searchParams.set("scope", params.scope || `repository:${this.repository}:pull`);
6348
+ url.searchParams.set(
6349
+ "scope",
6350
+ params.scope || `repository:${this.repository}:pull`
6351
+ );
6320
6352
  const headers = {};
6321
6353
  if (((_a3 = this.credentials) == null ? void 0 : _a3.username) && this.credentials.password) {
6322
6354
  headers.Authorization = basicHeader(this.credentials);
@@ -6517,6 +6549,8 @@ var init_template = __esm({
6517
6549
  // rather than written per call because the file is written once from the full
6518
6550
  // set -- a per-call write would clobber the previous call's file.
6519
6551
  this.envs = {};
6552
+ this.envDeclarations = [];
6553
+ this.imageEnvs = {};
6520
6554
  // Whether to restore what the base image declares -- see fromImage() and
6521
6555
  // resolveInheritedConfig(). Only meaningful for an image base; a Dockerfile
6522
6556
  // states its own ENV/WORKDIR/CMD, and a template base already carries them.
@@ -6791,6 +6825,7 @@ var init_template = __esm({
6791
6825
  }
6792
6826
  this.baseImage = baseImage;
6793
6827
  this.baseTemplate = void 0;
6828
+ this.resetInheritedConfig();
6794
6829
  this.inheritImageConfig = (_a3 = options == null ? void 0 : options.inheritConfig) != null ? _a3 : true;
6795
6830
  this.imageCredentials = credentials;
6796
6831
  this.imageOnConfigFailure = (_b = options == null ? void 0 : options.onConfigFailure) != null ? _b : "warn";
@@ -6811,6 +6846,7 @@ var init_template = __esm({
6811
6846
  fromTemplate(template) {
6812
6847
  this.baseTemplate = template;
6813
6848
  this.baseImage = void 0;
6849
+ this.resetInheritedConfig();
6814
6850
  if (this.forceNextLayer) {
6815
6851
  this.force = true;
6816
6852
  }
@@ -6825,6 +6861,8 @@ var init_template = __esm({
6825
6861
  );
6826
6862
  this.baseImage = baseImage;
6827
6863
  this.baseTemplate = void 0;
6864
+ this.resetInheritedConfig();
6865
+ this.inheritImageConfig = true;
6828
6866
  if (this.forceNextLayer) {
6829
6867
  this.force = true;
6830
6868
  }
@@ -6834,6 +6872,7 @@ var init_template = __esm({
6834
6872
  fromAWSRegistry(image, credentials) {
6835
6873
  this.baseImage = image;
6836
6874
  this.baseTemplate = void 0;
6875
+ this.resetInheritedConfig();
6837
6876
  this.registryConfig = {
6838
6877
  type: "aws",
6839
6878
  awsAccessKeyId: credentials.accessKeyId,
@@ -6849,6 +6888,7 @@ var init_template = __esm({
6849
6888
  fromGCPRegistry(image, credentials) {
6850
6889
  this.baseImage = image;
6851
6890
  this.baseTemplate = void 0;
6891
+ this.resetInheritedConfig();
6852
6892
  this.registryConfig = {
6853
6893
  type: "gcp",
6854
6894
  serviceAccountJson: readGCPServiceAccountJSON(
@@ -6865,6 +6905,7 @@ var init_template = __esm({
6865
6905
  fromOCIRegistry(image, credentials) {
6866
6906
  this.baseImage = image;
6867
6907
  this.baseTemplate = void 0;
6908
+ this.resetInheritedConfig();
6868
6909
  this.registryConfig = {
6869
6910
  type: "oci",
6870
6911
  tenancyOcid: credentials.tenancyOcid,
@@ -6882,6 +6923,7 @@ var init_template = __esm({
6882
6923
  fromHuaweiCloudRegistry(image, credentials) {
6883
6924
  this.baseImage = image;
6884
6925
  this.baseTemplate = void 0;
6926
+ this.resetInheritedConfig();
6885
6927
  this.registryConfig = {
6886
6928
  type: "huawei",
6887
6929
  accessKeyId: credentials.accessKeyId,
@@ -7143,7 +7185,8 @@ var init_template = __esm({
7143
7185
  this.collectStackTrace();
7144
7186
  return this;
7145
7187
  }
7146
- setEnvs(envs) {
7188
+ setEnvs(envs, options) {
7189
+ var _a3;
7147
7190
  if (Object.keys(envs).length === 0) {
7148
7191
  return this;
7149
7192
  }
@@ -7152,7 +7195,11 @@ var init_template = __esm({
7152
7195
  args: Object.entries(envs).flatMap(([key, value]) => [key, value]),
7153
7196
  force: this.forceNextLayer
7154
7197
  });
7155
- this.envs = __spreadValues(__spreadValues({}, this.envs), envs);
7198
+ this.envDeclarations.push({
7199
+ values: __spreadValues({}, envs),
7200
+ runtime: (_a3 = options == null ? void 0 : options.runtime) != null ? _a3 : false
7201
+ });
7202
+ if (options == null ? void 0 : options.runtime) this.envs = __spreadValues(__spreadValues({}, this.envs), envs);
7156
7203
  this.collectStackTrace();
7157
7204
  return this;
7158
7205
  }
@@ -7169,7 +7216,12 @@ var init_template = __esm({
7169
7216
  * second build of the same template append a duplicate layer.
7170
7217
  */
7171
7218
  runtimeEnvInstruction() {
7172
- const { command } = envFilesCommand(this.envs);
7219
+ const { command } = envFilesCommand(
7220
+ this.envs,
7221
+ this.imageEnvs,
7222
+ this.envDeclarations,
7223
+ envSnapshotCommand(this.envDeclarations) ? BASE_ENV_PATH : void 0
7224
+ );
7173
7225
  if (command === null) {
7174
7226
  return null;
7175
7227
  }
@@ -7188,7 +7240,10 @@ var init_template = __esm({
7188
7240
  */
7189
7241
  withRuntimeEnv(instructions) {
7190
7242
  const runtimeEnv = this.runtimeEnvInstruction();
7191
- return runtimeEnv ? [...instructions, runtimeEnv] : instructions;
7243
+ if (!runtimeEnv) return instructions;
7244
+ const snapshot = envSnapshotCommand(this.envDeclarations);
7245
+ const prefix = snapshot ? [{ type: "RUN" /* RUN */, args: [snapshot, "root"], force: false }] : [];
7246
+ return [...prefix, ...instructions, runtimeEnv];
7192
7247
  }
7193
7248
  /**
7194
7249
  * Restore what the base image declares: ENV, WORKDIR and its effective command.
@@ -7213,20 +7268,32 @@ var init_template = __esm({
7213
7268
  configFailureMessage() {
7214
7269
  return `Could not read ${this.baseImage}: ${this.imageConfigError}. The template will build without the environment, working directory and start command the image declares.`;
7215
7270
  }
7271
+ resetInheritedConfig() {
7272
+ this.imageEnvs = {};
7273
+ this.imageWorkdir = void 0;
7274
+ this.imageStartCmd = void 0;
7275
+ this.imageReadyCmd = void 0;
7276
+ this.imageConfigError = void 0;
7277
+ this.imageUnusable = void 0;
7278
+ this.imageCredentials = void 0;
7279
+ this.imageDispatcher = void 0;
7280
+ this.registryConfig = void 0;
7281
+ this.inheritImageConfig = false;
7282
+ }
7216
7283
  async resolveInheritedConfig(onBuildLogs) {
7217
- var _a3;
7218
- if (this.imageOnConfigFailure === "raise" && this.imageConfigError !== void 0) {
7219
- throw new ImageConfigError(this.configFailureMessage());
7220
- }
7284
+ var _a3, _b;
7221
7285
  if (!this.inheritImageConfig || this.baseImage === void 0) {
7222
7286
  return;
7223
7287
  }
7224
- this.inheritImageConfig = false;
7225
7288
  const config = await fetchImageConfig(
7226
7289
  this.baseImage,
7227
7290
  this.imageCredentials,
7228
7291
  this.imageDispatcher === void 0 ? void 0 : { dispatcher: this.imageDispatcher }
7229
7292
  );
7293
+ this.imageEnvs = {};
7294
+ this.imageWorkdir = void 0;
7295
+ this.imageStartCmd = void 0;
7296
+ this.imageReadyCmd = void 0;
7230
7297
  if (config.error) {
7231
7298
  this.imageConfigError = config.error;
7232
7299
  this.imageUnusable = config.unusable;
@@ -7240,18 +7307,14 @@ var init_template = __esm({
7240
7307
  }
7241
7308
  return;
7242
7309
  }
7243
- this.envs = __spreadValues(__spreadValues({}, config.env), this.envs);
7244
- if (config.workdir && !this.instructions.some((i) => i.type === "WORKDIR" /* WORKDIR */)) {
7245
- this.instructions.push({
7246
- type: "WORKDIR" /* WORKDIR */,
7247
- args: [config.workdir],
7248
- force: false
7249
- });
7250
- }
7310
+ this.imageEnvs = __spreadValues({}, config.env);
7311
+ this.imageWorkdir = (_a3 = config.workdir) != null ? _a3 : void 0;
7312
+ this.imageConfigError = void 0;
7313
+ this.imageUnusable = void 0;
7251
7314
  const startCmd = effectiveStartCmd(config.entrypoint, config.cmd);
7252
7315
  if (startCmd && this.startCmd === void 0) {
7253
- this.startCmd = startCmd;
7254
- this.readyCmd = (_a3 = this.readyCmd) != null ? _a3 : waitForTimeout(2e4).getCmd();
7316
+ this.imageStartCmd = startCmd;
7317
+ this.imageReadyCmd = (_b = this.readyCmd) != null ? _b : waitForTimeout(2e4).getCmd();
7255
7318
  }
7256
7319
  }
7257
7320
  /**
@@ -7589,9 +7652,20 @@ var init_template = __esm({
7589
7652
  * @returns Template data formatted for the API
7590
7653
  */
7591
7654
  serialize(steps) {
7655
+ var _a3, _b;
7656
+ if (this.imageWorkdir) {
7657
+ steps = [
7658
+ {
7659
+ type: "WORKDIR" /* WORKDIR */,
7660
+ args: [this.imageWorkdir],
7661
+ force: false
7662
+ },
7663
+ ...steps
7664
+ ];
7665
+ }
7592
7666
  const templateData = {
7593
- startCmd: this.startCmd,
7594
- readyCmd: this.readyCmd,
7667
+ startCmd: (_a3 = this.startCmd) != null ? _a3 : this.imageStartCmd,
7668
+ readyCmd: (_b = this.readyCmd) != null ? _b : this.imageReadyCmd,
7595
7669
  preBootScript: this.patchCmd,
7596
7670
  steps,
7597
7671
  force: this.force