ppio-sandbox 2.1.1 → 2.1.4-a1
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-PPBSBQ3N.mjs} +2 -2
- package/dist/{chunk-RIWYGA3J.mjs → chunk-Q4BOWZMT.mjs} +2 -2
- package/dist/chunk-Q4BOWZMT.mjs.map +1 -0
- package/dist/{chunk-M7G3KDGF.mjs → chunk-RWHOETVW.mjs} +695 -327
- package/dist/chunk-RWHOETVW.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 +705 -335
- 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 +705 -335
- package/dist/desktop.js.map +1 -1
- package/dist/desktop.mjs +4 -2
- package/dist/{index-CRwaZUdl.d.mts → index-DIHU8MXT.d.mts} +239 -61
- package/dist/{index-CRwaZUdl.d.ts → index-DIHU8MXT.d.ts} +239 -61
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +705 -335
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +3 -1
- package/dist/sandbox-6EPWOUGN.mjs +8 -0
- package/dist/sandbox-OKITI7WW.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-PPBSBQ3N.mjs.map} +0 -0
- /package/dist/{sandbox-5PUSVOHB.mjs.map → sandbox-6EPWOUGN.mjs.map} +0 -0
- /package/dist/{sandbox-VBQLLX3L.mjs.map → sandbox-OKITI7WW.mjs.map} +0 -0
package/dist/desktop.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.4-a1";
|
|
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,
|
|
@@ -3143,11 +3142,14 @@ var init_secret = __esm({
|
|
|
3143
3142
|
|
|
3144
3143
|
// src/core/sandbox/sandboxApi.ts
|
|
3145
3144
|
async function createRawApiError(response) {
|
|
3146
|
-
var _a3;
|
|
3145
|
+
var _a3, _b, _c;
|
|
3147
3146
|
let message = response.statusText;
|
|
3148
3147
|
try {
|
|
3149
3148
|
const body = await response.json();
|
|
3150
3149
|
message = (_a3 = body == null ? void 0 : body.message) != null ? _a3 : JSON.stringify(body);
|
|
3150
|
+
if ((body == null ? void 0 : body.item) || (body == null ? void 0 : body.reason)) {
|
|
3151
|
+
message = `${(_b = body.item) != null ? _b : "request"}: ${(_c = body.reason) != null ? _c : "error"}: ${message}`;
|
|
3152
|
+
}
|
|
3151
3153
|
} catch (e) {
|
|
3152
3154
|
try {
|
|
3153
3155
|
message = await response.text();
|
|
@@ -3169,6 +3171,50 @@ async function createRawApiError(response) {
|
|
|
3169
3171
|
function getRawApiHeaders(config, headers) {
|
|
3170
3172
|
return __spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues({}, defaultHeaders), config.apiKey ? { "X-API-KEY": config.apiKey } : {}), config.accessToken ? { Authorization: `Bearer ${config.accessToken}` } : {}), config.headers), headers != null ? headers : {});
|
|
3171
3173
|
}
|
|
3174
|
+
function gibToMib(value, name) {
|
|
3175
|
+
if (!Number.isFinite(value) || value <= 0) {
|
|
3176
|
+
throw new SandboxError(`resource target ${name} must be a positive number`);
|
|
3177
|
+
}
|
|
3178
|
+
const mib = value * MIB_PER_GIB;
|
|
3179
|
+
if (!Number.isSafeInteger(mib)) {
|
|
3180
|
+
throw new SandboxError(`resource target ${name} must be an exact number of MiB`);
|
|
3181
|
+
}
|
|
3182
|
+
return mib;
|
|
3183
|
+
}
|
|
3184
|
+
function resourceTargetsToApi(resources) {
|
|
3185
|
+
const unknown = Object.keys(resources != null ? resources : {}).filter(
|
|
3186
|
+
(key) => !["cpu", "memoryGiB", "diskGiB"].includes(key)
|
|
3187
|
+
);
|
|
3188
|
+
if (unknown.length) throw new SandboxError(`unsupported resource field: ${unknown.join(", ")}`);
|
|
3189
|
+
const body = {};
|
|
3190
|
+
const { cpu, memoryGiB, diskGiB } = resources != null ? resources : {};
|
|
3191
|
+
if (cpu !== void 0) {
|
|
3192
|
+
if (!Number.isSafeInteger(cpu) || cpu <= 0) {
|
|
3193
|
+
throw new SandboxError("resource target cpu must be a positive whole number");
|
|
3194
|
+
}
|
|
3195
|
+
body.vcpu = cpu;
|
|
3196
|
+
}
|
|
3197
|
+
if (memoryGiB !== void 0) body.memory_mb = gibToMib(memoryGiB, "memoryGiB");
|
|
3198
|
+
if (diskGiB !== void 0) body.disk_size_mb = gibToMib(diskGiB, "diskGiB");
|
|
3199
|
+
if (!Object.keys(body).length) throw new SandboxError("at least one resource target is required");
|
|
3200
|
+
return body;
|
|
3201
|
+
}
|
|
3202
|
+
function resizeResultFromApi(data) {
|
|
3203
|
+
var _a3, _b, _c;
|
|
3204
|
+
const result = {};
|
|
3205
|
+
for (const key of ["cpu", "memory", "disk"]) {
|
|
3206
|
+
const item = data == null ? void 0 : data[key];
|
|
3207
|
+
if (!item) continue;
|
|
3208
|
+
const divisor = key === "cpu" ? 1 : 1024;
|
|
3209
|
+
result[key] = __spreadProps(__spreadValues({}, item), {
|
|
3210
|
+
requested: ((_a3 = item.requested) != null ? _a3 : 0) / divisor,
|
|
3211
|
+
previous: ((_b = item.previous) != null ? _b : 0) / divisor,
|
|
3212
|
+
current: ((_c = item.current) != null ? _c : 0) / divisor,
|
|
3213
|
+
unit: key === "cpu" ? "cores" : "GiB"
|
|
3214
|
+
});
|
|
3215
|
+
}
|
|
3216
|
+
return result;
|
|
3217
|
+
}
|
|
3172
3218
|
function getLifecycle(opts) {
|
|
3173
3219
|
if (opts == null ? void 0 : opts.lifecycle) {
|
|
3174
3220
|
return opts.lifecycle;
|
|
@@ -3184,7 +3230,7 @@ function getLifecycle(opts) {
|
|
|
3184
3230
|
autoResume: false
|
|
3185
3231
|
};
|
|
3186
3232
|
}
|
|
3187
|
-
var import_compare_versions4, SandboxApi, BasePaginator, SandboxPaginator, SnapshotPaginator;
|
|
3233
|
+
var import_compare_versions4, MIB_PER_GIB, SandboxApi, BasePaginator, SandboxPaginator, SnapshotPaginator;
|
|
3188
3234
|
var init_sandboxApi = __esm({
|
|
3189
3235
|
"src/core/sandbox/sandboxApi.ts"() {
|
|
3190
3236
|
"use strict";
|
|
@@ -3195,6 +3241,7 @@ var init_sandboxApi = __esm({
|
|
|
3195
3241
|
init_utils();
|
|
3196
3242
|
init_metadata();
|
|
3197
3243
|
init_secret();
|
|
3244
|
+
MIB_PER_GIB = 1024;
|
|
3198
3245
|
SandboxApi = class {
|
|
3199
3246
|
constructor() {
|
|
3200
3247
|
}
|
|
@@ -3377,28 +3424,24 @@ var init_sandboxApi = __esm({
|
|
|
3377
3424
|
templateType: "snapshot_template"
|
|
3378
3425
|
};
|
|
3379
3426
|
}
|
|
3380
|
-
static async
|
|
3427
|
+
static async resize(sandboxId, resources, opts) {
|
|
3428
|
+
const body = resourceTargetsToApi(resources);
|
|
3381
3429
|
const config = new ConnectionConfig(opts);
|
|
3382
|
-
raiseIfLegacy(config, "Sandbox.
|
|
3430
|
+
raiseIfLegacy(config, "Sandbox.resize", SandboxError);
|
|
3383
3431
|
const response = await fetch(
|
|
3384
|
-
`${config.apiUrl}/sandboxes/${encodeURIComponent(sandboxId)}/
|
|
3432
|
+
`${config.apiUrl}/sandboxes/${encodeURIComponent(sandboxId)}/resize`,
|
|
3385
3433
|
{
|
|
3386
3434
|
method: "POST",
|
|
3387
|
-
headers: getRawApiHeaders(config, {
|
|
3388
|
-
|
|
3389
|
-
}),
|
|
3390
|
-
body: JSON.stringify({
|
|
3391
|
-
requested_size_mib: requestedSizeMib
|
|
3392
|
-
}),
|
|
3435
|
+
headers: getRawApiHeaders(config, { "Content-Type": "application/json" }),
|
|
3436
|
+
body: JSON.stringify(body),
|
|
3393
3437
|
signal: config.getSignal(opts == null ? void 0 : opts.requestTimeoutMs)
|
|
3394
3438
|
}
|
|
3395
3439
|
);
|
|
3396
3440
|
if (response.status === 404) {
|
|
3397
3441
|
throw new SandboxNotFoundError(`Sandbox ${sandboxId} not found`);
|
|
3398
3442
|
}
|
|
3399
|
-
if (!response.ok)
|
|
3400
|
-
|
|
3401
|
-
}
|
|
3443
|
+
if (!response.ok) throw await createRawApiError(response);
|
|
3444
|
+
return resizeResultFromApi(await response.json());
|
|
3402
3445
|
}
|
|
3403
3446
|
static async reset(sandboxId, opts) {
|
|
3404
3447
|
var _a3;
|
|
@@ -3437,7 +3480,7 @@ var init_sandboxApi = __esm({
|
|
|
3437
3480
|
}
|
|
3438
3481
|
return true;
|
|
3439
3482
|
}
|
|
3440
|
-
static async mountVolume(sandboxId, name,
|
|
3483
|
+
static async mountVolume(sandboxId, name, path3, opts) {
|
|
3441
3484
|
var _a3, _b;
|
|
3442
3485
|
const config = new ConnectionConfig(opts);
|
|
3443
3486
|
raiseIfLegacy(config, "Sandbox.mountVolume", SandboxError);
|
|
@@ -3448,7 +3491,7 @@ var init_sandboxApi = __esm({
|
|
|
3448
3491
|
headers: getRawApiHeaders(config, {
|
|
3449
3492
|
"Content-Type": "application/json"
|
|
3450
3493
|
}),
|
|
3451
|
-
body: JSON.stringify({ name, path:
|
|
3494
|
+
body: JSON.stringify({ name, path: path3 }),
|
|
3452
3495
|
signal: config.getSignal(opts == null ? void 0 : opts.requestTimeoutMs)
|
|
3453
3496
|
}
|
|
3454
3497
|
);
|
|
@@ -3473,14 +3516,14 @@ var init_sandboxApi = __esm({
|
|
|
3473
3516
|
volumeMounts: (_b = data.volumeMounts) != null ? _b : []
|
|
3474
3517
|
};
|
|
3475
3518
|
}
|
|
3476
|
-
static async unmountVolume(sandboxId,
|
|
3519
|
+
static async unmountVolume(sandboxId, path3, opts) {
|
|
3477
3520
|
var _a3, _b;
|
|
3478
3521
|
const config = new ConnectionConfig(opts);
|
|
3479
3522
|
raiseIfLegacy(config, "Sandbox.unmountVolume", SandboxError);
|
|
3480
3523
|
const url = new URL(
|
|
3481
3524
|
`${config.apiUrl}/sandboxes/${encodeURIComponent(sandboxId)}/volume-mounts`
|
|
3482
3525
|
);
|
|
3483
|
-
url.searchParams.set("path",
|
|
3526
|
+
url.searchParams.set("path", path3);
|
|
3484
3527
|
if (opts == null ? void 0 : opts.force) {
|
|
3485
3528
|
url.searchParams.set("force", "true");
|
|
3486
3529
|
}
|
|
@@ -3496,7 +3539,7 @@ var init_sandboxApi = __esm({
|
|
|
3496
3539
|
throw await createRawApiError(response);
|
|
3497
3540
|
}
|
|
3498
3541
|
const data = await response.json();
|
|
3499
|
-
return {
|
|
3542
|
+
return __spreadProps(__spreadValues({
|
|
3500
3543
|
sandboxId: data.sandboxID,
|
|
3501
3544
|
templateId: data.templateID,
|
|
3502
3545
|
name: data.name,
|
|
@@ -3505,10 +3548,11 @@ var init_sandboxApi = __esm({
|
|
|
3505
3548
|
endAt: new Date(data.endAt),
|
|
3506
3549
|
state: data.state,
|
|
3507
3550
|
cpuCount: data.cpuCount,
|
|
3508
|
-
memoryMB: data.memoryMB
|
|
3551
|
+
memoryMB: data.memoryMB
|
|
3552
|
+
}, data.diskSizeMB !== void 0 ? { diskSizeMB: data.diskSizeMB } : {}), {
|
|
3509
3553
|
envdVersion: data.envdVersion,
|
|
3510
3554
|
volumeMounts: (_b = data.volumeMounts) != null ? _b : []
|
|
3511
|
-
};
|
|
3555
|
+
});
|
|
3512
3556
|
}
|
|
3513
3557
|
static async setNetwork(sandboxId, opts) {
|
|
3514
3558
|
const config = new ConnectionConfig(opts);
|
|
@@ -3622,6 +3666,7 @@ var init_sandboxApi = __esm({
|
|
|
3622
3666
|
state: res.data.state,
|
|
3623
3667
|
cpuCount: res.data.cpuCount,
|
|
3624
3668
|
memoryMB: res.data.memoryMB,
|
|
3669
|
+
diskSizeMB: res.data.diskSizeMB,
|
|
3625
3670
|
network: res.data.network ? {
|
|
3626
3671
|
allowOut: res.data.network.allowOut,
|
|
3627
3672
|
denyOut: res.data.network.denyOut,
|
|
@@ -3774,17 +3819,25 @@ var init_sandboxApi = __esm({
|
|
|
3774
3819
|
return true;
|
|
3775
3820
|
}
|
|
3776
3821
|
static async createSandbox(template, timeoutMs, opts) {
|
|
3777
|
-
var _a3, _b, _c, _d, _e, _f;
|
|
3822
|
+
var _a3, _b, _c, _d, _e, _f, _g, _h;
|
|
3778
3823
|
const config = new ConnectionConfig(opts);
|
|
3824
|
+
const longRunning = ((_a3 = opts == null ? void 0 : opts.metadata) == null ? void 0 : _a3.long_running) === "true";
|
|
3825
|
+
const metadata = longRunning ? __spreadValues({}, opts == null ? void 0 : opts.metadata) : opts == null ? void 0 : opts.metadata;
|
|
3826
|
+
const timeout = longRunning ? void 0 : timeoutToSeconds(timeoutMs);
|
|
3779
3827
|
const lifecycle = getLifecycle(opts);
|
|
3780
3828
|
const autoPause = lifecycle.onTimeout === "pause";
|
|
3781
|
-
const autoResumeEnabled = lifecycle.onTimeout === "pause" ? (
|
|
3829
|
+
const autoResumeEnabled = lifecycle.onTimeout === "pause" ? (_b = lifecycle.autoResume) != null ? _b : false : void 0;
|
|
3782
3830
|
if (config.isLegacyDomain) {
|
|
3783
3831
|
if (opts == null ? void 0 : opts.mcp) {
|
|
3784
3832
|
raiseIfLegacy(config, "Sandbox.create mcp", SandboxError);
|
|
3785
3833
|
}
|
|
3786
|
-
|
|
3787
|
-
|
|
3834
|
+
const unsupportedNetworkOptions = Object.keys((_c = opts == null ? void 0 : opts.network) != null ? _c : {}).filter(
|
|
3835
|
+
(key) => key !== "allowPublicTraffic"
|
|
3836
|
+
);
|
|
3837
|
+
if (unsupportedNetworkOptions.length > 0) {
|
|
3838
|
+
throw new SandboxError(
|
|
3839
|
+
`Sandbox.create network only supports allowPublicTraffic on legacy domains; unsupported options: ${unsupportedNetworkOptions.join(", ")}`
|
|
3840
|
+
);
|
|
3788
3841
|
}
|
|
3789
3842
|
if (opts == null ? void 0 : opts.volumeMounts) {
|
|
3790
3843
|
raiseIfLegacy(config, "Sandbox.create volumeMounts", SandboxError);
|
|
@@ -3792,14 +3845,17 @@ var init_sandboxApi = __esm({
|
|
|
3792
3845
|
if (opts == null ? void 0 : opts.secretEnvs) {
|
|
3793
3846
|
raiseIfLegacy(config, "Sandbox.create secretEnvs", SandboxError);
|
|
3794
3847
|
}
|
|
3795
|
-
|
|
3848
|
+
if (opts == null ? void 0 : opts.resources) {
|
|
3849
|
+
raiseIfLegacy(config, "Sandbox.create resources", SandboxError);
|
|
3850
|
+
}
|
|
3851
|
+
const body2 = __spreadValues(__spreadValues({
|
|
3796
3852
|
templateID: template,
|
|
3797
|
-
timeout
|
|
3798
|
-
metadata:
|
|
3799
|
-
envVars: (
|
|
3800
|
-
secure: (
|
|
3853
|
+
timeout,
|
|
3854
|
+
metadata: metadata != null ? metadata : {},
|
|
3855
|
+
envVars: (_d = opts == null ? void 0 : opts.envs) != null ? _d : {},
|
|
3856
|
+
secure: (_e = opts == null ? void 0 : opts.secure) != null ? _e : false,
|
|
3801
3857
|
autoPause: autoPause != null ? autoPause : false
|
|
3802
|
-
}, (opts == null ? void 0 : opts.nodeId) ? { nodeID: opts.nodeId } : {});
|
|
3858
|
+
}, (opts == null ? void 0 : opts.network) ? { network: opts.network } : {}), (opts == null ? void 0 : opts.nodeId) ? { nodeID: opts.nodeId } : {});
|
|
3803
3859
|
const response = await fetch(`${config.apiUrl}/sandboxes`, {
|
|
3804
3860
|
method: "POST",
|
|
3805
3861
|
headers: getRawApiHeaders(config, {
|
|
@@ -3823,18 +3879,18 @@ var init_sandboxApi = __esm({
|
|
|
3823
3879
|
sandboxDomain: data.domain || void 0,
|
|
3824
3880
|
envdVersion: data.envdVersion,
|
|
3825
3881
|
envdAccessToken: data.envdAccessToken,
|
|
3826
|
-
trafficAccessToken: void 0
|
|
3882
|
+
trafficAccessToken: data.trafficAccessToken || void 0
|
|
3827
3883
|
};
|
|
3828
3884
|
}
|
|
3829
3885
|
const client = new ApiClient(config);
|
|
3830
3886
|
const body = __spreadValues(__spreadValues(__spreadValues({
|
|
3831
3887
|
templateID: template,
|
|
3832
|
-
metadata
|
|
3888
|
+
metadata,
|
|
3833
3889
|
mcp: opts == null ? void 0 : opts.mcp,
|
|
3834
3890
|
envVars: opts == null ? void 0 : opts.envs,
|
|
3835
|
-
timeout
|
|
3836
|
-
secure: (
|
|
3837
|
-
allow_internet_access: (
|
|
3891
|
+
timeout,
|
|
3892
|
+
secure: (_f = opts == null ? void 0 : opts.secure) != null ? _f : true,
|
|
3893
|
+
allow_internet_access: (_g = opts == null ? void 0 : opts.allowInternetAccess) != null ? _g : true,
|
|
3838
3894
|
network: opts == null ? void 0 : opts.network
|
|
3839
3895
|
}, (opts == null ? void 0 : opts.nodeId) ? { nodeID: opts.nodeId } : {}), autoPause !== void 0 ? { autoPause } : {}), autoResumeEnabled !== void 0 ? { autoResume: { enabled: autoResumeEnabled } } : {});
|
|
3840
3896
|
if (opts == null ? void 0 : opts.volumeMounts) {
|
|
@@ -3853,6 +3909,30 @@ var init_sandboxApi = __esm({
|
|
|
3853
3909
|
;
|
|
3854
3910
|
body.secrets = validatedSecretEnvs;
|
|
3855
3911
|
}
|
|
3912
|
+
if (opts == null ? void 0 : opts.resources) {
|
|
3913
|
+
const targets = resourceTargetsToApi(opts.resources);
|
|
3914
|
+
const response = await fetch(`${config.apiUrl}/sandboxes/custom`, {
|
|
3915
|
+
method: "POST",
|
|
3916
|
+
headers: getRawApiHeaders(config, { "Content-Type": "application/json" }),
|
|
3917
|
+
body: JSON.stringify(__spreadProps(__spreadValues({}, body), { resources: targets })),
|
|
3918
|
+
signal: config.getSignal((_h = opts == null ? void 0 : opts.requestTimeoutMs) != null ? _h : 36e4)
|
|
3919
|
+
});
|
|
3920
|
+
if (!response.ok) throw await createRawApiError(response);
|
|
3921
|
+
const data = await response.json();
|
|
3922
|
+
if ((0, import_compare_versions4.compareVersions)(data.envdVersion, "0.1.0") < 0) {
|
|
3923
|
+
await this.kill(data.sandboxID, opts);
|
|
3924
|
+
throw new TemplateError(
|
|
3925
|
+
"You need to update the template to use the new SDK. You can do this by running `ppio template build` in the directory with the template."
|
|
3926
|
+
);
|
|
3927
|
+
}
|
|
3928
|
+
return {
|
|
3929
|
+
sandboxId: data.sandboxID,
|
|
3930
|
+
sandboxDomain: data.domain || void 0,
|
|
3931
|
+
envdVersion: data.envdVersion,
|
|
3932
|
+
envdAccessToken: data.envdAccessToken,
|
|
3933
|
+
trafficAccessToken: data.trafficAccessToken || void 0
|
|
3934
|
+
};
|
|
3935
|
+
}
|
|
3856
3936
|
const res = await client.api.POST("/sandboxes", {
|
|
3857
3937
|
body,
|
|
3858
3938
|
signal: config.getSignal(opts == null ? void 0 : opts.requestTimeoutMs)
|
|
@@ -3887,7 +3967,9 @@ var init_sandboxApi = __esm({
|
|
|
3887
3967
|
headers: getRawApiHeaders(config, {
|
|
3888
3968
|
"Content-Type": "application/json"
|
|
3889
3969
|
}),
|
|
3890
|
-
body: JSON.stringify({
|
|
3970
|
+
body: JSON.stringify(__spreadValues(__spreadValues(__spreadValues({
|
|
3971
|
+
timeout: timeoutToSeconds(timeoutMs)
|
|
3972
|
+
}, (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
3973
|
signal: config.getSignal(opts == null ? void 0 : opts.requestTimeoutMs)
|
|
3892
3974
|
}
|
|
3893
3975
|
);
|
|
@@ -3903,7 +3985,7 @@ var init_sandboxApi = __esm({
|
|
|
3903
3985
|
sandboxDomain: data.domain || void 0,
|
|
3904
3986
|
envdVersion: data.envdVersion || "0.0.0",
|
|
3905
3987
|
envdAccessToken: data.envdAccessToken,
|
|
3906
|
-
trafficAccessToken: void 0
|
|
3988
|
+
trafficAccessToken: data.trafficAccessToken || void 0
|
|
3907
3989
|
};
|
|
3908
3990
|
}
|
|
3909
3991
|
const client = new ApiClient(config);
|
|
@@ -4162,7 +4244,7 @@ var init_sandboxApi = __esm({
|
|
|
4162
4244
|
|
|
4163
4245
|
// src/core/sandbox/signature.ts
|
|
4164
4246
|
async function getSignature({
|
|
4165
|
-
path:
|
|
4247
|
+
path: path3,
|
|
4166
4248
|
operation,
|
|
4167
4249
|
user,
|
|
4168
4250
|
expirationInSeconds,
|
|
@@ -4179,9 +4261,9 @@ async function getSignature({
|
|
|
4179
4261
|
user = "";
|
|
4180
4262
|
}
|
|
4181
4263
|
if (signatureExpiration === null) {
|
|
4182
|
-
signatureRaw = `${
|
|
4264
|
+
signatureRaw = `${path3}:${operation}:${user}:${envdAccessToken}`;
|
|
4183
4265
|
} else {
|
|
4184
|
-
signatureRaw = `${
|
|
4266
|
+
signatureRaw = `${path3}:${operation}:${user}:${envdAccessToken}:${signatureExpiration.toString()}`;
|
|
4185
4267
|
}
|
|
4186
4268
|
const hashBase64 = await sha256(signatureRaw);
|
|
4187
4269
|
const signature = "v1_" + hashBase64.replace(/=+$/, "");
|
|
@@ -4364,19 +4446,6 @@ var init_sandbox = __esm({
|
|
|
4364
4446
|
snapshotTemplateId: cloneResult.snapshotTemplateId
|
|
4365
4447
|
};
|
|
4366
4448
|
}
|
|
4367
|
-
/**
|
|
4368
|
-
* Dynamically adjust the hotplugged memory on a running sandbox.
|
|
4369
|
-
*
|
|
4370
|
-
* The value represents the new *total* plugged size in MiB, not a delta.
|
|
4371
|
-
* Use `0` to unplug all hotplugged memory.
|
|
4372
|
-
*/
|
|
4373
|
-
static async hotplugMemory(sandboxId, requestedSizeMib, opts) {
|
|
4374
|
-
return await SandboxApi.hotplugMemory(
|
|
4375
|
-
sandboxId,
|
|
4376
|
-
requestedSizeMib,
|
|
4377
|
-
opts
|
|
4378
|
-
);
|
|
4379
|
-
}
|
|
4380
4449
|
/**
|
|
4381
4450
|
* Mount a volume to a sandbox.
|
|
4382
4451
|
*
|
|
@@ -4387,8 +4456,12 @@ var init_sandbox = __esm({
|
|
|
4387
4456
|
*
|
|
4388
4457
|
* @returns updated sandbox information.
|
|
4389
4458
|
*/
|
|
4390
|
-
|
|
4391
|
-
|
|
4459
|
+
/** Increase running sandbox resources to absolute CPU and GiB targets. */
|
|
4460
|
+
static async resize(sandboxId, resources, opts) {
|
|
4461
|
+
return await SandboxApi.resize(sandboxId, resources, opts);
|
|
4462
|
+
}
|
|
4463
|
+
static async mountVolume(sandboxId, name, path3, opts) {
|
|
4464
|
+
return await SandboxApi.mountVolume(sandboxId, name, path3, opts);
|
|
4392
4465
|
}
|
|
4393
4466
|
/**
|
|
4394
4467
|
* Unmount a volume from a sandbox.
|
|
@@ -4400,8 +4473,8 @@ var init_sandbox = __esm({
|
|
|
4400
4473
|
*
|
|
4401
4474
|
* @returns updated sandbox information.
|
|
4402
4475
|
*/
|
|
4403
|
-
static async unmountVolume(sandboxId,
|
|
4404
|
-
return await SandboxApi.unmountVolume(sandboxId,
|
|
4476
|
+
static async unmountVolume(sandboxId, path3, opts) {
|
|
4477
|
+
return await SandboxApi.unmountVolume(sandboxId, path3, opts);
|
|
4405
4478
|
}
|
|
4406
4479
|
/**
|
|
4407
4480
|
* Commit a sandbox to create a snapshot template.
|
|
@@ -4636,11 +4709,11 @@ var init_sandbox = __esm({
|
|
|
4636
4709
|
*
|
|
4637
4710
|
* @returns updated sandbox information.
|
|
4638
4711
|
*/
|
|
4639
|
-
async mountVolume(name,
|
|
4712
|
+
async mountVolume(name, path3, opts) {
|
|
4640
4713
|
return await SandboxApi.mountVolume(
|
|
4641
4714
|
this.sandboxId,
|
|
4642
4715
|
name,
|
|
4643
|
-
|
|
4716
|
+
path3,
|
|
4644
4717
|
this.resolveApiOpts(opts)
|
|
4645
4718
|
);
|
|
4646
4719
|
}
|
|
@@ -4653,10 +4726,10 @@ var init_sandbox = __esm({
|
|
|
4653
4726
|
*
|
|
4654
4727
|
* @returns updated sandbox information.
|
|
4655
4728
|
*/
|
|
4656
|
-
async unmountVolume(
|
|
4729
|
+
async unmountVolume(path3, opts) {
|
|
4657
4730
|
return await SandboxApi.unmountVolume(
|
|
4658
4731
|
this.sandboxId,
|
|
4659
|
-
|
|
4732
|
+
path3,
|
|
4660
4733
|
this.resolveApiOpts(opts)
|
|
4661
4734
|
);
|
|
4662
4735
|
}
|
|
@@ -4671,21 +4744,9 @@ var init_sandbox = __esm({
|
|
|
4671
4744
|
}
|
|
4672
4745
|
await SandboxApi.kill(this.sandboxId, this.resolveApiOpts(opts));
|
|
4673
4746
|
}
|
|
4674
|
-
/**
|
|
4675
|
-
|
|
4676
|
-
|
|
4677
|
-
* The value represents the new *total* plugged size in MiB, not a delta.
|
|
4678
|
-
* Use `0` to unplug all hotplugged memory.
|
|
4679
|
-
*
|
|
4680
|
-
* @param requestedSizeMib new total plugged memory size in MiB.
|
|
4681
|
-
* @param opts connection options.
|
|
4682
|
-
*/
|
|
4683
|
-
async hotplugMemory(requestedSizeMib, opts) {
|
|
4684
|
-
await SandboxApi.hotplugMemory(
|
|
4685
|
-
this.sandboxId,
|
|
4686
|
-
requestedSizeMib,
|
|
4687
|
-
this.resolveApiOpts(opts)
|
|
4688
|
-
);
|
|
4747
|
+
/** Increase this sandbox's resources to absolute CPU and GiB targets. */
|
|
4748
|
+
async resize(resources, opts) {
|
|
4749
|
+
return await SandboxApi.resize(this.sandboxId, resources, this.resolveApiOpts(opts));
|
|
4689
4750
|
}
|
|
4690
4751
|
/**
|
|
4691
4752
|
* Pause a sandbox by its ID.
|
|
@@ -4790,7 +4851,7 @@ var init_sandbox = __esm({
|
|
|
4790
4851
|
*
|
|
4791
4852
|
* @returns URL for uploading file.
|
|
4792
4853
|
*/
|
|
4793
|
-
async uploadUrl(
|
|
4854
|
+
async uploadUrl(path3, opts) {
|
|
4794
4855
|
opts = opts != null ? opts : {};
|
|
4795
4856
|
const useSignature = !!this.envdAccessToken;
|
|
4796
4857
|
if (!useSignature && opts.useSignatureExpiration != void 0) {
|
|
@@ -4802,7 +4863,7 @@ var init_sandbox = __esm({
|
|
|
4802
4863
|
if (username == void 0 && (0, import_compare_versions5.compareVersions)(this.envdApi.version, ENVD_DEFAULT_USER) < 0) {
|
|
4803
4864
|
username = defaultUsername;
|
|
4804
4865
|
}
|
|
4805
|
-
const filePath =
|
|
4866
|
+
const filePath = path3 != null ? path3 : "";
|
|
4806
4867
|
const fileUrl = this.fileUrl(filePath, username);
|
|
4807
4868
|
if (useSignature) {
|
|
4808
4869
|
const url = new URL(fileUrl);
|
|
@@ -4830,7 +4891,7 @@ var init_sandbox = __esm({
|
|
|
4830
4891
|
*
|
|
4831
4892
|
* @returns URL for downloading file.
|
|
4832
4893
|
*/
|
|
4833
|
-
async downloadUrl(
|
|
4894
|
+
async downloadUrl(path3, opts) {
|
|
4834
4895
|
opts = opts != null ? opts : {};
|
|
4835
4896
|
const useSignature = !!this.envdAccessToken;
|
|
4836
4897
|
if (!useSignature && opts.useSignatureExpiration != void 0) {
|
|
@@ -4842,11 +4903,11 @@ var init_sandbox = __esm({
|
|
|
4842
4903
|
if (username == void 0 && (0, import_compare_versions5.compareVersions)(this.envdApi.version, ENVD_DEFAULT_USER) < 0) {
|
|
4843
4904
|
username = defaultUsername;
|
|
4844
4905
|
}
|
|
4845
|
-
const fileUrl = this.fileUrl(
|
|
4906
|
+
const fileUrl = this.fileUrl(path3, username);
|
|
4846
4907
|
if (useSignature) {
|
|
4847
4908
|
const url = new URL(fileUrl);
|
|
4848
4909
|
const sig = await getSignature({
|
|
4849
|
-
path:
|
|
4910
|
+
path: path3,
|
|
4850
4911
|
operation: "read",
|
|
4851
4912
|
user: username,
|
|
4852
4913
|
expirationInSeconds: opts.useSignatureExpiration,
|
|
@@ -4900,13 +4961,13 @@ var init_sandbox = __esm({
|
|
|
4900
4961
|
resolveApiOpts(opts) {
|
|
4901
4962
|
return __spreadValues(__spreadValues({}, this.connectionConfig), opts != null ? opts : {});
|
|
4902
4963
|
}
|
|
4903
|
-
fileUrl(
|
|
4964
|
+
fileUrl(path3, username) {
|
|
4904
4965
|
const url = new URL("/files", this.envdApiUrl);
|
|
4905
4966
|
if (username) {
|
|
4906
4967
|
url.searchParams.set("username", username);
|
|
4907
4968
|
}
|
|
4908
|
-
if (
|
|
4909
|
-
url.searchParams.set("path",
|
|
4969
|
+
if (path3) {
|
|
4970
|
+
url.searchParams.set("path", path3);
|
|
4910
4971
|
}
|
|
4911
4972
|
return url.toString();
|
|
4912
4973
|
}
|
|
@@ -5097,8 +5158,8 @@ function readDockerignore(contextPath) {
|
|
|
5097
5158
|
const content = import_node_fs.default.readFileSync(dockerignorePath, "utf-8");
|
|
5098
5159
|
return content.split("\n").map((line) => line.trim()).filter((line) => line && !line.startsWith("#"));
|
|
5099
5160
|
}
|
|
5100
|
-
function normalizePath(
|
|
5101
|
-
return
|
|
5161
|
+
function normalizePath(path3) {
|
|
5162
|
+
return path3.replace(/\\/g, "/");
|
|
5102
5163
|
}
|
|
5103
5164
|
async function getAllFilesInPath(src, contextPath, ignorePatterns, includeDirectories = true) {
|
|
5104
5165
|
const { glob } = await dynamicImport("glob");
|
|
@@ -5210,8 +5271,7 @@ function getCallerDirectory(depth) {
|
|
|
5210
5271
|
return void 0;
|
|
5211
5272
|
}
|
|
5212
5273
|
if (fileName.startsWith("file:")) {
|
|
5213
|
-
|
|
5214
|
-
fileName = fileURLToPath(fileName);
|
|
5274
|
+
fileName = (0, import_node_url.fileURLToPath)(fileName);
|
|
5215
5275
|
}
|
|
5216
5276
|
return import_node_path.default.dirname(fileName);
|
|
5217
5277
|
}
|
|
@@ -5260,13 +5320,14 @@ function readGCPServiceAccountJSON(contextPath, pathOrContent) {
|
|
|
5260
5320
|
}
|
|
5261
5321
|
return JSON.stringify(pathOrContent);
|
|
5262
5322
|
}
|
|
5263
|
-
var import_node_crypto, import_node_fs, import_node_path;
|
|
5323
|
+
var import_node_crypto, import_node_fs, import_node_path, import_node_url;
|
|
5264
5324
|
var init_utils3 = __esm({
|
|
5265
5325
|
"src/core/template/utils.ts"() {
|
|
5266
5326
|
"use strict";
|
|
5267
5327
|
import_node_crypto = __toESM(require("crypto"));
|
|
5268
5328
|
import_node_fs = __toESM(require("fs"));
|
|
5269
5329
|
import_node_path = __toESM(require("path"));
|
|
5330
|
+
import_node_url = require("url");
|
|
5270
5331
|
init_utils();
|
|
5271
5332
|
init_errors();
|
|
5272
5333
|
init_consts();
|
|
@@ -5693,54 +5754,15 @@ function handleUserInstruction(instruction, templateBuilder) {
|
|
|
5693
5754
|
}
|
|
5694
5755
|
}
|
|
5695
5756
|
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
|
-
}
|
|
5757
|
+
var _a3;
|
|
5758
|
+
const envVars = {};
|
|
5759
|
+
for (const property of instruction.getProperties()) {
|
|
5760
|
+
envVars[property.getName()] = (_a3 = property.getValue()) != null ? _a3 : "";
|
|
5761
|
+
}
|
|
5762
|
+
if (Object.keys(envVars).length) {
|
|
5763
|
+
templateBuilder.setEnvs(envVars, {
|
|
5764
|
+
runtime: instruction.getKeyword() === "ENV"
|
|
5765
|
+
});
|
|
5744
5766
|
}
|
|
5745
5767
|
}
|
|
5746
5768
|
function handleCmdEntrypointInstruction(instruction, templateBuilder) {
|
|
@@ -5787,61 +5809,120 @@ function expandableDoubleQuote(value) {
|
|
|
5787
5809
|
const escaped = value.split("\\").join("\\\\").split('"').join('\\"').split("`").join("\\`").replace(/\$\(/g, "\\$(");
|
|
5788
5810
|
return `"${escaped}"`;
|
|
5789
5811
|
}
|
|
5790
|
-
function envFilesScript(envs) {
|
|
5791
|
-
const
|
|
5792
|
-
|
|
5793
|
-
|
|
5794
|
-
|
|
5795
|
-
|
|
5796
|
-
|
|
5812
|
+
function envFilesScript(envs, literalEnvs = {}, envGroups, baseEnvPath) {
|
|
5813
|
+
const groups = envGroups != null ? envGroups : Object.entries(envs).map(([name, value]) => ({
|
|
5814
|
+
values: { [name]: value },
|
|
5815
|
+
runtime: true
|
|
5816
|
+
}));
|
|
5817
|
+
const lines = String.raw`set -e
|
|
5818
|
+
${baseEnvPath ? ". " + shellQuote2(baseEnvPath) : ":"}
|
|
5819
|
+
${baseEnvPath ? "command -p rm -f " + shellQuote2(baseEnvPath) : ":"}
|
|
5820
|
+
if [ -f "${PROFILE_PATH}" ]; then . "${PROFILE_PATH}"; fi
|
|
5821
|
+
command -p touch "${PROFILE_PATH}" "${ENVIRONMENT_PATH}"
|
|
5822
|
+
__ppio_build_env() {
|
|
5823
|
+
while [ "$#" -gt 0 ]; do export "$1=$2"; shift 2; done
|
|
5824
|
+
}
|
|
5825
|
+
__ppio_runtime_env() {
|
|
5826
|
+
while [ "$#" -gt 0 ]; do
|
|
5827
|
+
export "$1=$2"
|
|
5828
|
+
printf "export %s='" "$1" >> ${PROFILE_PATH}
|
|
5829
|
+
printf '%s' "$2" | command -p sed "s/'/'\\\\''/g" >> ${PROFILE_PATH}
|
|
5830
|
+
printf "'\n" >> ${PROFILE_PATH}
|
|
5831
|
+
command -p sed "/^$1=/d" ${ENVIRONMENT_PATH} > ${ENVIRONMENT_PATH}.tmp
|
|
5832
|
+
command -p cat ${ENVIRONMENT_PATH}.tmp > ${ENVIRONMENT_PATH}
|
|
5833
|
+
command -p rm -f ${ENVIRONMENT_PATH}.tmp
|
|
5834
|
+
case "$2" in
|
|
5835
|
+
*'"'*) ;;
|
|
5836
|
+
*) if [ "$(printf '%s' "$2" | command -p wc -l)" -eq 0 ]; then printf '%s=%s\n' "$1" "$2" >> ${ENVIRONMENT_PATH}; fi ;;
|
|
5837
|
+
esac
|
|
5838
|
+
shift 2
|
|
5839
|
+
done
|
|
5840
|
+
}`.split("\n");
|
|
5841
|
+
const quote = (value) => "'" + value.replace(/'/g, "'\\''") + "'";
|
|
5842
|
+
if (Object.keys(literalEnvs).length) {
|
|
5797
5843
|
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"
|
|
5844
|
+
"__ppio_runtime_env " + Object.entries(literalEnvs).map(([name, value]) => `${name} ${quote(value)}`).join(" ")
|
|
5815
5845
|
);
|
|
5816
5846
|
}
|
|
5817
|
-
|
|
5847
|
+
for (const group of groups) {
|
|
5848
|
+
if (!Object.keys(group.values).length) continue;
|
|
5849
|
+
const fn = group.runtime ? "__ppio_runtime_env" : "__ppio_build_env";
|
|
5850
|
+
lines.push(
|
|
5851
|
+
fn + " " + Object.entries(group.values).map(([name, value]) => `${name} ${expandableDoubleQuote(value)}`).join(" ")
|
|
5852
|
+
);
|
|
5853
|
+
}
|
|
5854
|
+
lines.push(`command -p chmod 0644 ${PROFILE_PATH} ${ENVIRONMENT_PATH}`);
|
|
5818
5855
|
return lines.join("\n");
|
|
5819
5856
|
}
|
|
5820
|
-
function envFilesCommand(envs) {
|
|
5821
|
-
const
|
|
5822
|
-
|
|
5823
|
-
|
|
5824
|
-
}
|
|
5825
|
-
const
|
|
5826
|
-
|
|
5857
|
+
function envFilesCommand(envs, literalEnvs = {}, envGroups, baseEnvPath) {
|
|
5858
|
+
const groups = envGroups != null ? envGroups : Object.entries(envs).map(([name, value]) => ({
|
|
5859
|
+
values: { [name]: value },
|
|
5860
|
+
runtime: true
|
|
5861
|
+
}));
|
|
5862
|
+
const names = [
|
|
5863
|
+
.../* @__PURE__ */ new Set([
|
|
5864
|
+
...Object.keys(literalEnvs),
|
|
5865
|
+
...groups.flatMap((group) => Object.keys(group.values))
|
|
5866
|
+
])
|
|
5867
|
+
];
|
|
5868
|
+
const { usable, skipped } = partitionEnvNames(names);
|
|
5869
|
+
const allowed = new Set(usable);
|
|
5870
|
+
const filter = (values) => Object.fromEntries(
|
|
5871
|
+
Object.entries(values).filter(([name]) => allowed.has(name))
|
|
5827
5872
|
);
|
|
5828
|
-
const
|
|
5873
|
+
const literals = filter(literalEnvs);
|
|
5874
|
+
const filtered = groups.map((group) => ({
|
|
5875
|
+
values: filter(group.values),
|
|
5876
|
+
runtime: group.runtime
|
|
5877
|
+
}));
|
|
5878
|
+
if (!Object.keys(literals).length && !filtered.some((group) => group.runtime && Object.keys(group.values).length))
|
|
5879
|
+
return { command: null, skipped };
|
|
5880
|
+
const b64 = Buffer.from(
|
|
5881
|
+
envFilesScript({}, literals, filtered, baseEnvPath),
|
|
5882
|
+
"utf8"
|
|
5883
|
+
).toString("base64");
|
|
5829
5884
|
return {
|
|
5830
5885
|
command: [
|
|
5831
|
-
`echo ${b64} | base64 -d > ${SCRIPT_PATH}`,
|
|
5832
|
-
`sh ${SCRIPT_PATH}`,
|
|
5833
|
-
`rm -f ${SCRIPT_PATH}`
|
|
5886
|
+
`echo ${b64} | command -p base64 -d > ${SCRIPT_PATH}`,
|
|
5887
|
+
`command -p sh ${SCRIPT_PATH}`,
|
|
5888
|
+
`command -p rm -f ${SCRIPT_PATH}`
|
|
5834
5889
|
].join(" && "),
|
|
5835
5890
|
skipped
|
|
5836
5891
|
};
|
|
5837
5892
|
}
|
|
5838
|
-
|
|
5893
|
+
function shellQuote2(value) {
|
|
5894
|
+
return "'" + value.replace(/'/g, "'\\''") + "'";
|
|
5895
|
+
}
|
|
5896
|
+
function envSnapshotCommand(groups) {
|
|
5897
|
+
const { usable } = partitionEnvNames([
|
|
5898
|
+
...new Set(groups.flatMap((group) => Object.keys(group.values)))
|
|
5899
|
+
]);
|
|
5900
|
+
if (!usable.length) return null;
|
|
5901
|
+
const lines = [
|
|
5902
|
+
"set -e",
|
|
5903
|
+
"umask 077",
|
|
5904
|
+
`: > ${BASE_ENV_PATH}`,
|
|
5905
|
+
`command -p chmod 0600 ${BASE_ENV_PATH}`
|
|
5906
|
+
];
|
|
5907
|
+
for (const name of usable) {
|
|
5908
|
+
lines.push(String.raw`if [ "${"${" + name + "+x}"}" = x ]; then
|
|
5909
|
+
printf "export ${name}='" >> ${BASE_ENV_PATH}
|
|
5910
|
+
printf '%s' "${"${" + name + "}"}" | command -p sed "s/'/'\\\\''/g" >> ${BASE_ENV_PATH}
|
|
5911
|
+
printf "'\n" >> ${BASE_ENV_PATH}
|
|
5912
|
+
else
|
|
5913
|
+
printf 'unset ${name}\n' >> ${BASE_ENV_PATH}
|
|
5914
|
+
fi`);
|
|
5915
|
+
}
|
|
5916
|
+
return "command -p sh -c " + shellQuote2(lines.join("\n"));
|
|
5917
|
+
}
|
|
5918
|
+
var PROFILE_PATH, ENVIRONMENT_PATH, SCRIPT_PATH, BASE_ENV_PATH;
|
|
5839
5919
|
var init_envFiles = __esm({
|
|
5840
5920
|
"src/core/template/envFiles.ts"() {
|
|
5841
5921
|
"use strict";
|
|
5842
5922
|
PROFILE_PATH = "/etc/profile.d/99-image-env.sh";
|
|
5843
5923
|
ENVIRONMENT_PATH = "/etc/environment";
|
|
5844
5924
|
SCRIPT_PATH = "/tmp/.ppio-image-env.sh";
|
|
5925
|
+
BASE_ENV_PATH = "/etc/.ppio-image-env-base.sh";
|
|
5845
5926
|
}
|
|
5846
5927
|
});
|
|
5847
5928
|
|
|
@@ -5858,9 +5939,15 @@ function unsupportedBase(blob) {
|
|
|
5858
5939
|
return null;
|
|
5859
5940
|
}
|
|
5860
5941
|
const families = [
|
|
5861
|
-
[
|
|
5942
|
+
[
|
|
5943
|
+
/alpine-minirootfs|etc\/alpine-release|apk add|apk --no-cache/i,
|
|
5944
|
+
"Alpine (musl)"
|
|
5945
|
+
],
|
|
5862
5946
|
[/^BusyBox /im, "BusyBox"],
|
|
5863
|
-
[
|
|
5947
|
+
[
|
|
5948
|
+
/microdnf|dnf install|yum install|rpm -i/i,
|
|
5949
|
+
"RPM-based (Fedora/RHEL/Rocky)"
|
|
5950
|
+
],
|
|
5864
5951
|
[/pacman -S/i, "Arch"],
|
|
5865
5952
|
[/zypper|KIWI /i, "SUSE"]
|
|
5866
5953
|
];
|
|
@@ -5902,7 +5989,7 @@ function parseImageRef(image) {
|
|
|
5902
5989
|
let reference;
|
|
5903
5990
|
const at = ref.indexOf("@");
|
|
5904
5991
|
if (at !== -1) {
|
|
5905
|
-
repository = ref.slice(0, at);
|
|
5992
|
+
repository = ref.slice(0, at).replace(/:[^/]*$/, "");
|
|
5906
5993
|
reference = ref.slice(at + 1);
|
|
5907
5994
|
} else {
|
|
5908
5995
|
const colon = ref.lastIndexOf(":");
|
|
@@ -5919,6 +6006,79 @@ function parseImageRef(image) {
|
|
|
5919
6006
|
}
|
|
5920
6007
|
return { host, repository, reference };
|
|
5921
6008
|
}
|
|
6009
|
+
function parseChallenges(header) {
|
|
6010
|
+
const text = header != null ? header : "";
|
|
6011
|
+
const challenges = [];
|
|
6012
|
+
let index = 0;
|
|
6013
|
+
const skipSeparators = () => {
|
|
6014
|
+
while (index < text.length && " ,".includes(text[index])) {
|
|
6015
|
+
index++;
|
|
6016
|
+
}
|
|
6017
|
+
};
|
|
6018
|
+
const readToken = () => {
|
|
6019
|
+
const start = index;
|
|
6020
|
+
while (index < text.length && /[A-Za-z0-9\-_.:]/.test(text[index])) {
|
|
6021
|
+
index++;
|
|
6022
|
+
}
|
|
6023
|
+
return text.slice(start, index);
|
|
6024
|
+
};
|
|
6025
|
+
for (; ; ) {
|
|
6026
|
+
skipSeparators();
|
|
6027
|
+
const scheme = readToken();
|
|
6028
|
+
if (!scheme) {
|
|
6029
|
+
break;
|
|
6030
|
+
}
|
|
6031
|
+
const params = {};
|
|
6032
|
+
for (; ; ) {
|
|
6033
|
+
skipSeparators();
|
|
6034
|
+
if (index >= text.length) {
|
|
6035
|
+
break;
|
|
6036
|
+
}
|
|
6037
|
+
const keyStart = index;
|
|
6038
|
+
const key = readToken();
|
|
6039
|
+
if (!key) {
|
|
6040
|
+
break;
|
|
6041
|
+
}
|
|
6042
|
+
while (index < text.length && " ".includes(text[index])) {
|
|
6043
|
+
index++;
|
|
6044
|
+
}
|
|
6045
|
+
if (index >= text.length || text[index] !== "=") {
|
|
6046
|
+
index = keyStart;
|
|
6047
|
+
break;
|
|
6048
|
+
}
|
|
6049
|
+
index++;
|
|
6050
|
+
while (index < text.length && " ".includes(text[index])) {
|
|
6051
|
+
index++;
|
|
6052
|
+
}
|
|
6053
|
+
if (index < text.length && text[index] === '"') {
|
|
6054
|
+
index++;
|
|
6055
|
+
const chars = [];
|
|
6056
|
+
while (index < text.length) {
|
|
6057
|
+
if (text[index] === "\\" && index + 1 < text.length) {
|
|
6058
|
+
chars.push(text[index + 1]);
|
|
6059
|
+
index += 2;
|
|
6060
|
+
continue;
|
|
6061
|
+
}
|
|
6062
|
+
if (text[index] === '"') {
|
|
6063
|
+
index++;
|
|
6064
|
+
break;
|
|
6065
|
+
}
|
|
6066
|
+
chars.push(text[index]);
|
|
6067
|
+
index++;
|
|
6068
|
+
}
|
|
6069
|
+
params[key.toLowerCase()] = chars.join("");
|
|
6070
|
+
} else {
|
|
6071
|
+
const valueStart = index;
|
|
6072
|
+
while (index < text.length && text[index] !== ",") {
|
|
6073
|
+
index++;
|
|
6074
|
+
}
|
|
6075
|
+
params[key.toLowerCase()] = text.slice(valueStart, index).trim();
|
|
6076
|
+
}
|
|
6077
|
+
}
|
|
6078
|
+
challenges.push({ scheme, params });
|
|
6079
|
+
}
|
|
6080
|
+
return challenges;
|
|
6081
|
+
}
|
|
5922
6082
|
function retryDelayMs(error, fallbackMs) {
|
|
5923
6083
|
const raw = error instanceof RegistryHttpError ? error.retryAfter : null;
|
|
5924
6084
|
const seconds = raw === null ? NaN : Number(raw);
|
|
@@ -5935,19 +6095,27 @@ async function registryGet(url, headers, options) {
|
|
|
5935
6095
|
for (let attempt = 0; attempt < attempts; attempt++) {
|
|
5936
6096
|
if (attempt > 0) {
|
|
5937
6097
|
await new Promise(
|
|
5938
|
-
(resolve) => setTimeout(
|
|
6098
|
+
(resolve) => setTimeout(
|
|
6099
|
+
resolve,
|
|
6100
|
+
retryDelayMs(last, 2 ** (attempt - 1) * backoffBaseMs)
|
|
6101
|
+
)
|
|
5939
6102
|
);
|
|
5940
6103
|
}
|
|
5941
6104
|
try {
|
|
5942
|
-
const
|
|
6105
|
+
const init = {
|
|
5943
6106
|
headers,
|
|
5944
6107
|
signal: AbortSignal.timeout(timeoutMs)
|
|
5945
|
-
}
|
|
6108
|
+
};
|
|
6109
|
+
if ((options == null ? void 0 : options.dispatcher) !== void 0) {
|
|
6110
|
+
init.dispatcher = options.dispatcher;
|
|
6111
|
+
}
|
|
6112
|
+
const response = await fetch(url, init);
|
|
5946
6113
|
if (!response.ok) {
|
|
5947
6114
|
const error = new RegistryHttpError(
|
|
5948
6115
|
response.status,
|
|
5949
6116
|
response.headers.get("retry-after"),
|
|
5950
|
-
`HTTP ${response.status} ${response.statusText}
|
|
6117
|
+
`HTTP ${response.status} ${response.statusText}`,
|
|
6118
|
+
response.headers.get("www-authenticate")
|
|
5951
6119
|
);
|
|
5952
6120
|
if (!RETRY_STATUS.has(response.status)) {
|
|
5953
6121
|
throw error;
|
|
@@ -5965,14 +6133,10 @@ async function registryGet(url, headers, options) {
|
|
|
5965
6133
|
}
|
|
5966
6134
|
throw last;
|
|
5967
6135
|
}
|
|
5968
|
-
async function authHeaders(host, repository, credentials) {
|
|
6136
|
+
async function authHeaders(host, repository, credentials, dispatcher) {
|
|
5969
6137
|
const headers = { Accept: MANIFEST_TYPES };
|
|
5970
|
-
if (credentials) {
|
|
5971
|
-
|
|
5972
|
-
`${credentials.username}:${credentials.password}`,
|
|
5973
|
-
"utf8"
|
|
5974
|
-
).toString("base64");
|
|
5975
|
-
headers.Authorization = `Basic ${basic}`;
|
|
6138
|
+
if ((credentials == null ? void 0 : credentials.username) && credentials.password) {
|
|
6139
|
+
headers.Authorization = basicHeader(credentials);
|
|
5976
6140
|
}
|
|
5977
6141
|
const services = {
|
|
5978
6142
|
"registry-1.docker.io": ["auth.docker.io", "registry.docker.io"],
|
|
@@ -5986,9 +6150,9 @@ async function authHeaders(host, repository, credentials) {
|
|
|
5986
6150
|
const url = `https://${authHost}/token?service=${serviceName}&scope=repository:${repository}:pull`;
|
|
5987
6151
|
try {
|
|
5988
6152
|
const tokenHeaders = headers.Authorization ? { Authorization: headers.Authorization } : {};
|
|
5989
|
-
const body = await registryGet(url, tokenHeaders, {
|
|
6153
|
+
const body = await registryGet(url, tokenHeaders, __spreadValues({
|
|
5990
6154
|
attempts: 1
|
|
5991
|
-
});
|
|
6155
|
+
}, dispatcher === void 0 ? {} : { dispatcher }));
|
|
5992
6156
|
if (body.token) {
|
|
5993
6157
|
headers.Authorization = `Bearer ${body.token}`;
|
|
5994
6158
|
}
|
|
@@ -5996,6 +6160,13 @@ async function authHeaders(host, repository, credentials) {
|
|
|
5996
6160
|
}
|
|
5997
6161
|
return headers;
|
|
5998
6162
|
}
|
|
6163
|
+
function basicHeader(credentials) {
|
|
6164
|
+
const encoded = Buffer.from(
|
|
6165
|
+
`${credentials.username}:${credentials.password}`,
|
|
6166
|
+
"utf8"
|
|
6167
|
+
).toString("base64");
|
|
6168
|
+
return `Basic ${encoded}`;
|
|
6169
|
+
}
|
|
5999
6170
|
function platformName(entry) {
|
|
6000
6171
|
var _a3, _b, _c;
|
|
6001
6172
|
const p = (_a3 = entry.platform) != null ? _a3 : {};
|
|
@@ -6040,41 +6211,53 @@ function describeFailure(error, image, host, repository, authenticated) {
|
|
|
6040
6211
|
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
6212
|
return __spreadProps(__spreadValues({}, empty), { error: reason, unusable: reason });
|
|
6042
6213
|
}
|
|
6214
|
+
if (error.status === 401) {
|
|
6215
|
+
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`;
|
|
6216
|
+
return __spreadProps(__spreadValues({}, empty), { error: reason });
|
|
6217
|
+
}
|
|
6043
6218
|
return __spreadProps(__spreadValues({}, empty), { error: `${error.name}: ${error.message}` });
|
|
6044
6219
|
}
|
|
6045
6220
|
const message = error instanceof Error ? error.message : String(error);
|
|
6046
6221
|
return __spreadProps(__spreadValues({}, empty), { error: message });
|
|
6047
6222
|
}
|
|
6048
|
-
async function fetchImageConfig(image, credentials) {
|
|
6223
|
+
async function fetchImageConfig(image, credentials, options) {
|
|
6049
6224
|
var _a3, _b, _c, _d, _e, _f, _g;
|
|
6225
|
+
const dispatcher = options == null ? void 0 : options.dispatcher;
|
|
6226
|
+
const cacheable = dispatcher === void 0 && image.includes("@");
|
|
6050
6227
|
const key = JSON.stringify([
|
|
6051
6228
|
image,
|
|
6052
6229
|
(_a3 = credentials == null ? void 0 : credentials.username) != null ? _a3 : null,
|
|
6053
6230
|
(_b = credentials == null ? void 0 : credentials.password) != null ? _b : null
|
|
6054
6231
|
]);
|
|
6055
|
-
|
|
6056
|
-
|
|
6057
|
-
|
|
6232
|
+
if (cacheable) {
|
|
6233
|
+
const cached = CACHE.get(key);
|
|
6234
|
+
if (cached) {
|
|
6235
|
+
return copyConfig(cached);
|
|
6236
|
+
}
|
|
6058
6237
|
}
|
|
6059
6238
|
const { host, repository, reference } = parseImageRef(image);
|
|
6060
6239
|
let result;
|
|
6061
6240
|
try {
|
|
6062
|
-
const auth = await authHeaders(host, repository, credentials);
|
|
6241
|
+
const auth = await authHeaders(host, repository, credentials, dispatcher);
|
|
6242
|
+
const session = new RegistrySession(
|
|
6243
|
+
repository,
|
|
6244
|
+
credentials,
|
|
6245
|
+
auth,
|
|
6246
|
+
dispatcher
|
|
6247
|
+
);
|
|
6063
6248
|
const base = `https://${host}/v2/${repository}`;
|
|
6064
|
-
let manifest = await
|
|
6065
|
-
`${base}/manifests/${reference}
|
|
6066
|
-
auth
|
|
6249
|
+
let manifest = await session.get(
|
|
6250
|
+
`${base}/manifests/${reference}`
|
|
6067
6251
|
);
|
|
6068
6252
|
if (manifest.manifests) {
|
|
6069
6253
|
const digest = pickAmd64(manifest, image);
|
|
6070
|
-
manifest = await
|
|
6254
|
+
manifest = await session.get(`${base}/manifests/${digest}`);
|
|
6071
6255
|
}
|
|
6072
6256
|
if (!((_c = manifest.config) == null ? void 0 : _c.digest)) {
|
|
6073
6257
|
throw new Error(`${image}: manifest names no config blob`);
|
|
6074
6258
|
}
|
|
6075
|
-
const blob = await
|
|
6076
|
-
`${base}/blobs/${manifest.config.digest}
|
|
6077
|
-
auth
|
|
6259
|
+
const blob = await session.get(
|
|
6260
|
+
`${base}/blobs/${manifest.config.digest}`
|
|
6078
6261
|
);
|
|
6079
6262
|
const declared = (_d = blob.config) != null ? _d : {};
|
|
6080
6263
|
const env = {};
|
|
@@ -6101,10 +6284,14 @@ async function fetchImageConfig(image, credentials) {
|
|
|
6101
6284
|
image,
|
|
6102
6285
|
host,
|
|
6103
6286
|
repository,
|
|
6104
|
-
|
|
6287
|
+
// Both, because that is what the request actually carried: a lone username
|
|
6288
|
+
// is not a credential the registry could have rejected.
|
|
6289
|
+
Boolean((credentials == null ? void 0 : credentials.username) && (credentials == null ? void 0 : credentials.password))
|
|
6105
6290
|
);
|
|
6106
6291
|
}
|
|
6107
|
-
|
|
6292
|
+
if (cacheable && !result.error) {
|
|
6293
|
+
CACHE.set(key, result);
|
|
6294
|
+
}
|
|
6108
6295
|
return copyConfig(result);
|
|
6109
6296
|
}
|
|
6110
6297
|
function effectiveStartCmd(entrypoint, cmd) {
|
|
@@ -6112,12 +6299,12 @@ function effectiveStartCmd(entrypoint, cmd) {
|
|
|
6112
6299
|
return parts.length > 0 ? parts.map(shellQuoteArg).join(" ") : null;
|
|
6113
6300
|
}
|
|
6114
6301
|
function shellQuoteArg(value) {
|
|
6115
|
-
return /^[A-Za-z0-9_./:@%+=,-]+$/.test(value) ? value : `'${value.replace(/'/g,
|
|
6302
|
+
return /^[A-Za-z0-9_./:@%+=,-]+$/.test(value) ? value : `'${value.replace(/'/g, "'\\''")}'`;
|
|
6116
6303
|
}
|
|
6117
6304
|
function clearImageConfigCache() {
|
|
6118
6305
|
CACHE.clear();
|
|
6119
6306
|
}
|
|
6120
|
-
var HUB_HOST, HUB_OFFICIAL, MANIFEST_TYPES, SKIP_ENV, RETRY_STATUS, READ_ATTEMPTS, backoffBaseMs, CACHE, RegistryHttpError, UnusableImageError;
|
|
6307
|
+
var HUB_HOST, HUB_OFFICIAL, MANIFEST_TYPES, SKIP_ENV, RETRY_STATUS, READ_ATTEMPTS, TOKEN_CLIENT_ID, backoffBaseMs, CACHE, RegistryHttpError, UnusableImageError, RegistrySession;
|
|
6121
6308
|
var init_imageConfig = __esm({
|
|
6122
6309
|
"src/core/template/imageConfig.ts"() {
|
|
6123
6310
|
"use strict";
|
|
@@ -6140,13 +6327,15 @@ var init_imageConfig = __esm({
|
|
|
6140
6327
|
]);
|
|
6141
6328
|
RETRY_STATUS = /* @__PURE__ */ new Set([429, 500, 502, 503, 504]);
|
|
6142
6329
|
READ_ATTEMPTS = 3;
|
|
6330
|
+
TOKEN_CLIENT_ID = "ppio-sandbox";
|
|
6143
6331
|
backoffBaseMs = 1e3;
|
|
6144
6332
|
CACHE = /* @__PURE__ */ new Map();
|
|
6145
6333
|
RegistryHttpError = class extends Error {
|
|
6146
|
-
constructor(status, retryAfter, message) {
|
|
6334
|
+
constructor(status, retryAfter, message, challenge = null) {
|
|
6147
6335
|
super(message);
|
|
6148
6336
|
this.status = status;
|
|
6149
6337
|
this.retryAfter = retryAfter;
|
|
6338
|
+
this.challenge = challenge;
|
|
6150
6339
|
this.name = "RegistryHttpError";
|
|
6151
6340
|
}
|
|
6152
6341
|
};
|
|
@@ -6156,6 +6345,75 @@ var init_imageConfig = __esm({
|
|
|
6156
6345
|
this.name = "UnusableImageError";
|
|
6157
6346
|
}
|
|
6158
6347
|
};
|
|
6348
|
+
RegistrySession = class {
|
|
6349
|
+
constructor(repository, credentials, headers, dispatcher) {
|
|
6350
|
+
this.repository = repository;
|
|
6351
|
+
this.credentials = credentials;
|
|
6352
|
+
this.headers = headers;
|
|
6353
|
+
this.dispatcher = dispatcher;
|
|
6354
|
+
this.token = null;
|
|
6355
|
+
}
|
|
6356
|
+
/** GET `url`, resolving one Bearer challenge if the registry asks for it. */
|
|
6357
|
+
async get(url) {
|
|
6358
|
+
const headers = __spreadValues({}, this.headers);
|
|
6359
|
+
if (this.token) {
|
|
6360
|
+
headers.Authorization = `Bearer ${this.token}`;
|
|
6361
|
+
}
|
|
6362
|
+
try {
|
|
6363
|
+
return await registryGet(url, headers, __spreadValues({
|
|
6364
|
+
attempts: READ_ATTEMPTS
|
|
6365
|
+
}, this.dispatcher === void 0 ? {} : { dispatcher: this.dispatcher }));
|
|
6366
|
+
} catch (error) {
|
|
6367
|
+
if (!(error instanceof RegistryHttpError) || error.status !== 401) {
|
|
6368
|
+
throw error;
|
|
6369
|
+
}
|
|
6370
|
+
const token = await this.tokenFrom(error.challenge);
|
|
6371
|
+
if (token === null) {
|
|
6372
|
+
throw error;
|
|
6373
|
+
}
|
|
6374
|
+
this.token = token;
|
|
6375
|
+
headers.Authorization = `Bearer ${token}`;
|
|
6376
|
+
return registryGet(url, headers, __spreadValues({
|
|
6377
|
+
attempts: READ_ATTEMPTS
|
|
6378
|
+
}, this.dispatcher === void 0 ? {} : { dispatcher: this.dispatcher }));
|
|
6379
|
+
}
|
|
6380
|
+
}
|
|
6381
|
+
async tokenFrom(challenge) {
|
|
6382
|
+
for (const { scheme, params } of parseChallenges(challenge)) {
|
|
6383
|
+
if (scheme.toLowerCase() === "bearer") {
|
|
6384
|
+
return this.bearer(params);
|
|
6385
|
+
}
|
|
6386
|
+
}
|
|
6387
|
+
return null;
|
|
6388
|
+
}
|
|
6389
|
+
async bearer(params) {
|
|
6390
|
+
var _a3;
|
|
6391
|
+
const realm = params.realm;
|
|
6392
|
+
if (!realm || !/^https?:\/\//.test(realm)) {
|
|
6393
|
+
return null;
|
|
6394
|
+
}
|
|
6395
|
+
const url = new URL(realm);
|
|
6396
|
+
url.searchParams.set("client_id", TOKEN_CLIENT_ID);
|
|
6397
|
+
if (params.service) {
|
|
6398
|
+
url.searchParams.set("service", params.service);
|
|
6399
|
+
}
|
|
6400
|
+
url.searchParams.set(
|
|
6401
|
+
"scope",
|
|
6402
|
+
params.scope || `repository:${this.repository}:pull`
|
|
6403
|
+
);
|
|
6404
|
+
const headers = {};
|
|
6405
|
+
if (((_a3 = this.credentials) == null ? void 0 : _a3.username) && this.credentials.password) {
|
|
6406
|
+
headers.Authorization = basicHeader(this.credentials);
|
|
6407
|
+
}
|
|
6408
|
+
const body = await registryGet(url.toString(), headers, __spreadValues({
|
|
6409
|
+
attempts: 1
|
|
6410
|
+
}, this.dispatcher === void 0 ? {} : { dispatcher: this.dispatcher }));
|
|
6411
|
+
if (body === null || typeof body !== "object") {
|
|
6412
|
+
return null;
|
|
6413
|
+
}
|
|
6414
|
+
return body.token || body.access_token || null;
|
|
6415
|
+
}
|
|
6416
|
+
};
|
|
6159
6417
|
}
|
|
6160
6418
|
});
|
|
6161
6419
|
|
|
@@ -6343,6 +6601,8 @@ var init_template = __esm({
|
|
|
6343
6601
|
// rather than written per call because the file is written once from the full
|
|
6344
6602
|
// set -- a per-call write would clobber the previous call's file.
|
|
6345
6603
|
this.envs = {};
|
|
6604
|
+
this.envDeclarations = [];
|
|
6605
|
+
this.imageEnvs = {};
|
|
6346
6606
|
// Whether to restore what the base image declares -- see fromImage() and
|
|
6347
6607
|
// resolveInheritedConfig(). Only meaningful for an image base; a Dockerfile
|
|
6348
6608
|
// states its own ENV/WORKDIR/CMD, and a template base already carries them.
|
|
@@ -6354,6 +6614,13 @@ var init_template = __esm({
|
|
|
6354
6614
|
// image's PATH -- the exact failure this reading exists to prevent.
|
|
6355
6615
|
this.imageConfigError = void 0;
|
|
6356
6616
|
this.imageUnusable = void 0;
|
|
6617
|
+
// What a failed read does. "warn" by default: one unreachable registry must not
|
|
6618
|
+
// abort a batch conversion, but a template silently missing the image's PATH is
|
|
6619
|
+
// the failure this reading exists to prevent, so it cannot pass unmentioned.
|
|
6620
|
+
this.imageOnConfigFailure = "warn";
|
|
6621
|
+
// Carries the TLS trust and proxy settings for a self-hosted registry, which
|
|
6622
|
+
// Node's fetch cannot be told about in any other per-request way.
|
|
6623
|
+
this.imageDispatcher = void 0;
|
|
6357
6624
|
this.fileContextPath = runtime === "browser" ? "." : (_a2 = getCallerDirectory(STACK_TRACE_DEPTH)) != null ? _a2 : ".";
|
|
6358
6625
|
this.fileIgnorePatterns = [];
|
|
6359
6626
|
this.logsRefreshFrequency = 200;
|
|
@@ -6580,12 +6847,41 @@ var init_template = __esm({
|
|
|
6580
6847
|
fromBaseImage() {
|
|
6581
6848
|
return this.fromImage(this.defaultBaseImage);
|
|
6582
6849
|
}
|
|
6850
|
+
/**
|
|
6851
|
+
* Build from a Docker image, restoring what the image declares.
|
|
6852
|
+
*
|
|
6853
|
+
* The image's ENV, WORKDIR and start command are read from its registry config
|
|
6854
|
+
* because the platform's own pull does not apply them. Reading is best-effort
|
|
6855
|
+
* and asynchronous, so it happens at build/serialize time.
|
|
6856
|
+
*
|
|
6857
|
+
* @param credentials registry username and password, for a private image.
|
|
6858
|
+
* @param options.inheritConfig restore the image's config (default true).
|
|
6859
|
+
* @param options.onConfigFailure what a failed read does — see
|
|
6860
|
+
* {@link ImageConfigFailureMode}. Defaults to `warn`.
|
|
6861
|
+
* @param options.dispatcher Node fetch `dispatcher` (an undici `Agent`), for a
|
|
6862
|
+
* self-hosted registry behind a private CA, a client certificate or a proxy.
|
|
6863
|
+
* For example, with a private CA:
|
|
6864
|
+
*
|
|
6865
|
+
* ```ts
|
|
6866
|
+
* import { Agent } from 'undici'
|
|
6867
|
+
* const dispatcher = new Agent({ connect: { ca: readFileSync('/ca.pem') } })
|
|
6868
|
+
* Template().fromImage('harbor.internal/app:1', undefined, { dispatcher })
|
|
6869
|
+
* ```
|
|
6870
|
+
*/
|
|
6583
6871
|
fromImage(baseImage, credentials, options) {
|
|
6584
|
-
var _a3;
|
|
6872
|
+
var _a3, _b;
|
|
6873
|
+
if ((options == null ? void 0 : options.onConfigFailure) !== void 0 && !["warn", "raise", "ignore"].includes(options.onConfigFailure)) {
|
|
6874
|
+
throw new InvalidArgumentError(
|
|
6875
|
+
'onConfigFailure must be "warn", "raise" or "ignore", got ' + String(options.onConfigFailure)
|
|
6876
|
+
);
|
|
6877
|
+
}
|
|
6585
6878
|
this.baseImage = baseImage;
|
|
6586
6879
|
this.baseTemplate = void 0;
|
|
6880
|
+
this.resetInheritedConfig();
|
|
6587
6881
|
this.inheritImageConfig = (_a3 = options == null ? void 0 : options.inheritConfig) != null ? _a3 : true;
|
|
6588
6882
|
this.imageCredentials = credentials;
|
|
6883
|
+
this.imageOnConfigFailure = (_b = options == null ? void 0 : options.onConfigFailure) != null ? _b : "warn";
|
|
6884
|
+
this.imageDispatcher = options == null ? void 0 : options.dispatcher;
|
|
6589
6885
|
if (credentials) {
|
|
6590
6886
|
this.registryConfig = {
|
|
6591
6887
|
type: "registry",
|
|
@@ -6602,6 +6898,7 @@ var init_template = __esm({
|
|
|
6602
6898
|
fromTemplate(template) {
|
|
6603
6899
|
this.baseTemplate = template;
|
|
6604
6900
|
this.baseImage = void 0;
|
|
6901
|
+
this.resetInheritedConfig();
|
|
6605
6902
|
if (this.forceNextLayer) {
|
|
6606
6903
|
this.force = true;
|
|
6607
6904
|
}
|
|
@@ -6616,6 +6913,8 @@ var init_template = __esm({
|
|
|
6616
6913
|
);
|
|
6617
6914
|
this.baseImage = baseImage;
|
|
6618
6915
|
this.baseTemplate = void 0;
|
|
6916
|
+
this.resetInheritedConfig();
|
|
6917
|
+
this.inheritImageConfig = true;
|
|
6619
6918
|
if (this.forceNextLayer) {
|
|
6620
6919
|
this.force = true;
|
|
6621
6920
|
}
|
|
@@ -6625,6 +6924,7 @@ var init_template = __esm({
|
|
|
6625
6924
|
fromAWSRegistry(image, credentials) {
|
|
6626
6925
|
this.baseImage = image;
|
|
6627
6926
|
this.baseTemplate = void 0;
|
|
6927
|
+
this.resetInheritedConfig();
|
|
6628
6928
|
this.registryConfig = {
|
|
6629
6929
|
type: "aws",
|
|
6630
6930
|
awsAccessKeyId: credentials.accessKeyId,
|
|
@@ -6640,6 +6940,7 @@ var init_template = __esm({
|
|
|
6640
6940
|
fromGCPRegistry(image, credentials) {
|
|
6641
6941
|
this.baseImage = image;
|
|
6642
6942
|
this.baseTemplate = void 0;
|
|
6943
|
+
this.resetInheritedConfig();
|
|
6643
6944
|
this.registryConfig = {
|
|
6644
6945
|
type: "gcp",
|
|
6645
6946
|
serviceAccountJson: readGCPServiceAccountJSON(
|
|
@@ -6656,6 +6957,7 @@ var init_template = __esm({
|
|
|
6656
6957
|
fromOCIRegistry(image, credentials) {
|
|
6657
6958
|
this.baseImage = image;
|
|
6658
6959
|
this.baseTemplate = void 0;
|
|
6960
|
+
this.resetInheritedConfig();
|
|
6659
6961
|
this.registryConfig = {
|
|
6660
6962
|
type: "oci",
|
|
6661
6963
|
tenancyOcid: credentials.tenancyOcid,
|
|
@@ -6673,6 +6975,7 @@ var init_template = __esm({
|
|
|
6673
6975
|
fromHuaweiCloudRegistry(image, credentials) {
|
|
6674
6976
|
this.baseImage = image;
|
|
6675
6977
|
this.baseTemplate = void 0;
|
|
6978
|
+
this.resetInheritedConfig();
|
|
6676
6979
|
this.registryConfig = {
|
|
6677
6980
|
type: "huawei",
|
|
6678
6981
|
accessKeyId: credentials.accessKeyId,
|
|
@@ -6735,8 +7038,8 @@ var init_template = __esm({
|
|
|
6735
7038
|
});
|
|
6736
7039
|
return this;
|
|
6737
7040
|
}
|
|
6738
|
-
remove(
|
|
6739
|
-
const paths2 = Array.isArray(
|
|
7041
|
+
remove(path3, options) {
|
|
7042
|
+
const paths2 = Array.isArray(path3) ? path3 : [path3];
|
|
6740
7043
|
const args = ["rm"];
|
|
6741
7044
|
if (options == null ? void 0 : options.recursive) {
|
|
6742
7045
|
args.push("-r");
|
|
@@ -6758,8 +7061,8 @@ var init_template = __esm({
|
|
|
6758
7061
|
() => this.runCmd(args.join(" "), { user: options == null ? void 0 : options.user })
|
|
6759
7062
|
);
|
|
6760
7063
|
}
|
|
6761
|
-
makeDir(
|
|
6762
|
-
const paths2 = Array.isArray(
|
|
7064
|
+
makeDir(path3, options) {
|
|
7065
|
+
const paths2 = Array.isArray(path3) ? path3 : [path3];
|
|
6763
7066
|
const args = ["mkdir", "-p"];
|
|
6764
7067
|
if (options == null ? void 0 : options.mode) {
|
|
6765
7068
|
args.push(`-m ${padOctal(options.mode)}`);
|
|
@@ -6894,7 +7197,7 @@ var init_template = __esm({
|
|
|
6894
7197
|
})
|
|
6895
7198
|
);
|
|
6896
7199
|
}
|
|
6897
|
-
gitClone(url,
|
|
7200
|
+
gitClone(url, path3, options) {
|
|
6898
7201
|
const args = ["git", "clone", url];
|
|
6899
7202
|
if (options == null ? void 0 : options.branch) {
|
|
6900
7203
|
args.push(`--branch ${options.branch}`);
|
|
@@ -6903,8 +7206,8 @@ var init_template = __esm({
|
|
|
6903
7206
|
if (options == null ? void 0 : options.depth) {
|
|
6904
7207
|
args.push(`--depth ${options.depth}`);
|
|
6905
7208
|
}
|
|
6906
|
-
if (
|
|
6907
|
-
args.push(
|
|
7209
|
+
if (path3) {
|
|
7210
|
+
args.push(path3.toString());
|
|
6908
7211
|
}
|
|
6909
7212
|
return this.runInNewStackTraceContext(
|
|
6910
7213
|
() => this.runCmd(args.join(" "), { user: options == null ? void 0 : options.user })
|
|
@@ -6934,7 +7237,8 @@ var init_template = __esm({
|
|
|
6934
7237
|
this.collectStackTrace();
|
|
6935
7238
|
return this;
|
|
6936
7239
|
}
|
|
6937
|
-
setEnvs(envs) {
|
|
7240
|
+
setEnvs(envs, options) {
|
|
7241
|
+
var _a3;
|
|
6938
7242
|
if (Object.keys(envs).length === 0) {
|
|
6939
7243
|
return this;
|
|
6940
7244
|
}
|
|
@@ -6943,7 +7247,11 @@ var init_template = __esm({
|
|
|
6943
7247
|
args: Object.entries(envs).flatMap(([key, value]) => [key, value]),
|
|
6944
7248
|
force: this.forceNextLayer
|
|
6945
7249
|
});
|
|
6946
|
-
this.
|
|
7250
|
+
this.envDeclarations.push({
|
|
7251
|
+
values: __spreadValues({}, envs),
|
|
7252
|
+
runtime: (_a3 = options == null ? void 0 : options.runtime) != null ? _a3 : false
|
|
7253
|
+
});
|
|
7254
|
+
if (options == null ? void 0 : options.runtime) this.envs = __spreadValues(__spreadValues({}, this.envs), envs);
|
|
6947
7255
|
this.collectStackTrace();
|
|
6948
7256
|
return this;
|
|
6949
7257
|
}
|
|
@@ -6960,7 +7268,12 @@ var init_template = __esm({
|
|
|
6960
7268
|
* second build of the same template append a duplicate layer.
|
|
6961
7269
|
*/
|
|
6962
7270
|
runtimeEnvInstruction() {
|
|
6963
|
-
const { command } = envFilesCommand(
|
|
7271
|
+
const { command } = envFilesCommand(
|
|
7272
|
+
this.envs,
|
|
7273
|
+
this.imageEnvs,
|
|
7274
|
+
this.envDeclarations,
|
|
7275
|
+
envSnapshotCommand(this.envDeclarations) ? BASE_ENV_PATH : void 0
|
|
7276
|
+
);
|
|
6964
7277
|
if (command === null) {
|
|
6965
7278
|
return null;
|
|
6966
7279
|
}
|
|
@@ -6979,7 +7292,10 @@ var init_template = __esm({
|
|
|
6979
7292
|
*/
|
|
6980
7293
|
withRuntimeEnv(instructions) {
|
|
6981
7294
|
const runtimeEnv = this.runtimeEnvInstruction();
|
|
6982
|
-
|
|
7295
|
+
if (!runtimeEnv) return instructions;
|
|
7296
|
+
const snapshot = envSnapshotCommand(this.envDeclarations);
|
|
7297
|
+
const prefix = snapshot ? [{ type: "RUN" /* RUN */, args: [snapshot, "root"], force: false }] : [];
|
|
7298
|
+
return [...prefix, ...instructions, runtimeEnv];
|
|
6983
7299
|
}
|
|
6984
7300
|
/**
|
|
6985
7301
|
* Restore what the base image declares: ENV, WORKDIR and its effective command.
|
|
@@ -7000,37 +7316,57 @@ var init_template = __esm({
|
|
|
7000
7316
|
* restored config — but it is reported, since an image whose toolchain lives
|
|
7001
7317
|
* behind its ENV will otherwise look installed and behave as though it is not.
|
|
7002
7318
|
*/
|
|
7319
|
+
/** The one wording a failed read is reported with, on every channel. */
|
|
7320
|
+
configFailureMessage() {
|
|
7321
|
+
return `Could not read ${this.baseImage}: ${this.imageConfigError}. The template will build without the environment, working directory and start command the image declares.`;
|
|
7322
|
+
}
|
|
7323
|
+
resetInheritedConfig() {
|
|
7324
|
+
this.imageEnvs = {};
|
|
7325
|
+
this.imageWorkdir = void 0;
|
|
7326
|
+
this.imageStartCmd = void 0;
|
|
7327
|
+
this.imageReadyCmd = void 0;
|
|
7328
|
+
this.imageConfigError = void 0;
|
|
7329
|
+
this.imageUnusable = void 0;
|
|
7330
|
+
this.imageCredentials = void 0;
|
|
7331
|
+
this.imageDispatcher = void 0;
|
|
7332
|
+
this.registryConfig = void 0;
|
|
7333
|
+
this.inheritImageConfig = false;
|
|
7334
|
+
}
|
|
7003
7335
|
async resolveInheritedConfig(onBuildLogs) {
|
|
7004
|
-
var _a3;
|
|
7336
|
+
var _a3, _b;
|
|
7005
7337
|
if (!this.inheritImageConfig || this.baseImage === void 0) {
|
|
7006
7338
|
return;
|
|
7007
7339
|
}
|
|
7008
|
-
|
|
7009
|
-
|
|
7340
|
+
const config = await fetchImageConfig(
|
|
7341
|
+
this.baseImage,
|
|
7342
|
+
this.imageCredentials,
|
|
7343
|
+
this.imageDispatcher === void 0 ? void 0 : { dispatcher: this.imageDispatcher }
|
|
7344
|
+
);
|
|
7345
|
+
this.imageEnvs = {};
|
|
7346
|
+
this.imageWorkdir = void 0;
|
|
7347
|
+
this.imageStartCmd = void 0;
|
|
7348
|
+
this.imageReadyCmd = void 0;
|
|
7010
7349
|
if (config.error) {
|
|
7011
7350
|
this.imageConfigError = config.error;
|
|
7012
7351
|
this.imageUnusable = config.unusable;
|
|
7013
|
-
|
|
7014
|
-
|
|
7015
|
-
|
|
7016
|
-
|
|
7017
|
-
|
|
7018
|
-
)
|
|
7019
|
-
|
|
7352
|
+
const message = this.configFailureMessage();
|
|
7353
|
+
if (this.imageOnConfigFailure === "raise") {
|
|
7354
|
+
throw new ImageConfigError(message);
|
|
7355
|
+
}
|
|
7356
|
+
if (this.imageOnConfigFailure !== "ignore") {
|
|
7357
|
+
console.warn(message);
|
|
7358
|
+
onBuildLogs == null ? void 0 : onBuildLogs(new LogEntry(/* @__PURE__ */ new Date(), "warn", message));
|
|
7359
|
+
}
|
|
7020
7360
|
return;
|
|
7021
7361
|
}
|
|
7022
|
-
this.
|
|
7023
|
-
|
|
7024
|
-
|
|
7025
|
-
|
|
7026
|
-
args: [config.workdir],
|
|
7027
|
-
force: false
|
|
7028
|
-
});
|
|
7029
|
-
}
|
|
7362
|
+
this.imageEnvs = __spreadValues({}, config.env);
|
|
7363
|
+
this.imageWorkdir = (_a3 = config.workdir) != null ? _a3 : void 0;
|
|
7364
|
+
this.imageConfigError = void 0;
|
|
7365
|
+
this.imageUnusable = void 0;
|
|
7030
7366
|
const startCmd = effectiveStartCmd(config.entrypoint, config.cmd);
|
|
7031
7367
|
if (startCmd && this.startCmd === void 0) {
|
|
7032
|
-
this.
|
|
7033
|
-
this.
|
|
7368
|
+
this.imageStartCmd = startCmd;
|
|
7369
|
+
this.imageReadyCmd = (_b = this.readyCmd) != null ? _b : waitForTimeout(2e4).getCmd();
|
|
7034
7370
|
}
|
|
7035
7371
|
}
|
|
7036
7372
|
/**
|
|
@@ -7368,9 +7704,20 @@ var init_template = __esm({
|
|
|
7368
7704
|
* @returns Template data formatted for the API
|
|
7369
7705
|
*/
|
|
7370
7706
|
serialize(steps) {
|
|
7707
|
+
var _a3, _b;
|
|
7708
|
+
if (this.imageWorkdir) {
|
|
7709
|
+
steps = [
|
|
7710
|
+
{
|
|
7711
|
+
type: "WORKDIR" /* WORKDIR */,
|
|
7712
|
+
args: [this.imageWorkdir],
|
|
7713
|
+
force: false
|
|
7714
|
+
},
|
|
7715
|
+
...steps
|
|
7716
|
+
];
|
|
7717
|
+
}
|
|
7371
7718
|
const templateData = {
|
|
7372
|
-
startCmd: this.startCmd,
|
|
7373
|
-
readyCmd: this.readyCmd,
|
|
7719
|
+
startCmd: (_a3 = this.startCmd) != null ? _a3 : this.imageStartCmd,
|
|
7720
|
+
readyCmd: (_b = this.readyCmd) != null ? _b : this.imageReadyCmd,
|
|
7374
7721
|
preBootScript: this.patchCmd,
|
|
7375
7722
|
steps,
|
|
7376
7723
|
force: this.force
|
|
@@ -7400,6 +7747,7 @@ var init_template = __esm({
|
|
|
7400
7747
|
Template.delete = TemplateBase.delete;
|
|
7401
7748
|
Template.toJSON = TemplateBase.toJSON;
|
|
7402
7749
|
Template.toDockerfile = TemplateBase.toDockerfile;
|
|
7750
|
+
Template.imageConfigFailure = TemplateBase.imageConfigFailure;
|
|
7403
7751
|
}
|
|
7404
7752
|
});
|
|
7405
7753
|
|
|
@@ -8305,10 +8653,10 @@ var init_sandbox3 = __esm({
|
|
|
8305
8653
|
}
|
|
8306
8654
|
}
|
|
8307
8655
|
async screenshot(format = "bytes") {
|
|
8308
|
-
const
|
|
8309
|
-
await this.commands.run(`scrot --pointer ${
|
|
8310
|
-
const file = await this.files.read(
|
|
8311
|
-
this.files.remove(
|
|
8656
|
+
const path3 = `/tmp/screenshot-${generateRandomString()}.png`;
|
|
8657
|
+
await this.commands.run(`scrot --pointer ${path3}`);
|
|
8658
|
+
const file = await this.files.read(path3, { format });
|
|
8659
|
+
this.files.remove(path3);
|
|
8312
8660
|
return file;
|
|
8313
8661
|
}
|
|
8314
8662
|
/**
|
|
@@ -8657,7 +9005,7 @@ function mergeConnectionOpts(base, next) {
|
|
|
8657
9005
|
headers: __spreadValues(__spreadValues({}, baseHeaders), nextHeaders)
|
|
8658
9006
|
});
|
|
8659
9007
|
}
|
|
8660
|
-
var RuntimeSandboxNamespace, SandboxNamespace, TemplateNamespace, VolumeNamespace, SecretNamespace, PPIO;
|
|
9008
|
+
var import_node_path2, import_node_url2, RuntimeSandboxNamespace, SandboxNamespace, TemplateNamespace, VolumeNamespace, SecretNamespace, PPIO;
|
|
8661
9009
|
var init_client = __esm({
|
|
8662
9010
|
"src/core/client.ts"() {
|
|
8663
9011
|
"use strict";
|
|
@@ -8665,6 +9013,9 @@ var init_client = __esm({
|
|
|
8665
9013
|
init_template();
|
|
8666
9014
|
init_volume();
|
|
8667
9015
|
init_secret();
|
|
9016
|
+
init_utils3();
|
|
9017
|
+
import_node_path2 = __toESM(require("path"));
|
|
9018
|
+
import_node_url2 = require("url");
|
|
8668
9019
|
RuntimeSandboxNamespace = class {
|
|
8669
9020
|
constructor(opts, loadSandbox) {
|
|
8670
9021
|
this.opts = opts;
|
|
@@ -8763,6 +9114,9 @@ var init_client = __esm({
|
|
|
8763
9114
|
getQuota(opts) {
|
|
8764
9115
|
return Sandbox.getQuota(mergeConnectionOpts(this.opts, opts));
|
|
8765
9116
|
}
|
|
9117
|
+
resize(sandboxId, resources, opts) {
|
|
9118
|
+
return Sandbox.resize(sandboxId, resources, mergeConnectionOpts(this.opts, opts));
|
|
9119
|
+
}
|
|
8766
9120
|
getEvents(opts) {
|
|
8767
9121
|
return Sandbox.getEvents(mergeConnectionOpts(this.opts, opts));
|
|
8768
9122
|
}
|
|
@@ -8850,6 +9204,9 @@ var init_client = __esm({
|
|
|
8850
9204
|
getQuota(opts) {
|
|
8851
9205
|
return Sandbox.getQuota(mergeConnectionOpts(this.opts, opts));
|
|
8852
9206
|
}
|
|
9207
|
+
resize(sandboxId, resources, opts) {
|
|
9208
|
+
return Sandbox.resize(sandboxId, resources, mergeConnectionOpts(this.opts, opts));
|
|
9209
|
+
}
|
|
8853
9210
|
getEvents(opts) {
|
|
8854
9211
|
return Sandbox.getEvents(mergeConnectionOpts(this.opts, opts));
|
|
8855
9212
|
}
|
|
@@ -8861,7 +9218,18 @@ var init_client = __esm({
|
|
|
8861
9218
|
this.toDockerfile = Template.toDockerfile;
|
|
8862
9219
|
}
|
|
8863
9220
|
new(options) {
|
|
8864
|
-
|
|
9221
|
+
var _a3;
|
|
9222
|
+
let callerContext = ".";
|
|
9223
|
+
for (const site of callsites(2)) {
|
|
9224
|
+
const fileName = site.getFileName();
|
|
9225
|
+
if (fileName && (!fileName.includes("/src/core/") || fileName.includes("/src/core/tests/")) && !fileName.includes("/node_modules/ppio-sandbox/")) {
|
|
9226
|
+
callerContext = import_node_path2.default.dirname(fileName.startsWith("file:") ? (0, import_node_url2.fileURLToPath)(fileName) : fileName);
|
|
9227
|
+
break;
|
|
9228
|
+
}
|
|
9229
|
+
}
|
|
9230
|
+
return Template(__spreadProps(__spreadValues({}, options), {
|
|
9231
|
+
fileContextPath: (_a3 = options == null ? void 0 : options.fileContextPath) != null ? _a3 : callerContext
|
|
9232
|
+
}));
|
|
8865
9233
|
}
|
|
8866
9234
|
list(opts) {
|
|
8867
9235
|
return Template.list(mergeConnectionOpts(this.opts, opts));
|
|
@@ -9063,6 +9431,7 @@ __export(desktop_exports, {
|
|
|
9063
9431
|
Git: () => Git,
|
|
9064
9432
|
GitAuthError: () => GitAuthError,
|
|
9065
9433
|
GitUpstreamError: () => GitUpstreamError,
|
|
9434
|
+
ImageConfigError: () => ImageConfigError,
|
|
9066
9435
|
InvalidArgumentError: () => InvalidArgumentError,
|
|
9067
9436
|
LogEntry: () => LogEntry,
|
|
9068
9437
|
LogEntryEnd: () => LogEntryEnd,
|
|
@@ -9116,6 +9485,7 @@ init_sandbox3();
|
|
|
9116
9485
|
Git,
|
|
9117
9486
|
GitAuthError,
|
|
9118
9487
|
GitUpstreamError,
|
|
9488
|
+
ImageConfigError,
|
|
9119
9489
|
InvalidArgumentError,
|
|
9120
9490
|
LogEntry,
|
|
9121
9491
|
LogEntryEnd,
|