ppio-sandbox 2.1.1 → 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/README.md +19 -0
- package/dist/{chunk-NRHSODSZ.mjs → chunk-3L3K3WO3.mjs} +2 -2
- package/dist/{chunk-RIWYGA3J.mjs → chunk-3OWF5GCM.mjs} +2 -2
- package/dist/chunk-3OWF5GCM.mjs.map +1 -0
- package/dist/{chunk-M7G3KDGF.mjs → chunk-PQGBLWKQ.mjs} +593 -283
- package/dist/chunk-PQGBLWKQ.mjs.map +1 -0
- package/dist/code-interpreter.d.mts +2 -2
- package/dist/code-interpreter.d.ts +2 -2
- package/dist/code-interpreter.js +602 -290
- package/dist/code-interpreter.js.map +1 -1
- package/dist/code-interpreter.mjs +4 -2
- package/dist/code-interpreter.mjs.map +1 -1
- package/dist/desktop.d.mts +1 -1
- package/dist/desktop.d.ts +1 -1
- package/dist/desktop.js +602 -290
- package/dist/desktop.js.map +1 -1
- package/dist/desktop.mjs +4 -2
- package/dist/{index-CRwaZUdl.d.mts → index-CAD08VLb.d.mts} +76 -58
- package/dist/{index-CRwaZUdl.d.ts → index-CAD08VLb.d.ts} +76 -58
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +602 -290
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +3 -1
- package/dist/sandbox-DMY2YDSO.mjs +8 -0
- package/dist/sandbox-TS3DDCSN.mjs +8 -0
- package/package.json +1 -1
- package/dist/chunk-M7G3KDGF.mjs.map +0 -1
- package/dist/chunk-RIWYGA3J.mjs.map +0 -1
- package/dist/sandbox-5PUSVOHB.mjs +0 -8
- package/dist/sandbox-VBQLLX3L.mjs +0 -8
- /package/dist/{chunk-NRHSODSZ.mjs.map → chunk-3L3K3WO3.mjs.map} +0 -0
- /package/dist/{sandbox-5PUSVOHB.mjs.map → sandbox-DMY2YDSO.mjs.map} +0 -0
- /package/dist/{sandbox-VBQLLX3L.mjs.map → sandbox-TS3DDCSN.mjs.map} +0 -0
package/dist/code-interpreter.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.
|
|
83
|
+
version = "2.1.2";
|
|
84
84
|
}
|
|
85
85
|
});
|
|
86
86
|
|
|
@@ -122,12 +122,6 @@ async function sha256(data) {
|
|
|
122
122
|
function timeoutToSeconds(timeout) {
|
|
123
123
|
return Math.ceil(timeout / 1e3);
|
|
124
124
|
}
|
|
125
|
-
function dynamicRequire(module2) {
|
|
126
|
-
if (runtime === "browser") {
|
|
127
|
-
throw new Error("Browser runtime is not supported for require");
|
|
128
|
-
}
|
|
129
|
-
return require(module2);
|
|
130
|
-
}
|
|
131
125
|
async function dynamicImport(module2) {
|
|
132
126
|
if (runtime === "browser") {
|
|
133
127
|
throw new Error("Browser runtime is not supported for dynamic import");
|
|
@@ -148,6 +142,9 @@ function toBlob(data) {
|
|
|
148
142
|
if (data instanceof Blob) {
|
|
149
143
|
return data;
|
|
150
144
|
}
|
|
145
|
+
if (data instanceof Uint8Array) {
|
|
146
|
+
return new Blob([new Uint8Array(data)]);
|
|
147
|
+
}
|
|
151
148
|
if (typeof data === "string" || data instanceof ArrayBuffer) {
|
|
152
149
|
return new Blob([data]);
|
|
153
150
|
}
|
|
@@ -158,7 +155,7 @@ function shellQuote(s) {
|
|
|
158
155
|
}
|
|
159
156
|
async function toUploadBody(data, gzip) {
|
|
160
157
|
if (gzip) {
|
|
161
|
-
const stream = data instanceof ReadableStream ? data :
|
|
158
|
+
const stream = data instanceof ReadableStream ? data : (await toBlob(data)).stream();
|
|
162
159
|
const compressed = stream.pipeThrough(new CompressionStream("gzip"));
|
|
163
160
|
return new Response(compressed).blob();
|
|
164
161
|
}
|
|
@@ -208,7 +205,7 @@ function formatSandboxTimeoutError(message) {
|
|
|
208
205
|
`${message}: This error is likely due to sandbox timeout. You can modify the sandbox timeout by passing 'timeoutMs' when starting the sandbox or calling '.setTimeout' on the sandbox with the desired timeout.`
|
|
209
206
|
);
|
|
210
207
|
}
|
|
211
|
-
var SandboxError, TimeoutError, InvalidArgumentError, NotEnoughSpaceError, NotFoundError, FileNotFoundError, SandboxNotFoundError, AuthenticationError, GitAuthError, GitUpstreamError, TemplateError, RateLimitError, BuildError, FileUploadError, VolumeError, SecretError;
|
|
208
|
+
var SandboxError, TimeoutError, InvalidArgumentError, NotEnoughSpaceError, NotFoundError, FileNotFoundError, SandboxNotFoundError, AuthenticationError, GitAuthError, GitUpstreamError, TemplateError, RateLimitError, BuildError, FileUploadError, ImageConfigError, VolumeError, SecretError;
|
|
212
209
|
var init_errors = __esm({
|
|
213
210
|
"src/core/errors.ts"() {
|
|
214
211
|
"use strict";
|
|
@@ -302,6 +299,8 @@ var init_errors = __esm({
|
|
|
302
299
|
this.name = "FileUploadError";
|
|
303
300
|
}
|
|
304
301
|
};
|
|
302
|
+
ImageConfigError = class extends BuildError {
|
|
303
|
+
};
|
|
305
304
|
VolumeError = class extends Error {
|
|
306
305
|
constructor(message) {
|
|
307
306
|
super(message);
|
|
@@ -1580,7 +1579,7 @@ var init_filesystem = __esm({
|
|
|
1580
1579
|
this.defaultWatchRecursive = false;
|
|
1581
1580
|
this.rpc = (0, import_connect5.createClient)(Filesystem, transport);
|
|
1582
1581
|
}
|
|
1583
|
-
async read(
|
|
1582
|
+
async read(path3, opts) {
|
|
1584
1583
|
var _a3;
|
|
1585
1584
|
const format = (_a3 = opts == null ? void 0 : opts.format) != null ? _a3 : "text";
|
|
1586
1585
|
let user = opts == null ? void 0 : opts.user;
|
|
@@ -1594,7 +1593,7 @@ var init_filesystem = __esm({
|
|
|
1594
1593
|
const res = await this.envdApi.api.GET("/files", {
|
|
1595
1594
|
params: {
|
|
1596
1595
|
query: {
|
|
1597
|
-
path:
|
|
1596
|
+
path: path3,
|
|
1598
1597
|
username: user
|
|
1599
1598
|
}
|
|
1600
1599
|
},
|
|
@@ -1627,7 +1626,7 @@ var init_filesystem = __esm({
|
|
|
1627
1626
|
"Cannot specify both path and array of files. You have to specify either path and data for a single file or an array for multiple files."
|
|
1628
1627
|
);
|
|
1629
1628
|
}
|
|
1630
|
-
const { path:
|
|
1629
|
+
const { path: path3, writeOpts, writeFiles } = typeof pathOrFiles === "string" ? {
|
|
1631
1630
|
path: pathOrFiles,
|
|
1632
1631
|
writeOpts: opts,
|
|
1633
1632
|
writeFiles: [
|
|
@@ -1657,7 +1656,7 @@ var init_filesystem = __esm({
|
|
|
1657
1656
|
}
|
|
1658
1657
|
const uploadResults = await Promise.all(
|
|
1659
1658
|
writeFiles.map(async (file) => {
|
|
1660
|
-
const filePath =
|
|
1659
|
+
const filePath = path3 != null ? path3 : file.path;
|
|
1661
1660
|
const body = await toUploadBody(file.data, useGzip);
|
|
1662
1661
|
const res = await this.envdApi.api.POST("/files", {
|
|
1663
1662
|
params: {
|
|
@@ -1695,13 +1694,13 @@ var init_filesystem = __esm({
|
|
|
1695
1694
|
formData.append(
|
|
1696
1695
|
"file",
|
|
1697
1696
|
await toBlob(file.data),
|
|
1698
|
-
(_a3 = file.path) != null ? _a3 :
|
|
1697
|
+
(_a3 = file.path) != null ? _a3 : path3
|
|
1699
1698
|
);
|
|
1700
1699
|
}
|
|
1701
1700
|
const res = await this.envdApi.api.POST("/files", {
|
|
1702
1701
|
params: {
|
|
1703
1702
|
query: {
|
|
1704
|
-
path:
|
|
1703
|
+
path: path3,
|
|
1705
1704
|
username: user
|
|
1706
1705
|
}
|
|
1707
1706
|
},
|
|
@@ -1719,7 +1718,7 @@ var init_filesystem = __esm({
|
|
|
1719
1718
|
}
|
|
1720
1719
|
results.push(...files);
|
|
1721
1720
|
}
|
|
1722
|
-
return results.length === 1 &&
|
|
1721
|
+
return results.length === 1 && path3 ? results[0] : results;
|
|
1723
1722
|
}
|
|
1724
1723
|
/**
|
|
1725
1724
|
* Write multiple files.
|
|
@@ -1747,7 +1746,7 @@ var init_filesystem = __esm({
|
|
|
1747
1746
|
*
|
|
1748
1747
|
* @returns list of entries in the sandbox filesystem directory.
|
|
1749
1748
|
*/
|
|
1750
|
-
async list(
|
|
1749
|
+
async list(path3, opts) {
|
|
1751
1750
|
var _a3;
|
|
1752
1751
|
if (typeof (opts == null ? void 0 : opts.depth) === "number" && opts.depth < 1) {
|
|
1753
1752
|
throw new InvalidArgumentError("depth should be at least one");
|
|
@@ -1755,7 +1754,7 @@ var init_filesystem = __esm({
|
|
|
1755
1754
|
try {
|
|
1756
1755
|
const res = await this.rpc.listDir(
|
|
1757
1756
|
{
|
|
1758
|
-
path:
|
|
1757
|
+
path: path3,
|
|
1759
1758
|
depth: (_a3 = opts == null ? void 0 : opts.depth) != null ? _a3 : 1
|
|
1760
1759
|
},
|
|
1761
1760
|
{
|
|
@@ -1794,10 +1793,10 @@ var init_filesystem = __esm({
|
|
|
1794
1793
|
*
|
|
1795
1794
|
* @returns `true` if the directory was created, `false` if it already exists.
|
|
1796
1795
|
*/
|
|
1797
|
-
async makeDir(
|
|
1796
|
+
async makeDir(path3, opts) {
|
|
1798
1797
|
try {
|
|
1799
1798
|
await this.rpc.makeDir(
|
|
1800
|
-
{ path:
|
|
1799
|
+
{ path: path3 },
|
|
1801
1800
|
{
|
|
1802
1801
|
headers: authenticationHeader(this.envdApi.version, opts == null ? void 0 : opts.user),
|
|
1803
1802
|
signal: this.connectionConfig.getSignal(opts == null ? void 0 : opts.requestTimeoutMs)
|
|
@@ -1860,10 +1859,10 @@ var init_filesystem = __esm({
|
|
|
1860
1859
|
* @param path path to a file or directory.
|
|
1861
1860
|
* @param opts connection options.
|
|
1862
1861
|
*/
|
|
1863
|
-
async remove(
|
|
1862
|
+
async remove(path3, opts) {
|
|
1864
1863
|
try {
|
|
1865
1864
|
await this.rpc.remove(
|
|
1866
|
-
{ path:
|
|
1865
|
+
{ path: path3 },
|
|
1867
1866
|
{
|
|
1868
1867
|
headers: authenticationHeader(this.envdApi.version, opts == null ? void 0 : opts.user),
|
|
1869
1868
|
signal: this.connectionConfig.getSignal(opts == null ? void 0 : opts.requestTimeoutMs)
|
|
@@ -1881,10 +1880,10 @@ var init_filesystem = __esm({
|
|
|
1881
1880
|
*
|
|
1882
1881
|
* @returns `true` if the file or directory exists, `false` otherwise
|
|
1883
1882
|
*/
|
|
1884
|
-
async exists(
|
|
1883
|
+
async exists(path3, opts) {
|
|
1885
1884
|
try {
|
|
1886
1885
|
await this.rpc.stat(
|
|
1887
|
-
{ path:
|
|
1886
|
+
{ path: path3 },
|
|
1888
1887
|
{
|
|
1889
1888
|
headers: authenticationHeader(this.envdApi.version, opts == null ? void 0 : opts.user),
|
|
1890
1889
|
signal: this.connectionConfig.getSignal(opts == null ? void 0 : opts.requestTimeoutMs)
|
|
@@ -1908,10 +1907,10 @@ var init_filesystem = __esm({
|
|
|
1908
1907
|
*
|
|
1909
1908
|
* @returns information about the file or directory like name, type, and path.
|
|
1910
1909
|
*/
|
|
1911
|
-
async getInfo(
|
|
1910
|
+
async getInfo(path3, opts) {
|
|
1912
1911
|
try {
|
|
1913
1912
|
const res = await this.rpc.stat(
|
|
1914
|
-
{ path:
|
|
1913
|
+
{ path: path3 },
|
|
1915
1914
|
{
|
|
1916
1915
|
headers: authenticationHeader(this.envdApi.version, opts == null ? void 0 : opts.user),
|
|
1917
1916
|
signal: this.connectionConfig.getSignal(opts == null ? void 0 : opts.requestTimeoutMs)
|
|
@@ -1947,7 +1946,7 @@ var init_filesystem = __esm({
|
|
|
1947
1946
|
*
|
|
1948
1947
|
* @returns `WatchHandle` object for stopping watching directory.
|
|
1949
1948
|
*/
|
|
1950
|
-
async watchDir(
|
|
1949
|
+
async watchDir(path3, onEvent, opts) {
|
|
1951
1950
|
var _a3, _b, _c;
|
|
1952
1951
|
if ((opts == null ? void 0 : opts.recursive) && this.envdApi.version && (0, import_compare_versions3.compareVersions)(this.envdApi.version, ENVD_VERSION_RECURSIVE_WATCH) < 0) {
|
|
1953
1952
|
throw new TemplateError(
|
|
@@ -1961,7 +1960,7 @@ var init_filesystem = __esm({
|
|
|
1961
1960
|
}, requestTimeoutMs) : void 0;
|
|
1962
1961
|
const events = this.rpc.watchDir(
|
|
1963
1962
|
{
|
|
1964
|
-
path:
|
|
1963
|
+
path: path3,
|
|
1965
1964
|
recursive: (_b = opts == null ? void 0 : opts.recursive) != null ? _b : this.defaultWatchRecursive
|
|
1966
1965
|
},
|
|
1967
1966
|
{
|
|
@@ -2184,11 +2183,11 @@ function parseGitStatus(output) {
|
|
|
2184
2183
|
}
|
|
2185
2184
|
const indexStatus = line[0];
|
|
2186
2185
|
const workingTreeStatus = line[1];
|
|
2187
|
-
const
|
|
2186
|
+
const path3 = line.slice(3);
|
|
2188
2187
|
let renamedFrom;
|
|
2189
|
-
let name =
|
|
2190
|
-
if (
|
|
2191
|
-
const parts =
|
|
2188
|
+
let name = path3;
|
|
2189
|
+
if (path3.includes(" -> ")) {
|
|
2190
|
+
const parts = path3.split(" -> ");
|
|
2192
2191
|
renamedFrom = parts[0];
|
|
2193
2192
|
name = parts.slice(1).join(" -> ");
|
|
2194
2193
|
}
|
|
@@ -2297,16 +2296,16 @@ function buildUpstreamErrorMessage(action) {
|
|
|
2297
2296
|
}
|
|
2298
2297
|
return "Git pull failed because no upstream branch is configured. Pass remote and branch explicitly, or set upstream once (push with { setUpstream: true } or run: git branch --set-upstream-to=origin/<branch> <branch>).";
|
|
2299
2298
|
}
|
|
2300
|
-
function getRepoPathForScope(scope,
|
|
2299
|
+
function getRepoPathForScope(scope, path3) {
|
|
2301
2300
|
if (scope !== "local") {
|
|
2302
2301
|
return void 0;
|
|
2303
2302
|
}
|
|
2304
|
-
if (!
|
|
2303
|
+
if (!path3) {
|
|
2305
2304
|
throw new InvalidArgumentError(
|
|
2306
2305
|
'A repository path is required when using scope "local".'
|
|
2307
2306
|
);
|
|
2308
2307
|
}
|
|
2309
|
-
return
|
|
2308
|
+
return path3;
|
|
2310
2309
|
}
|
|
2311
2310
|
var init_utils2 = __esm({
|
|
2312
2311
|
"src/core/sandbox/git/utils.ts"() {
|
|
@@ -2343,7 +2342,7 @@ var init_git = __esm({
|
|
|
2343
2342
|
password,
|
|
2344
2343
|
branch,
|
|
2345
2344
|
depth,
|
|
2346
|
-
path:
|
|
2345
|
+
path: path3,
|
|
2347
2346
|
dangerouslyStoreCredentials
|
|
2348
2347
|
} = _a3, rest = __objRest(_a3, [
|
|
2349
2348
|
"username",
|
|
@@ -2362,7 +2361,7 @@ var init_git = __esm({
|
|
|
2362
2361
|
const urlWithCreds = authUsername && authPassword ? withCredentials(url, authUsername, authPassword) : url;
|
|
2363
2362
|
const sanitizedUrl = stripCredentials(urlWithCreds);
|
|
2364
2363
|
const stripInlineCreds = !dangerouslyStoreCredentials && sanitizedUrl !== urlWithCreds;
|
|
2365
|
-
const repoPath = stripInlineCreds ?
|
|
2364
|
+
const repoPath = stripInlineCreds ? path3 != null ? path3 : deriveRepoDirFromUrl(url) : path3;
|
|
2366
2365
|
if (stripInlineCreds && !repoPath) {
|
|
2367
2366
|
throw new InvalidArgumentError(
|
|
2368
2367
|
"A destination path is required when using credentials without storing them."
|
|
@@ -2400,7 +2399,7 @@ var init_git = __esm({
|
|
|
2400
2399
|
* @param opts Init options.
|
|
2401
2400
|
* @returns Command result from the command runner.
|
|
2402
2401
|
*/
|
|
2403
|
-
async init(
|
|
2402
|
+
async init(path3, opts) {
|
|
2404
2403
|
const _a3 = opts != null ? opts : {}, { bare, initialBranch } = _a3, rest = __objRest(_a3, ["bare", "initialBranch"]);
|
|
2405
2404
|
const args = ["init"];
|
|
2406
2405
|
if (initialBranch) {
|
|
@@ -2409,7 +2408,7 @@ var init_git = __esm({
|
|
|
2409
2408
|
if (bare) {
|
|
2410
2409
|
args.push("--bare");
|
|
2411
2410
|
}
|
|
2412
|
-
args.push(
|
|
2411
|
+
args.push(path3);
|
|
2413
2412
|
return this.runGit(args, void 0, rest);
|
|
2414
2413
|
}
|
|
2415
2414
|
/**
|
|
@@ -2421,7 +2420,7 @@ var init_git = __esm({
|
|
|
2421
2420
|
* @param opts Remote add options.
|
|
2422
2421
|
* @returns Command result from the command runner.
|
|
2423
2422
|
*/
|
|
2424
|
-
async remoteAdd(
|
|
2423
|
+
async remoteAdd(path3, name, url, opts) {
|
|
2425
2424
|
if (!name || !url) {
|
|
2426
2425
|
throw new InvalidArgumentError(
|
|
2427
2426
|
"Both remote name and URL are required to add a git remote."
|
|
@@ -2434,13 +2433,13 @@ var init_git = __esm({
|
|
|
2434
2433
|
}
|
|
2435
2434
|
addArgs.push(name, url);
|
|
2436
2435
|
if (!overwrite) {
|
|
2437
|
-
return this.runGit(addArgs,
|
|
2436
|
+
return this.runGit(addArgs, path3, rest);
|
|
2438
2437
|
}
|
|
2439
|
-
const addCmd = buildGitCommand(addArgs,
|
|
2440
|
-
const setUrlCmd = buildGitCommand(["remote", "set-url", name, url],
|
|
2438
|
+
const addCmd = buildGitCommand(addArgs, path3);
|
|
2439
|
+
const setUrlCmd = buildGitCommand(["remote", "set-url", name, url], path3);
|
|
2441
2440
|
let cmd = `${addCmd} || ${setUrlCmd}`;
|
|
2442
2441
|
if (fetch2) {
|
|
2443
|
-
const fetchCmd = buildGitCommand(["fetch", name],
|
|
2442
|
+
const fetchCmd = buildGitCommand(["fetch", name], path3);
|
|
2444
2443
|
cmd = `(${cmd}) && ${fetchCmd}`;
|
|
2445
2444
|
}
|
|
2446
2445
|
return this.runShell(cmd, rest);
|
|
@@ -2455,11 +2454,11 @@ var init_git = __esm({
|
|
|
2455
2454
|
* @param opts Command execution options.
|
|
2456
2455
|
* @returns Remote URL if present.
|
|
2457
2456
|
*/
|
|
2458
|
-
async remoteGet(
|
|
2457
|
+
async remoteGet(path3, name, opts) {
|
|
2459
2458
|
if (!name) {
|
|
2460
2459
|
throw new InvalidArgumentError("Remote name is required.");
|
|
2461
2460
|
}
|
|
2462
|
-
const cmd = `${buildGitCommand(["remote", "get-url", name],
|
|
2461
|
+
const cmd = `${buildGitCommand(["remote", "get-url", name], path3)} || true`;
|
|
2463
2462
|
const result = await this.runShell(cmd, opts);
|
|
2464
2463
|
const trimmed = result.stdout.trim();
|
|
2465
2464
|
return trimmed.length > 0 ? trimmed : void 0;
|
|
@@ -2471,10 +2470,10 @@ var init_git = __esm({
|
|
|
2471
2470
|
* @param opts Command execution options.
|
|
2472
2471
|
* @returns Parsed git status.
|
|
2473
2472
|
*/
|
|
2474
|
-
async status(
|
|
2473
|
+
async status(path3, opts) {
|
|
2475
2474
|
const result = await this.runGit(
|
|
2476
2475
|
["status", "--porcelain=1", "-b"],
|
|
2477
|
-
|
|
2476
|
+
path3,
|
|
2478
2477
|
opts
|
|
2479
2478
|
);
|
|
2480
2479
|
return parseGitStatus(result.stdout);
|
|
@@ -2486,10 +2485,10 @@ var init_git = __esm({
|
|
|
2486
2485
|
* @param opts Command execution options.
|
|
2487
2486
|
* @returns Parsed branch list.
|
|
2488
2487
|
*/
|
|
2489
|
-
async branches(
|
|
2488
|
+
async branches(path3, opts) {
|
|
2490
2489
|
const result = await this.runGit(
|
|
2491
2490
|
["branch", "--format=%(refname:short) %(HEAD)"],
|
|
2492
|
-
|
|
2491
|
+
path3,
|
|
2493
2492
|
opts
|
|
2494
2493
|
);
|
|
2495
2494
|
return parseGitBranches(result.stdout);
|
|
@@ -2502,8 +2501,8 @@ var init_git = __esm({
|
|
|
2502
2501
|
* @param opts Command execution options.
|
|
2503
2502
|
* @returns Command result from the command runner.
|
|
2504
2503
|
*/
|
|
2505
|
-
async createBranch(
|
|
2506
|
-
return this.runGit(["checkout", "-b", branch],
|
|
2504
|
+
async createBranch(path3, branch, opts) {
|
|
2505
|
+
return this.runGit(["checkout", "-b", branch], path3, opts);
|
|
2507
2506
|
}
|
|
2508
2507
|
/**
|
|
2509
2508
|
* Check out an existing branch.
|
|
@@ -2513,8 +2512,8 @@ var init_git = __esm({
|
|
|
2513
2512
|
* @param opts Command execution options.
|
|
2514
2513
|
* @returns Command result from the command runner.
|
|
2515
2514
|
*/
|
|
2516
|
-
async checkoutBranch(
|
|
2517
|
-
return this.runGit(["checkout", branch],
|
|
2515
|
+
async checkoutBranch(path3, branch, opts) {
|
|
2516
|
+
return this.runGit(["checkout", branch], path3, opts);
|
|
2518
2517
|
}
|
|
2519
2518
|
/**
|
|
2520
2519
|
* Delete a branch.
|
|
@@ -2524,10 +2523,10 @@ var init_git = __esm({
|
|
|
2524
2523
|
* @param opts Delete options.
|
|
2525
2524
|
* @returns Command result from the command runner.
|
|
2526
2525
|
*/
|
|
2527
|
-
async deleteBranch(
|
|
2526
|
+
async deleteBranch(path3, branch, opts) {
|
|
2528
2527
|
const _a3 = opts != null ? opts : {}, { force } = _a3, rest = __objRest(_a3, ["force"]);
|
|
2529
2528
|
const args = ["branch", force ? "-D" : "-d", branch];
|
|
2530
|
-
return this.runGit(args,
|
|
2529
|
+
return this.runGit(args, path3, rest);
|
|
2531
2530
|
}
|
|
2532
2531
|
/**
|
|
2533
2532
|
* Stage files for commit.
|
|
@@ -2536,7 +2535,7 @@ var init_git = __esm({
|
|
|
2536
2535
|
* @param opts Add options.
|
|
2537
2536
|
* @returns Command result from the command runner.
|
|
2538
2537
|
*/
|
|
2539
|
-
async add(
|
|
2538
|
+
async add(path3, opts) {
|
|
2540
2539
|
const _a3 = opts != null ? opts : {}, { files, all = true } = _a3, rest = __objRest(_a3, ["files", "all"]);
|
|
2541
2540
|
const args = ["add"];
|
|
2542
2541
|
if (!files || files.length === 0) {
|
|
@@ -2544,7 +2543,7 @@ var init_git = __esm({
|
|
|
2544
2543
|
} else {
|
|
2545
2544
|
args.push("--", ...files);
|
|
2546
2545
|
}
|
|
2547
|
-
return this.runGit(args,
|
|
2546
|
+
return this.runGit(args, path3, rest);
|
|
2548
2547
|
}
|
|
2549
2548
|
/**
|
|
2550
2549
|
* Create a commit in the repository.
|
|
@@ -2554,7 +2553,7 @@ var init_git = __esm({
|
|
|
2554
2553
|
* @param opts Commit options.
|
|
2555
2554
|
* @returns Command result from the command runner.
|
|
2556
2555
|
*/
|
|
2557
|
-
async commit(
|
|
2556
|
+
async commit(path3, message, opts) {
|
|
2558
2557
|
const _a3 = opts != null ? opts : {}, { authorName, authorEmail, allowEmpty } = _a3, rest = __objRest(_a3, ["authorName", "authorEmail", "allowEmpty"]);
|
|
2559
2558
|
const args = ["commit", "-m", message];
|
|
2560
2559
|
if (allowEmpty) {
|
|
@@ -2567,7 +2566,7 @@ var init_git = __esm({
|
|
|
2567
2566
|
if (authorEmail) {
|
|
2568
2567
|
authorArgs.push("-c", `user.email=${authorEmail}`);
|
|
2569
2568
|
}
|
|
2570
|
-
return this.runGit([...authorArgs, ...args],
|
|
2569
|
+
return this.runGit([...authorArgs, ...args], path3, rest);
|
|
2571
2570
|
}
|
|
2572
2571
|
/**
|
|
2573
2572
|
* Reset the current HEAD to a specified state.
|
|
@@ -2576,7 +2575,7 @@ var init_git = __esm({
|
|
|
2576
2575
|
* @param opts Reset options.
|
|
2577
2576
|
* @returns Command result from the command runner.
|
|
2578
2577
|
*/
|
|
2579
|
-
async reset(
|
|
2578
|
+
async reset(path3, opts) {
|
|
2580
2579
|
const _a3 = opts != null ? opts : {}, { mode, target, paths: paths2 } = _a3, rest = __objRest(_a3, ["mode", "target", "paths"]);
|
|
2581
2580
|
const allowedModes = [
|
|
2582
2581
|
"soft",
|
|
@@ -2600,7 +2599,7 @@ var init_git = __esm({
|
|
|
2600
2599
|
if (paths2 && paths2.length > 0) {
|
|
2601
2600
|
args.push("--", ...paths2);
|
|
2602
2601
|
}
|
|
2603
|
-
return this.runGit(args,
|
|
2602
|
+
return this.runGit(args, path3, rest);
|
|
2604
2603
|
}
|
|
2605
2604
|
/**
|
|
2606
2605
|
* Restore working tree files or unstage changes.
|
|
@@ -2609,7 +2608,7 @@ var init_git = __esm({
|
|
|
2609
2608
|
* @param opts Restore options.
|
|
2610
2609
|
* @returns Command result from the command runner.
|
|
2611
2610
|
*/
|
|
2612
|
-
async restore(
|
|
2611
|
+
async restore(path3, opts) {
|
|
2613
2612
|
const _a3 = opts, { paths: paths2, staged, worktree, source } = _a3, rest = __objRest(_a3, ["paths", "staged", "worktree", "source"]);
|
|
2614
2613
|
if (!paths2 || paths2.length === 0) {
|
|
2615
2614
|
throw new InvalidArgumentError("At least one path is required.");
|
|
@@ -2639,7 +2638,7 @@ var init_git = __esm({
|
|
|
2639
2638
|
args.push("--source", source);
|
|
2640
2639
|
}
|
|
2641
2640
|
args.push("--", ...paths2);
|
|
2642
|
-
return this.runGit(args,
|
|
2641
|
+
return this.runGit(args, path3, rest);
|
|
2643
2642
|
}
|
|
2644
2643
|
/**
|
|
2645
2644
|
* Push commits to a remote.
|
|
@@ -2648,7 +2647,7 @@ var init_git = __esm({
|
|
|
2648
2647
|
* @param opts Push options.
|
|
2649
2648
|
* @returns Command result from the command runner.
|
|
2650
2649
|
*/
|
|
2651
|
-
async push(
|
|
2650
|
+
async push(path3, opts) {
|
|
2652
2651
|
const _a3 = opts != null ? opts : {}, {
|
|
2653
2652
|
remote,
|
|
2654
2653
|
branch,
|
|
@@ -2668,16 +2667,16 @@ var init_git = __esm({
|
|
|
2668
2667
|
);
|
|
2669
2668
|
}
|
|
2670
2669
|
if (username && password) {
|
|
2671
|
-
const remoteName = await this.resolveRemoteName(
|
|
2670
|
+
const remoteName = await this.resolveRemoteName(path3, remote, rest);
|
|
2672
2671
|
return this.withRemoteCredentials(
|
|
2673
|
-
|
|
2672
|
+
path3,
|
|
2674
2673
|
remoteName,
|
|
2675
2674
|
username,
|
|
2676
2675
|
password,
|
|
2677
2676
|
rest,
|
|
2678
2677
|
() => this.runGit(
|
|
2679
2678
|
buildPushArgs(remoteName, { remote, branch, setUpstream }),
|
|
2680
|
-
|
|
2679
|
+
path3,
|
|
2681
2680
|
rest
|
|
2682
2681
|
)
|
|
2683
2682
|
);
|
|
@@ -2685,7 +2684,7 @@ var init_git = __esm({
|
|
|
2685
2684
|
try {
|
|
2686
2685
|
return await this.runGit(
|
|
2687
2686
|
buildPushArgs(void 0, { remote, branch, setUpstream }),
|
|
2688
|
-
|
|
2687
|
+
path3,
|
|
2689
2688
|
rest
|
|
2690
2689
|
);
|
|
2691
2690
|
} catch (err) {
|
|
@@ -2707,7 +2706,7 @@ var init_git = __esm({
|
|
|
2707
2706
|
* @param opts Pull options.
|
|
2708
2707
|
* @returns Command result from the command runner.
|
|
2709
2708
|
*/
|
|
2710
|
-
async pull(
|
|
2709
|
+
async pull(path3, opts) {
|
|
2711
2710
|
const _a3 = opts != null ? opts : {}, { remote, branch, username, password } = _a3, rest = __objRest(_a3, ["remote", "branch", "username", "password"]);
|
|
2712
2711
|
if (password && !username) {
|
|
2713
2712
|
throw new InvalidArgumentError(
|
|
@@ -2715,7 +2714,7 @@ var init_git = __esm({
|
|
|
2715
2714
|
);
|
|
2716
2715
|
}
|
|
2717
2716
|
if (!remote && !branch) {
|
|
2718
|
-
const hasUpstream = await this.hasUpstream(
|
|
2717
|
+
const hasUpstream = await this.hasUpstream(path3, rest);
|
|
2719
2718
|
if (!hasUpstream) {
|
|
2720
2719
|
throw new GitUpstreamError(buildUpstreamErrorMessage("pull"));
|
|
2721
2720
|
}
|
|
@@ -2732,18 +2731,18 @@ var init_git = __esm({
|
|
|
2732
2731
|
return args;
|
|
2733
2732
|
};
|
|
2734
2733
|
if (username && password) {
|
|
2735
|
-
const remoteName = await this.resolveRemoteName(
|
|
2734
|
+
const remoteName = await this.resolveRemoteName(path3, remote, rest);
|
|
2736
2735
|
return this.withRemoteCredentials(
|
|
2737
|
-
|
|
2736
|
+
path3,
|
|
2738
2737
|
remoteName,
|
|
2739
2738
|
username,
|
|
2740
2739
|
password,
|
|
2741
2740
|
rest,
|
|
2742
|
-
() => this.runGit(buildArgs(remoteName),
|
|
2741
|
+
() => this.runGit(buildArgs(remoteName), path3, rest)
|
|
2743
2742
|
);
|
|
2744
2743
|
}
|
|
2745
2744
|
try {
|
|
2746
|
-
return await this.runGit(buildArgs(),
|
|
2745
|
+
return await this.runGit(buildArgs(), path3, rest);
|
|
2747
2746
|
} catch (err) {
|
|
2748
2747
|
if (isAuthFailure(err)) {
|
|
2749
2748
|
throw new GitAuthError(
|
|
@@ -2880,8 +2879,8 @@ var init_git = __esm({
|
|
|
2880
2879
|
envs: mergedEnvs
|
|
2881
2880
|
}));
|
|
2882
2881
|
}
|
|
2883
|
-
async getRemoteUrl(
|
|
2884
|
-
const result = await this.runGit(["remote", "get-url", remote],
|
|
2882
|
+
async getRemoteUrl(path3, remote, opts) {
|
|
2883
|
+
const result = await this.runGit(["remote", "get-url", remote], path3, opts);
|
|
2885
2884
|
const url = result.stdout.trim();
|
|
2886
2885
|
if (!url) {
|
|
2887
2886
|
throw new InvalidArgumentError(
|
|
@@ -2890,11 +2889,11 @@ var init_git = __esm({
|
|
|
2890
2889
|
}
|
|
2891
2890
|
return url;
|
|
2892
2891
|
}
|
|
2893
|
-
async resolveRemoteName(
|
|
2892
|
+
async resolveRemoteName(path3, remote, opts) {
|
|
2894
2893
|
if (remote) {
|
|
2895
2894
|
return remote;
|
|
2896
2895
|
}
|
|
2897
|
-
const result = await this.runGit(["remote"],
|
|
2896
|
+
const result = await this.runGit(["remote"], path3, opts);
|
|
2898
2897
|
const remotes = result.stdout.split("\n").map((line) => line.trim()).filter(Boolean);
|
|
2899
2898
|
if (remotes.length === 1) {
|
|
2900
2899
|
return remotes[0];
|
|
@@ -2903,10 +2902,10 @@ var init_git = __esm({
|
|
|
2903
2902
|
"Remote is required when using username/password and the repository has multiple remotes."
|
|
2904
2903
|
);
|
|
2905
2904
|
}
|
|
2906
|
-
async withRemoteCredentials(
|
|
2907
|
-
const originalUrl = await this.getRemoteUrl(
|
|
2905
|
+
async withRemoteCredentials(path3, remote, username, password, opts, operation) {
|
|
2906
|
+
const originalUrl = await this.getRemoteUrl(path3, remote, opts);
|
|
2908
2907
|
const credentialUrl = withCredentials(originalUrl, username, password);
|
|
2909
|
-
await this.runGit(["remote", "set-url", remote, credentialUrl],
|
|
2908
|
+
await this.runGit(["remote", "set-url", remote, credentialUrl], path3, opts);
|
|
2910
2909
|
let result;
|
|
2911
2910
|
let operationError;
|
|
2912
2911
|
try {
|
|
@@ -2916,7 +2915,7 @@ var init_git = __esm({
|
|
|
2916
2915
|
}
|
|
2917
2916
|
let restoreError;
|
|
2918
2917
|
try {
|
|
2919
|
-
await this.runGit(["remote", "set-url", remote, originalUrl],
|
|
2918
|
+
await this.runGit(["remote", "set-url", remote, originalUrl], path3, opts);
|
|
2920
2919
|
} catch (err) {
|
|
2921
2920
|
restoreError = err;
|
|
2922
2921
|
}
|
|
@@ -2928,11 +2927,11 @@ var init_git = __esm({
|
|
|
2928
2927
|
}
|
|
2929
2928
|
return result;
|
|
2930
2929
|
}
|
|
2931
|
-
async hasUpstream(
|
|
2930
|
+
async hasUpstream(path3, opts) {
|
|
2932
2931
|
try {
|
|
2933
2932
|
const result = await this.runGit(
|
|
2934
2933
|
["rev-parse", "--abbrev-ref", "--symbolic-full-name", "@{u}"],
|
|
2935
|
-
|
|
2934
|
+
path3,
|
|
2936
2935
|
opts
|
|
2937
2936
|
);
|
|
2938
2937
|
return result.stdout.trim().length > 0;
|
|
@@ -3015,11 +3014,11 @@ function normalizeSecretHosts(hosts) {
|
|
|
3015
3014
|
}
|
|
3016
3015
|
return normalizedHosts;
|
|
3017
3016
|
}
|
|
3018
|
-
async function request(method,
|
|
3017
|
+
async function request(method, path3, feature, opts, body) {
|
|
3019
3018
|
const config = new ConnectionConfig(opts);
|
|
3020
3019
|
raiseIfLegacy(config, feature, SecretError);
|
|
3021
3020
|
const headers = __spreadValues(__spreadValues(__spreadValues(__spreadValues({}, config.headers), body ? { "Content-Type": "application/json" } : {}), config.apiKey ? { "X-API-KEY": config.apiKey } : {}), config.accessToken ? { Authorization: `Bearer ${config.accessToken}` } : {});
|
|
3022
|
-
const response = await fetch(`${config.apiUrl}${
|
|
3021
|
+
const response = await fetch(`${config.apiUrl}${path3}`, {
|
|
3023
3022
|
method,
|
|
3024
3023
|
headers,
|
|
3025
3024
|
body: body ? JSON.stringify(body) : void 0,
|
|
@@ -3437,7 +3436,7 @@ var init_sandboxApi = __esm({
|
|
|
3437
3436
|
}
|
|
3438
3437
|
return true;
|
|
3439
3438
|
}
|
|
3440
|
-
static async mountVolume(sandboxId, name,
|
|
3439
|
+
static async mountVolume(sandboxId, name, path3, opts) {
|
|
3441
3440
|
var _a3, _b;
|
|
3442
3441
|
const config = new ConnectionConfig(opts);
|
|
3443
3442
|
raiseIfLegacy(config, "Sandbox.mountVolume", SandboxError);
|
|
@@ -3448,7 +3447,7 @@ var init_sandboxApi = __esm({
|
|
|
3448
3447
|
headers: getRawApiHeaders(config, {
|
|
3449
3448
|
"Content-Type": "application/json"
|
|
3450
3449
|
}),
|
|
3451
|
-
body: JSON.stringify({ name, path:
|
|
3450
|
+
body: JSON.stringify({ name, path: path3 }),
|
|
3452
3451
|
signal: config.getSignal(opts == null ? void 0 : opts.requestTimeoutMs)
|
|
3453
3452
|
}
|
|
3454
3453
|
);
|
|
@@ -3473,14 +3472,14 @@ var init_sandboxApi = __esm({
|
|
|
3473
3472
|
volumeMounts: (_b = data.volumeMounts) != null ? _b : []
|
|
3474
3473
|
};
|
|
3475
3474
|
}
|
|
3476
|
-
static async unmountVolume(sandboxId,
|
|
3475
|
+
static async unmountVolume(sandboxId, path3, opts) {
|
|
3477
3476
|
var _a3, _b;
|
|
3478
3477
|
const config = new ConnectionConfig(opts);
|
|
3479
3478
|
raiseIfLegacy(config, "Sandbox.unmountVolume", SandboxError);
|
|
3480
3479
|
const url = new URL(
|
|
3481
3480
|
`${config.apiUrl}/sandboxes/${encodeURIComponent(sandboxId)}/volume-mounts`
|
|
3482
3481
|
);
|
|
3483
|
-
url.searchParams.set("path",
|
|
3482
|
+
url.searchParams.set("path", path3);
|
|
3484
3483
|
if (opts == null ? void 0 : opts.force) {
|
|
3485
3484
|
url.searchParams.set("force", "true");
|
|
3486
3485
|
}
|
|
@@ -3774,17 +3773,25 @@ var init_sandboxApi = __esm({
|
|
|
3774
3773
|
return true;
|
|
3775
3774
|
}
|
|
3776
3775
|
static async createSandbox(template, timeoutMs, opts) {
|
|
3777
|
-
var _a3, _b, _c, _d, _e, _f;
|
|
3776
|
+
var _a3, _b, _c, _d, _e, _f, _g;
|
|
3778
3777
|
const config = new ConnectionConfig(opts);
|
|
3778
|
+
const longRunning = ((_a3 = opts == null ? void 0 : opts.metadata) == null ? void 0 : _a3.long_running) === "true";
|
|
3779
|
+
const metadata = longRunning ? __spreadValues({}, opts == null ? void 0 : opts.metadata) : opts == null ? void 0 : opts.metadata;
|
|
3780
|
+
const timeout = longRunning ? void 0 : timeoutToSeconds(timeoutMs);
|
|
3779
3781
|
const lifecycle = getLifecycle(opts);
|
|
3780
3782
|
const autoPause = lifecycle.onTimeout === "pause";
|
|
3781
|
-
const autoResumeEnabled = lifecycle.onTimeout === "pause" ? (
|
|
3783
|
+
const autoResumeEnabled = lifecycle.onTimeout === "pause" ? (_b = lifecycle.autoResume) != null ? _b : false : void 0;
|
|
3782
3784
|
if (config.isLegacyDomain) {
|
|
3783
3785
|
if (opts == null ? void 0 : opts.mcp) {
|
|
3784
3786
|
raiseIfLegacy(config, "Sandbox.create mcp", SandboxError);
|
|
3785
3787
|
}
|
|
3786
|
-
|
|
3787
|
-
|
|
3788
|
+
const unsupportedNetworkOptions = Object.keys((_c = opts == null ? void 0 : opts.network) != null ? _c : {}).filter(
|
|
3789
|
+
(key) => key !== "allowPublicTraffic"
|
|
3790
|
+
);
|
|
3791
|
+
if (unsupportedNetworkOptions.length > 0) {
|
|
3792
|
+
throw new SandboxError(
|
|
3793
|
+
`Sandbox.create network only supports allowPublicTraffic on legacy domains; unsupported options: ${unsupportedNetworkOptions.join(", ")}`
|
|
3794
|
+
);
|
|
3788
3795
|
}
|
|
3789
3796
|
if (opts == null ? void 0 : opts.volumeMounts) {
|
|
3790
3797
|
raiseIfLegacy(config, "Sandbox.create volumeMounts", SandboxError);
|
|
@@ -3792,14 +3799,14 @@ var init_sandboxApi = __esm({
|
|
|
3792
3799
|
if (opts == null ? void 0 : opts.secretEnvs) {
|
|
3793
3800
|
raiseIfLegacy(config, "Sandbox.create secretEnvs", SandboxError);
|
|
3794
3801
|
}
|
|
3795
|
-
const body2 = __spreadValues({
|
|
3802
|
+
const body2 = __spreadValues(__spreadValues({
|
|
3796
3803
|
templateID: template,
|
|
3797
|
-
timeout
|
|
3798
|
-
metadata:
|
|
3799
|
-
envVars: (
|
|
3800
|
-
secure: (
|
|
3804
|
+
timeout,
|
|
3805
|
+
metadata: metadata != null ? metadata : {},
|
|
3806
|
+
envVars: (_d = opts == null ? void 0 : opts.envs) != null ? _d : {},
|
|
3807
|
+
secure: (_e = opts == null ? void 0 : opts.secure) != null ? _e : false,
|
|
3801
3808
|
autoPause: autoPause != null ? autoPause : false
|
|
3802
|
-
}, (opts == null ? void 0 : opts.nodeId) ? { nodeID: opts.nodeId } : {});
|
|
3809
|
+
}, (opts == null ? void 0 : opts.network) ? { network: opts.network } : {}), (opts == null ? void 0 : opts.nodeId) ? { nodeID: opts.nodeId } : {});
|
|
3803
3810
|
const response = await fetch(`${config.apiUrl}/sandboxes`, {
|
|
3804
3811
|
method: "POST",
|
|
3805
3812
|
headers: getRawApiHeaders(config, {
|
|
@@ -3823,18 +3830,18 @@ var init_sandboxApi = __esm({
|
|
|
3823
3830
|
sandboxDomain: data.domain || void 0,
|
|
3824
3831
|
envdVersion: data.envdVersion,
|
|
3825
3832
|
envdAccessToken: data.envdAccessToken,
|
|
3826
|
-
trafficAccessToken: void 0
|
|
3833
|
+
trafficAccessToken: data.trafficAccessToken || void 0
|
|
3827
3834
|
};
|
|
3828
3835
|
}
|
|
3829
3836
|
const client = new ApiClient(config);
|
|
3830
3837
|
const body = __spreadValues(__spreadValues(__spreadValues({
|
|
3831
3838
|
templateID: template,
|
|
3832
|
-
metadata
|
|
3839
|
+
metadata,
|
|
3833
3840
|
mcp: opts == null ? void 0 : opts.mcp,
|
|
3834
3841
|
envVars: opts == null ? void 0 : opts.envs,
|
|
3835
|
-
timeout
|
|
3836
|
-
secure: (
|
|
3837
|
-
allow_internet_access: (
|
|
3842
|
+
timeout,
|
|
3843
|
+
secure: (_f = opts == null ? void 0 : opts.secure) != null ? _f : true,
|
|
3844
|
+
allow_internet_access: (_g = opts == null ? void 0 : opts.allowInternetAccess) != null ? _g : true,
|
|
3838
3845
|
network: opts == null ? void 0 : opts.network
|
|
3839
3846
|
}, (opts == null ? void 0 : opts.nodeId) ? { nodeID: opts.nodeId } : {}), autoPause !== void 0 ? { autoPause } : {}), autoResumeEnabled !== void 0 ? { autoResume: { enabled: autoResumeEnabled } } : {});
|
|
3840
3847
|
if (opts == null ? void 0 : opts.volumeMounts) {
|
|
@@ -3887,7 +3894,9 @@ var init_sandboxApi = __esm({
|
|
|
3887
3894
|
headers: getRawApiHeaders(config, {
|
|
3888
3895
|
"Content-Type": "application/json"
|
|
3889
3896
|
}),
|
|
3890
|
-
body: JSON.stringify({
|
|
3897
|
+
body: JSON.stringify(__spreadValues(__spreadValues(__spreadValues({
|
|
3898
|
+
timeout: timeoutToSeconds(timeoutMs)
|
|
3899
|
+
}, (opts == null ? void 0 : opts.secure) !== void 0 ? { secure: opts.secure } : {}), (opts == null ? void 0 : opts.allowPublicTraffic) !== void 0 ? { allowPublicTraffic: opts.allowPublicTraffic } : {}), (opts == null ? void 0 : opts.network) ? { network: opts.network } : {})),
|
|
3891
3900
|
signal: config.getSignal(opts == null ? void 0 : opts.requestTimeoutMs)
|
|
3892
3901
|
}
|
|
3893
3902
|
);
|
|
@@ -3903,7 +3912,7 @@ var init_sandboxApi = __esm({
|
|
|
3903
3912
|
sandboxDomain: data.domain || void 0,
|
|
3904
3913
|
envdVersion: data.envdVersion || "0.0.0",
|
|
3905
3914
|
envdAccessToken: data.envdAccessToken,
|
|
3906
|
-
trafficAccessToken: void 0
|
|
3915
|
+
trafficAccessToken: data.trafficAccessToken || void 0
|
|
3907
3916
|
};
|
|
3908
3917
|
}
|
|
3909
3918
|
const client = new ApiClient(config);
|
|
@@ -4162,7 +4171,7 @@ var init_sandboxApi = __esm({
|
|
|
4162
4171
|
|
|
4163
4172
|
// src/core/sandbox/signature.ts
|
|
4164
4173
|
async function getSignature({
|
|
4165
|
-
path:
|
|
4174
|
+
path: path3,
|
|
4166
4175
|
operation,
|
|
4167
4176
|
user,
|
|
4168
4177
|
expirationInSeconds,
|
|
@@ -4179,9 +4188,9 @@ async function getSignature({
|
|
|
4179
4188
|
user = "";
|
|
4180
4189
|
}
|
|
4181
4190
|
if (signatureExpiration === null) {
|
|
4182
|
-
signatureRaw = `${
|
|
4191
|
+
signatureRaw = `${path3}:${operation}:${user}:${envdAccessToken}`;
|
|
4183
4192
|
} else {
|
|
4184
|
-
signatureRaw = `${
|
|
4193
|
+
signatureRaw = `${path3}:${operation}:${user}:${envdAccessToken}:${signatureExpiration.toString()}`;
|
|
4185
4194
|
}
|
|
4186
4195
|
const hashBase64 = await sha256(signatureRaw);
|
|
4187
4196
|
const signature = "v1_" + hashBase64.replace(/=+$/, "");
|
|
@@ -4387,8 +4396,8 @@ var init_sandbox = __esm({
|
|
|
4387
4396
|
*
|
|
4388
4397
|
* @returns updated sandbox information.
|
|
4389
4398
|
*/
|
|
4390
|
-
static async mountVolume(sandboxId, name,
|
|
4391
|
-
return await SandboxApi.mountVolume(sandboxId, name,
|
|
4399
|
+
static async mountVolume(sandboxId, name, path3, opts) {
|
|
4400
|
+
return await SandboxApi.mountVolume(sandboxId, name, path3, opts);
|
|
4392
4401
|
}
|
|
4393
4402
|
/**
|
|
4394
4403
|
* Unmount a volume from a sandbox.
|
|
@@ -4400,8 +4409,8 @@ var init_sandbox = __esm({
|
|
|
4400
4409
|
*
|
|
4401
4410
|
* @returns updated sandbox information.
|
|
4402
4411
|
*/
|
|
4403
|
-
static async unmountVolume(sandboxId,
|
|
4404
|
-
return await SandboxApi.unmountVolume(sandboxId,
|
|
4412
|
+
static async unmountVolume(sandboxId, path3, opts) {
|
|
4413
|
+
return await SandboxApi.unmountVolume(sandboxId, path3, opts);
|
|
4405
4414
|
}
|
|
4406
4415
|
/**
|
|
4407
4416
|
* Commit a sandbox to create a snapshot template.
|
|
@@ -4636,11 +4645,11 @@ var init_sandbox = __esm({
|
|
|
4636
4645
|
*
|
|
4637
4646
|
* @returns updated sandbox information.
|
|
4638
4647
|
*/
|
|
4639
|
-
async mountVolume(name,
|
|
4648
|
+
async mountVolume(name, path3, opts) {
|
|
4640
4649
|
return await SandboxApi.mountVolume(
|
|
4641
4650
|
this.sandboxId,
|
|
4642
4651
|
name,
|
|
4643
|
-
|
|
4652
|
+
path3,
|
|
4644
4653
|
this.resolveApiOpts(opts)
|
|
4645
4654
|
);
|
|
4646
4655
|
}
|
|
@@ -4653,10 +4662,10 @@ var init_sandbox = __esm({
|
|
|
4653
4662
|
*
|
|
4654
4663
|
* @returns updated sandbox information.
|
|
4655
4664
|
*/
|
|
4656
|
-
async unmountVolume(
|
|
4665
|
+
async unmountVolume(path3, opts) {
|
|
4657
4666
|
return await SandboxApi.unmountVolume(
|
|
4658
4667
|
this.sandboxId,
|
|
4659
|
-
|
|
4668
|
+
path3,
|
|
4660
4669
|
this.resolveApiOpts(opts)
|
|
4661
4670
|
);
|
|
4662
4671
|
}
|
|
@@ -4790,7 +4799,7 @@ var init_sandbox = __esm({
|
|
|
4790
4799
|
*
|
|
4791
4800
|
* @returns URL for uploading file.
|
|
4792
4801
|
*/
|
|
4793
|
-
async uploadUrl(
|
|
4802
|
+
async uploadUrl(path3, opts) {
|
|
4794
4803
|
opts = opts != null ? opts : {};
|
|
4795
4804
|
const useSignature = !!this.envdAccessToken;
|
|
4796
4805
|
if (!useSignature && opts.useSignatureExpiration != void 0) {
|
|
@@ -4802,7 +4811,7 @@ var init_sandbox = __esm({
|
|
|
4802
4811
|
if (username == void 0 && (0, import_compare_versions5.compareVersions)(this.envdApi.version, ENVD_DEFAULT_USER) < 0) {
|
|
4803
4812
|
username = defaultUsername;
|
|
4804
4813
|
}
|
|
4805
|
-
const filePath =
|
|
4814
|
+
const filePath = path3 != null ? path3 : "";
|
|
4806
4815
|
const fileUrl = this.fileUrl(filePath, username);
|
|
4807
4816
|
if (useSignature) {
|
|
4808
4817
|
const url = new URL(fileUrl);
|
|
@@ -4830,7 +4839,7 @@ var init_sandbox = __esm({
|
|
|
4830
4839
|
*
|
|
4831
4840
|
* @returns URL for downloading file.
|
|
4832
4841
|
*/
|
|
4833
|
-
async downloadUrl(
|
|
4842
|
+
async downloadUrl(path3, opts) {
|
|
4834
4843
|
opts = opts != null ? opts : {};
|
|
4835
4844
|
const useSignature = !!this.envdAccessToken;
|
|
4836
4845
|
if (!useSignature && opts.useSignatureExpiration != void 0) {
|
|
@@ -4842,11 +4851,11 @@ var init_sandbox = __esm({
|
|
|
4842
4851
|
if (username == void 0 && (0, import_compare_versions5.compareVersions)(this.envdApi.version, ENVD_DEFAULT_USER) < 0) {
|
|
4843
4852
|
username = defaultUsername;
|
|
4844
4853
|
}
|
|
4845
|
-
const fileUrl = this.fileUrl(
|
|
4854
|
+
const fileUrl = this.fileUrl(path3, username);
|
|
4846
4855
|
if (useSignature) {
|
|
4847
4856
|
const url = new URL(fileUrl);
|
|
4848
4857
|
const sig = await getSignature({
|
|
4849
|
-
path:
|
|
4858
|
+
path: path3,
|
|
4850
4859
|
operation: "read",
|
|
4851
4860
|
user: username,
|
|
4852
4861
|
expirationInSeconds: opts.useSignatureExpiration,
|
|
@@ -4900,13 +4909,13 @@ var init_sandbox = __esm({
|
|
|
4900
4909
|
resolveApiOpts(opts) {
|
|
4901
4910
|
return __spreadValues(__spreadValues({}, this.connectionConfig), opts != null ? opts : {});
|
|
4902
4911
|
}
|
|
4903
|
-
fileUrl(
|
|
4912
|
+
fileUrl(path3, username) {
|
|
4904
4913
|
const url = new URL("/files", this.envdApiUrl);
|
|
4905
4914
|
if (username) {
|
|
4906
4915
|
url.searchParams.set("username", username);
|
|
4907
4916
|
}
|
|
4908
|
-
if (
|
|
4909
|
-
url.searchParams.set("path",
|
|
4917
|
+
if (path3) {
|
|
4918
|
+
url.searchParams.set("path", path3);
|
|
4910
4919
|
}
|
|
4911
4920
|
return url.toString();
|
|
4912
4921
|
}
|
|
@@ -5097,8 +5106,8 @@ function readDockerignore(contextPath) {
|
|
|
5097
5106
|
const content = import_node_fs.default.readFileSync(dockerignorePath, "utf-8");
|
|
5098
5107
|
return content.split("\n").map((line) => line.trim()).filter((line) => line && !line.startsWith("#"));
|
|
5099
5108
|
}
|
|
5100
|
-
function normalizePath(
|
|
5101
|
-
return
|
|
5109
|
+
function normalizePath(path3) {
|
|
5110
|
+
return path3.replace(/\\/g, "/");
|
|
5102
5111
|
}
|
|
5103
5112
|
async function getAllFilesInPath(src, contextPath, ignorePatterns, includeDirectories = true) {
|
|
5104
5113
|
const { glob } = await dynamicImport("glob");
|
|
@@ -5210,8 +5219,7 @@ function getCallerDirectory(depth) {
|
|
|
5210
5219
|
return void 0;
|
|
5211
5220
|
}
|
|
5212
5221
|
if (fileName.startsWith("file:")) {
|
|
5213
|
-
|
|
5214
|
-
fileName = fileURLToPath(fileName);
|
|
5222
|
+
fileName = (0, import_node_url.fileURLToPath)(fileName);
|
|
5215
5223
|
}
|
|
5216
5224
|
return import_node_path.default.dirname(fileName);
|
|
5217
5225
|
}
|
|
@@ -5260,13 +5268,14 @@ function readGCPServiceAccountJSON(contextPath, pathOrContent) {
|
|
|
5260
5268
|
}
|
|
5261
5269
|
return JSON.stringify(pathOrContent);
|
|
5262
5270
|
}
|
|
5263
|
-
var import_node_crypto, import_node_fs, import_node_path;
|
|
5271
|
+
var import_node_crypto, import_node_fs, import_node_path, import_node_url;
|
|
5264
5272
|
var init_utils3 = __esm({
|
|
5265
5273
|
"src/core/template/utils.ts"() {
|
|
5266
5274
|
"use strict";
|
|
5267
5275
|
import_node_crypto = __toESM(require("crypto"));
|
|
5268
5276
|
import_node_fs = __toESM(require("fs"));
|
|
5269
5277
|
import_node_path = __toESM(require("path"));
|
|
5278
|
+
import_node_url = require("url");
|
|
5270
5279
|
init_utils();
|
|
5271
5280
|
init_errors();
|
|
5272
5281
|
init_consts();
|
|
@@ -5693,54 +5702,15 @@ function handleUserInstruction(instruction, templateBuilder) {
|
|
|
5693
5702
|
}
|
|
5694
5703
|
}
|
|
5695
5704
|
function handleEnvInstruction(instruction, templateBuilder) {
|
|
5696
|
-
|
|
5697
|
-
const
|
|
5698
|
-
|
|
5699
|
-
|
|
5700
|
-
|
|
5701
|
-
|
|
5702
|
-
|
|
5703
|
-
|
|
5704
|
-
|
|
5705
|
-
const envString = arg.getValue();
|
|
5706
|
-
const equalIndex = envString.indexOf("=");
|
|
5707
|
-
if (equalIndex > 0) {
|
|
5708
|
-
const key = envString.substring(0, equalIndex);
|
|
5709
|
-
const value = envString.substring(equalIndex + 1);
|
|
5710
|
-
envVars[key] = value;
|
|
5711
|
-
}
|
|
5712
|
-
}
|
|
5713
|
-
} else {
|
|
5714
|
-
envVars[firstArg] = secondArg;
|
|
5715
|
-
}
|
|
5716
|
-
} else if (argumentsData.length === 1) {
|
|
5717
|
-
const envString = argumentsData[0].getValue();
|
|
5718
|
-
const equalIndex = envString.indexOf("=");
|
|
5719
|
-
if (equalIndex > 0) {
|
|
5720
|
-
const key = envString.substring(0, equalIndex);
|
|
5721
|
-
const value = envString.substring(equalIndex + 1);
|
|
5722
|
-
envVars[key] = value;
|
|
5723
|
-
} else if (keyword === "ARG" && envString.trim()) {
|
|
5724
|
-
const key = envString.trim();
|
|
5725
|
-
envVars[key] = "";
|
|
5726
|
-
}
|
|
5727
|
-
} else {
|
|
5728
|
-
for (const arg of argumentsData) {
|
|
5729
|
-
const envString = arg.getValue();
|
|
5730
|
-
const equalIndex = envString.indexOf("=");
|
|
5731
|
-
if (equalIndex > 0) {
|
|
5732
|
-
const key = envString.substring(0, equalIndex);
|
|
5733
|
-
const value = envString.substring(equalIndex + 1);
|
|
5734
|
-
envVars[key] = value;
|
|
5735
|
-
} else if (keyword === "ARG") {
|
|
5736
|
-
const key = envString;
|
|
5737
|
-
envVars[key] = "";
|
|
5738
|
-
}
|
|
5739
|
-
}
|
|
5740
|
-
}
|
|
5741
|
-
if (Object.keys(envVars).length > 0) {
|
|
5742
|
-
templateBuilder.setEnvs(envVars);
|
|
5743
|
-
}
|
|
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
|
+
});
|
|
5744
5714
|
}
|
|
5745
5715
|
}
|
|
5746
5716
|
function handleCmdEntrypointInstruction(instruction, templateBuilder) {
|
|
@@ -5787,61 +5757,120 @@ function expandableDoubleQuote(value) {
|
|
|
5787
5757
|
const escaped = value.split("\\").join("\\\\").split('"').join('\\"').split("`").join("\\`").replace(/\$\(/g, "\\$(");
|
|
5788
5758
|
return `"${escaped}"`;
|
|
5789
5759
|
}
|
|
5790
|
-
function envFilesScript(envs) {
|
|
5791
|
-
const
|
|
5792
|
-
|
|
5793
|
-
|
|
5794
|
-
|
|
5795
|
-
|
|
5796
|
-
|
|
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) {
|
|
5797
5791
|
lines.push(
|
|
5798
|
-
|
|
5799
|
-
`v=${expandableDoubleQuote(declared)}`,
|
|
5800
|
-
// Export it before moving on, so a later value can reference this one --
|
|
5801
|
-
// `ENV VIRTUAL_ENV=/opt/venv PYTHONPATH=$VIRTUAL_ENV/lib` is ordinary, and
|
|
5802
|
-
// the platform's own ENV handling cannot be relied on for it (it ignores
|
|
5803
|
-
// PATH entirely). Without this the reference expanded to empty.
|
|
5804
|
-
`export ${name}="$v"`,
|
|
5805
|
-
// profile.d: single-quoted, with any embedded quote closed and reopened.
|
|
5806
|
-
`printf "export ${name}='%s'\\n" "$(printf '%s' "$v" | sed "s/'/'\\\\\\\\''/g")" >> ${PROFILE_PATH}`,
|
|
5807
|
-
// pam_env: bare, and only when it can represent the value at all.
|
|
5808
|
-
'case "$v" in',
|
|
5809
|
-
` *'"'*) v= ;;`,
|
|
5810
|
-
"esac",
|
|
5811
|
-
`[ -n "$v" ] && [ "$(printf '%s' "$v" | wc -l)" -eq 0 ] && printf '${name}=%s\\n' "$v" >> ${ENVIRONMENT_PATH}`,
|
|
5812
|
-
// `[ ... ] &&` above exits non-zero when the value is skipped, which would
|
|
5813
|
-
// abort the script under `set -e`.
|
|
5814
|
-
"true"
|
|
5792
|
+
"__ppio_runtime_env " + Object.entries(literalEnvs).map(([name, value]) => `${name} ${quote(value)}`).join(" ")
|
|
5815
5793
|
);
|
|
5816
5794
|
}
|
|
5817
|
-
|
|
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";
|
|
5798
|
+
lines.push(
|
|
5799
|
+
fn + " " + Object.entries(group.values).map(([name, value]) => `${name} ${expandableDoubleQuote(value)}`).join(" ")
|
|
5800
|
+
);
|
|
5801
|
+
}
|
|
5802
|
+
lines.push(`command -p chmod 0644 ${PROFILE_PATH} ${ENVIRONMENT_PATH}`);
|
|
5818
5803
|
return lines.join("\n");
|
|
5819
5804
|
}
|
|
5820
|
-
function envFilesCommand(envs) {
|
|
5821
|
-
const
|
|
5822
|
-
|
|
5823
|
-
|
|
5824
|
-
}
|
|
5825
|
-
const
|
|
5826
|
-
|
|
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))
|
|
5827
5820
|
);
|
|
5828
|
-
const
|
|
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");
|
|
5829
5832
|
return {
|
|
5830
5833
|
command: [
|
|
5831
|
-
`echo ${b64} | base64 -d > ${SCRIPT_PATH}`,
|
|
5832
|
-
`sh ${SCRIPT_PATH}`,
|
|
5833
|
-
`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}`
|
|
5834
5837
|
].join(" && "),
|
|
5835
5838
|
skipped
|
|
5836
5839
|
};
|
|
5837
5840
|
}
|
|
5838
|
-
|
|
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;
|
|
5839
5867
|
var init_envFiles = __esm({
|
|
5840
5868
|
"src/core/template/envFiles.ts"() {
|
|
5841
5869
|
"use strict";
|
|
5842
5870
|
PROFILE_PATH = "/etc/profile.d/99-image-env.sh";
|
|
5843
5871
|
ENVIRONMENT_PATH = "/etc/environment";
|
|
5844
5872
|
SCRIPT_PATH = "/tmp/.ppio-image-env.sh";
|
|
5873
|
+
BASE_ENV_PATH = "/etc/.ppio-image-env-base.sh";
|
|
5845
5874
|
}
|
|
5846
5875
|
});
|
|
5847
5876
|
|
|
@@ -5858,9 +5887,15 @@ function unsupportedBase(blob) {
|
|
|
5858
5887
|
return null;
|
|
5859
5888
|
}
|
|
5860
5889
|
const families = [
|
|
5861
|
-
[
|
|
5890
|
+
[
|
|
5891
|
+
/alpine-minirootfs|etc\/alpine-release|apk add|apk --no-cache/i,
|
|
5892
|
+
"Alpine (musl)"
|
|
5893
|
+
],
|
|
5862
5894
|
[/^BusyBox /im, "BusyBox"],
|
|
5863
|
-
[
|
|
5895
|
+
[
|
|
5896
|
+
/microdnf|dnf install|yum install|rpm -i/i,
|
|
5897
|
+
"RPM-based (Fedora/RHEL/Rocky)"
|
|
5898
|
+
],
|
|
5864
5899
|
[/pacman -S/i, "Arch"],
|
|
5865
5900
|
[/zypper|KIWI /i, "SUSE"]
|
|
5866
5901
|
];
|
|
@@ -5902,7 +5937,7 @@ function parseImageRef(image) {
|
|
|
5902
5937
|
let reference;
|
|
5903
5938
|
const at = ref.indexOf("@");
|
|
5904
5939
|
if (at !== -1) {
|
|
5905
|
-
repository = ref.slice(0, at);
|
|
5940
|
+
repository = ref.slice(0, at).replace(/:[^/]*$/, "");
|
|
5906
5941
|
reference = ref.slice(at + 1);
|
|
5907
5942
|
} else {
|
|
5908
5943
|
const colon = ref.lastIndexOf(":");
|
|
@@ -5919,6 +5954,79 @@ function parseImageRef(image) {
|
|
|
5919
5954
|
}
|
|
5920
5955
|
return { host, repository, reference };
|
|
5921
5956
|
}
|
|
5957
|
+
function parseChallenges(header) {
|
|
5958
|
+
const text = header != null ? header : "";
|
|
5959
|
+
const challenges = [];
|
|
5960
|
+
let index = 0;
|
|
5961
|
+
const skipSeparators = () => {
|
|
5962
|
+
while (index < text.length && " ,".includes(text[index])) {
|
|
5963
|
+
index++;
|
|
5964
|
+
}
|
|
5965
|
+
};
|
|
5966
|
+
const readToken = () => {
|
|
5967
|
+
const start = index;
|
|
5968
|
+
while (index < text.length && /[A-Za-z0-9\-_.:]/.test(text[index])) {
|
|
5969
|
+
index++;
|
|
5970
|
+
}
|
|
5971
|
+
return text.slice(start, index);
|
|
5972
|
+
};
|
|
5973
|
+
for (; ; ) {
|
|
5974
|
+
skipSeparators();
|
|
5975
|
+
const scheme = readToken();
|
|
5976
|
+
if (!scheme) {
|
|
5977
|
+
break;
|
|
5978
|
+
}
|
|
5979
|
+
const params = {};
|
|
5980
|
+
for (; ; ) {
|
|
5981
|
+
skipSeparators();
|
|
5982
|
+
if (index >= text.length) {
|
|
5983
|
+
break;
|
|
5984
|
+
}
|
|
5985
|
+
const keyStart = index;
|
|
5986
|
+
const key = readToken();
|
|
5987
|
+
if (!key) {
|
|
5988
|
+
break;
|
|
5989
|
+
}
|
|
5990
|
+
while (index < text.length && " ".includes(text[index])) {
|
|
5991
|
+
index++;
|
|
5992
|
+
}
|
|
5993
|
+
if (index >= text.length || text[index] !== "=") {
|
|
5994
|
+
index = keyStart;
|
|
5995
|
+
break;
|
|
5996
|
+
}
|
|
5997
|
+
index++;
|
|
5998
|
+
while (index < text.length && " ".includes(text[index])) {
|
|
5999
|
+
index++;
|
|
6000
|
+
}
|
|
6001
|
+
if (index < text.length && text[index] === '"') {
|
|
6002
|
+
index++;
|
|
6003
|
+
const chars = [];
|
|
6004
|
+
while (index < text.length) {
|
|
6005
|
+
if (text[index] === "\\" && index + 1 < text.length) {
|
|
6006
|
+
chars.push(text[index + 1]);
|
|
6007
|
+
index += 2;
|
|
6008
|
+
continue;
|
|
6009
|
+
}
|
|
6010
|
+
if (text[index] === '"') {
|
|
6011
|
+
index++;
|
|
6012
|
+
break;
|
|
6013
|
+
}
|
|
6014
|
+
chars.push(text[index]);
|
|
6015
|
+
index++;
|
|
6016
|
+
}
|
|
6017
|
+
params[key.toLowerCase()] = chars.join("");
|
|
6018
|
+
} else {
|
|
6019
|
+
const valueStart = index;
|
|
6020
|
+
while (index < text.length && text[index] !== ",") {
|
|
6021
|
+
index++;
|
|
6022
|
+
}
|
|
6023
|
+
params[key.toLowerCase()] = text.slice(valueStart, index).trim();
|
|
6024
|
+
}
|
|
6025
|
+
}
|
|
6026
|
+
challenges.push({ scheme, params });
|
|
6027
|
+
}
|
|
6028
|
+
return challenges;
|
|
6029
|
+
}
|
|
5922
6030
|
function retryDelayMs(error, fallbackMs) {
|
|
5923
6031
|
const raw = error instanceof RegistryHttpError ? error.retryAfter : null;
|
|
5924
6032
|
const seconds = raw === null ? NaN : Number(raw);
|
|
@@ -5935,19 +6043,27 @@ async function registryGet(url, headers, options) {
|
|
|
5935
6043
|
for (let attempt = 0; attempt < attempts; attempt++) {
|
|
5936
6044
|
if (attempt > 0) {
|
|
5937
6045
|
await new Promise(
|
|
5938
|
-
(resolve) => setTimeout(
|
|
6046
|
+
(resolve) => setTimeout(
|
|
6047
|
+
resolve,
|
|
6048
|
+
retryDelayMs(last, 2 ** (attempt - 1) * backoffBaseMs)
|
|
6049
|
+
)
|
|
5939
6050
|
);
|
|
5940
6051
|
}
|
|
5941
6052
|
try {
|
|
5942
|
-
const
|
|
6053
|
+
const init = {
|
|
5943
6054
|
headers,
|
|
5944
6055
|
signal: AbortSignal.timeout(timeoutMs)
|
|
5945
|
-
}
|
|
6056
|
+
};
|
|
6057
|
+
if ((options == null ? void 0 : options.dispatcher) !== void 0) {
|
|
6058
|
+
init.dispatcher = options.dispatcher;
|
|
6059
|
+
}
|
|
6060
|
+
const response = await fetch(url, init);
|
|
5946
6061
|
if (!response.ok) {
|
|
5947
6062
|
const error = new RegistryHttpError(
|
|
5948
6063
|
response.status,
|
|
5949
6064
|
response.headers.get("retry-after"),
|
|
5950
|
-
`HTTP ${response.status} ${response.statusText}
|
|
6065
|
+
`HTTP ${response.status} ${response.statusText}`,
|
|
6066
|
+
response.headers.get("www-authenticate")
|
|
5951
6067
|
);
|
|
5952
6068
|
if (!RETRY_STATUS.has(response.status)) {
|
|
5953
6069
|
throw error;
|
|
@@ -5965,14 +6081,10 @@ async function registryGet(url, headers, options) {
|
|
|
5965
6081
|
}
|
|
5966
6082
|
throw last;
|
|
5967
6083
|
}
|
|
5968
|
-
async function authHeaders(host, repository, credentials) {
|
|
6084
|
+
async function authHeaders(host, repository, credentials, dispatcher) {
|
|
5969
6085
|
const headers = { Accept: MANIFEST_TYPES };
|
|
5970
|
-
if (credentials) {
|
|
5971
|
-
|
|
5972
|
-
`${credentials.username}:${credentials.password}`,
|
|
5973
|
-
"utf8"
|
|
5974
|
-
).toString("base64");
|
|
5975
|
-
headers.Authorization = `Basic ${basic}`;
|
|
6086
|
+
if ((credentials == null ? void 0 : credentials.username) && credentials.password) {
|
|
6087
|
+
headers.Authorization = basicHeader(credentials);
|
|
5976
6088
|
}
|
|
5977
6089
|
const services = {
|
|
5978
6090
|
"registry-1.docker.io": ["auth.docker.io", "registry.docker.io"],
|
|
@@ -5986,9 +6098,9 @@ async function authHeaders(host, repository, credentials) {
|
|
|
5986
6098
|
const url = `https://${authHost}/token?service=${serviceName}&scope=repository:${repository}:pull`;
|
|
5987
6099
|
try {
|
|
5988
6100
|
const tokenHeaders = headers.Authorization ? { Authorization: headers.Authorization } : {};
|
|
5989
|
-
const body = await registryGet(url, tokenHeaders, {
|
|
6101
|
+
const body = await registryGet(url, tokenHeaders, __spreadValues({
|
|
5990
6102
|
attempts: 1
|
|
5991
|
-
});
|
|
6103
|
+
}, dispatcher === void 0 ? {} : { dispatcher }));
|
|
5992
6104
|
if (body.token) {
|
|
5993
6105
|
headers.Authorization = `Bearer ${body.token}`;
|
|
5994
6106
|
}
|
|
@@ -5996,6 +6108,13 @@ async function authHeaders(host, repository, credentials) {
|
|
|
5996
6108
|
}
|
|
5997
6109
|
return headers;
|
|
5998
6110
|
}
|
|
6111
|
+
function basicHeader(credentials) {
|
|
6112
|
+
const encoded = Buffer.from(
|
|
6113
|
+
`${credentials.username}:${credentials.password}`,
|
|
6114
|
+
"utf8"
|
|
6115
|
+
).toString("base64");
|
|
6116
|
+
return `Basic ${encoded}`;
|
|
6117
|
+
}
|
|
5999
6118
|
function platformName(entry) {
|
|
6000
6119
|
var _a3, _b, _c;
|
|
6001
6120
|
const p = (_a3 = entry.platform) != null ? _a3 : {};
|
|
@@ -6040,41 +6159,53 @@ function describeFailure(error, image, host, repository, authenticated) {
|
|
|
6040
6159
|
const reason = `no such image: Docker Hub has no official image '${image}' (HTTP 401). The \`library/\` namespace has no private repositories, so this is a typo rather than a permissions problem`;
|
|
6041
6160
|
return __spreadProps(__spreadValues({}, empty), { error: reason, unusable: reason });
|
|
6042
6161
|
}
|
|
6162
|
+
if (error.status === 401) {
|
|
6163
|
+
const reason = authenticated ? `cannot read '${image}' (HTTP 401): the registry rejected the credentials. Check the username, the password, and the read permission on the repository` : `cannot read '${image}' (HTTP 401): the registry wants pull credentials for it. Pass the registry username and password, or check that the reference names an existing public image`;
|
|
6164
|
+
return __spreadProps(__spreadValues({}, empty), { error: reason });
|
|
6165
|
+
}
|
|
6043
6166
|
return __spreadProps(__spreadValues({}, empty), { error: `${error.name}: ${error.message}` });
|
|
6044
6167
|
}
|
|
6045
6168
|
const message = error instanceof Error ? error.message : String(error);
|
|
6046
6169
|
return __spreadProps(__spreadValues({}, empty), { error: message });
|
|
6047
6170
|
}
|
|
6048
|
-
async function fetchImageConfig(image, credentials) {
|
|
6171
|
+
async function fetchImageConfig(image, credentials, options) {
|
|
6049
6172
|
var _a3, _b, _c, _d, _e, _f, _g;
|
|
6173
|
+
const dispatcher = options == null ? void 0 : options.dispatcher;
|
|
6174
|
+
const cacheable = dispatcher === void 0 && image.includes("@");
|
|
6050
6175
|
const key = JSON.stringify([
|
|
6051
6176
|
image,
|
|
6052
6177
|
(_a3 = credentials == null ? void 0 : credentials.username) != null ? _a3 : null,
|
|
6053
6178
|
(_b = credentials == null ? void 0 : credentials.password) != null ? _b : null
|
|
6054
6179
|
]);
|
|
6055
|
-
|
|
6056
|
-
|
|
6057
|
-
|
|
6180
|
+
if (cacheable) {
|
|
6181
|
+
const cached = CACHE.get(key);
|
|
6182
|
+
if (cached) {
|
|
6183
|
+
return copyConfig(cached);
|
|
6184
|
+
}
|
|
6058
6185
|
}
|
|
6059
6186
|
const { host, repository, reference } = parseImageRef(image);
|
|
6060
6187
|
let result;
|
|
6061
6188
|
try {
|
|
6062
|
-
const auth = await authHeaders(host, repository, credentials);
|
|
6189
|
+
const auth = await authHeaders(host, repository, credentials, dispatcher);
|
|
6190
|
+
const session = new RegistrySession(
|
|
6191
|
+
repository,
|
|
6192
|
+
credentials,
|
|
6193
|
+
auth,
|
|
6194
|
+
dispatcher
|
|
6195
|
+
);
|
|
6063
6196
|
const base = `https://${host}/v2/${repository}`;
|
|
6064
|
-
let manifest = await
|
|
6065
|
-
`${base}/manifests/${reference}
|
|
6066
|
-
auth
|
|
6197
|
+
let manifest = await session.get(
|
|
6198
|
+
`${base}/manifests/${reference}`
|
|
6067
6199
|
);
|
|
6068
6200
|
if (manifest.manifests) {
|
|
6069
6201
|
const digest = pickAmd64(manifest, image);
|
|
6070
|
-
manifest = await
|
|
6202
|
+
manifest = await session.get(`${base}/manifests/${digest}`);
|
|
6071
6203
|
}
|
|
6072
6204
|
if (!((_c = manifest.config) == null ? void 0 : _c.digest)) {
|
|
6073
6205
|
throw new Error(`${image}: manifest names no config blob`);
|
|
6074
6206
|
}
|
|
6075
|
-
const blob = await
|
|
6076
|
-
`${base}/blobs/${manifest.config.digest}
|
|
6077
|
-
auth
|
|
6207
|
+
const blob = await session.get(
|
|
6208
|
+
`${base}/blobs/${manifest.config.digest}`
|
|
6078
6209
|
);
|
|
6079
6210
|
const declared = (_d = blob.config) != null ? _d : {};
|
|
6080
6211
|
const env = {};
|
|
@@ -6101,10 +6232,14 @@ async function fetchImageConfig(image, credentials) {
|
|
|
6101
6232
|
image,
|
|
6102
6233
|
host,
|
|
6103
6234
|
repository,
|
|
6104
|
-
|
|
6235
|
+
// Both, because that is what the request actually carried: a lone username
|
|
6236
|
+
// is not a credential the registry could have rejected.
|
|
6237
|
+
Boolean((credentials == null ? void 0 : credentials.username) && (credentials == null ? void 0 : credentials.password))
|
|
6105
6238
|
);
|
|
6106
6239
|
}
|
|
6107
|
-
|
|
6240
|
+
if (cacheable && !result.error) {
|
|
6241
|
+
CACHE.set(key, result);
|
|
6242
|
+
}
|
|
6108
6243
|
return copyConfig(result);
|
|
6109
6244
|
}
|
|
6110
6245
|
function effectiveStartCmd(entrypoint, cmd) {
|
|
@@ -6112,12 +6247,12 @@ function effectiveStartCmd(entrypoint, cmd) {
|
|
|
6112
6247
|
return parts.length > 0 ? parts.map(shellQuoteArg).join(" ") : null;
|
|
6113
6248
|
}
|
|
6114
6249
|
function shellQuoteArg(value) {
|
|
6115
|
-
return /^[A-Za-z0-9_./:@%+=,-]+$/.test(value) ? value : `'${value.replace(/'/g,
|
|
6250
|
+
return /^[A-Za-z0-9_./:@%+=,-]+$/.test(value) ? value : `'${value.replace(/'/g, "'\\''")}'`;
|
|
6116
6251
|
}
|
|
6117
6252
|
function clearImageConfigCache() {
|
|
6118
6253
|
CACHE.clear();
|
|
6119
6254
|
}
|
|
6120
|
-
var HUB_HOST, HUB_OFFICIAL, MANIFEST_TYPES, SKIP_ENV, RETRY_STATUS, READ_ATTEMPTS, backoffBaseMs, CACHE, RegistryHttpError, UnusableImageError;
|
|
6255
|
+
var HUB_HOST, HUB_OFFICIAL, MANIFEST_TYPES, SKIP_ENV, RETRY_STATUS, READ_ATTEMPTS, TOKEN_CLIENT_ID, backoffBaseMs, CACHE, RegistryHttpError, UnusableImageError, RegistrySession;
|
|
6121
6256
|
var init_imageConfig = __esm({
|
|
6122
6257
|
"src/core/template/imageConfig.ts"() {
|
|
6123
6258
|
"use strict";
|
|
@@ -6140,13 +6275,15 @@ var init_imageConfig = __esm({
|
|
|
6140
6275
|
]);
|
|
6141
6276
|
RETRY_STATUS = /* @__PURE__ */ new Set([429, 500, 502, 503, 504]);
|
|
6142
6277
|
READ_ATTEMPTS = 3;
|
|
6278
|
+
TOKEN_CLIENT_ID = "ppio-sandbox";
|
|
6143
6279
|
backoffBaseMs = 1e3;
|
|
6144
6280
|
CACHE = /* @__PURE__ */ new Map();
|
|
6145
6281
|
RegistryHttpError = class extends Error {
|
|
6146
|
-
constructor(status, retryAfter, message) {
|
|
6282
|
+
constructor(status, retryAfter, message, challenge = null) {
|
|
6147
6283
|
super(message);
|
|
6148
6284
|
this.status = status;
|
|
6149
6285
|
this.retryAfter = retryAfter;
|
|
6286
|
+
this.challenge = challenge;
|
|
6150
6287
|
this.name = "RegistryHttpError";
|
|
6151
6288
|
}
|
|
6152
6289
|
};
|
|
@@ -6156,6 +6293,75 @@ var init_imageConfig = __esm({
|
|
|
6156
6293
|
this.name = "UnusableImageError";
|
|
6157
6294
|
}
|
|
6158
6295
|
};
|
|
6296
|
+
RegistrySession = class {
|
|
6297
|
+
constructor(repository, credentials, headers, dispatcher) {
|
|
6298
|
+
this.repository = repository;
|
|
6299
|
+
this.credentials = credentials;
|
|
6300
|
+
this.headers = headers;
|
|
6301
|
+
this.dispatcher = dispatcher;
|
|
6302
|
+
this.token = null;
|
|
6303
|
+
}
|
|
6304
|
+
/** GET `url`, resolving one Bearer challenge if the registry asks for it. */
|
|
6305
|
+
async get(url) {
|
|
6306
|
+
const headers = __spreadValues({}, this.headers);
|
|
6307
|
+
if (this.token) {
|
|
6308
|
+
headers.Authorization = `Bearer ${this.token}`;
|
|
6309
|
+
}
|
|
6310
|
+
try {
|
|
6311
|
+
return await registryGet(url, headers, __spreadValues({
|
|
6312
|
+
attempts: READ_ATTEMPTS
|
|
6313
|
+
}, this.dispatcher === void 0 ? {} : { dispatcher: this.dispatcher }));
|
|
6314
|
+
} catch (error) {
|
|
6315
|
+
if (!(error instanceof RegistryHttpError) || error.status !== 401) {
|
|
6316
|
+
throw error;
|
|
6317
|
+
}
|
|
6318
|
+
const token = await this.tokenFrom(error.challenge);
|
|
6319
|
+
if (token === null) {
|
|
6320
|
+
throw error;
|
|
6321
|
+
}
|
|
6322
|
+
this.token = token;
|
|
6323
|
+
headers.Authorization = `Bearer ${token}`;
|
|
6324
|
+
return registryGet(url, headers, __spreadValues({
|
|
6325
|
+
attempts: READ_ATTEMPTS
|
|
6326
|
+
}, this.dispatcher === void 0 ? {} : { dispatcher: this.dispatcher }));
|
|
6327
|
+
}
|
|
6328
|
+
}
|
|
6329
|
+
async tokenFrom(challenge) {
|
|
6330
|
+
for (const { scheme, params } of parseChallenges(challenge)) {
|
|
6331
|
+
if (scheme.toLowerCase() === "bearer") {
|
|
6332
|
+
return this.bearer(params);
|
|
6333
|
+
}
|
|
6334
|
+
}
|
|
6335
|
+
return null;
|
|
6336
|
+
}
|
|
6337
|
+
async bearer(params) {
|
|
6338
|
+
var _a3;
|
|
6339
|
+
const realm = params.realm;
|
|
6340
|
+
if (!realm || !/^https?:\/\//.test(realm)) {
|
|
6341
|
+
return null;
|
|
6342
|
+
}
|
|
6343
|
+
const url = new URL(realm);
|
|
6344
|
+
url.searchParams.set("client_id", TOKEN_CLIENT_ID);
|
|
6345
|
+
if (params.service) {
|
|
6346
|
+
url.searchParams.set("service", params.service);
|
|
6347
|
+
}
|
|
6348
|
+
url.searchParams.set(
|
|
6349
|
+
"scope",
|
|
6350
|
+
params.scope || `repository:${this.repository}:pull`
|
|
6351
|
+
);
|
|
6352
|
+
const headers = {};
|
|
6353
|
+
if (((_a3 = this.credentials) == null ? void 0 : _a3.username) && this.credentials.password) {
|
|
6354
|
+
headers.Authorization = basicHeader(this.credentials);
|
|
6355
|
+
}
|
|
6356
|
+
const body = await registryGet(url.toString(), headers, __spreadValues({
|
|
6357
|
+
attempts: 1
|
|
6358
|
+
}, this.dispatcher === void 0 ? {} : { dispatcher: this.dispatcher }));
|
|
6359
|
+
if (body === null || typeof body !== "object") {
|
|
6360
|
+
return null;
|
|
6361
|
+
}
|
|
6362
|
+
return body.token || body.access_token || null;
|
|
6363
|
+
}
|
|
6364
|
+
};
|
|
6159
6365
|
}
|
|
6160
6366
|
});
|
|
6161
6367
|
|
|
@@ -6343,6 +6549,8 @@ var init_template = __esm({
|
|
|
6343
6549
|
// rather than written per call because the file is written once from the full
|
|
6344
6550
|
// set -- a per-call write would clobber the previous call's file.
|
|
6345
6551
|
this.envs = {};
|
|
6552
|
+
this.envDeclarations = [];
|
|
6553
|
+
this.imageEnvs = {};
|
|
6346
6554
|
// Whether to restore what the base image declares -- see fromImage() and
|
|
6347
6555
|
// resolveInheritedConfig(). Only meaningful for an image base; a Dockerfile
|
|
6348
6556
|
// states its own ENV/WORKDIR/CMD, and a template base already carries them.
|
|
@@ -6354,6 +6562,13 @@ var init_template = __esm({
|
|
|
6354
6562
|
// image's PATH -- the exact failure this reading exists to prevent.
|
|
6355
6563
|
this.imageConfigError = void 0;
|
|
6356
6564
|
this.imageUnusable = void 0;
|
|
6565
|
+
// What a failed read does. "warn" by default: one unreachable registry must not
|
|
6566
|
+
// abort a batch conversion, but a template silently missing the image's PATH is
|
|
6567
|
+
// the failure this reading exists to prevent, so it cannot pass unmentioned.
|
|
6568
|
+
this.imageOnConfigFailure = "warn";
|
|
6569
|
+
// Carries the TLS trust and proxy settings for a self-hosted registry, which
|
|
6570
|
+
// Node's fetch cannot be told about in any other per-request way.
|
|
6571
|
+
this.imageDispatcher = void 0;
|
|
6357
6572
|
this.fileContextPath = runtime === "browser" ? "." : (_a2 = getCallerDirectory(STACK_TRACE_DEPTH)) != null ? _a2 : ".";
|
|
6358
6573
|
this.fileIgnorePatterns = [];
|
|
6359
6574
|
this.logsRefreshFrequency = 200;
|
|
@@ -6580,12 +6795,41 @@ var init_template = __esm({
|
|
|
6580
6795
|
fromBaseImage() {
|
|
6581
6796
|
return this.fromImage(this.defaultBaseImage);
|
|
6582
6797
|
}
|
|
6798
|
+
/**
|
|
6799
|
+
* Build from a Docker image, restoring what the image declares.
|
|
6800
|
+
*
|
|
6801
|
+
* The image's ENV, WORKDIR and start command are read from its registry config
|
|
6802
|
+
* because the platform's own pull does not apply them. Reading is best-effort
|
|
6803
|
+
* and asynchronous, so it happens at build/serialize time.
|
|
6804
|
+
*
|
|
6805
|
+
* @param credentials registry username and password, for a private image.
|
|
6806
|
+
* @param options.inheritConfig restore the image's config (default true).
|
|
6807
|
+
* @param options.onConfigFailure what a failed read does — see
|
|
6808
|
+
* {@link ImageConfigFailureMode}. Defaults to `warn`.
|
|
6809
|
+
* @param options.dispatcher Node fetch `dispatcher` (an undici `Agent`), for a
|
|
6810
|
+
* self-hosted registry behind a private CA, a client certificate or a proxy.
|
|
6811
|
+
* For example, with a private CA:
|
|
6812
|
+
*
|
|
6813
|
+
* ```ts
|
|
6814
|
+
* import { Agent } from 'undici'
|
|
6815
|
+
* const dispatcher = new Agent({ connect: { ca: readFileSync('/ca.pem') } })
|
|
6816
|
+
* Template().fromImage('harbor.internal/app:1', undefined, { dispatcher })
|
|
6817
|
+
* ```
|
|
6818
|
+
*/
|
|
6583
6819
|
fromImage(baseImage, credentials, options) {
|
|
6584
|
-
var _a3;
|
|
6820
|
+
var _a3, _b;
|
|
6821
|
+
if ((options == null ? void 0 : options.onConfigFailure) !== void 0 && !["warn", "raise", "ignore"].includes(options.onConfigFailure)) {
|
|
6822
|
+
throw new InvalidArgumentError(
|
|
6823
|
+
'onConfigFailure must be "warn", "raise" or "ignore", got ' + String(options.onConfigFailure)
|
|
6824
|
+
);
|
|
6825
|
+
}
|
|
6585
6826
|
this.baseImage = baseImage;
|
|
6586
6827
|
this.baseTemplate = void 0;
|
|
6828
|
+
this.resetInheritedConfig();
|
|
6587
6829
|
this.inheritImageConfig = (_a3 = options == null ? void 0 : options.inheritConfig) != null ? _a3 : true;
|
|
6588
6830
|
this.imageCredentials = credentials;
|
|
6831
|
+
this.imageOnConfigFailure = (_b = options == null ? void 0 : options.onConfigFailure) != null ? _b : "warn";
|
|
6832
|
+
this.imageDispatcher = options == null ? void 0 : options.dispatcher;
|
|
6589
6833
|
if (credentials) {
|
|
6590
6834
|
this.registryConfig = {
|
|
6591
6835
|
type: "registry",
|
|
@@ -6602,6 +6846,7 @@ var init_template = __esm({
|
|
|
6602
6846
|
fromTemplate(template) {
|
|
6603
6847
|
this.baseTemplate = template;
|
|
6604
6848
|
this.baseImage = void 0;
|
|
6849
|
+
this.resetInheritedConfig();
|
|
6605
6850
|
if (this.forceNextLayer) {
|
|
6606
6851
|
this.force = true;
|
|
6607
6852
|
}
|
|
@@ -6616,6 +6861,8 @@ var init_template = __esm({
|
|
|
6616
6861
|
);
|
|
6617
6862
|
this.baseImage = baseImage;
|
|
6618
6863
|
this.baseTemplate = void 0;
|
|
6864
|
+
this.resetInheritedConfig();
|
|
6865
|
+
this.inheritImageConfig = true;
|
|
6619
6866
|
if (this.forceNextLayer) {
|
|
6620
6867
|
this.force = true;
|
|
6621
6868
|
}
|
|
@@ -6625,6 +6872,7 @@ var init_template = __esm({
|
|
|
6625
6872
|
fromAWSRegistry(image, credentials) {
|
|
6626
6873
|
this.baseImage = image;
|
|
6627
6874
|
this.baseTemplate = void 0;
|
|
6875
|
+
this.resetInheritedConfig();
|
|
6628
6876
|
this.registryConfig = {
|
|
6629
6877
|
type: "aws",
|
|
6630
6878
|
awsAccessKeyId: credentials.accessKeyId,
|
|
@@ -6640,6 +6888,7 @@ var init_template = __esm({
|
|
|
6640
6888
|
fromGCPRegistry(image, credentials) {
|
|
6641
6889
|
this.baseImage = image;
|
|
6642
6890
|
this.baseTemplate = void 0;
|
|
6891
|
+
this.resetInheritedConfig();
|
|
6643
6892
|
this.registryConfig = {
|
|
6644
6893
|
type: "gcp",
|
|
6645
6894
|
serviceAccountJson: readGCPServiceAccountJSON(
|
|
@@ -6656,6 +6905,7 @@ var init_template = __esm({
|
|
|
6656
6905
|
fromOCIRegistry(image, credentials) {
|
|
6657
6906
|
this.baseImage = image;
|
|
6658
6907
|
this.baseTemplate = void 0;
|
|
6908
|
+
this.resetInheritedConfig();
|
|
6659
6909
|
this.registryConfig = {
|
|
6660
6910
|
type: "oci",
|
|
6661
6911
|
tenancyOcid: credentials.tenancyOcid,
|
|
@@ -6673,6 +6923,7 @@ var init_template = __esm({
|
|
|
6673
6923
|
fromHuaweiCloudRegistry(image, credentials) {
|
|
6674
6924
|
this.baseImage = image;
|
|
6675
6925
|
this.baseTemplate = void 0;
|
|
6926
|
+
this.resetInheritedConfig();
|
|
6676
6927
|
this.registryConfig = {
|
|
6677
6928
|
type: "huawei",
|
|
6678
6929
|
accessKeyId: credentials.accessKeyId,
|
|
@@ -6735,8 +6986,8 @@ var init_template = __esm({
|
|
|
6735
6986
|
});
|
|
6736
6987
|
return this;
|
|
6737
6988
|
}
|
|
6738
|
-
remove(
|
|
6739
|
-
const paths2 = Array.isArray(
|
|
6989
|
+
remove(path3, options) {
|
|
6990
|
+
const paths2 = Array.isArray(path3) ? path3 : [path3];
|
|
6740
6991
|
const args = ["rm"];
|
|
6741
6992
|
if (options == null ? void 0 : options.recursive) {
|
|
6742
6993
|
args.push("-r");
|
|
@@ -6758,8 +7009,8 @@ var init_template = __esm({
|
|
|
6758
7009
|
() => this.runCmd(args.join(" "), { user: options == null ? void 0 : options.user })
|
|
6759
7010
|
);
|
|
6760
7011
|
}
|
|
6761
|
-
makeDir(
|
|
6762
|
-
const paths2 = Array.isArray(
|
|
7012
|
+
makeDir(path3, options) {
|
|
7013
|
+
const paths2 = Array.isArray(path3) ? path3 : [path3];
|
|
6763
7014
|
const args = ["mkdir", "-p"];
|
|
6764
7015
|
if (options == null ? void 0 : options.mode) {
|
|
6765
7016
|
args.push(`-m ${padOctal(options.mode)}`);
|
|
@@ -6894,7 +7145,7 @@ var init_template = __esm({
|
|
|
6894
7145
|
})
|
|
6895
7146
|
);
|
|
6896
7147
|
}
|
|
6897
|
-
gitClone(url,
|
|
7148
|
+
gitClone(url, path3, options) {
|
|
6898
7149
|
const args = ["git", "clone", url];
|
|
6899
7150
|
if (options == null ? void 0 : options.branch) {
|
|
6900
7151
|
args.push(`--branch ${options.branch}`);
|
|
@@ -6903,8 +7154,8 @@ var init_template = __esm({
|
|
|
6903
7154
|
if (options == null ? void 0 : options.depth) {
|
|
6904
7155
|
args.push(`--depth ${options.depth}`);
|
|
6905
7156
|
}
|
|
6906
|
-
if (
|
|
6907
|
-
args.push(
|
|
7157
|
+
if (path3) {
|
|
7158
|
+
args.push(path3.toString());
|
|
6908
7159
|
}
|
|
6909
7160
|
return this.runInNewStackTraceContext(
|
|
6910
7161
|
() => this.runCmd(args.join(" "), { user: options == null ? void 0 : options.user })
|
|
@@ -6934,7 +7185,8 @@ var init_template = __esm({
|
|
|
6934
7185
|
this.collectStackTrace();
|
|
6935
7186
|
return this;
|
|
6936
7187
|
}
|
|
6937
|
-
setEnvs(envs) {
|
|
7188
|
+
setEnvs(envs, options) {
|
|
7189
|
+
var _a3;
|
|
6938
7190
|
if (Object.keys(envs).length === 0) {
|
|
6939
7191
|
return this;
|
|
6940
7192
|
}
|
|
@@ -6943,7 +7195,11 @@ var init_template = __esm({
|
|
|
6943
7195
|
args: Object.entries(envs).flatMap(([key, value]) => [key, value]),
|
|
6944
7196
|
force: this.forceNextLayer
|
|
6945
7197
|
});
|
|
6946
|
-
this.
|
|
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);
|
|
6947
7203
|
this.collectStackTrace();
|
|
6948
7204
|
return this;
|
|
6949
7205
|
}
|
|
@@ -6960,7 +7216,12 @@ var init_template = __esm({
|
|
|
6960
7216
|
* second build of the same template append a duplicate layer.
|
|
6961
7217
|
*/
|
|
6962
7218
|
runtimeEnvInstruction() {
|
|
6963
|
-
const { command } = envFilesCommand(
|
|
7219
|
+
const { command } = envFilesCommand(
|
|
7220
|
+
this.envs,
|
|
7221
|
+
this.imageEnvs,
|
|
7222
|
+
this.envDeclarations,
|
|
7223
|
+
envSnapshotCommand(this.envDeclarations) ? BASE_ENV_PATH : void 0
|
|
7224
|
+
);
|
|
6964
7225
|
if (command === null) {
|
|
6965
7226
|
return null;
|
|
6966
7227
|
}
|
|
@@ -6979,7 +7240,10 @@ var init_template = __esm({
|
|
|
6979
7240
|
*/
|
|
6980
7241
|
withRuntimeEnv(instructions) {
|
|
6981
7242
|
const runtimeEnv = this.runtimeEnvInstruction();
|
|
6982
|
-
|
|
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];
|
|
6983
7247
|
}
|
|
6984
7248
|
/**
|
|
6985
7249
|
* Restore what the base image declares: ENV, WORKDIR and its effective command.
|
|
@@ -7000,37 +7264,57 @@ var init_template = __esm({
|
|
|
7000
7264
|
* restored config — but it is reported, since an image whose toolchain lives
|
|
7001
7265
|
* behind its ENV will otherwise look installed and behave as though it is not.
|
|
7002
7266
|
*/
|
|
7267
|
+
/** The one wording a failed read is reported with, on every channel. */
|
|
7268
|
+
configFailureMessage() {
|
|
7269
|
+
return `Could not read ${this.baseImage}: ${this.imageConfigError}. The template will build without the environment, working directory and start command the image declares.`;
|
|
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
|
+
}
|
|
7003
7283
|
async resolveInheritedConfig(onBuildLogs) {
|
|
7004
|
-
var _a3;
|
|
7284
|
+
var _a3, _b;
|
|
7005
7285
|
if (!this.inheritImageConfig || this.baseImage === void 0) {
|
|
7006
7286
|
return;
|
|
7007
7287
|
}
|
|
7008
|
-
|
|
7009
|
-
|
|
7288
|
+
const config = await fetchImageConfig(
|
|
7289
|
+
this.baseImage,
|
|
7290
|
+
this.imageCredentials,
|
|
7291
|
+
this.imageDispatcher === void 0 ? void 0 : { dispatcher: this.imageDispatcher }
|
|
7292
|
+
);
|
|
7293
|
+
this.imageEnvs = {};
|
|
7294
|
+
this.imageWorkdir = void 0;
|
|
7295
|
+
this.imageStartCmd = void 0;
|
|
7296
|
+
this.imageReadyCmd = void 0;
|
|
7010
7297
|
if (config.error) {
|
|
7011
7298
|
this.imageConfigError = config.error;
|
|
7012
7299
|
this.imageUnusable = config.unusable;
|
|
7013
|
-
|
|
7014
|
-
|
|
7015
|
-
|
|
7016
|
-
|
|
7017
|
-
|
|
7018
|
-
)
|
|
7019
|
-
|
|
7300
|
+
const message = this.configFailureMessage();
|
|
7301
|
+
if (this.imageOnConfigFailure === "raise") {
|
|
7302
|
+
throw new ImageConfigError(message);
|
|
7303
|
+
}
|
|
7304
|
+
if (this.imageOnConfigFailure !== "ignore") {
|
|
7305
|
+
console.warn(message);
|
|
7306
|
+
onBuildLogs == null ? void 0 : onBuildLogs(new LogEntry(/* @__PURE__ */ new Date(), "warn", message));
|
|
7307
|
+
}
|
|
7020
7308
|
return;
|
|
7021
7309
|
}
|
|
7022
|
-
this.
|
|
7023
|
-
|
|
7024
|
-
|
|
7025
|
-
|
|
7026
|
-
args: [config.workdir],
|
|
7027
|
-
force: false
|
|
7028
|
-
});
|
|
7029
|
-
}
|
|
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;
|
|
7030
7314
|
const startCmd = effectiveStartCmd(config.entrypoint, config.cmd);
|
|
7031
7315
|
if (startCmd && this.startCmd === void 0) {
|
|
7032
|
-
this.
|
|
7033
|
-
this.
|
|
7316
|
+
this.imageStartCmd = startCmd;
|
|
7317
|
+
this.imageReadyCmd = (_b = this.readyCmd) != null ? _b : waitForTimeout(2e4).getCmd();
|
|
7034
7318
|
}
|
|
7035
7319
|
}
|
|
7036
7320
|
/**
|
|
@@ -7368,9 +7652,20 @@ var init_template = __esm({
|
|
|
7368
7652
|
* @returns Template data formatted for the API
|
|
7369
7653
|
*/
|
|
7370
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
|
+
}
|
|
7371
7666
|
const templateData = {
|
|
7372
|
-
startCmd: this.startCmd,
|
|
7373
|
-
readyCmd: this.readyCmd,
|
|
7667
|
+
startCmd: (_a3 = this.startCmd) != null ? _a3 : this.imageStartCmd,
|
|
7668
|
+
readyCmd: (_b = this.readyCmd) != null ? _b : this.imageReadyCmd,
|
|
7374
7669
|
preBootScript: this.patchCmd,
|
|
7375
7670
|
steps,
|
|
7376
7671
|
force: this.force
|
|
@@ -7400,6 +7695,7 @@ var init_template = __esm({
|
|
|
7400
7695
|
Template.delete = TemplateBase.delete;
|
|
7401
7696
|
Template.toJSON = TemplateBase.toJSON;
|
|
7402
7697
|
Template.toDockerfile = TemplateBase.toDockerfile;
|
|
7698
|
+
Template.imageConfigFailure = TemplateBase.imageConfigFailure;
|
|
7403
7699
|
}
|
|
7404
7700
|
});
|
|
7405
7701
|
|
|
@@ -8305,10 +8601,10 @@ var init_sandbox3 = __esm({
|
|
|
8305
8601
|
}
|
|
8306
8602
|
}
|
|
8307
8603
|
async screenshot(format = "bytes") {
|
|
8308
|
-
const
|
|
8309
|
-
await this.commands.run(`scrot --pointer ${
|
|
8310
|
-
const file = await this.files.read(
|
|
8311
|
-
this.files.remove(
|
|
8604
|
+
const path3 = `/tmp/screenshot-${generateRandomString()}.png`;
|
|
8605
|
+
await this.commands.run(`scrot --pointer ${path3}`);
|
|
8606
|
+
const file = await this.files.read(path3, { format });
|
|
8607
|
+
this.files.remove(path3);
|
|
8312
8608
|
return file;
|
|
8313
8609
|
}
|
|
8314
8610
|
/**
|
|
@@ -8657,7 +8953,7 @@ function mergeConnectionOpts(base, next) {
|
|
|
8657
8953
|
headers: __spreadValues(__spreadValues({}, baseHeaders), nextHeaders)
|
|
8658
8954
|
});
|
|
8659
8955
|
}
|
|
8660
|
-
var RuntimeSandboxNamespace, SandboxNamespace, TemplateNamespace, VolumeNamespace, SecretNamespace, PPIO;
|
|
8956
|
+
var import_node_path2, import_node_url2, RuntimeSandboxNamespace, SandboxNamespace, TemplateNamespace, VolumeNamespace, SecretNamespace, PPIO;
|
|
8661
8957
|
var init_client = __esm({
|
|
8662
8958
|
"src/core/client.ts"() {
|
|
8663
8959
|
"use strict";
|
|
@@ -8665,6 +8961,9 @@ var init_client = __esm({
|
|
|
8665
8961
|
init_template();
|
|
8666
8962
|
init_volume();
|
|
8667
8963
|
init_secret();
|
|
8964
|
+
init_utils3();
|
|
8965
|
+
import_node_path2 = __toESM(require("path"));
|
|
8966
|
+
import_node_url2 = require("url");
|
|
8668
8967
|
RuntimeSandboxNamespace = class {
|
|
8669
8968
|
constructor(opts, loadSandbox) {
|
|
8670
8969
|
this.opts = opts;
|
|
@@ -8861,7 +9160,18 @@ var init_client = __esm({
|
|
|
8861
9160
|
this.toDockerfile = Template.toDockerfile;
|
|
8862
9161
|
}
|
|
8863
9162
|
new(options) {
|
|
8864
|
-
|
|
9163
|
+
var _a3;
|
|
9164
|
+
let callerContext = ".";
|
|
9165
|
+
for (const site of callsites(2)) {
|
|
9166
|
+
const fileName = site.getFileName();
|
|
9167
|
+
if (fileName && (!fileName.includes("/src/core/") || fileName.includes("/src/core/tests/")) && !fileName.includes("/node_modules/ppio-sandbox/")) {
|
|
9168
|
+
callerContext = import_node_path2.default.dirname(fileName.startsWith("file:") ? (0, import_node_url2.fileURLToPath)(fileName) : fileName);
|
|
9169
|
+
break;
|
|
9170
|
+
}
|
|
9171
|
+
}
|
|
9172
|
+
return Template(__spreadProps(__spreadValues({}, options), {
|
|
9173
|
+
fileContextPath: (_a3 = options == null ? void 0 : options.fileContextPath) != null ? _a3 : callerContext
|
|
9174
|
+
}));
|
|
8865
9175
|
}
|
|
8866
9176
|
list(opts) {
|
|
8867
9177
|
return Template.list(mergeConnectionOpts(this.opts, opts));
|
|
@@ -9063,6 +9373,7 @@ __export(code_interpreter_exports, {
|
|
|
9063
9373
|
Git: () => Git,
|
|
9064
9374
|
GitAuthError: () => GitAuthError,
|
|
9065
9375
|
GitUpstreamError: () => GitUpstreamError,
|
|
9376
|
+
ImageConfigError: () => ImageConfigError,
|
|
9066
9377
|
InvalidArgumentError: () => InvalidArgumentError,
|
|
9067
9378
|
LogEntry: () => LogEntry,
|
|
9068
9379
|
LogEntryEnd: () => LogEntryEnd,
|
|
@@ -9119,6 +9430,7 @@ var code_interpreter_default = Sandbox2;
|
|
|
9119
9430
|
Git,
|
|
9120
9431
|
GitAuthError,
|
|
9121
9432
|
GitUpstreamError,
|
|
9433
|
+
ImageConfigError,
|
|
9122
9434
|
InvalidArgumentError,
|
|
9123
9435
|
LogEntry,
|
|
9124
9436
|
LogEntryEnd,
|