@digitalocean/functions-deployer 5.0.19 → 5.0.20
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/lib/index.js +68 -31
- package/lib/index.js.map +3 -3
- package/lib/version.d.ts +1 -1
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -2423,7 +2423,7 @@ var path4 = __toESM(require("path"));
|
|
|
2423
2423
|
var fs4 = __toESM(require("fs"));
|
|
2424
2424
|
var yaml2 = __toESM(require("js-yaml"));
|
|
2425
2425
|
var import_ignore = __toESM(require("ignore"));
|
|
2426
|
-
var
|
|
2426
|
+
var import_axios4 = __toESM(require("axios"));
|
|
2427
2427
|
var import_archiver = __toESM(require("archiver"));
|
|
2428
2428
|
var import_touch = __toESM(require("touch"));
|
|
2429
2429
|
var import_debug7 = __toESM(require("debug"));
|
|
@@ -2435,23 +2435,15 @@ var fs3 = __toESM(require("fs"));
|
|
|
2435
2435
|
var import_debug6 = __toESM(require("debug"));
|
|
2436
2436
|
var import_adm_zip = __toESM(require("adm-zip"));
|
|
2437
2437
|
var rimraf = __toESM(require("rimraf"));
|
|
2438
|
-
var import_client_s3 = require("@aws-sdk/client-s3");
|
|
2439
2438
|
var import_memory_streams = require("memory-streams");
|
|
2439
|
+
var import_axios3 = __toESM(require("axios"));
|
|
2440
|
+
var import_openwhisk = __toESM(require("openwhisk"));
|
|
2440
2441
|
var debug6 = (0, import_debug6.default)("nim:deployer:slice-reader");
|
|
2441
2442
|
var TEMP = process.platform === "win32" ? process.env.TEMP : "/tmp";
|
|
2442
|
-
var bucket = process.env.BUILDER_BUCKET_NAME;
|
|
2443
|
-
var endpoint = process.env.S3_ENDPOINT;
|
|
2444
2443
|
var MAX_SLICE_UPLOAD_SIZE = parseInt(process.env.MAX_SLICE_UPLOAD_SIZE) || 64 * 1024 * 1024;
|
|
2445
|
-
var s3Client;
|
|
2446
2444
|
function cacheArea() {
|
|
2447
2445
|
return path3.join(TEMP, "slices");
|
|
2448
2446
|
}
|
|
2449
|
-
function getS3Client() {
|
|
2450
|
-
if (!s3Client) {
|
|
2451
|
-
s3Client = new import_client_s3.S3Client({ endpoint, region: "us-east-1" });
|
|
2452
|
-
}
|
|
2453
|
-
return s3Client;
|
|
2454
|
-
}
|
|
2455
2447
|
function pipe(input, output) {
|
|
2456
2448
|
const toWait = new Promise(function(resolve5) {
|
|
2457
2449
|
output.on("close", () => {
|
|
@@ -2465,20 +2457,49 @@ function pipe(input, output) {
|
|
|
2465
2457
|
return toWait;
|
|
2466
2458
|
}
|
|
2467
2459
|
async function fetchSlice(sliceName) {
|
|
2460
|
+
var _a, _b;
|
|
2461
|
+
const GET_DOWNLOAD_URL = `/${BUILDER_NAMESPACE}/builder/getDownloadUrl`;
|
|
2462
|
+
const credentials = getCredentialsFromEnvironment();
|
|
2463
|
+
const owClient = (0, import_openwhisk.default)({
|
|
2464
|
+
apihost: credentials.ow.apihost,
|
|
2465
|
+
api_key: credentials.ow.api_key,
|
|
2466
|
+
namespace: credentials.namespace
|
|
2467
|
+
});
|
|
2468
|
+
const invoked = await owClient.actions.invoke({
|
|
2469
|
+
name: GET_DOWNLOAD_URL,
|
|
2470
|
+
params: {
|
|
2471
|
+
name: sliceName
|
|
2472
|
+
}
|
|
2473
|
+
});
|
|
2474
|
+
const activation = await waitForActivation(
|
|
2475
|
+
invoked.activationId,
|
|
2476
|
+
owClient,
|
|
2477
|
+
() => {
|
|
2478
|
+
debug6("fetching build assets ...");
|
|
2479
|
+
},
|
|
2480
|
+
60
|
|
2481
|
+
);
|
|
2482
|
+
if (!activation) {
|
|
2483
|
+
throw new Error(`Timed out fetching assets url for '${sliceName}'`);
|
|
2484
|
+
}
|
|
2485
|
+
const activationResponse = activation.response;
|
|
2486
|
+
const downloadUrl = (_b = (_a = activation.response) == null ? void 0 : _a.result) == null ? void 0 : _b.url;
|
|
2487
|
+
if (!activationResponse || !(activationResponse == null ? void 0 : activationResponse.success) || !downloadUrl) {
|
|
2488
|
+
throw new Error(`Failed to fetch assets url for '${sliceName}'`);
|
|
2489
|
+
}
|
|
2490
|
+
const response = await import_axios3.default.get(downloadUrl, {
|
|
2491
|
+
responseType: "stream"
|
|
2492
|
+
});
|
|
2468
2493
|
const cache = path3.join(cacheArea(), sliceName);
|
|
2469
2494
|
if (fs3.existsSync(cache)) {
|
|
2470
2495
|
rimraf.sync(cache);
|
|
2471
2496
|
}
|
|
2472
2497
|
debug6("Making cache directory: %s", cache);
|
|
2473
2498
|
fs3.mkdirSync(cache, { recursive: true });
|
|
2474
|
-
const s3 = getS3Client();
|
|
2475
|
-
const cmd = new import_client_s3.GetObjectCommand({ Bucket: bucket, Key: sliceName });
|
|
2476
|
-
const result = await s3.send(cmd);
|
|
2477
|
-
const content = result.Body;
|
|
2478
2499
|
const destination = new import_memory_streams.WritableStream({
|
|
2479
2500
|
highWaterMark: MAX_SLICE_UPLOAD_SIZE
|
|
2480
2501
|
});
|
|
2481
|
-
await pipe(
|
|
2502
|
+
await pipe(response.data, destination);
|
|
2482
2503
|
const data = destination.toBuffer();
|
|
2483
2504
|
const zip = new import_adm_zip.default(data);
|
|
2484
2505
|
debug6("zip file has %d entries", zip.getEntries().length);
|
|
@@ -2495,14 +2516,30 @@ async function fetchSlice(sliceName) {
|
|
|
2495
2516
|
return cache;
|
|
2496
2517
|
}
|
|
2497
2518
|
async function deleteSlice(project) {
|
|
2519
|
+
const DELETE_ASSETS_URL = `/${BUILDER_NAMESPACE}/builder/deleteBuildAssets`;
|
|
2498
2520
|
const sliceName = path3.relative(cacheArea(), project.filePath);
|
|
2499
|
-
const
|
|
2500
|
-
const
|
|
2501
|
-
|
|
2521
|
+
const credentials = getCredentialsFromEnvironment();
|
|
2522
|
+
const owClient = (0, import_openwhisk.default)({
|
|
2523
|
+
apihost: credentials.ow.apihost,
|
|
2524
|
+
api_key: credentials.ow.api_key,
|
|
2525
|
+
namespace: credentials.namespace
|
|
2526
|
+
});
|
|
2527
|
+
const invoked = await owClient.actions.invoke({
|
|
2528
|
+
name: DELETE_ASSETS_URL,
|
|
2529
|
+
params: {
|
|
2530
|
+
name: sliceName
|
|
2531
|
+
}
|
|
2532
|
+
});
|
|
2533
|
+
await waitForActivation(
|
|
2534
|
+
invoked.activationId,
|
|
2535
|
+
owClient,
|
|
2536
|
+
() => debug6("removing build assets ..."),
|
|
2537
|
+
60
|
|
2538
|
+
);
|
|
2502
2539
|
}
|
|
2503
2540
|
|
|
2504
2541
|
// src/finder-builder.ts
|
|
2505
|
-
var
|
|
2542
|
+
var openwhisk2 = require("openwhisk");
|
|
2506
2543
|
var debug7 = (0, import_debug7.default)("nim:deployer:finder-builder");
|
|
2507
2544
|
var zipDebug = (0, import_debug7.default)("nim:deployer:zip");
|
|
2508
2545
|
var ZIP_TARGET = "__deployer__.zip";
|
|
@@ -3184,7 +3221,7 @@ async function invokeRemoteBuilder(zipped, owClient, feedback, action, encryptio
|
|
|
3184
3221
|
maxBodyLength: MAX_SLICE_UPLOAD_SIZE,
|
|
3185
3222
|
maxContentLength: MAX_SLICE_UPLOAD_SIZE
|
|
3186
3223
|
};
|
|
3187
|
-
const result = await
|
|
3224
|
+
const result = await import_axios4.default.put(url, zipped, axiosConfig);
|
|
3188
3225
|
if (result.status !== 200) {
|
|
3189
3226
|
throw new Error(
|
|
3190
3227
|
`Bad response [$result.status}] when uploading '${sliceName}' for remote build`
|
|
@@ -3575,7 +3612,7 @@ var import_debug9 = __toESM(require("debug"));
|
|
|
3575
3612
|
// src/file-reader.ts
|
|
3576
3613
|
var fs5 = __toESM(require("fs"));
|
|
3577
3614
|
var Path = __toESM(require("path"));
|
|
3578
|
-
var
|
|
3615
|
+
var import_util5 = require("util");
|
|
3579
3616
|
var import_debug8 = __toESM(require("debug"));
|
|
3580
3617
|
var debug8 = (0, import_debug8.default)("nim:deployer:file-reader");
|
|
3581
3618
|
var fs_readdir;
|
|
@@ -3585,11 +3622,11 @@ var fs_realpath;
|
|
|
3585
3622
|
var fs_readlink;
|
|
3586
3623
|
function makeFileReader(basepath) {
|
|
3587
3624
|
debug8("making file reader on basepath '%s'", basepath);
|
|
3588
|
-
fs_readdir = (0,
|
|
3589
|
-
fs_readfile = (0,
|
|
3590
|
-
fs_lstat = (0,
|
|
3591
|
-
fs_realpath = (0,
|
|
3592
|
-
fs_readlink = (0,
|
|
3625
|
+
fs_readdir = (0, import_util5.promisify)(fs5.readdir);
|
|
3626
|
+
fs_readfile = (0, import_util5.promisify)(fs5.readFile);
|
|
3627
|
+
fs_lstat = (0, import_util5.promisify)(fs5.lstat);
|
|
3628
|
+
fs_realpath = (0, import_util5.promisify)(fs5.realpath);
|
|
3629
|
+
fs_readlink = (0, import_util5.promisify)(fs5.readlink);
|
|
3593
3630
|
return new FileProjectReader(basepath);
|
|
3594
3631
|
}
|
|
3595
3632
|
var FileProjectReader = class {
|
|
@@ -4116,7 +4153,7 @@ var IncluderImpl = class {
|
|
|
4116
4153
|
|
|
4117
4154
|
// src/api.ts
|
|
4118
4155
|
var import_debug11 = __toESM(require("debug"));
|
|
4119
|
-
var
|
|
4156
|
+
var openwhisk3 = require("openwhisk");
|
|
4120
4157
|
var debug11 = (0, import_debug11.default)("nim:deployer:api");
|
|
4121
4158
|
function initializeAPI(userAgent) {
|
|
4122
4159
|
const result = {};
|
|
@@ -4300,7 +4337,7 @@ async function prepareToDeploy(inputSpec, credentials, flags) {
|
|
|
4300
4337
|
inputSpec.flags = flags;
|
|
4301
4338
|
debug11("Options merged");
|
|
4302
4339
|
debug11("Auth sufficiency established");
|
|
4303
|
-
inputSpec.owClient =
|
|
4340
|
+
inputSpec.owClient = openwhisk3(wskoptions);
|
|
4304
4341
|
if (!credentials.namespace) {
|
|
4305
4342
|
credentials.namespace = await getTargetNamespace(inputSpec.owClient);
|
|
4306
4343
|
} else {
|
|
@@ -4321,7 +4358,7 @@ async function wipeNamespace(credentials) {
|
|
|
4321
4358
|
apihost: credentials.ow.apihost,
|
|
4322
4359
|
api_key: credentials.ow.api_key
|
|
4323
4360
|
};
|
|
4324
|
-
const client =
|
|
4361
|
+
const client = openwhisk3(init);
|
|
4325
4362
|
debug11("Client opened");
|
|
4326
4363
|
return wipe(client, credentials);
|
|
4327
4364
|
}
|
|
@@ -4404,7 +4441,7 @@ var import_http = require("http");
|
|
|
4404
4441
|
var import_debug12 = __toESM(require("debug"));
|
|
4405
4442
|
|
|
4406
4443
|
// src/version.ts
|
|
4407
|
-
var version = "5.0.
|
|
4444
|
+
var version = "5.0.20";
|
|
4408
4445
|
|
|
4409
4446
|
// src/main.ts
|
|
4410
4447
|
var verboseError = (0, import_debug12.default)("nim:error");
|