@digitalocean/functions-deployer 5.0.18
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/LICENSE +201 -0
- package/README.md +32 -0
- package/bin/run +18 -0
- package/lib/api.d.ts +16 -0
- package/lib/credentials.d.ts +23 -0
- package/lib/deploy-struct.d.ts +217 -0
- package/lib/deploy.d.ts +12 -0
- package/lib/file-reader.d.ts +2 -0
- package/lib/finder-builder.d.ts +8 -0
- package/lib/includer.d.ts +2 -0
- package/lib/index.d.ts +8 -0
- package/lib/index.js +5048 -0
- package/lib/index.js.map +7 -0
- package/lib/main.d.ts +37 -0
- package/lib/project-reader.d.ts +18 -0
- package/lib/runtimes.d.ts +21 -0
- package/lib/slice-reader.d.ts +4 -0
- package/lib/triggers.d.ts +4 -0
- package/lib/util.d.ts +66 -0
- package/lib/version.d.ts +1 -0
- package/lib/watch.d.ts +3 -0
- package/package.json +96 -0
package/lib/index.js
ADDED
|
@@ -0,0 +1,5048 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
21
|
+
mod
|
|
22
|
+
));
|
|
23
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
24
|
+
|
|
25
|
+
// src/index.ts
|
|
26
|
+
var src_exports = {};
|
|
27
|
+
__export(src_exports, {
|
|
28
|
+
API_ENDPOINT: () => API_ENDPOINT,
|
|
29
|
+
CaptureLogger: () => CaptureLogger,
|
|
30
|
+
DefaultFeedback: () => DefaultFeedback,
|
|
31
|
+
DefaultLogger: () => DefaultLogger,
|
|
32
|
+
SYSTEM_EXCLUDE_PATTERNS: () => SYSTEM_EXCLUDE_PATTERNS,
|
|
33
|
+
addCredentialAndSave: () => addCredentialAndSave,
|
|
34
|
+
authPersister: () => authPersister,
|
|
35
|
+
buildProject: () => buildProject,
|
|
36
|
+
canonicalRuntime: () => canonicalRuntime,
|
|
37
|
+
defaultRuntime: () => defaultRuntime,
|
|
38
|
+
delay: () => delay,
|
|
39
|
+
deleteAction: () => deleteAction,
|
|
40
|
+
deleteSlice: () => deleteSlice,
|
|
41
|
+
deploy: () => deploy,
|
|
42
|
+
deployProject: () => deployProject,
|
|
43
|
+
emptyStructure: () => emptyStructure,
|
|
44
|
+
fileExtensionForRuntime: () => fileExtensionForRuntime,
|
|
45
|
+
flush: () => flush,
|
|
46
|
+
forgetNamespace: () => forgetNamespace,
|
|
47
|
+
fromPlatform: () => fromPlatform,
|
|
48
|
+
getApiHosts: () => getApiHosts,
|
|
49
|
+
getBestProjectName: () => getBestProjectName,
|
|
50
|
+
getCredentialDict: () => getCredentialDict,
|
|
51
|
+
getCredentialList: () => getCredentialList,
|
|
52
|
+
getCredentials: () => getCredentials,
|
|
53
|
+
getCredentialsForNamespace: () => getCredentialsForNamespace,
|
|
54
|
+
getCredentialsFromEnvironment: () => getCredentialsFromEnvironment,
|
|
55
|
+
getCurrentNamespace: () => getCurrentNamespace,
|
|
56
|
+
getExclusionList: () => getExclusionList,
|
|
57
|
+
getRuntimeForAction: () => getRuntimeForAction,
|
|
58
|
+
getRuntimes: () => getRuntimes,
|
|
59
|
+
getUserAgent: () => getUserAgent,
|
|
60
|
+
handleError: () => handleError,
|
|
61
|
+
initializeAPI: () => initializeAPI,
|
|
62
|
+
invokeWebSecure: () => invokeWebSecure,
|
|
63
|
+
isBinaryFileExtension: () => isBinaryFileExtension,
|
|
64
|
+
isExcluded: () => isExcluded,
|
|
65
|
+
isValidRuntime: () => isValidRuntime,
|
|
66
|
+
load: () => load,
|
|
67
|
+
main: () => main,
|
|
68
|
+
makeIncluder: () => makeIncluder,
|
|
69
|
+
nimbellaDir: () => nimbellaDir,
|
|
70
|
+
prepareToDeploy: () => prepareToDeploy,
|
|
71
|
+
readAndPrepare: () => readAndPrepare,
|
|
72
|
+
readPrepareAndBuild: () => readPrepareAndBuild,
|
|
73
|
+
readProject: () => readProject,
|
|
74
|
+
renameActionsToFunctions: () => renameActionsToFunctions,
|
|
75
|
+
renamePackage: () => renamePackage,
|
|
76
|
+
runCommand: () => runCommand,
|
|
77
|
+
runtimeForFileExtension: () => runtimeForFileExtension,
|
|
78
|
+
runtimeForZipMid: () => runtimeForZipMid,
|
|
79
|
+
switchNamespace: () => switchNamespace,
|
|
80
|
+
wipeNamespace: () => wipeNamespace,
|
|
81
|
+
wipePackage: () => wipePackage,
|
|
82
|
+
writeSliceResult: () => writeSliceResult,
|
|
83
|
+
wskRequest: () => wskRequest
|
|
84
|
+
});
|
|
85
|
+
module.exports = __toCommonJS(src_exports);
|
|
86
|
+
|
|
87
|
+
// src/deploy-struct.ts
|
|
88
|
+
var TriggerType = /* @__PURE__ */ ((TriggerType2) => {
|
|
89
|
+
TriggerType2["SCHEDULED"] = "SCHEDULED";
|
|
90
|
+
return TriggerType2;
|
|
91
|
+
})(TriggerType || {});
|
|
92
|
+
var DefaultFeedback = class {
|
|
93
|
+
warn(message, ...optionalParams) {
|
|
94
|
+
console.warn(message, ...optionalParams);
|
|
95
|
+
}
|
|
96
|
+
progress(message, ...optionalParams) {
|
|
97
|
+
console.log(message, ...optionalParams);
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
// src/util.ts
|
|
102
|
+
var import_xmlhttprequest = require("xmlhttprequest");
|
|
103
|
+
var import_cron_validator = require("cron-validator");
|
|
104
|
+
var fs2 = __toESM(require("fs"));
|
|
105
|
+
var os = __toESM(require("os"));
|
|
106
|
+
var path2 = __toESM(require("path"));
|
|
107
|
+
var import_simple_git = __toESM(require("simple-git"));
|
|
108
|
+
var randomstring = __toESM(require("randomstring"));
|
|
109
|
+
var crypto = __toESM(require("crypto"));
|
|
110
|
+
var yaml = __toESM(require("js-yaml"));
|
|
111
|
+
var import_debug4 = __toESM(require("debug"));
|
|
112
|
+
var import_anymatch = __toESM(require("anymatch"));
|
|
113
|
+
|
|
114
|
+
// src/credentials.ts
|
|
115
|
+
var fs = __toESM(require("fs"));
|
|
116
|
+
var path = __toESM(require("path"));
|
|
117
|
+
var import_debug = __toESM(require("debug"));
|
|
118
|
+
var debug = (0, import_debug.default)("nimbella.cli");
|
|
119
|
+
var HOME = process.env[process.platform === "win32" ? "USERPROFILE" : "HOME"];
|
|
120
|
+
var NAMESPACE_URL_PATH = "/api/v1/namespaces";
|
|
121
|
+
var NIMBELLA_DIR = ".nimbella";
|
|
122
|
+
var WSK_PROPS = "wskprops";
|
|
123
|
+
var CREDENTIAL_STORE = "credentials.json";
|
|
124
|
+
function nimbellaDir() {
|
|
125
|
+
const fromEnv = process.env.NIMBELLA_DIR;
|
|
126
|
+
if (fromEnv && fromEnv.length > 0) {
|
|
127
|
+
return fromEnv;
|
|
128
|
+
}
|
|
129
|
+
return path.join(HOME, NIMBELLA_DIR);
|
|
130
|
+
}
|
|
131
|
+
function wskProps() {
|
|
132
|
+
return path.join(nimbellaDir(), WSK_PROPS);
|
|
133
|
+
}
|
|
134
|
+
function credentialStore() {
|
|
135
|
+
return path.join(nimbellaDir(), CREDENTIAL_STORE);
|
|
136
|
+
}
|
|
137
|
+
var fileSystemPersister = {
|
|
138
|
+
loadCredentialStoreIfPresent,
|
|
139
|
+
loadCredentialStore,
|
|
140
|
+
saveCredentialStore,
|
|
141
|
+
saveLegacyInfo
|
|
142
|
+
};
|
|
143
|
+
var authPersister = fileSystemPersister;
|
|
144
|
+
function addCredential(store, apihost, namespace, api_key) {
|
|
145
|
+
debug("Adding credential to credential store");
|
|
146
|
+
let nsMap = store.credentials[apihost];
|
|
147
|
+
if (!nsMap) {
|
|
148
|
+
nsMap = {};
|
|
149
|
+
store.credentials[apihost] = nsMap;
|
|
150
|
+
}
|
|
151
|
+
nsMap[namespace] = { api_key };
|
|
152
|
+
store.currentHost = apihost;
|
|
153
|
+
store.currentNamespace = namespace;
|
|
154
|
+
return {
|
|
155
|
+
namespace,
|
|
156
|
+
ow: { apihost, api_key },
|
|
157
|
+
do_token: process.env.DO_API_KEY
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
async function forgetNamespace(namespace, apihost, feedback) {
|
|
161
|
+
const store = await authPersister.loadCredentialStore();
|
|
162
|
+
const creds = getUniqueCredentials(namespace, apihost, store);
|
|
163
|
+
const host = apihost || creds.ow.apihost;
|
|
164
|
+
const hostMap = store.credentials[host];
|
|
165
|
+
let undefinedWarning = false;
|
|
166
|
+
if (hostMap && hostMap[namespace]) {
|
|
167
|
+
delete hostMap[namespace];
|
|
168
|
+
if (host === store.currentHost && store.currentNamespace === namespace) {
|
|
169
|
+
store.currentNamespace = void 0;
|
|
170
|
+
undefinedWarning = true;
|
|
171
|
+
try {
|
|
172
|
+
fs.unlinkSync(wskProps());
|
|
173
|
+
} catch {
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
authPersister.saveCredentialStore(store);
|
|
177
|
+
if (undefinedWarning) {
|
|
178
|
+
feedback.warn(`'${namespace}' was the current namespace`);
|
|
179
|
+
feedback.warn(
|
|
180
|
+
"A new namespace target must be specified on or before the next project deployment"
|
|
181
|
+
);
|
|
182
|
+
}
|
|
183
|
+
} else {
|
|
184
|
+
feedback.warn(
|
|
185
|
+
`There is no credential entry for namespace '${namespace}' on API host '${host}'`
|
|
186
|
+
);
|
|
187
|
+
}
|
|
188
|
+
return creds;
|
|
189
|
+
}
|
|
190
|
+
async function switchNamespace(namespace, apihost) {
|
|
191
|
+
const store = await authPersister.loadCredentialStore();
|
|
192
|
+
const answer = getUniqueCredentials(namespace, apihost, store);
|
|
193
|
+
const newHost = answer.ow.apihost;
|
|
194
|
+
if (store.currentHost === newHost && store.currentNamespace === namespace) {
|
|
195
|
+
debug("not an actual change");
|
|
196
|
+
return answer;
|
|
197
|
+
}
|
|
198
|
+
store.currentHost = newHost;
|
|
199
|
+
store.currentNamespace = namespace;
|
|
200
|
+
authPersister.saveCredentialStore(store);
|
|
201
|
+
authPersister.saveLegacyInfo(newHost, answer.ow.api_key);
|
|
202
|
+
debug(`Switched target namespace to '${namespace}' on API host '${newHost}'`);
|
|
203
|
+
return answer;
|
|
204
|
+
}
|
|
205
|
+
function getCredentialsFromEnvironment() {
|
|
206
|
+
const apihost = process.env.__OW_API_HOST;
|
|
207
|
+
const namespace = process.env.__OW_NAMESPACE;
|
|
208
|
+
const api_key = process.env.__OW_API_KEY;
|
|
209
|
+
const do_token = process.env.DO_API_KEY;
|
|
210
|
+
return { namespace, ow: { api_key, apihost }, do_token };
|
|
211
|
+
}
|
|
212
|
+
async function getCredentialsForNamespace(namespace, apihost) {
|
|
213
|
+
const store = await authPersister.loadCredentialStore();
|
|
214
|
+
return getUniqueCredentials(namespace, apihost, store);
|
|
215
|
+
}
|
|
216
|
+
async function getCredentials() {
|
|
217
|
+
const store = await authPersister.loadCredentialStore();
|
|
218
|
+
if (!store.currentHost || !store.currentNamespace) {
|
|
219
|
+
throw new Error(
|
|
220
|
+
"You do not have a current namespace. Use 'nim auth login' to create a new one or 'nim auth switch' to use an existing one"
|
|
221
|
+
);
|
|
222
|
+
}
|
|
223
|
+
const entry = store.credentials[store.currentHost][store.currentNamespace];
|
|
224
|
+
const { api_key } = entry;
|
|
225
|
+
return {
|
|
226
|
+
namespace: store.currentNamespace,
|
|
227
|
+
ow: { apihost: store.currentHost, api_key },
|
|
228
|
+
do_token: process.env.DO_API_KEY
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
async function addCredentialAndSave(apihost, auth, namespace) {
|
|
232
|
+
const credStore = await authPersister.loadCredentialStore();
|
|
233
|
+
const nsPromise = namespace ? Promise.resolve(namespace) : getNamespace(apihost, auth);
|
|
234
|
+
return nsPromise.then((namespace2) => {
|
|
235
|
+
const credentials = addCredential(credStore, apihost, namespace2, auth);
|
|
236
|
+
authPersister.saveCredentialStore(credStore);
|
|
237
|
+
return credentials;
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
async function getCredentialDict() {
|
|
241
|
+
const store = await authPersister.loadCredentialStore();
|
|
242
|
+
const result = {};
|
|
243
|
+
for (const apihost in store.credentials) {
|
|
244
|
+
let rows = [];
|
|
245
|
+
for (const namespace in store.credentials[apihost]) {
|
|
246
|
+
const current = apihost === store.currentHost && namespace === store.currentNamespace;
|
|
247
|
+
rows.push({ namespace, current, apihost });
|
|
248
|
+
rows = rows.sort((a, b) => a.namespace.localeCompare(b.namespace));
|
|
249
|
+
}
|
|
250
|
+
result[apihost] = rows;
|
|
251
|
+
}
|
|
252
|
+
return result;
|
|
253
|
+
}
|
|
254
|
+
async function getApiHosts(persister) {
|
|
255
|
+
const store = await persister.loadCredentialStore();
|
|
256
|
+
return Object.keys(store.credentials);
|
|
257
|
+
}
|
|
258
|
+
async function getCredentialList() {
|
|
259
|
+
const dict = await getCredentialDict();
|
|
260
|
+
return Object.values(dict).reduce((acc, val) => acc.concat(val), []);
|
|
261
|
+
}
|
|
262
|
+
function getNamespace(host, auth) {
|
|
263
|
+
debug("getting current namespace");
|
|
264
|
+
const url = host + NAMESPACE_URL_PATH;
|
|
265
|
+
return wskRequest(url, auth).then((list) => list[0]);
|
|
266
|
+
}
|
|
267
|
+
async function getCurrentNamespace() {
|
|
268
|
+
debug("getting current namespace");
|
|
269
|
+
const store = await authPersister.loadCredentialStore();
|
|
270
|
+
return store.currentNamespace;
|
|
271
|
+
}
|
|
272
|
+
function saveCredentialStore(store) {
|
|
273
|
+
const toWrite = JSON.stringify(store, null, 2);
|
|
274
|
+
debug("writing credential store");
|
|
275
|
+
fs.writeFileSync(credentialStore(), toWrite, { mode: 384 });
|
|
276
|
+
}
|
|
277
|
+
function saveLegacyInfo(apihost, auth) {
|
|
278
|
+
saveWskProps(apihost, auth);
|
|
279
|
+
debug("stored .wskprops with API host %s", apihost);
|
|
280
|
+
}
|
|
281
|
+
function loadCredentialStore() {
|
|
282
|
+
if (!fs.existsSync(credentialStore())) {
|
|
283
|
+
return Promise.resolve(initialCredentialStore());
|
|
284
|
+
}
|
|
285
|
+
const contents = fs.readFileSync(credentialStore());
|
|
286
|
+
return Promise.resolve(JSON.parse(String(contents)));
|
|
287
|
+
}
|
|
288
|
+
function loadCredentialStoreIfPresent() {
|
|
289
|
+
if (!fs.existsSync(credentialStore())) {
|
|
290
|
+
return void 0;
|
|
291
|
+
}
|
|
292
|
+
const contents = fs.readFileSync(credentialStore());
|
|
293
|
+
return JSON.parse(String(contents));
|
|
294
|
+
}
|
|
295
|
+
function initialCredentialStore() {
|
|
296
|
+
if (!fs.existsSync(nimbellaDir())) {
|
|
297
|
+
fs.mkdirSync(nimbellaDir(), { mode: 448 });
|
|
298
|
+
}
|
|
299
|
+
return {
|
|
300
|
+
currentHost: void 0,
|
|
301
|
+
currentNamespace: void 0,
|
|
302
|
+
credentials: {}
|
|
303
|
+
};
|
|
304
|
+
}
|
|
305
|
+
function saveWskProps(apihost, auth) {
|
|
306
|
+
const wskPropsContents = `APIHOST=${apihost}
|
|
307
|
+
AUTH=${auth}
|
|
308
|
+
`;
|
|
309
|
+
fs.writeFileSync(wskProps(), wskPropsContents, { mode: 384 });
|
|
310
|
+
}
|
|
311
|
+
function getUniqueCredentials(namespace, apihost, store) {
|
|
312
|
+
const possibles = {};
|
|
313
|
+
let credentialEntry;
|
|
314
|
+
let newHost;
|
|
315
|
+
for (const host in store.credentials) {
|
|
316
|
+
const entry = store.credentials[host][namespace];
|
|
317
|
+
if (entry) {
|
|
318
|
+
possibles[host] = entry;
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
if (apihost) {
|
|
322
|
+
if (possibles[apihost]) {
|
|
323
|
+
credentialEntry = possibles[apihost];
|
|
324
|
+
newHost = apihost;
|
|
325
|
+
} else {
|
|
326
|
+
throw new Error(
|
|
327
|
+
`No credentials found for namespace '${namespace}' on API host '${apihost}'`
|
|
328
|
+
);
|
|
329
|
+
}
|
|
330
|
+
} else {
|
|
331
|
+
const pairs = Object.entries(possibles);
|
|
332
|
+
if (pairs.length === 1) {
|
|
333
|
+
[newHost, credentialEntry] = pairs[0];
|
|
334
|
+
} else if (pairs.length === 0) {
|
|
335
|
+
throw new Error(
|
|
336
|
+
`No credentials found for namespace '${namespace}' on any API host`
|
|
337
|
+
);
|
|
338
|
+
} else {
|
|
339
|
+
throw new Error(
|
|
340
|
+
`The namespace '${namespace}' exists on more than one API host. An '--apihost' argument is required`
|
|
341
|
+
);
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
const { api_key } = credentialEntry;
|
|
345
|
+
debug("have authkey: %s", api_key);
|
|
346
|
+
return {
|
|
347
|
+
namespace,
|
|
348
|
+
ow: { apihost: newHost, api_key },
|
|
349
|
+
do_token: process.env.DO_API_KEY
|
|
350
|
+
};
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
// src/runtimes.ts
|
|
354
|
+
var import_axios = __toESM(require("axios"));
|
|
355
|
+
var import_debug2 = __toESM(require("debug"));
|
|
356
|
+
var debug_log = (0, import_debug2.default)("nim:deployer:runtimes");
|
|
357
|
+
var API_ENDPOINT = "/api/v1";
|
|
358
|
+
var cachedRuntimes;
|
|
359
|
+
var staticRuntimes = {
|
|
360
|
+
go: [
|
|
361
|
+
{
|
|
362
|
+
default: false,
|
|
363
|
+
kind: "go:1.15"
|
|
364
|
+
},
|
|
365
|
+
{
|
|
366
|
+
default: true,
|
|
367
|
+
kind: "go:1.17"
|
|
368
|
+
}
|
|
369
|
+
],
|
|
370
|
+
nodejs: [
|
|
371
|
+
{
|
|
372
|
+
default: true,
|
|
373
|
+
kind: "nodejs:14"
|
|
374
|
+
},
|
|
375
|
+
{
|
|
376
|
+
default: false,
|
|
377
|
+
kind: "nodejs-lambda:14"
|
|
378
|
+
},
|
|
379
|
+
{
|
|
380
|
+
default: false,
|
|
381
|
+
kind: "nodejs:18"
|
|
382
|
+
},
|
|
383
|
+
{
|
|
384
|
+
default: false,
|
|
385
|
+
kind: "nodejs-lambda:18"
|
|
386
|
+
}
|
|
387
|
+
],
|
|
388
|
+
php: [
|
|
389
|
+
{
|
|
390
|
+
default: true,
|
|
391
|
+
kind: "php:8.0"
|
|
392
|
+
}
|
|
393
|
+
],
|
|
394
|
+
python: [
|
|
395
|
+
{
|
|
396
|
+
default: true,
|
|
397
|
+
kind: "python:3.9"
|
|
398
|
+
}
|
|
399
|
+
]
|
|
400
|
+
};
|
|
401
|
+
var FileExtensionRuntimes = {
|
|
402
|
+
go: ["go"],
|
|
403
|
+
nodejs: ["js", "ts"],
|
|
404
|
+
php: ["php"],
|
|
405
|
+
python: ["py"]
|
|
406
|
+
};
|
|
407
|
+
var BinaryFileExtensions = /* @__PURE__ */ new Set(["zip", "jar"]);
|
|
408
|
+
async function fromPlatform(httpClient, platformUrl) {
|
|
409
|
+
const url = `${platformUrl}${API_ENDPOINT}`;
|
|
410
|
+
debug_log(`loading runtimes from platform @ ${url}`);
|
|
411
|
+
try {
|
|
412
|
+
const { data } = await httpClient.get(url);
|
|
413
|
+
debug_log(`loaded runtimes json: ${JSON.stringify(data)}`);
|
|
414
|
+
return data == null ? void 0 : data.runtimes;
|
|
415
|
+
} catch (err) {
|
|
416
|
+
if (err.response) {
|
|
417
|
+
throw new Error(
|
|
418
|
+
`http request failed (${url}) with status (${err.response.status}): ${err.response.statusText} `
|
|
419
|
+
);
|
|
420
|
+
} else if (err.request) {
|
|
421
|
+
throw new Error(`http request failed: GET ${url}`);
|
|
422
|
+
} else {
|
|
423
|
+
throw err;
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
function runtimeForFileExtension(fileExtension) {
|
|
428
|
+
const runtime = Object.entries(FileExtensionRuntimes).find(
|
|
429
|
+
(item) => item[1].includes(fileExtension)
|
|
430
|
+
);
|
|
431
|
+
return runtime && runtime.length > 0 ? `${runtime[0]}:default` : void 0;
|
|
432
|
+
}
|
|
433
|
+
function isBinaryFileExtension(fileExtension) {
|
|
434
|
+
return BinaryFileExtensions.has(fileExtension);
|
|
435
|
+
}
|
|
436
|
+
function fileExtensionForRuntime(runtime, isBinaryExtension) {
|
|
437
|
+
debug_log(
|
|
438
|
+
`fileExtensionForRuntime: runtime (${runtime}) binary (${isBinaryExtension})`
|
|
439
|
+
);
|
|
440
|
+
const isSameRuntime = (r) => r.includes(runtime);
|
|
441
|
+
const isValidRuntime2 = Object.keys(FileExtensionRuntimes).some(isSameRuntime);
|
|
442
|
+
if (!isValidRuntime2)
|
|
443
|
+
throw new Error(`Invalid runtime ${runtime} encountered`);
|
|
444
|
+
return isBinaryExtension ? FileExtensionRuntimes[runtime].filter(
|
|
445
|
+
(item) => BinaryFileExtensions.has(item)
|
|
446
|
+
)[0] : FileExtensionRuntimes[runtime][0];
|
|
447
|
+
}
|
|
448
|
+
async function isValidRuntime(kind) {
|
|
449
|
+
debug_log(`isValidRuntime: kind (${kind})`);
|
|
450
|
+
let exactMatch = true;
|
|
451
|
+
if (kind.endsWith(":default")) {
|
|
452
|
+
kind = kind.split(":")[0] + ":";
|
|
453
|
+
exactMatch = false;
|
|
454
|
+
}
|
|
455
|
+
debug_log("searching");
|
|
456
|
+
const runtimes = await getRuntimes();
|
|
457
|
+
for (const runtimeArray of Object.values(runtimes)) {
|
|
458
|
+
for (const runtime of runtimeArray) {
|
|
459
|
+
if (exactMatch && kind === runtime.kind) {
|
|
460
|
+
debug_log(`${kind}===${runtime.kind}`);
|
|
461
|
+
return true;
|
|
462
|
+
} else if (!exactMatch && runtime.kind.startsWith(kind) && runtime.default) {
|
|
463
|
+
debug_log(`${runtime.kind} starts with ${kind} and is the default`);
|
|
464
|
+
return true;
|
|
465
|
+
}
|
|
466
|
+
debug_log(`no match on ${runtime.kind}`);
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
return false;
|
|
470
|
+
}
|
|
471
|
+
function defaultRuntime(runtimes, label) {
|
|
472
|
+
debug_log(`defaultRuntime: runtimes (${runtimes}) label (${label})`);
|
|
473
|
+
const kinds = runtimes[label] ?? [];
|
|
474
|
+
const defaultRuntime2 = kinds.find((k) => k.default) ?? { kind: void 0 };
|
|
475
|
+
return defaultRuntime2.kind;
|
|
476
|
+
}
|
|
477
|
+
async function runtimeForZipMid(mid) {
|
|
478
|
+
const runtime = mid.includes("-") ? mid.replace("-", ":") : `${mid}:default`;
|
|
479
|
+
return await isValidRuntime(runtime) ? runtime : void 0;
|
|
480
|
+
}
|
|
481
|
+
async function canonicalRuntime(runtime) {
|
|
482
|
+
if (runtime.endsWith(":default")) {
|
|
483
|
+
const [label] = runtime.split(":");
|
|
484
|
+
const runtimes = await getRuntimes();
|
|
485
|
+
return defaultRuntime(runtimes, label);
|
|
486
|
+
}
|
|
487
|
+
return runtime;
|
|
488
|
+
}
|
|
489
|
+
function isValidRuntimesJson(src) {
|
|
490
|
+
return Object.values(src).every(
|
|
491
|
+
(v) => Array.isArray(v) && v.every((k) => k.hasOwnProperty("kind"))
|
|
492
|
+
);
|
|
493
|
+
}
|
|
494
|
+
async function load(apihost) {
|
|
495
|
+
const runtimes = await fromPlatform(import_axios.default, apihost);
|
|
496
|
+
if (!isValidRuntimesJson(runtimes)) {
|
|
497
|
+
throw new Error(
|
|
498
|
+
`Invalid runtime JSON received from platform API: ${apihost}`
|
|
499
|
+
);
|
|
500
|
+
}
|
|
501
|
+
return runtimes;
|
|
502
|
+
}
|
|
503
|
+
async function getRuntimes() {
|
|
504
|
+
var _a;
|
|
505
|
+
if (cachedRuntimes) {
|
|
506
|
+
return cachedRuntimes;
|
|
507
|
+
}
|
|
508
|
+
let creds;
|
|
509
|
+
try {
|
|
510
|
+
creds = await getCredentials();
|
|
511
|
+
} catch {
|
|
512
|
+
}
|
|
513
|
+
const apihost = ((_a = creds == null ? void 0 : creds.ow) == null ? void 0 : _a.apihost) || process.env.__OW_API_HOST || process.env.savedOW_API_HOST;
|
|
514
|
+
if (apihost) {
|
|
515
|
+
cachedRuntimes = await load(apihost);
|
|
516
|
+
} else {
|
|
517
|
+
cachedRuntimes = staticRuntimes;
|
|
518
|
+
}
|
|
519
|
+
return cachedRuntimes;
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
// src/triggers.ts
|
|
523
|
+
var import_axios2 = __toESM(require("axios"));
|
|
524
|
+
var import_debug3 = __toESM(require("debug"));
|
|
525
|
+
var debug3 = (0, import_debug3.default)("nim:deployer:triggers");
|
|
526
|
+
var doAPIEndpoint = "https://api.digitalocean.com";
|
|
527
|
+
async function deployTriggers(triggers, functionName, credentials) {
|
|
528
|
+
const result = [];
|
|
529
|
+
for (const trigger of triggers) {
|
|
530
|
+
result.push(await deployTrigger(trigger, functionName, credentials));
|
|
531
|
+
}
|
|
532
|
+
debug3("finished deploying triggers, returning result");
|
|
533
|
+
return result;
|
|
534
|
+
}
|
|
535
|
+
async function undeployTriggers(triggers, credentials) {
|
|
536
|
+
const errors = [];
|
|
537
|
+
for (const trigger of triggers) {
|
|
538
|
+
try {
|
|
539
|
+
await undeployTrigger(trigger, credentials);
|
|
540
|
+
} catch (err) {
|
|
541
|
+
const msg = err.message ? err.message : err;
|
|
542
|
+
errors.push(new Error(`unable to undeploy trigger '${trigger}': ${msg}`));
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
return errors;
|
|
546
|
+
}
|
|
547
|
+
async function deployTrigger(trigger, functionName, credentials) {
|
|
548
|
+
const details = trigger.scheduledDetails;
|
|
549
|
+
const { cron, body } = details;
|
|
550
|
+
const { enabled } = trigger;
|
|
551
|
+
const { do_token } = credentials;
|
|
552
|
+
try {
|
|
553
|
+
if (do_token) {
|
|
554
|
+
debug3("calling the trigger API to create %s", trigger.name);
|
|
555
|
+
return await doTriggerCreate(
|
|
556
|
+
trigger.name,
|
|
557
|
+
functionName,
|
|
558
|
+
credentials,
|
|
559
|
+
cron,
|
|
560
|
+
enabled,
|
|
561
|
+
body
|
|
562
|
+
);
|
|
563
|
+
}
|
|
564
|
+
} catch (err) {
|
|
565
|
+
debug3("caught an error while deploying trigger; will return it");
|
|
566
|
+
if (typeof err === "string") {
|
|
567
|
+
return new Error(err);
|
|
568
|
+
}
|
|
569
|
+
return err;
|
|
570
|
+
}
|
|
571
|
+
return { name: trigger.name, kind: "trigger", skipped: true };
|
|
572
|
+
}
|
|
573
|
+
async function doTriggerCreate(trigger, fcn, credentials, cron, enabled, withBody) {
|
|
574
|
+
try {
|
|
575
|
+
await doTriggerDelete(trigger, credentials);
|
|
576
|
+
} catch {
|
|
577
|
+
}
|
|
578
|
+
const config = {
|
|
579
|
+
url: `${doAPIEndpoint}/v2/functions/namespaces/${credentials.namespace}/triggers`,
|
|
580
|
+
method: "post",
|
|
581
|
+
data: {
|
|
582
|
+
name: trigger,
|
|
583
|
+
function: fcn,
|
|
584
|
+
is_enabled: enabled !== false,
|
|
585
|
+
type: "SCHEDULED",
|
|
586
|
+
scheduled_details: {
|
|
587
|
+
cron,
|
|
588
|
+
body: withBody
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
};
|
|
592
|
+
debug3("trigger create request config is: %O", config);
|
|
593
|
+
await doAxios(config, credentials.do_token);
|
|
594
|
+
return { name: trigger, kind: "trigger", skipped: false };
|
|
595
|
+
}
|
|
596
|
+
async function doAxios(config, token) {
|
|
597
|
+
config.headers = {
|
|
598
|
+
Authorization: `Bearer ${token}`
|
|
599
|
+
};
|
|
600
|
+
const response = await (0, import_axios2.default)(config);
|
|
601
|
+
return response.data;
|
|
602
|
+
}
|
|
603
|
+
async function undeployTrigger(trigger, credentials) {
|
|
604
|
+
debug3("undeploying trigger %s", trigger);
|
|
605
|
+
const { do_token } = credentials;
|
|
606
|
+
if (do_token) {
|
|
607
|
+
return doTriggerDelete(trigger, credentials);
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
async function doTriggerDelete(trigger, credentials) {
|
|
611
|
+
const config = {
|
|
612
|
+
url: `${doAPIEndpoint}/v2/functions/namespaces/${credentials.namespace}/triggers/${trigger}`,
|
|
613
|
+
method: "delete"
|
|
614
|
+
};
|
|
615
|
+
return doAxios(config, credentials.do_token);
|
|
616
|
+
}
|
|
617
|
+
async function listTriggersForNamespace(namespace, credentials, fcn) {
|
|
618
|
+
debug3("listing triggers");
|
|
619
|
+
const { do_token } = credentials;
|
|
620
|
+
if (do_token) {
|
|
621
|
+
return doTriggerList(namespace, credentials, fcn);
|
|
622
|
+
}
|
|
623
|
+
return [];
|
|
624
|
+
}
|
|
625
|
+
async function doTriggerList(namespace, credentials, fcn) {
|
|
626
|
+
const config = {
|
|
627
|
+
url: `${doAPIEndpoint}/v2/functions/namespaces/${namespace}/triggers`,
|
|
628
|
+
method: "get"
|
|
629
|
+
};
|
|
630
|
+
let triggers;
|
|
631
|
+
try {
|
|
632
|
+
triggers = await doAxios(config, credentials.do_token);
|
|
633
|
+
} catch (err) {
|
|
634
|
+
debug3("error listing triggers: %s", err.message);
|
|
635
|
+
return [];
|
|
636
|
+
}
|
|
637
|
+
debug3("got trigger list result from the API: %O", triggers);
|
|
638
|
+
if (!triggers.triggers) {
|
|
639
|
+
debug3("result did not have triggers member");
|
|
640
|
+
return [];
|
|
641
|
+
}
|
|
642
|
+
const filtered = fcn ? triggers.triggers.filter((trig) => trig.function === fcn) : triggers.triggers;
|
|
643
|
+
const names = filtered.map((trig) => trig.name);
|
|
644
|
+
debug3("reduced the list to %O", names);
|
|
645
|
+
return names;
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
// src/util.ts
|
|
649
|
+
var debug4 = (0, import_debug4.default)("nim:deployer:util");
|
|
650
|
+
var SYSTEM_EXCLUDE_PATTERNS = [
|
|
651
|
+
".gitignore",
|
|
652
|
+
".DS_Store",
|
|
653
|
+
"**/.git/**",
|
|
654
|
+
(s) => s.includes(".nimbella"),
|
|
655
|
+
(s) => s.includes(".deployed"),
|
|
656
|
+
(s) => s.includes("_tmp_"),
|
|
657
|
+
(s) => s.includes(".#"),
|
|
658
|
+
(s) => s.endsWith("~"),
|
|
659
|
+
"**/*.swp",
|
|
660
|
+
"**/*.swx"
|
|
661
|
+
];
|
|
662
|
+
async function loadProjectConfig(configFile, envPath, buildEnvPath, filePath, reader, feedback, noTriggers) {
|
|
663
|
+
const learnMore = " Learn more about the project configuration file https://docs.digitalocean.com/products/functions/reference/project-configuration/";
|
|
664
|
+
return reader.readFileContents(configFile).then(async (data) => {
|
|
665
|
+
let configData = String(data);
|
|
666
|
+
const encryptionKey = process.env.ENCRYPTION_KEY;
|
|
667
|
+
if (encryptionKey) {
|
|
668
|
+
configData = decryptProjectConfig(configData, encryptionKey);
|
|
669
|
+
}
|
|
670
|
+
try {
|
|
671
|
+
const { content, badVars } = substituteFromEnvAndFiles(
|
|
672
|
+
String(configData),
|
|
673
|
+
envPath,
|
|
674
|
+
filePath,
|
|
675
|
+
feedback
|
|
676
|
+
);
|
|
677
|
+
let config;
|
|
678
|
+
if (configFile.endsWith(".json")) {
|
|
679
|
+
config = JSON.parse(content);
|
|
680
|
+
} else {
|
|
681
|
+
if (content.includes(" ")) {
|
|
682
|
+
throw new Error("YAML configuration may not contain tabs");
|
|
683
|
+
} else {
|
|
684
|
+
config = yaml.safeLoad(content);
|
|
685
|
+
}
|
|
686
|
+
}
|
|
687
|
+
if (!config) {
|
|
688
|
+
throw new Error("configuration is empty or unparseable");
|
|
689
|
+
}
|
|
690
|
+
renameFunctionsToActions(config);
|
|
691
|
+
const configError = await validateDeployConfig(config, noTriggers);
|
|
692
|
+
if (configError) {
|
|
693
|
+
throw new Error(configError);
|
|
694
|
+
} else {
|
|
695
|
+
removeEmptyStringMembers(config);
|
|
696
|
+
}
|
|
697
|
+
if (buildEnvPath) {
|
|
698
|
+
config.buildEnv = getPropsFromFile(buildEnvPath);
|
|
699
|
+
}
|
|
700
|
+
config.unresolvedVariables = badVars;
|
|
701
|
+
if (badVars && badVars.length > 0) {
|
|
702
|
+
const formatted = "'" + badVars.join("', '") + "'";
|
|
703
|
+
config.error = new Error(
|
|
704
|
+
"The following substitutions could not be resolved: " + formatted
|
|
705
|
+
);
|
|
706
|
+
}
|
|
707
|
+
return config;
|
|
708
|
+
} catch (err) {
|
|
709
|
+
const errMsgPrefix = `Invalid project configuration file (${configFile})`;
|
|
710
|
+
if (err.message) {
|
|
711
|
+
err.message = `${errMsgPrefix}: ${err.message}`;
|
|
712
|
+
} else {
|
|
713
|
+
err.message = `${errMsgPrefix}`;
|
|
714
|
+
}
|
|
715
|
+
err.message = `${err.message}
|
|
716
|
+
${learnMore}`;
|
|
717
|
+
return errorStructure(err);
|
|
718
|
+
}
|
|
719
|
+
});
|
|
720
|
+
}
|
|
721
|
+
function encryptProjectConfig(config) {
|
|
722
|
+
const key = crypto.randomBytes(32);
|
|
723
|
+
const iv = Buffer.alloc(16).fill(0);
|
|
724
|
+
const cipher = crypto.createCipheriv("aes256", key, iv);
|
|
725
|
+
const encrypted = cipher.update(config, "utf8", "hex") + cipher.final("hex");
|
|
726
|
+
return {
|
|
727
|
+
config: encrypted,
|
|
728
|
+
key: key.toString("hex")
|
|
729
|
+
};
|
|
730
|
+
}
|
|
731
|
+
function decryptProjectConfig(config, key) {
|
|
732
|
+
const iv = Buffer.alloc(16).fill(0);
|
|
733
|
+
const decipher = crypto.createDecipheriv(
|
|
734
|
+
"aes256",
|
|
735
|
+
Buffer.from(key, "hex"),
|
|
736
|
+
iv
|
|
737
|
+
);
|
|
738
|
+
const decryptedMessage = Buffer.concat([
|
|
739
|
+
decipher.update(config, "hex"),
|
|
740
|
+
decipher.final()
|
|
741
|
+
]);
|
|
742
|
+
return decryptedMessage.toString("utf8");
|
|
743
|
+
}
|
|
744
|
+
function renameFunctionsToActions(config) {
|
|
745
|
+
if (config.packages) {
|
|
746
|
+
for (const pkg of config.packages) {
|
|
747
|
+
if (pkg.functions) {
|
|
748
|
+
pkg.actions = pkg.functions;
|
|
749
|
+
delete pkg.functions;
|
|
750
|
+
}
|
|
751
|
+
}
|
|
752
|
+
}
|
|
753
|
+
}
|
|
754
|
+
function renameActionsToFunctions(config) {
|
|
755
|
+
if (config.packages) {
|
|
756
|
+
for (const pkg of config.packages) {
|
|
757
|
+
if (pkg.actions) {
|
|
758
|
+
pkg.functions = pkg.actions;
|
|
759
|
+
delete pkg.actions;
|
|
760
|
+
}
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
}
|
|
764
|
+
function isRealBuild(buildField) {
|
|
765
|
+
switch (buildField) {
|
|
766
|
+
case "build.sh":
|
|
767
|
+
case "build.cmd":
|
|
768
|
+
case "package.json":
|
|
769
|
+
return true;
|
|
770
|
+
default:
|
|
771
|
+
return false;
|
|
772
|
+
}
|
|
773
|
+
}
|
|
774
|
+
function locateBuild(buildField, remoteRequested, defaultRemote2, remoteRequired, localRequired) {
|
|
775
|
+
if (!isRealBuild(buildField)) {
|
|
776
|
+
if (defaultRemote2 && !localRequired) {
|
|
777
|
+
return "remote-default";
|
|
778
|
+
}
|
|
779
|
+
return buildField;
|
|
780
|
+
}
|
|
781
|
+
if (remoteRequired || remoteRequested && !localRequired) {
|
|
782
|
+
return "remote";
|
|
783
|
+
}
|
|
784
|
+
return buildField;
|
|
785
|
+
}
|
|
786
|
+
async function checkBuildingRequirements(todeploy, requestRemote) {
|
|
787
|
+
var _a;
|
|
788
|
+
const checkConflicts = (buildField, remote, local, tag) => {
|
|
789
|
+
if (remote && local) {
|
|
790
|
+
throw new Error(
|
|
791
|
+
`Local and remote building cannot both be required (${tag})`
|
|
792
|
+
);
|
|
793
|
+
}
|
|
794
|
+
};
|
|
795
|
+
if (todeploy.packages) {
|
|
796
|
+
for (const pkg of todeploy.packages) {
|
|
797
|
+
if (pkg.actions) {
|
|
798
|
+
for (const action of pkg.actions) {
|
|
799
|
+
checkConflicts(
|
|
800
|
+
action.build,
|
|
801
|
+
action.remoteBuild,
|
|
802
|
+
action.localBuild,
|
|
803
|
+
`action ${action.name}`
|
|
804
|
+
);
|
|
805
|
+
}
|
|
806
|
+
}
|
|
807
|
+
}
|
|
808
|
+
}
|
|
809
|
+
let needsLocal = false;
|
|
810
|
+
if (todeploy.packages) {
|
|
811
|
+
for (const pkg of todeploy.packages) {
|
|
812
|
+
if (pkg.actions) {
|
|
813
|
+
for (const action of pkg.actions) {
|
|
814
|
+
const defaultRemote2 = await hasDefaultRemote(action, todeploy.reader);
|
|
815
|
+
action.build = locateBuild(
|
|
816
|
+
action.build,
|
|
817
|
+
requestRemote,
|
|
818
|
+
defaultRemote2,
|
|
819
|
+
action.remoteBuild,
|
|
820
|
+
action.localBuild
|
|
821
|
+
);
|
|
822
|
+
needsLocal = needsLocal || !((_a = action.build) == null ? void 0 : _a.startsWith("remote")) && isRealBuild(action.build);
|
|
823
|
+
}
|
|
824
|
+
}
|
|
825
|
+
}
|
|
826
|
+
}
|
|
827
|
+
return needsLocal;
|
|
828
|
+
}
|
|
829
|
+
async function hasDefaultRemote(action, reader) {
|
|
830
|
+
const runtime = await getRuntimeForAction(action, reader);
|
|
831
|
+
if (!runtime) {
|
|
832
|
+
return false;
|
|
833
|
+
}
|
|
834
|
+
const kind = runtime.split(":")[0];
|
|
835
|
+
switch (kind) {
|
|
836
|
+
case "go":
|
|
837
|
+
case "swift":
|
|
838
|
+
return true;
|
|
839
|
+
default:
|
|
840
|
+
return false;
|
|
841
|
+
}
|
|
842
|
+
}
|
|
843
|
+
async function getRuntimeForAction(action, reader) {
|
|
844
|
+
if (action.runtime) {
|
|
845
|
+
return action.runtime;
|
|
846
|
+
}
|
|
847
|
+
if (action.sequence && action.sequence.length > 0) {
|
|
848
|
+
return "";
|
|
849
|
+
}
|
|
850
|
+
const pathKind = await reader.getPathKind(action.file);
|
|
851
|
+
if (pathKind.isFile) {
|
|
852
|
+
const { runtime } = await actionFileToParts(pathKind.name);
|
|
853
|
+
return runtime;
|
|
854
|
+
} else if (pathKind.isDirectory) {
|
|
855
|
+
const files = await promiseFilesAndFilterFiles(action.file, reader);
|
|
856
|
+
return agreeOnRuntime(files);
|
|
857
|
+
} else {
|
|
858
|
+
return "";
|
|
859
|
+
}
|
|
860
|
+
}
|
|
861
|
+
async function agreeOnRuntime(items) {
|
|
862
|
+
let agreedRuntime;
|
|
863
|
+
const partsArray = await Promise.all(
|
|
864
|
+
items.map((item) => actionFileToParts(item))
|
|
865
|
+
);
|
|
866
|
+
partsArray.forEach((answer) => {
|
|
867
|
+
if (answer.runtime) {
|
|
868
|
+
if (agreedRuntime && answer.runtime !== agreedRuntime) {
|
|
869
|
+
return void 0;
|
|
870
|
+
}
|
|
871
|
+
agreedRuntime = answer.runtime;
|
|
872
|
+
}
|
|
873
|
+
});
|
|
874
|
+
return agreedRuntime;
|
|
875
|
+
}
|
|
876
|
+
function removeEmptyStringMembers(config) {
|
|
877
|
+
if (config.targetNamespace && config.targetNamespace === "") {
|
|
878
|
+
delete config.targetNamespace;
|
|
879
|
+
}
|
|
880
|
+
removeEmptyStringMembersFromPackages(config.packages);
|
|
881
|
+
}
|
|
882
|
+
function removeEmptyStringMembersFromPackages(packages) {
|
|
883
|
+
if (!packages)
|
|
884
|
+
return;
|
|
885
|
+
for (const pkg of packages) {
|
|
886
|
+
if (pkg.actions) {
|
|
887
|
+
for (const action of pkg.actions) {
|
|
888
|
+
if (action.main && action.main === "") {
|
|
889
|
+
delete action.main;
|
|
890
|
+
}
|
|
891
|
+
if (action.runtime && action.runtime === "") {
|
|
892
|
+
delete action.runtime;
|
|
893
|
+
}
|
|
894
|
+
}
|
|
895
|
+
}
|
|
896
|
+
}
|
|
897
|
+
}
|
|
898
|
+
async function validateDeployConfig(arg, noTriggers) {
|
|
899
|
+
const isNimbellaDeploy = arg.targetNamespace === "nimbella";
|
|
900
|
+
const slice = !!arg.slice;
|
|
901
|
+
for (const item in arg) {
|
|
902
|
+
if (!arg[item])
|
|
903
|
+
continue;
|
|
904
|
+
switch (item) {
|
|
905
|
+
case "slice":
|
|
906
|
+
continue;
|
|
907
|
+
case "cleanNamespace":
|
|
908
|
+
if (!(typeof arg[item] === "boolean")) {
|
|
909
|
+
return `${item} must be a boolean`;
|
|
910
|
+
}
|
|
911
|
+
break;
|
|
912
|
+
case "targetNamespace": {
|
|
913
|
+
if (!(typeof arg[item] === "string") && !isValidOwnership(arg[item])) {
|
|
914
|
+
return `${item} must be a string or a dictionary containing 'test' and/or 'production' members`;
|
|
915
|
+
}
|
|
916
|
+
break;
|
|
917
|
+
}
|
|
918
|
+
case "packages": {
|
|
919
|
+
if (!Array.isArray(arg[item])) {
|
|
920
|
+
return "packages member must be an array";
|
|
921
|
+
}
|
|
922
|
+
for (const subitem of arg[item]) {
|
|
923
|
+
const pkgError = await validatePackageSpec(
|
|
924
|
+
subitem,
|
|
925
|
+
slice,
|
|
926
|
+
isNimbellaDeploy,
|
|
927
|
+
noTriggers
|
|
928
|
+
);
|
|
929
|
+
if (pkgError) {
|
|
930
|
+
return pkgError;
|
|
931
|
+
}
|
|
932
|
+
}
|
|
933
|
+
break;
|
|
934
|
+
}
|
|
935
|
+
case "parameters":
|
|
936
|
+
case "environment": {
|
|
937
|
+
if (!isDictionary(arg[item])) {
|
|
938
|
+
return `${item} member must be a dictionary`;
|
|
939
|
+
}
|
|
940
|
+
break;
|
|
941
|
+
}
|
|
942
|
+
case "credentials":
|
|
943
|
+
case "flags":
|
|
944
|
+
case "deployerAnnotation":
|
|
945
|
+
case "buildEnv":
|
|
946
|
+
if (slice)
|
|
947
|
+
continue;
|
|
948
|
+
default:
|
|
949
|
+
return `Invalid key '${item}' found in project.yml`;
|
|
950
|
+
}
|
|
951
|
+
}
|
|
952
|
+
return void 0;
|
|
953
|
+
}
|
|
954
|
+
function isDictionary(item) {
|
|
955
|
+
return typeof item === "object" && !Array.isArray(item) && item != null;
|
|
956
|
+
}
|
|
957
|
+
function isValidOwnership(item) {
|
|
958
|
+
return isDictionary(item) && (typeof item.production === "string" || typeof item.test === "string");
|
|
959
|
+
}
|
|
960
|
+
async function validatePackageSpec(arg, slice, isNimbella, noTriggers) {
|
|
961
|
+
var _a, _b;
|
|
962
|
+
const isDefault = arg.name === "default";
|
|
963
|
+
for (const item in arg) {
|
|
964
|
+
if (!arg[item])
|
|
965
|
+
continue;
|
|
966
|
+
if (item === "name") {
|
|
967
|
+
if (!(typeof arg[item] === "string")) {
|
|
968
|
+
return `'${item}' member of a 'package' must be a string`;
|
|
969
|
+
}
|
|
970
|
+
} else if (item === "actions") {
|
|
971
|
+
if (!Array.isArray(arg[item])) {
|
|
972
|
+
return "functions member of a 'package' must be an array";
|
|
973
|
+
}
|
|
974
|
+
for (const subitem of arg[item]) {
|
|
975
|
+
const actionError = await validateActionSpec(
|
|
976
|
+
subitem,
|
|
977
|
+
isNimbella,
|
|
978
|
+
noTriggers
|
|
979
|
+
);
|
|
980
|
+
if (actionError) {
|
|
981
|
+
return actionError;
|
|
982
|
+
}
|
|
983
|
+
}
|
|
984
|
+
} else if (item === "shared" || item === "clean") {
|
|
985
|
+
if (!(typeof arg[item] === "boolean")) {
|
|
986
|
+
return `'${item}' member of a 'package' must be a boolean`;
|
|
987
|
+
} else if (isDefault && arg[item]) {
|
|
988
|
+
return `'${item}' must be absent or false for the default package`;
|
|
989
|
+
}
|
|
990
|
+
} else if (item === "web") {
|
|
991
|
+
if (!(typeof arg[item] === "boolean" || arg[item] === "raw")) {
|
|
992
|
+
return `${item} member of an 'package' must be a boolean or the string 'raw'`;
|
|
993
|
+
}
|
|
994
|
+
} else if (item === "environment") {
|
|
995
|
+
const envErr = validateEnvironment(arg[item]);
|
|
996
|
+
if (envErr) {
|
|
997
|
+
return envErr;
|
|
998
|
+
}
|
|
999
|
+
} else if (item === "parameters" || item === "annotations") {
|
|
1000
|
+
if (!isDictionary(arg[item])) {
|
|
1001
|
+
return `${item} must be a dictionary`;
|
|
1002
|
+
}
|
|
1003
|
+
if (isDefault && Object.keys(arg[item]).length > 0) {
|
|
1004
|
+
return `'${item}' must be absent or empty for the default package`;
|
|
1005
|
+
}
|
|
1006
|
+
} else if (item === "binding") {
|
|
1007
|
+
if (typeof ((_a = arg[item]) == null ? void 0 : _a.namespace) !== "string" || typeof ((_b = arg[item]) == null ? void 0 : _b.name) != "string") {
|
|
1008
|
+
return "binding information is incomplete: namespace and package name are both required";
|
|
1009
|
+
}
|
|
1010
|
+
} else if (item === "deployedDuringBuild" && slice) {
|
|
1011
|
+
continue;
|
|
1012
|
+
} else {
|
|
1013
|
+
return `Invalid key '${item}' found in 'package' in project.yml`;
|
|
1014
|
+
}
|
|
1015
|
+
}
|
|
1016
|
+
return void 0;
|
|
1017
|
+
}
|
|
1018
|
+
async function validateActionSpec(arg, isNimbella, noTriggers) {
|
|
1019
|
+
for (const item in arg) {
|
|
1020
|
+
if (!arg[item])
|
|
1021
|
+
continue;
|
|
1022
|
+
switch (item) {
|
|
1023
|
+
case "name":
|
|
1024
|
+
case "file":
|
|
1025
|
+
case "runtime":
|
|
1026
|
+
case "main":
|
|
1027
|
+
case "docker":
|
|
1028
|
+
if (!(typeof arg[item] === "string")) {
|
|
1029
|
+
return `'${item}' member of a function must be a string`;
|
|
1030
|
+
}
|
|
1031
|
+
if (item === "runtime" && !await isValidRuntime(arg[item])) {
|
|
1032
|
+
return `'${arg[item]}' is not a valid runtime value`;
|
|
1033
|
+
}
|
|
1034
|
+
break;
|
|
1035
|
+
case "binary":
|
|
1036
|
+
case "clean":
|
|
1037
|
+
case "remoteBuild":
|
|
1038
|
+
case "localBuild":
|
|
1039
|
+
if (!(typeof arg[item] === "boolean")) {
|
|
1040
|
+
return `'${item}' member of a function must be a boolean`;
|
|
1041
|
+
}
|
|
1042
|
+
break;
|
|
1043
|
+
case "sequence":
|
|
1044
|
+
if (!Array.isArray(arg[item]) || arg[item].length === 0 || typeof arg[item][0] !== "string") {
|
|
1045
|
+
return `'${item}' member of a function must be an array of one or more strings naming other functions`;
|
|
1046
|
+
}
|
|
1047
|
+
break;
|
|
1048
|
+
case "web":
|
|
1049
|
+
if (!(typeof arg[item] === "boolean" || arg[item] === "raw")) {
|
|
1050
|
+
return `${item} member of a function must be a boolean or the string 'raw'`;
|
|
1051
|
+
}
|
|
1052
|
+
break;
|
|
1053
|
+
case "webSecure":
|
|
1054
|
+
if (isNimbella && arg[item] === true) {
|
|
1055
|
+
continue;
|
|
1056
|
+
}
|
|
1057
|
+
if (!(arg[item] === false || typeof arg[item] === "string")) {
|
|
1058
|
+
return `'${item}' member of a function must be a boolean false or a string`;
|
|
1059
|
+
}
|
|
1060
|
+
break;
|
|
1061
|
+
case "environment": {
|
|
1062
|
+
const envError = validateEnvironment(arg[item]);
|
|
1063
|
+
if (envError) {
|
|
1064
|
+
return envError;
|
|
1065
|
+
}
|
|
1066
|
+
}
|
|
1067
|
+
case "annotations": {
|
|
1068
|
+
if (!isDictionary(arg[item])) {
|
|
1069
|
+
return `${item} must be a dictionary`;
|
|
1070
|
+
}
|
|
1071
|
+
const annotErr = screenForbiddenAnnotations(arg[item]);
|
|
1072
|
+
if (annotErr) {
|
|
1073
|
+
return annotErr;
|
|
1074
|
+
}
|
|
1075
|
+
break;
|
|
1076
|
+
}
|
|
1077
|
+
case "parameters":
|
|
1078
|
+
if (!isDictionary(arg[item])) {
|
|
1079
|
+
return `${item} must be a dictionary`;
|
|
1080
|
+
}
|
|
1081
|
+
break;
|
|
1082
|
+
case "limits": {
|
|
1083
|
+
const limitsError = validateLimits(arg[item]);
|
|
1084
|
+
if (limitsError) {
|
|
1085
|
+
return limitsError;
|
|
1086
|
+
}
|
|
1087
|
+
break;
|
|
1088
|
+
}
|
|
1089
|
+
case "triggers": {
|
|
1090
|
+
if (noTriggers) {
|
|
1091
|
+
return `the project requests triggers but triggers are not available`;
|
|
1092
|
+
}
|
|
1093
|
+
const triggerArs = transformLegacyTriggers(arg[item]);
|
|
1094
|
+
const trigErr = validateTriggers(triggerArs);
|
|
1095
|
+
if (trigErr) {
|
|
1096
|
+
return trigErr;
|
|
1097
|
+
}
|
|
1098
|
+
break;
|
|
1099
|
+
}
|
|
1100
|
+
default:
|
|
1101
|
+
return `Invalid key '${item}' found in 'action' clause in project.yml`;
|
|
1102
|
+
}
|
|
1103
|
+
}
|
|
1104
|
+
return void 0;
|
|
1105
|
+
}
|
|
1106
|
+
function screenForbiddenAnnotations(annots) {
|
|
1107
|
+
const forbidden = {
|
|
1108
|
+
"require-whisk-auth": "webSecure",
|
|
1109
|
+
"web-export": 'web=true|false|"raw"',
|
|
1110
|
+
"raw-http": "web=raw"
|
|
1111
|
+
};
|
|
1112
|
+
for (const annot of Object.keys(annots)) {
|
|
1113
|
+
const subst = forbidden[annot];
|
|
1114
|
+
if (subst) {
|
|
1115
|
+
return `the '${annot}' annotation may not be set explicitly; use '${subst}'`;
|
|
1116
|
+
}
|
|
1117
|
+
}
|
|
1118
|
+
return "";
|
|
1119
|
+
}
|
|
1120
|
+
function transformLegacyTriggers(args) {
|
|
1121
|
+
const transformedArgs = args;
|
|
1122
|
+
if (!Array.isArray(transformedArgs)) {
|
|
1123
|
+
return args;
|
|
1124
|
+
}
|
|
1125
|
+
transformedArgs.forEach((trigger, index) => {
|
|
1126
|
+
var _a, _b;
|
|
1127
|
+
if (!trigger.sourceType && !trigger.sourceDetails) {
|
|
1128
|
+
return;
|
|
1129
|
+
}
|
|
1130
|
+
transformedArgs[index].scheduledDetails = {
|
|
1131
|
+
cron: (_a = trigger.sourceDetails) == null ? void 0 : _a.cron,
|
|
1132
|
+
body: (_b = trigger.sourceDetails) == null ? void 0 : _b.withBody
|
|
1133
|
+
};
|
|
1134
|
+
transformedArgs[index].type = trigger.sourceType === "scheduler" ? "SCHEDULED" : trigger.sourceType;
|
|
1135
|
+
delete transformedArgs[index].sourceType;
|
|
1136
|
+
delete transformedArgs[index].sourceDetails;
|
|
1137
|
+
});
|
|
1138
|
+
return transformedArgs;
|
|
1139
|
+
}
|
|
1140
|
+
function validateTriggers(arg) {
|
|
1141
|
+
if (!Array.isArray(arg)) {
|
|
1142
|
+
return `a 'triggers' clause must be an array`;
|
|
1143
|
+
}
|
|
1144
|
+
for (const trigger of arg) {
|
|
1145
|
+
if (!isDictionary(trigger)) {
|
|
1146
|
+
return "an individual trigger must be a dictionary";
|
|
1147
|
+
}
|
|
1148
|
+
for (const item of Object.keys(trigger)) {
|
|
1149
|
+
if (!["name", "enabled", "type", "scheduledDetails"].includes(item)) {
|
|
1150
|
+
return `Invalid key '${item}' found in 'triggers' clause in project.yml`;
|
|
1151
|
+
}
|
|
1152
|
+
}
|
|
1153
|
+
const name = trigger.name;
|
|
1154
|
+
const type = typeof trigger.type === "string" ? trigger.type.toUpperCase() : trigger.type;
|
|
1155
|
+
const scheduledDetails = trigger.scheduledDetails;
|
|
1156
|
+
if (typeof name !== "string") {
|
|
1157
|
+
return `the 'name' field of a trigger is required`;
|
|
1158
|
+
}
|
|
1159
|
+
if (!["SCHEDULED" /* SCHEDULED */].includes(type)) {
|
|
1160
|
+
return `the trigger 'type' field must be '${Object.values(
|
|
1161
|
+
TriggerType
|
|
1162
|
+
).join(" | ")}'`;
|
|
1163
|
+
}
|
|
1164
|
+
if (type === "SCHEDULED" /* SCHEDULED */) {
|
|
1165
|
+
if (!isDictionary(scheduledDetails)) {
|
|
1166
|
+
return `the 'scheduledDetails' property of a trigger is required for type="${"SCHEDULED" /* SCHEDULED */}"`;
|
|
1167
|
+
}
|
|
1168
|
+
const err = validateScheduledTriggerDetails(scheduledDetails);
|
|
1169
|
+
if (err) {
|
|
1170
|
+
return err;
|
|
1171
|
+
}
|
|
1172
|
+
}
|
|
1173
|
+
if (trigger.enabled && typeof trigger.enabled !== "boolean") {
|
|
1174
|
+
return `the 'enabled' property of a trigger must be boolean'`;
|
|
1175
|
+
}
|
|
1176
|
+
}
|
|
1177
|
+
return void 0;
|
|
1178
|
+
}
|
|
1179
|
+
function validateScheduledTriggerDetails(details) {
|
|
1180
|
+
if (!isDictionary(details)) {
|
|
1181
|
+
return "the scheduledDetails field of a trigger specification must be a dictionary";
|
|
1182
|
+
}
|
|
1183
|
+
for (const item of Object.keys(details)) {
|
|
1184
|
+
if (!["cron", "body"].includes(item)) {
|
|
1185
|
+
return `Invalid key '${item}' found in scheduledDetails in project.yml`;
|
|
1186
|
+
}
|
|
1187
|
+
}
|
|
1188
|
+
const cron = details.cron;
|
|
1189
|
+
const body = details.body;
|
|
1190
|
+
if (typeof cron !== "string") {
|
|
1191
|
+
return `the 'cron' member of 'scheduledDetails' must be a string`;
|
|
1192
|
+
}
|
|
1193
|
+
if (!(0, import_cron_validator.isValidCron)(cron)) {
|
|
1194
|
+
return `the cron expression '${cron}' is not valid crontab syntax`;
|
|
1195
|
+
}
|
|
1196
|
+
if (body && !isDictionary(body)) {
|
|
1197
|
+
return `the 'body' member of scheduledDetails must be a dictionary`;
|
|
1198
|
+
}
|
|
1199
|
+
}
|
|
1200
|
+
function validateEnvironment(item) {
|
|
1201
|
+
if (!isDictionary(item)) {
|
|
1202
|
+
return "the environment clause must be a dictionary";
|
|
1203
|
+
}
|
|
1204
|
+
for (const entry in item) {
|
|
1205
|
+
const value = item[entry];
|
|
1206
|
+
if (typeof value !== "string") {
|
|
1207
|
+
return `All environment values must be strings but '${entry}' has type '${typeof value}'`;
|
|
1208
|
+
}
|
|
1209
|
+
}
|
|
1210
|
+
return void 0;
|
|
1211
|
+
}
|
|
1212
|
+
function validateLimits(arg) {
|
|
1213
|
+
for (const item in arg) {
|
|
1214
|
+
const value = arg[item];
|
|
1215
|
+
switch (item) {
|
|
1216
|
+
case "timeout":
|
|
1217
|
+
case "memory":
|
|
1218
|
+
case "logs":
|
|
1219
|
+
if (typeof value !== "number") {
|
|
1220
|
+
return `'${item}' member of a 'limits' clause must be a number`;
|
|
1221
|
+
}
|
|
1222
|
+
break;
|
|
1223
|
+
default:
|
|
1224
|
+
return `Invalid key '${item}' found in 'limits' clause in project.yml`;
|
|
1225
|
+
}
|
|
1226
|
+
}
|
|
1227
|
+
return void 0;
|
|
1228
|
+
}
|
|
1229
|
+
function keyVal(from) {
|
|
1230
|
+
if (!from) {
|
|
1231
|
+
return void 0;
|
|
1232
|
+
}
|
|
1233
|
+
return Object.keys(from).map((key) => ({ key, value: from[key] }));
|
|
1234
|
+
}
|
|
1235
|
+
function makeDict(keyVal2) {
|
|
1236
|
+
const ans = {};
|
|
1237
|
+
keyVal2.forEach((pair) => {
|
|
1238
|
+
ans[pair.key] = pair.value;
|
|
1239
|
+
});
|
|
1240
|
+
return ans;
|
|
1241
|
+
}
|
|
1242
|
+
function emptyStructure() {
|
|
1243
|
+
return { packages: [], strays: [] };
|
|
1244
|
+
}
|
|
1245
|
+
function errorStructure(err) {
|
|
1246
|
+
const ans = emptyStructure();
|
|
1247
|
+
ans.error = err;
|
|
1248
|
+
return ans;
|
|
1249
|
+
}
|
|
1250
|
+
function emptyResponse() {
|
|
1251
|
+
return {
|
|
1252
|
+
successes: [],
|
|
1253
|
+
failures: [],
|
|
1254
|
+
ignored: [],
|
|
1255
|
+
namespace: void 0,
|
|
1256
|
+
packageVersions: {},
|
|
1257
|
+
actionVersions: {}
|
|
1258
|
+
};
|
|
1259
|
+
}
|
|
1260
|
+
function combineResponses(responses) {
|
|
1261
|
+
if (responses.length === 0) {
|
|
1262
|
+
return emptyResponse();
|
|
1263
|
+
}
|
|
1264
|
+
const combinedSuccesses = responses.map(
|
|
1265
|
+
(response) => response.successes
|
|
1266
|
+
);
|
|
1267
|
+
const successes = combinedSuccesses.reduce(
|
|
1268
|
+
(prev, curr) => prev.concat(curr),
|
|
1269
|
+
[]
|
|
1270
|
+
);
|
|
1271
|
+
const combinedFailures = responses.map(
|
|
1272
|
+
(response) => response.failures
|
|
1273
|
+
);
|
|
1274
|
+
const failures = combinedFailures.reduce(
|
|
1275
|
+
(prev, curr) => prev.concat(curr),
|
|
1276
|
+
[]
|
|
1277
|
+
);
|
|
1278
|
+
const combinedIgnored = responses.map(
|
|
1279
|
+
(response) => response.ignored
|
|
1280
|
+
);
|
|
1281
|
+
const ignored = combinedIgnored.reduce((prev, curr) => prev.concat(curr));
|
|
1282
|
+
const packageVersions = responses.reduce(
|
|
1283
|
+
(prev, curr) => Object.assign(prev, curr.packageVersions),
|
|
1284
|
+
{}
|
|
1285
|
+
);
|
|
1286
|
+
const actionVersions = responses.reduce(
|
|
1287
|
+
(prev, curr) => Object.assign(prev, curr.actionVersions),
|
|
1288
|
+
{}
|
|
1289
|
+
);
|
|
1290
|
+
const webHashes = responses.reduce(
|
|
1291
|
+
(prev, curr) => Object.assign(prev, curr.webHashes || {}),
|
|
1292
|
+
{}
|
|
1293
|
+
);
|
|
1294
|
+
const namespace = responses.map((r) => r.namespace).reduce((prev, curr) => prev || curr);
|
|
1295
|
+
return {
|
|
1296
|
+
successes,
|
|
1297
|
+
failures,
|
|
1298
|
+
ignored,
|
|
1299
|
+
packageVersions,
|
|
1300
|
+
actionVersions,
|
|
1301
|
+
webHashes,
|
|
1302
|
+
namespace
|
|
1303
|
+
};
|
|
1304
|
+
}
|
|
1305
|
+
function straysToResponse(strays) {
|
|
1306
|
+
return {
|
|
1307
|
+
successes: [],
|
|
1308
|
+
ignored: strays,
|
|
1309
|
+
failures: [],
|
|
1310
|
+
packageVersions: {},
|
|
1311
|
+
actionVersions: {},
|
|
1312
|
+
namespace: void 0
|
|
1313
|
+
};
|
|
1314
|
+
}
|
|
1315
|
+
function wrapSuccess(name, kind, skipped, actionVersions, namespace) {
|
|
1316
|
+
const success = { name, kind, skipped };
|
|
1317
|
+
return {
|
|
1318
|
+
successes: [success],
|
|
1319
|
+
failures: [],
|
|
1320
|
+
ignored: [],
|
|
1321
|
+
namespace,
|
|
1322
|
+
packageVersions: {},
|
|
1323
|
+
actionVersions
|
|
1324
|
+
};
|
|
1325
|
+
}
|
|
1326
|
+
function wrapError(err, context) {
|
|
1327
|
+
debug4("wrapping an error: %O", err);
|
|
1328
|
+
if (typeof err === "object") {
|
|
1329
|
+
err.context = context;
|
|
1330
|
+
}
|
|
1331
|
+
const result = {
|
|
1332
|
+
successes: [],
|
|
1333
|
+
failures: [err],
|
|
1334
|
+
ignored: [],
|
|
1335
|
+
packageVersions: {},
|
|
1336
|
+
actionVersions: {},
|
|
1337
|
+
namespace: void 0
|
|
1338
|
+
};
|
|
1339
|
+
debug4("wrapped error: %O", result);
|
|
1340
|
+
return result;
|
|
1341
|
+
}
|
|
1342
|
+
function getActionName(action) {
|
|
1343
|
+
if (action.package && action.package !== "default") {
|
|
1344
|
+
return action.package + "/" + action.name;
|
|
1345
|
+
}
|
|
1346
|
+
return action.name;
|
|
1347
|
+
}
|
|
1348
|
+
function isTargetNamespaceValid(client, namespace) {
|
|
1349
|
+
return getTargetNamespace(client).then((ns) => {
|
|
1350
|
+
if (ns === namespace) {
|
|
1351
|
+
return Promise.resolve(true);
|
|
1352
|
+
} else {
|
|
1353
|
+
throw new Error(
|
|
1354
|
+
`Supplied credentials do not match target namespace '${namespace}'; deployment aborted`
|
|
1355
|
+
);
|
|
1356
|
+
}
|
|
1357
|
+
});
|
|
1358
|
+
}
|
|
1359
|
+
function getTargetNamespace(client) {
|
|
1360
|
+
return client.namespaces.list().then((ns) => ns[0]);
|
|
1361
|
+
}
|
|
1362
|
+
async function actionFileToParts(fileName) {
|
|
1363
|
+
let runtime;
|
|
1364
|
+
let binary;
|
|
1365
|
+
let zipped;
|
|
1366
|
+
let name = path2.basename(fileName);
|
|
1367
|
+
const split = name.indexOf(".");
|
|
1368
|
+
if (split > 0) {
|
|
1369
|
+
const parts = name.split(".");
|
|
1370
|
+
const ext = parts[parts.length - 1];
|
|
1371
|
+
let mid;
|
|
1372
|
+
if (parts.length === 2) {
|
|
1373
|
+
name = parts[0];
|
|
1374
|
+
} else if (ext === "zip") {
|
|
1375
|
+
[name, mid] = getNameAndMid(parts.slice(0, -1));
|
|
1376
|
+
} else {
|
|
1377
|
+
name = parts.slice(0, -1).join(".");
|
|
1378
|
+
}
|
|
1379
|
+
runtime = mid ? await runtimeForZipMid(mid) : runtimeForFileExtension(ext);
|
|
1380
|
+
binary = isBinaryFileExtension(ext);
|
|
1381
|
+
zipped = ext === "zip";
|
|
1382
|
+
} else {
|
|
1383
|
+
binary = true;
|
|
1384
|
+
zipped = false;
|
|
1385
|
+
}
|
|
1386
|
+
const z = zipped ? "" : "not ";
|
|
1387
|
+
debug4(`action ${name} is ${z}zipped`);
|
|
1388
|
+
return { name, binary, zipped, runtime };
|
|
1389
|
+
}
|
|
1390
|
+
function getNameAndMid(parts) {
|
|
1391
|
+
if (parts.length === 2) {
|
|
1392
|
+
return parts;
|
|
1393
|
+
}
|
|
1394
|
+
const last = parts[parts.length - 1];
|
|
1395
|
+
const nextToLast = parts[parts.length - 2];
|
|
1396
|
+
if (/^\d+$/.test(last) && nextToLast.includes("-")) {
|
|
1397
|
+
const name = parts.slice(0, -2).join(".");
|
|
1398
|
+
const mid = parts.slice(-2).join(".");
|
|
1399
|
+
return [name, mid];
|
|
1400
|
+
} else {
|
|
1401
|
+
const name = parts.slice(0, -1).join(".");
|
|
1402
|
+
return [name, last];
|
|
1403
|
+
}
|
|
1404
|
+
}
|
|
1405
|
+
function filterFiles(entries) {
|
|
1406
|
+
return entries.filter((entry) => {
|
|
1407
|
+
if (!entry.isDirectory) {
|
|
1408
|
+
return !(0, import_anymatch.default)(getExclusionList(), entry.name);
|
|
1409
|
+
} else {
|
|
1410
|
+
return entry;
|
|
1411
|
+
}
|
|
1412
|
+
});
|
|
1413
|
+
}
|
|
1414
|
+
async function promiseFilesAndFilterFiles(root, reader) {
|
|
1415
|
+
let items = await promiseFiles(root, reader);
|
|
1416
|
+
debug4("items before filtering: %O", items);
|
|
1417
|
+
const exclusions = getExclusionList();
|
|
1418
|
+
debug4("exclusion list: %O", exclusions);
|
|
1419
|
+
items = items.filter((item) => !(0, import_anymatch.default)(exclusions, item));
|
|
1420
|
+
debug4("items after filtering: %O", items);
|
|
1421
|
+
return items;
|
|
1422
|
+
}
|
|
1423
|
+
async function promiseFiles(dir, reader) {
|
|
1424
|
+
debug4("promiseFiles called on directory %s", dir);
|
|
1425
|
+
const files = [];
|
|
1426
|
+
let subdirs = await promiseFilesRound(dir, files, [], reader);
|
|
1427
|
+
while (subdirs.length > 0) {
|
|
1428
|
+
const next = subdirs.pop();
|
|
1429
|
+
debug4(
|
|
1430
|
+
"promiseFiles recursing on subdirectory '%s', with '%d' files accumulated and '%d' subdirectories still pending",
|
|
1431
|
+
next,
|
|
1432
|
+
files.length,
|
|
1433
|
+
subdirs.length
|
|
1434
|
+
);
|
|
1435
|
+
subdirs = await promiseFilesRound(next, files, subdirs, reader);
|
|
1436
|
+
}
|
|
1437
|
+
debug4("promiseFiles returning with %d files", files.length);
|
|
1438
|
+
return files;
|
|
1439
|
+
}
|
|
1440
|
+
async function promiseFilesRound(dir, files, subdirs, reader) {
|
|
1441
|
+
const items = await reader.readdir(dir);
|
|
1442
|
+
items.forEach(async (item) => {
|
|
1443
|
+
const itemPath = path2.join(dir, item.name);
|
|
1444
|
+
if (item.isDirectory) {
|
|
1445
|
+
subdirs.push(itemPath);
|
|
1446
|
+
} else {
|
|
1447
|
+
files.push(itemPath);
|
|
1448
|
+
}
|
|
1449
|
+
});
|
|
1450
|
+
return subdirs;
|
|
1451
|
+
}
|
|
1452
|
+
function substituteFromEnvAndFiles(input, envPath, projectPath, feedback) {
|
|
1453
|
+
let result = "";
|
|
1454
|
+
const badVars = [];
|
|
1455
|
+
const props = envPath ? getPropsFromFile(envPath) : {};
|
|
1456
|
+
debug4("envPath: %s", envPath);
|
|
1457
|
+
debug4("props %O", props);
|
|
1458
|
+
let nextSym = findNextSymbol(input);
|
|
1459
|
+
let warn = false;
|
|
1460
|
+
while (nextSym.index >= 0) {
|
|
1461
|
+
const before = input.substr(0, nextSym.index);
|
|
1462
|
+
const after = input.substr(nextSym.index + 2);
|
|
1463
|
+
const endVar = after.indexOf(nextSym.terminator);
|
|
1464
|
+
if (endVar < 0) {
|
|
1465
|
+
throw new Error("Runaway variable name or path directive in project.yml");
|
|
1466
|
+
}
|
|
1467
|
+
let subst;
|
|
1468
|
+
let doStringEscapes = true;
|
|
1469
|
+
let envar = after.substr(0, endVar).trim();
|
|
1470
|
+
debug4("substituting for envar: %s", envar);
|
|
1471
|
+
if (nextSym.terminator === ")" || /\s/.test(envar)) {
|
|
1472
|
+
warn = warn || nextSym.terminator !== ")";
|
|
1473
|
+
subst = getDictionarySubstitution(envar, props, badVars);
|
|
1474
|
+
} else if (envar.startsWith("<")) {
|
|
1475
|
+
if (nextSym.terminator === ")") {
|
|
1476
|
+
throw new Error("Invalid substitution: $(" + envar + ")");
|
|
1477
|
+
}
|
|
1478
|
+
const fileSubst = path2.join(projectPath, envar.slice(1).trim());
|
|
1479
|
+
subst = getSubstituteFromFile(fileSubst);
|
|
1480
|
+
} else {
|
|
1481
|
+
if (envar.startsWith("|")) {
|
|
1482
|
+
envar = envar.slice(1).trim();
|
|
1483
|
+
doStringEscapes = false;
|
|
1484
|
+
}
|
|
1485
|
+
subst = process.env[envar] || props[envar];
|
|
1486
|
+
}
|
|
1487
|
+
if (!subst) {
|
|
1488
|
+
badVars.push(envar);
|
|
1489
|
+
subst = `<${envar}>`;
|
|
1490
|
+
} else if (doStringEscapes) {
|
|
1491
|
+
subst = escapeNewlines(subst);
|
|
1492
|
+
}
|
|
1493
|
+
debug4("substitution is: %s", subst);
|
|
1494
|
+
result = result + before + subst;
|
|
1495
|
+
input = after.substr(endVar + 1);
|
|
1496
|
+
nextSym = findNextSymbol(input);
|
|
1497
|
+
}
|
|
1498
|
+
result = result + input;
|
|
1499
|
+
if (warn) {
|
|
1500
|
+
feedback.warn(
|
|
1501
|
+
"Using '${}' for dictionary substitution is now deprecated; use '$()'"
|
|
1502
|
+
);
|
|
1503
|
+
}
|
|
1504
|
+
if (badVars.length > 0) {
|
|
1505
|
+
return { content: result, badVars };
|
|
1506
|
+
}
|
|
1507
|
+
return { content: result, badVars: void 0 };
|
|
1508
|
+
}
|
|
1509
|
+
function escapeNewlines(original) {
|
|
1510
|
+
const parts = original.split("\n");
|
|
1511
|
+
return parts.join("\\n");
|
|
1512
|
+
}
|
|
1513
|
+
function findNextSymbol(input) {
|
|
1514
|
+
const nextBrace = input.indexOf("${");
|
|
1515
|
+
const nextParen = input.indexOf("$(");
|
|
1516
|
+
const haveBrace = nextBrace >= 0;
|
|
1517
|
+
const haveParen = nextParen >= 0;
|
|
1518
|
+
if (haveBrace) {
|
|
1519
|
+
if (haveParen) {
|
|
1520
|
+
return nextBrace < nextParen ? { index: nextBrace, terminator: "}" } : { index: nextParen, terminator: ")" };
|
|
1521
|
+
} else {
|
|
1522
|
+
return { index: nextBrace, terminator: "}" };
|
|
1523
|
+
}
|
|
1524
|
+
} else if (haveParen) {
|
|
1525
|
+
return { index: nextParen, terminator: ")" };
|
|
1526
|
+
} else {
|
|
1527
|
+
return { index: -1, terminator: "" };
|
|
1528
|
+
}
|
|
1529
|
+
}
|
|
1530
|
+
function getDictionarySubstitution(tokens, props, badVars) {
|
|
1531
|
+
debug4("dictionary substitution with %s", tokens);
|
|
1532
|
+
const ans = {};
|
|
1533
|
+
for (const tok of tokens.split(/\s+/)) {
|
|
1534
|
+
debug4("token: %s", tok);
|
|
1535
|
+
const value = process.env[tok] || props[tok];
|
|
1536
|
+
if (value) {
|
|
1537
|
+
ans[tok] = value;
|
|
1538
|
+
} else {
|
|
1539
|
+
badVars.push(tok);
|
|
1540
|
+
ans[tok] = `<${tok}>`;
|
|
1541
|
+
}
|
|
1542
|
+
}
|
|
1543
|
+
return JSON.stringify(ans);
|
|
1544
|
+
}
|
|
1545
|
+
function getSubstituteFromFile(path7) {
|
|
1546
|
+
if (!fs2.existsSync(path7)) {
|
|
1547
|
+
return void 0;
|
|
1548
|
+
}
|
|
1549
|
+
const props = getPropsFromFile(path7);
|
|
1550
|
+
const answer = JSON.stringify(props);
|
|
1551
|
+
return answer === "{}" ? void 0 : answer;
|
|
1552
|
+
}
|
|
1553
|
+
function getPropsFromFile(filePath) {
|
|
1554
|
+
if (!fs2.existsSync(filePath)) {
|
|
1555
|
+
return {};
|
|
1556
|
+
}
|
|
1557
|
+
const contents = fs2.readFileSync(filePath);
|
|
1558
|
+
try {
|
|
1559
|
+
return JSON.parse(String(contents));
|
|
1560
|
+
} catch {
|
|
1561
|
+
}
|
|
1562
|
+
const propParser = require("dotenv");
|
|
1563
|
+
return propParser.parse(contents);
|
|
1564
|
+
}
|
|
1565
|
+
function mapPackages(packages) {
|
|
1566
|
+
const ans = {};
|
|
1567
|
+
for (const pkg of packages) {
|
|
1568
|
+
ans[pkg.name] = pkg;
|
|
1569
|
+
}
|
|
1570
|
+
return ans;
|
|
1571
|
+
}
|
|
1572
|
+
function mapActions(actions) {
|
|
1573
|
+
const ans = {};
|
|
1574
|
+
for (const action of actions || []) {
|
|
1575
|
+
ans[action.name] = action;
|
|
1576
|
+
}
|
|
1577
|
+
return ans;
|
|
1578
|
+
}
|
|
1579
|
+
function getBestProjectName(project) {
|
|
1580
|
+
const annot = project.deployerAnnotation;
|
|
1581
|
+
if (!annot) {
|
|
1582
|
+
return project.filePath;
|
|
1583
|
+
}
|
|
1584
|
+
if (annot.repository) {
|
|
1585
|
+
let repo = annot.repository;
|
|
1586
|
+
if (repo.includes(":")) {
|
|
1587
|
+
repo = repo.split(":")[1];
|
|
1588
|
+
}
|
|
1589
|
+
if (repo.endsWith(".git")) {
|
|
1590
|
+
repo = repo.slice(0, -4);
|
|
1591
|
+
}
|
|
1592
|
+
while (repo.startsWith("/")) {
|
|
1593
|
+
repo = repo.slice(1);
|
|
1594
|
+
}
|
|
1595
|
+
return repo + "/" + annot.projectPath;
|
|
1596
|
+
}
|
|
1597
|
+
return annot.projectPath;
|
|
1598
|
+
}
|
|
1599
|
+
async function getDeployerAnnotation(project) {
|
|
1600
|
+
const digest = void 0;
|
|
1601
|
+
try {
|
|
1602
|
+
const git = (0, import_simple_git.default)();
|
|
1603
|
+
const root = await git.revparse(["--show-toplevel"]);
|
|
1604
|
+
const repo = await git.raw(["config", "--get", "remote.origin.url"]);
|
|
1605
|
+
const user = (await git.raw(["config", "--get", "user.email"])).trim();
|
|
1606
|
+
const projectPath = path2.relative(root, path2.resolve(project));
|
|
1607
|
+
let commit = await git.revparse(["head"]);
|
|
1608
|
+
commit = commit.substring(0, 8);
|
|
1609
|
+
const status = await git.status();
|
|
1610
|
+
if (!status.isClean()) {
|
|
1611
|
+
commit += "++";
|
|
1612
|
+
}
|
|
1613
|
+
return { user, repository: repo.trim(), projectPath, commit, digest };
|
|
1614
|
+
} catch {
|
|
1615
|
+
const user = os.userInfo().username.trim();
|
|
1616
|
+
const projectPath = path2.resolve(project);
|
|
1617
|
+
return { user, projectPath, digest };
|
|
1618
|
+
}
|
|
1619
|
+
}
|
|
1620
|
+
async function wipe(client, credentials) {
|
|
1621
|
+
const errors = [];
|
|
1622
|
+
await wipeActions(client, credentials, errors);
|
|
1623
|
+
debug4("Actions wiped");
|
|
1624
|
+
await wipeAll(client.packages, "Package", errors);
|
|
1625
|
+
debug4("Packages wiped");
|
|
1626
|
+
const namespace = await getTargetNamespace(client);
|
|
1627
|
+
const triggers = await listTriggersForNamespace(namespace, credentials, "");
|
|
1628
|
+
const errs = await undeployTriggers(triggers, credentials);
|
|
1629
|
+
if (errs.length > 0) {
|
|
1630
|
+
errors.push(...errs);
|
|
1631
|
+
}
|
|
1632
|
+
await wipeAll(client.rules, "Rule", errors);
|
|
1633
|
+
debug4("Rules wiped");
|
|
1634
|
+
await wipeAll(client.triggers, "Trigger", errors);
|
|
1635
|
+
debug4("OpenWhisk triggers wiped");
|
|
1636
|
+
if (errors.length > 1) {
|
|
1637
|
+
const combined = Error(
|
|
1638
|
+
"multiple errors occurred while cleaning the namespace"
|
|
1639
|
+
);
|
|
1640
|
+
combined.errors = errors;
|
|
1641
|
+
throw combined;
|
|
1642
|
+
}
|
|
1643
|
+
if (errors.length == 1) {
|
|
1644
|
+
throw errors[0];
|
|
1645
|
+
}
|
|
1646
|
+
}
|
|
1647
|
+
async function wipeAll(handle, kind, errors) {
|
|
1648
|
+
while (true) {
|
|
1649
|
+
const entities = await handle.list({ limit: 200 });
|
|
1650
|
+
if (entities.length === 0) {
|
|
1651
|
+
return;
|
|
1652
|
+
}
|
|
1653
|
+
for (const entity of entities) {
|
|
1654
|
+
let name = entity.name;
|
|
1655
|
+
const nsparts = entity.namespace.split("/");
|
|
1656
|
+
if (nsparts.length > 1) {
|
|
1657
|
+
name = nsparts[1] + "/" + name;
|
|
1658
|
+
}
|
|
1659
|
+
try {
|
|
1660
|
+
await handle.delete(name);
|
|
1661
|
+
debug4("%s %s deleted", kind, name);
|
|
1662
|
+
} catch (err) {
|
|
1663
|
+
debug4("error deleting %s %s: %O", err);
|
|
1664
|
+
errors.push(err);
|
|
1665
|
+
}
|
|
1666
|
+
}
|
|
1667
|
+
}
|
|
1668
|
+
}
|
|
1669
|
+
async function wipeActions(client, credentials, errors) {
|
|
1670
|
+
while (true) {
|
|
1671
|
+
const actions = await client.actions.list({ limit: 200 });
|
|
1672
|
+
if (actions.length === 0) {
|
|
1673
|
+
return;
|
|
1674
|
+
}
|
|
1675
|
+
for (const action of actions) {
|
|
1676
|
+
let name = action.name;
|
|
1677
|
+
const nsparts = action.namespace.split("/");
|
|
1678
|
+
if (nsparts.length > 1) {
|
|
1679
|
+
name = nsparts[1] + "/" + name;
|
|
1680
|
+
}
|
|
1681
|
+
const result = await deleteAction(name, client, credentials);
|
|
1682
|
+
if (Array.isArray(result)) {
|
|
1683
|
+
errors.push(...result);
|
|
1684
|
+
debug4("error deleting the triggers");
|
|
1685
|
+
}
|
|
1686
|
+
debug4("action %s deleted", name);
|
|
1687
|
+
}
|
|
1688
|
+
}
|
|
1689
|
+
}
|
|
1690
|
+
async function deleteAction(actionName, owClient, credentials) {
|
|
1691
|
+
const namespace = await getTargetNamespace(owClient);
|
|
1692
|
+
const triggers = await listTriggersForNamespace(
|
|
1693
|
+
namespace,
|
|
1694
|
+
credentials,
|
|
1695
|
+
actionName
|
|
1696
|
+
);
|
|
1697
|
+
const errs = await undeployTriggers(triggers, credentials);
|
|
1698
|
+
if (errs.length > 0) {
|
|
1699
|
+
return errs;
|
|
1700
|
+
}
|
|
1701
|
+
try {
|
|
1702
|
+
return await owClient.actions.delete({ name: actionName });
|
|
1703
|
+
} catch (err) {
|
|
1704
|
+
const msg = err.message ? err.message : err;
|
|
1705
|
+
return [new Error(`unable to undeploy action '${actionName}': ${msg}`)];
|
|
1706
|
+
}
|
|
1707
|
+
}
|
|
1708
|
+
function digestPackage(pkg) {
|
|
1709
|
+
const hash = crypto.createHash("sha256");
|
|
1710
|
+
digestBoolean(hash, pkg.shared);
|
|
1711
|
+
digestBoolean(hash, pkg.clean);
|
|
1712
|
+
digestBoolean(hash, pkg.web);
|
|
1713
|
+
digestDictionary(hash, pkg.annotations);
|
|
1714
|
+
digestDictionary(hash, pkg.parameters);
|
|
1715
|
+
digestDictionary(hash, pkg.environment);
|
|
1716
|
+
digestDictionary(hash, pkg.binding);
|
|
1717
|
+
for (const action of pkg.actions || []) {
|
|
1718
|
+
hash.update(action.name);
|
|
1719
|
+
}
|
|
1720
|
+
return String(hash.digest("hex"));
|
|
1721
|
+
}
|
|
1722
|
+
function digestBoolean(hash, toDigest) {
|
|
1723
|
+
hash.update(String(!!toDigest));
|
|
1724
|
+
}
|
|
1725
|
+
function digestStringArray(hash, toDigest) {
|
|
1726
|
+
if (toDigest) {
|
|
1727
|
+
for (const value of toDigest) {
|
|
1728
|
+
hash.update(value);
|
|
1729
|
+
}
|
|
1730
|
+
}
|
|
1731
|
+
}
|
|
1732
|
+
function digestDictionary(hash, toDigest) {
|
|
1733
|
+
if (toDigest) {
|
|
1734
|
+
const keys = Object.keys(toDigest).sort();
|
|
1735
|
+
for (const key of keys) {
|
|
1736
|
+
hash.update(key);
|
|
1737
|
+
const value = toDigest[key];
|
|
1738
|
+
switch (typeof value) {
|
|
1739
|
+
case "string":
|
|
1740
|
+
hash.update(value);
|
|
1741
|
+
break;
|
|
1742
|
+
case "boolean":
|
|
1743
|
+
digestBoolean(hash, value);
|
|
1744
|
+
break;
|
|
1745
|
+
case "object":
|
|
1746
|
+
digestDictionary(hash, value);
|
|
1747
|
+
break;
|
|
1748
|
+
default:
|
|
1749
|
+
hash.update(String(value));
|
|
1750
|
+
break;
|
|
1751
|
+
}
|
|
1752
|
+
}
|
|
1753
|
+
}
|
|
1754
|
+
}
|
|
1755
|
+
function digestAction(action, code) {
|
|
1756
|
+
const hash = crypto.createHash("sha256");
|
|
1757
|
+
digestBoolean(hash, action.clean);
|
|
1758
|
+
digestBoolean(hash, action.binary);
|
|
1759
|
+
digestBoolean(hash, action.zipped);
|
|
1760
|
+
hash.update(String(action.web));
|
|
1761
|
+
hash.update(String(action.webSecure));
|
|
1762
|
+
digestDictionary(hash, action.annotations);
|
|
1763
|
+
digestDictionary(hash, action.parameters);
|
|
1764
|
+
digestDictionary(hash, action.environment);
|
|
1765
|
+
digestDictionary(hash, action.limits);
|
|
1766
|
+
digestStringArray(hash, action.sequence);
|
|
1767
|
+
hash.update(code);
|
|
1768
|
+
if (action.main) {
|
|
1769
|
+
hash.update(action.main);
|
|
1770
|
+
}
|
|
1771
|
+
hash.update(action.runtime);
|
|
1772
|
+
return String(hash.digest("hex"));
|
|
1773
|
+
}
|
|
1774
|
+
function getStatusDir(project) {
|
|
1775
|
+
const statusDir = path2.join(project, ".deployed");
|
|
1776
|
+
let created = false;
|
|
1777
|
+
if (!fs2.existsSync(statusDir)) {
|
|
1778
|
+
fs2.mkdirSync(statusDir);
|
|
1779
|
+
created = true;
|
|
1780
|
+
}
|
|
1781
|
+
return { statusDir, created };
|
|
1782
|
+
}
|
|
1783
|
+
function writeSliceResult(project, result) {
|
|
1784
|
+
const file = path2.join(getStatusDir(project).statusDir, "sliceResult");
|
|
1785
|
+
fs2.writeFileSync(file, result);
|
|
1786
|
+
}
|
|
1787
|
+
function writeProjectStatus(project, results, replace) {
|
|
1788
|
+
debug4("writing project status with %O", results);
|
|
1789
|
+
const { apihost, namespace, packageVersions, actionVersions, webHashes } = results;
|
|
1790
|
+
if (Object.keys(actionVersions).length === 0 && Object.keys(packageVersions).length === 0 && Object.keys(webHashes).length === 0) {
|
|
1791
|
+
debug4("there is no meaningful project status to write");
|
|
1792
|
+
return "";
|
|
1793
|
+
}
|
|
1794
|
+
const { statusDir, created } = getStatusDir(project);
|
|
1795
|
+
let versionList = [];
|
|
1796
|
+
const versionFile = path2.join(statusDir, "versions.json");
|
|
1797
|
+
if (fs2.existsSync(versionFile)) {
|
|
1798
|
+
debug4("version file already exists");
|
|
1799
|
+
const old = JSON.parse(String(fs2.readFileSync(versionFile)));
|
|
1800
|
+
if (Array.isArray(old)) {
|
|
1801
|
+
versionList = old;
|
|
1802
|
+
debug4("version list using legacy format, not preserved");
|
|
1803
|
+
}
|
|
1804
|
+
}
|
|
1805
|
+
const versionInfo = {
|
|
1806
|
+
apihost,
|
|
1807
|
+
namespace,
|
|
1808
|
+
packageVersions,
|
|
1809
|
+
actionVersions,
|
|
1810
|
+
webHashes
|
|
1811
|
+
};
|
|
1812
|
+
const oldEntry = versionList.find(
|
|
1813
|
+
(entry) => entry.apihost === apihost && entry.namespace === namespace
|
|
1814
|
+
);
|
|
1815
|
+
if (!oldEntry) {
|
|
1816
|
+
debug4("new entry pushed to version list");
|
|
1817
|
+
versionList.push(versionInfo);
|
|
1818
|
+
} else {
|
|
1819
|
+
debug4("merging new entry into old");
|
|
1820
|
+
mergeVersions(oldEntry, versionInfo, replace);
|
|
1821
|
+
}
|
|
1822
|
+
fs2.writeFileSync(versionFile, JSON.stringify(versionList, null, 2));
|
|
1823
|
+
debug4("wrote version info to %s", versionFile);
|
|
1824
|
+
return created ? statusDir : "";
|
|
1825
|
+
}
|
|
1826
|
+
function mergeVersions(oldEntry, newEntry, replace) {
|
|
1827
|
+
if (replace) {
|
|
1828
|
+
Object.assign(oldEntry, newEntry);
|
|
1829
|
+
} else {
|
|
1830
|
+
Object.assign(oldEntry.actionVersions, newEntry.actionVersions);
|
|
1831
|
+
Object.assign(oldEntry.packageVersions, newEntry.packageVersions);
|
|
1832
|
+
Object.assign(oldEntry.webHashes, newEntry.webHashes);
|
|
1833
|
+
}
|
|
1834
|
+
}
|
|
1835
|
+
function loadVersions(projectPath, namespace, apihost) {
|
|
1836
|
+
const versionFile = path2.join(projectPath, ".deployed", "versions.json");
|
|
1837
|
+
if (fs2.existsSync(versionFile)) {
|
|
1838
|
+
const allEntries = JSON.parse(String(fs2.readFileSync(versionFile)));
|
|
1839
|
+
for (const entry of allEntries) {
|
|
1840
|
+
if (namespace === entry.namespace && apihost === entry.apihost) {
|
|
1841
|
+
return entry;
|
|
1842
|
+
}
|
|
1843
|
+
}
|
|
1844
|
+
}
|
|
1845
|
+
return {
|
|
1846
|
+
namespace,
|
|
1847
|
+
apihost,
|
|
1848
|
+
packageVersions: {},
|
|
1849
|
+
actionVersions: {},
|
|
1850
|
+
webHashes: {}
|
|
1851
|
+
};
|
|
1852
|
+
}
|
|
1853
|
+
function delay(millis) {
|
|
1854
|
+
return new Promise(function(resolve5) {
|
|
1855
|
+
setTimeout(() => resolve5(), millis);
|
|
1856
|
+
});
|
|
1857
|
+
}
|
|
1858
|
+
async function waitForActivation(id, wsk, waiting, total) {
|
|
1859
|
+
debug4(`waiting for activation with id ${id}`);
|
|
1860
|
+
let errors = 0;
|
|
1861
|
+
const maxErrors = 3;
|
|
1862
|
+
for (let i = 1; i <= total; i++) {
|
|
1863
|
+
try {
|
|
1864
|
+
const activation = await wsk.activations.get(id);
|
|
1865
|
+
if (activation.end || activation.response.status) {
|
|
1866
|
+
debug4("activation %s found after %d iterations", id, i);
|
|
1867
|
+
return activation;
|
|
1868
|
+
}
|
|
1869
|
+
} catch (err) {
|
|
1870
|
+
if (err.statusCode !== 404) {
|
|
1871
|
+
errors++;
|
|
1872
|
+
}
|
|
1873
|
+
if (errors > maxErrors) {
|
|
1874
|
+
throw err;
|
|
1875
|
+
}
|
|
1876
|
+
}
|
|
1877
|
+
if (i % 10 === 0) {
|
|
1878
|
+
waiting();
|
|
1879
|
+
}
|
|
1880
|
+
await delay(1e3);
|
|
1881
|
+
}
|
|
1882
|
+
return void 0;
|
|
1883
|
+
}
|
|
1884
|
+
function invokeWebSecure(actionAndQuery, auth, apihost) {
|
|
1885
|
+
const url = apihost + "/api/v1/web" + actionAndQuery;
|
|
1886
|
+
return wskRequest(url, auth);
|
|
1887
|
+
}
|
|
1888
|
+
function wskRequest(url, auth = void 0) {
|
|
1889
|
+
debug4("Request to: %s", url);
|
|
1890
|
+
return new Promise(function(resolve5, reject) {
|
|
1891
|
+
const xhr = new import_xmlhttprequest.XMLHttpRequest();
|
|
1892
|
+
xhr.open("GET", url);
|
|
1893
|
+
const userAgent = getUserAgent();
|
|
1894
|
+
xhr.setRequestHeader("User-Agent", userAgent);
|
|
1895
|
+
xhr.onload = function() {
|
|
1896
|
+
if (this.status >= 200 && this.status < 300) {
|
|
1897
|
+
debug4("useful response");
|
|
1898
|
+
resolve5(JSON.parse(xhr.responseText));
|
|
1899
|
+
} else {
|
|
1900
|
+
debug4("Error from OW %s %s", xhr.status, xhr.responseText);
|
|
1901
|
+
reject(new Error(xhr.responseText));
|
|
1902
|
+
}
|
|
1903
|
+
};
|
|
1904
|
+
xhr.onerror = function() {
|
|
1905
|
+
debug4("network error");
|
|
1906
|
+
reject(new Error("Network error"));
|
|
1907
|
+
};
|
|
1908
|
+
if (auth) {
|
|
1909
|
+
if (auth.includes(":")) {
|
|
1910
|
+
debug4("Setting basic authorization header");
|
|
1911
|
+
xhr.setRequestHeader(
|
|
1912
|
+
"Authorization",
|
|
1913
|
+
"Basic " + Buffer.from(auth).toString("base64")
|
|
1914
|
+
);
|
|
1915
|
+
} else {
|
|
1916
|
+
debug4("Setting X-Require-Whisk-Auth header to %s", auth);
|
|
1917
|
+
xhr.setRequestHeader("X-Require-Whisk-Auth", auth);
|
|
1918
|
+
}
|
|
1919
|
+
}
|
|
1920
|
+
xhr.send();
|
|
1921
|
+
});
|
|
1922
|
+
}
|
|
1923
|
+
function renamePackage(spec, oldName, newName) {
|
|
1924
|
+
var _a;
|
|
1925
|
+
const pkg = (_a = spec.packages) == null ? void 0 : _a.find((pkg2) => pkg2.name === oldName);
|
|
1926
|
+
if (!pkg) {
|
|
1927
|
+
throw new Error(
|
|
1928
|
+
`Package '${oldName}' was not found in the DeployStructure`
|
|
1929
|
+
);
|
|
1930
|
+
}
|
|
1931
|
+
pkg.name = newName;
|
|
1932
|
+
if (pkg.actions) {
|
|
1933
|
+
for (const action of pkg.actions) {
|
|
1934
|
+
action.package = newName;
|
|
1935
|
+
}
|
|
1936
|
+
}
|
|
1937
|
+
return spec;
|
|
1938
|
+
}
|
|
1939
|
+
function isExcluded(match) {
|
|
1940
|
+
return (0, import_anymatch.default)(getExclusionList(), match);
|
|
1941
|
+
}
|
|
1942
|
+
function getExclusionList() {
|
|
1943
|
+
let userDefinedPatterns = [];
|
|
1944
|
+
try {
|
|
1945
|
+
const globalExcludeFile = path2.join(nimbellaDir(), ".exclude");
|
|
1946
|
+
userDefinedPatterns = fs2.readFileSync(globalExcludeFile).toString().split("\n").filter((e) => e.toString().trim() !== "");
|
|
1947
|
+
} catch (e) {
|
|
1948
|
+
debug4(e.message);
|
|
1949
|
+
}
|
|
1950
|
+
const allPatterns = [...userDefinedPatterns, ...SYSTEM_EXCLUDE_PATTERNS];
|
|
1951
|
+
return allPatterns;
|
|
1952
|
+
}
|
|
1953
|
+
|
|
1954
|
+
// src/deploy.ts
|
|
1955
|
+
var import_debug5 = __toESM(require("debug"));
|
|
1956
|
+
var debug5 = (0, import_debug5.default)("nim:deployer:deploy");
|
|
1957
|
+
var seqDebug = (0, import_debug5.default)("nim:deployer:sequences");
|
|
1958
|
+
var chunkDebug = (0, import_debug5.default)("nim:deployer:chunk");
|
|
1959
|
+
var DEPLOYMENT_CHUNK_SIZE = parseInt(process.env.DEPLOYMENT_CHUNK_SIZE) || 25;
|
|
1960
|
+
async function cleanOrLoadVersions(todeploy) {
|
|
1961
|
+
if (todeploy.flags.incremental) {
|
|
1962
|
+
todeploy.versions = loadVersions(
|
|
1963
|
+
todeploy.filePath,
|
|
1964
|
+
todeploy.credentials.namespace,
|
|
1965
|
+
todeploy.credentials.ow.apihost
|
|
1966
|
+
);
|
|
1967
|
+
} else {
|
|
1968
|
+
if (todeploy.cleanNamespace && todeploy.includer.isIncludingEverything()) {
|
|
1969
|
+
await wipe(todeploy.owClient, todeploy.credentials);
|
|
1970
|
+
} else {
|
|
1971
|
+
await cleanActionsAndPackages(todeploy);
|
|
1972
|
+
}
|
|
1973
|
+
}
|
|
1974
|
+
return Promise.resolve(todeploy);
|
|
1975
|
+
}
|
|
1976
|
+
async function doDeploy(todeploy) {
|
|
1977
|
+
const skipPkgDeploy = todeploy.slice && todeploy.deployerAnnotation.newSliceHandling;
|
|
1978
|
+
delete todeploy.deployerAnnotation.newSliceHandling;
|
|
1979
|
+
const actionPromises = (todeploy.packages || []).map(
|
|
1980
|
+
(pkg) => deployPackage(pkg, todeploy, skipPkgDeploy)
|
|
1981
|
+
);
|
|
1982
|
+
const responses = await Promise.all(actionPromises);
|
|
1983
|
+
responses.push(straysToResponse(todeploy.strays));
|
|
1984
|
+
const sequenceResponses = await deploySequences(todeploy);
|
|
1985
|
+
responses.push(...sequenceResponses);
|
|
1986
|
+
const response = combineResponses(responses);
|
|
1987
|
+
response.apihost = todeploy.credentials.ow.apihost;
|
|
1988
|
+
if (!response.namespace) {
|
|
1989
|
+
response.namespace = todeploy.credentials.namespace;
|
|
1990
|
+
}
|
|
1991
|
+
return response;
|
|
1992
|
+
}
|
|
1993
|
+
async function processRemoteResponse(activationId, owClient, context, feedback) {
|
|
1994
|
+
var _a, _b;
|
|
1995
|
+
let activation;
|
|
1996
|
+
const tick = () => feedback.progress(`Processing of ${context} is still running remotely ...`);
|
|
1997
|
+
try {
|
|
1998
|
+
activation = await waitForActivation(activationId, owClient, tick, 15 * 60);
|
|
1999
|
+
} catch (err) {
|
|
2000
|
+
return wrapError(err, context + " (waiting for remote build response)");
|
|
2001
|
+
}
|
|
2002
|
+
if (!activation) {
|
|
2003
|
+
return wrapError(
|
|
2004
|
+
new Error("Build timed out"),
|
|
2005
|
+
" (waiting for remote build response)"
|
|
2006
|
+
);
|
|
2007
|
+
}
|
|
2008
|
+
if (!activation.response || !activation.response.success) {
|
|
2009
|
+
let err = "Remote build failed to provide a result";
|
|
2010
|
+
const resultError = (_b = (_a = activation == null ? void 0 : activation.response) == null ? void 0 : _a.result) == null ? void 0 : _b.error;
|
|
2011
|
+
if (resultError) {
|
|
2012
|
+
const errMsg = typeof resultError === "string" ? resultError : resultError.message;
|
|
2013
|
+
if (typeof errMsg === "string") {
|
|
2014
|
+
const parts = errMsg.split("Error:");
|
|
2015
|
+
err = parts[parts.length - 1];
|
|
2016
|
+
}
|
|
2017
|
+
}
|
|
2018
|
+
const thrown = new Error(err);
|
|
2019
|
+
thrown.activation = JSON.stringify(activation, null, 2);
|
|
2020
|
+
return wrapError(thrown, context + " (running remote build)");
|
|
2021
|
+
}
|
|
2022
|
+
const result = activation.response.result;
|
|
2023
|
+
debug5("Remote result was %O", result);
|
|
2024
|
+
const { transcript, outcome } = result;
|
|
2025
|
+
if (transcript && transcript.length > 0) {
|
|
2026
|
+
feedback.progress(`Transcript of remote build session for ${context}:`);
|
|
2027
|
+
for (const line of transcript) {
|
|
2028
|
+
feedback.progress(line);
|
|
2029
|
+
}
|
|
2030
|
+
}
|
|
2031
|
+
return outcome;
|
|
2032
|
+
}
|
|
2033
|
+
function cleanActionsAndPackages(todeploy) {
|
|
2034
|
+
if (!todeploy.packages) {
|
|
2035
|
+
return Promise.resolve(todeploy);
|
|
2036
|
+
}
|
|
2037
|
+
const promises = [];
|
|
2038
|
+
for (const pkg of todeploy.packages) {
|
|
2039
|
+
const defaultPkg = pkg.name === "default";
|
|
2040
|
+
if (pkg.clean && !defaultPkg && todeploy.includer.isPackageIncluded(pkg.name, true)) {
|
|
2041
|
+
promises.push(
|
|
2042
|
+
cleanPackage(
|
|
2043
|
+
todeploy.owClient,
|
|
2044
|
+
todeploy.credentials,
|
|
2045
|
+
pkg.name,
|
|
2046
|
+
todeploy.versions
|
|
2047
|
+
)
|
|
2048
|
+
);
|
|
2049
|
+
} else if (pkg.actions) {
|
|
2050
|
+
for (const action of pkg.actions) {
|
|
2051
|
+
if (action.clean && todeploy.includer.isActionIncluded(pkg.name, action.name) && !action.buildResult) {
|
|
2052
|
+
if (todeploy.versions && todeploy.versions.actionVersions) {
|
|
2053
|
+
delete todeploy.versions.actionVersions[action.name];
|
|
2054
|
+
}
|
|
2055
|
+
promises.push(
|
|
2056
|
+
deleteAction(
|
|
2057
|
+
getActionName(action),
|
|
2058
|
+
todeploy.owClient,
|
|
2059
|
+
todeploy.credentials
|
|
2060
|
+
).catch(() => void 0)
|
|
2061
|
+
);
|
|
2062
|
+
}
|
|
2063
|
+
}
|
|
2064
|
+
}
|
|
2065
|
+
}
|
|
2066
|
+
return Promise.all(promises).then(() => todeploy);
|
|
2067
|
+
}
|
|
2068
|
+
async function cleanPackage(client, credentials, name, versions) {
|
|
2069
|
+
debug5("Cleaning package %s", name);
|
|
2070
|
+
while (true) {
|
|
2071
|
+
const pkg = await client.packages.get({ name }).catch(() => void 0);
|
|
2072
|
+
if (!pkg) {
|
|
2073
|
+
return { name };
|
|
2074
|
+
}
|
|
2075
|
+
if (!pkg.actions || pkg.actions.length === 0) {
|
|
2076
|
+
debug5("No more actions, removing package");
|
|
2077
|
+
if (versions && versions.packageVersions) {
|
|
2078
|
+
delete versions.packageVersions[name];
|
|
2079
|
+
}
|
|
2080
|
+
return client.packages.delete({ name });
|
|
2081
|
+
}
|
|
2082
|
+
for (const action of pkg.actions) {
|
|
2083
|
+
debug5("deleting action %s", action.name);
|
|
2084
|
+
if (versions && versions.actionVersions) {
|
|
2085
|
+
delete versions.actionVersions[action.name];
|
|
2086
|
+
}
|
|
2087
|
+
await deleteAction(name + "/" + action.name, client, credentials);
|
|
2088
|
+
}
|
|
2089
|
+
}
|
|
2090
|
+
}
|
|
2091
|
+
async function deployActionArray(actions, spec, cleanFlag) {
|
|
2092
|
+
let pending = actions;
|
|
2093
|
+
const responses = [];
|
|
2094
|
+
while (pending.length > 0) {
|
|
2095
|
+
const chunk = pending.length > DEPLOYMENT_CHUNK_SIZE ? pending.slice(0, DEPLOYMENT_CHUNK_SIZE) : pending;
|
|
2096
|
+
pending = pending.slice(chunk.length);
|
|
2097
|
+
const chunkResults = await Promise.all(
|
|
2098
|
+
chunk.map((action) => deployAction(action, spec, cleanFlag))
|
|
2099
|
+
).then(combineResponses);
|
|
2100
|
+
responses.push(chunkResults);
|
|
2101
|
+
chunkDebug("Deployed chunk of %d actions", chunk.length);
|
|
2102
|
+
}
|
|
2103
|
+
return combineResponses(responses);
|
|
2104
|
+
}
|
|
2105
|
+
async function onlyDeployPackage(pkg, spec) {
|
|
2106
|
+
const {
|
|
2107
|
+
parameters: projectParams,
|
|
2108
|
+
environment: projectEnv,
|
|
2109
|
+
cleanNamespace: namespaceIsClean,
|
|
2110
|
+
versions,
|
|
2111
|
+
owClient: wsk,
|
|
2112
|
+
deployerAnnotation: deployer,
|
|
2113
|
+
flags
|
|
2114
|
+
} = spec;
|
|
2115
|
+
const digest = digestPackage(pkg);
|
|
2116
|
+
if (flags.incremental && versions.packageVersions && versions.packageVersions[pkg.name] && digest === versions.packageVersions[pkg.name].digest) {
|
|
2117
|
+
const packageVersions = {};
|
|
2118
|
+
packageVersions[pkg.name] = versions.packageVersions[pkg.name];
|
|
2119
|
+
return {
|
|
2120
|
+
successes: [],
|
|
2121
|
+
failures: [],
|
|
2122
|
+
ignored: [],
|
|
2123
|
+
packageVersions,
|
|
2124
|
+
actionVersions: {},
|
|
2125
|
+
namespace: void 0
|
|
2126
|
+
};
|
|
2127
|
+
} else {
|
|
2128
|
+
let former;
|
|
2129
|
+
if (!pkg.clean && !namespaceIsClean) {
|
|
2130
|
+
former = await wsk.packages.get({ name: pkg.name }).catch(() => void 0);
|
|
2131
|
+
}
|
|
2132
|
+
const oldAnnots = former && former.annotations ? makeDict(former.annotations) : {};
|
|
2133
|
+
delete oldAnnots.deployerAnnot;
|
|
2134
|
+
deployer.digest = digest.substring(0, 8);
|
|
2135
|
+
const annotDict = Object.assign({}, oldAnnots, pkg.annotations, {
|
|
2136
|
+
deployer
|
|
2137
|
+
});
|
|
2138
|
+
const annotations = keyVal(annotDict);
|
|
2139
|
+
const mergedParams = Object.assign({}, projectParams, pkg.parameters);
|
|
2140
|
+
const mergedEnv = Object.assign({}, projectEnv, pkg.environment);
|
|
2141
|
+
const params = encodeParameters(mergedParams, mergedEnv);
|
|
2142
|
+
const owPkg = {
|
|
2143
|
+
parameters: params,
|
|
2144
|
+
annotations,
|
|
2145
|
+
publish: pkg.shared
|
|
2146
|
+
};
|
|
2147
|
+
let successes = [];
|
|
2148
|
+
if (pkg.binding) {
|
|
2149
|
+
if (pkg.actions && pkg.actions.length > 0) {
|
|
2150
|
+
throw new Error("a bound package may not contain functions of its own");
|
|
2151
|
+
}
|
|
2152
|
+
owPkg.binding = pkg.binding;
|
|
2153
|
+
successes = [{ name: pkg.name, kind: "binding", skipped: false }];
|
|
2154
|
+
}
|
|
2155
|
+
debug5("successes: %O", successes);
|
|
2156
|
+
return await wsk.packages.update({ name: pkg.name, package: owPkg }).then((result) => {
|
|
2157
|
+
const packageVersions = {};
|
|
2158
|
+
packageVersions[pkg.name] = { version: result.version, digest };
|
|
2159
|
+
return {
|
|
2160
|
+
successes,
|
|
2161
|
+
failures: [],
|
|
2162
|
+
ignored: [],
|
|
2163
|
+
packageVersions,
|
|
2164
|
+
actionVersions: {},
|
|
2165
|
+
namespace: result.namespace
|
|
2166
|
+
};
|
|
2167
|
+
}).catch((err) => {
|
|
2168
|
+
return wrapError(err, `package '${pkg.name}'`);
|
|
2169
|
+
});
|
|
2170
|
+
}
|
|
2171
|
+
}
|
|
2172
|
+
async function deployPackage(pkg, spec, skipPkgDeploy) {
|
|
2173
|
+
const {
|
|
2174
|
+
parameters: projectParams,
|
|
2175
|
+
environment: projectEnv,
|
|
2176
|
+
cleanNamespace: namespaceIsClean
|
|
2177
|
+
} = spec;
|
|
2178
|
+
if (pkg.name === "default" && (pkg.binding || isAtLeastOneNonEmpty([
|
|
2179
|
+
projectParams,
|
|
2180
|
+
projectEnv,
|
|
2181
|
+
pkg.parameters,
|
|
2182
|
+
pkg.environment,
|
|
2183
|
+
pkg.annotations
|
|
2184
|
+
]))) {
|
|
2185
|
+
return wrapError(
|
|
2186
|
+
new Error(
|
|
2187
|
+
"The default package does not support attaching environment, parameters, or binding"
|
|
2188
|
+
),
|
|
2189
|
+
`package 'default'`
|
|
2190
|
+
);
|
|
2191
|
+
}
|
|
2192
|
+
if (pkg.name === "default" || skipPkgDeploy || pkg.deployedDuringBuild) {
|
|
2193
|
+
return deployActionArray(pkg.actions, spec, namespaceIsClean);
|
|
2194
|
+
}
|
|
2195
|
+
const pkgResponse = await onlyDeployPackage(pkg, spec);
|
|
2196
|
+
const actionPromise = await deployActionArray(
|
|
2197
|
+
pkg.actions || [],
|
|
2198
|
+
spec,
|
|
2199
|
+
pkg.clean || namespaceIsClean
|
|
2200
|
+
);
|
|
2201
|
+
return combineResponses([actionPromise, pkgResponse]);
|
|
2202
|
+
}
|
|
2203
|
+
function isAtLeastOneNonEmpty(toCheck) {
|
|
2204
|
+
for (const source of toCheck) {
|
|
2205
|
+
if (source && Object.keys(source).length > 0) {
|
|
2206
|
+
return true;
|
|
2207
|
+
}
|
|
2208
|
+
}
|
|
2209
|
+
return false;
|
|
2210
|
+
}
|
|
2211
|
+
function deployAction(action, spec, pkgIsClean) {
|
|
2212
|
+
const { owClient: wsk, feedback, reader } = spec;
|
|
2213
|
+
const context = `action '${getActionName(action)}'`;
|
|
2214
|
+
debug5("deploying %s", context);
|
|
2215
|
+
if (action.buildError) {
|
|
2216
|
+
return Promise.resolve(wrapError(action.buildError, context));
|
|
2217
|
+
}
|
|
2218
|
+
if (action.buildResult) {
|
|
2219
|
+
return processRemoteResponse(action.buildResult, wsk, context, feedback);
|
|
2220
|
+
}
|
|
2221
|
+
if (action.code) {
|
|
2222
|
+
debug5("action already has code");
|
|
2223
|
+
return deployActionFromCodeOrSequence(
|
|
2224
|
+
action,
|
|
2225
|
+
spec,
|
|
2226
|
+
action.code,
|
|
2227
|
+
void 0,
|
|
2228
|
+
pkgIsClean
|
|
2229
|
+
);
|
|
2230
|
+
}
|
|
2231
|
+
if (action.sequence) {
|
|
2232
|
+
const error = checkForLegalSequence(action);
|
|
2233
|
+
if (error) {
|
|
2234
|
+
return Promise.resolve(wrapError(error, context));
|
|
2235
|
+
}
|
|
2236
|
+
if (!spec.sequences) {
|
|
2237
|
+
spec.sequences = [];
|
|
2238
|
+
}
|
|
2239
|
+
spec.sequences.push(action);
|
|
2240
|
+
return Promise.resolve(emptyResponse());
|
|
2241
|
+
}
|
|
2242
|
+
const codeFile = action.file;
|
|
2243
|
+
if (codeFile) {
|
|
2244
|
+
debug5("reading action code from %s", codeFile);
|
|
2245
|
+
return reader.readFileContents(codeFile).then((data) => {
|
|
2246
|
+
const code = action.binary ? data.toString("base64") : String(data);
|
|
2247
|
+
return code;
|
|
2248
|
+
}).then(
|
|
2249
|
+
(code) => deployActionFromCodeOrSequence(
|
|
2250
|
+
action,
|
|
2251
|
+
spec,
|
|
2252
|
+
code,
|
|
2253
|
+
void 0,
|
|
2254
|
+
pkgIsClean
|
|
2255
|
+
)
|
|
2256
|
+
).catch((err) => Promise.resolve(wrapError(err, context)));
|
|
2257
|
+
} else {
|
|
2258
|
+
return Promise.resolve(
|
|
2259
|
+
wrapError(
|
|
2260
|
+
new Error(
|
|
2261
|
+
"Action is named in the config but does not exist in the project"
|
|
2262
|
+
),
|
|
2263
|
+
context
|
|
2264
|
+
)
|
|
2265
|
+
);
|
|
2266
|
+
}
|
|
2267
|
+
}
|
|
2268
|
+
function checkForLegalSequence(action) {
|
|
2269
|
+
if (action.file) {
|
|
2270
|
+
return new Error(
|
|
2271
|
+
"An action cannot be a sequence and also exist in the project directory structure"
|
|
2272
|
+
);
|
|
2273
|
+
}
|
|
2274
|
+
if (action.runtime || action.binary || action.main) {
|
|
2275
|
+
return new Error(
|
|
2276
|
+
"An action cannot be a sequence and also have the runtime, binary, or main attributes"
|
|
2277
|
+
);
|
|
2278
|
+
}
|
|
2279
|
+
return false;
|
|
2280
|
+
}
|
|
2281
|
+
function sortSequences(sequences, spec) {
|
|
2282
|
+
const {
|
|
2283
|
+
credentials: { namespace }
|
|
2284
|
+
} = spec;
|
|
2285
|
+
const actionNames = getAllActionFqns(spec, namespace);
|
|
2286
|
+
const inProgress = /* @__PURE__ */ new Set();
|
|
2287
|
+
const completed = /* @__PURE__ */ new Set();
|
|
2288
|
+
const result = [];
|
|
2289
|
+
for (const seq of sequences) {
|
|
2290
|
+
if (!addSequenceToList(
|
|
2291
|
+
seq,
|
|
2292
|
+
namespace,
|
|
2293
|
+
result,
|
|
2294
|
+
inProgress,
|
|
2295
|
+
completed,
|
|
2296
|
+
sequences,
|
|
2297
|
+
actionNames,
|
|
2298
|
+
spec.feedback
|
|
2299
|
+
)) {
|
|
2300
|
+
throw new Error("A cycle was detected in mutually dependent sequences");
|
|
2301
|
+
}
|
|
2302
|
+
}
|
|
2303
|
+
return result;
|
|
2304
|
+
}
|
|
2305
|
+
function addSequenceToList(seq, namespace, result, inProgress, completed, sequences, actionNames, feedback) {
|
|
2306
|
+
const seqName = fqnFromActionSpec(seq, namespace);
|
|
2307
|
+
seqDebug("addSequenceToList %s", seqName);
|
|
2308
|
+
if (inProgress.has(seqName)) {
|
|
2309
|
+
seqDebug("found in inProgress");
|
|
2310
|
+
return false;
|
|
2311
|
+
}
|
|
2312
|
+
if (completed.has(seqName)) {
|
|
2313
|
+
seqDebug("found in completed");
|
|
2314
|
+
return true;
|
|
2315
|
+
}
|
|
2316
|
+
inProgress.add(seqName);
|
|
2317
|
+
const thisNsPrefix = "/" + namespace + "/";
|
|
2318
|
+
for (const member of seq.sequence) {
|
|
2319
|
+
const memberName = fqn(member, namespace);
|
|
2320
|
+
const preReq = sequences.find(
|
|
2321
|
+
(cand) => memberName === fqnFromActionSpec(cand, namespace)
|
|
2322
|
+
);
|
|
2323
|
+
if (preReq) {
|
|
2324
|
+
seqDebug("Found pre-requisite sequence %s", preReq.name);
|
|
2325
|
+
if (!addSequenceToList(
|
|
2326
|
+
preReq,
|
|
2327
|
+
namespace,
|
|
2328
|
+
result,
|
|
2329
|
+
inProgress,
|
|
2330
|
+
completed,
|
|
2331
|
+
sequences,
|
|
2332
|
+
actionNames,
|
|
2333
|
+
feedback
|
|
2334
|
+
)) {
|
|
2335
|
+
return false;
|
|
2336
|
+
}
|
|
2337
|
+
}
|
|
2338
|
+
if (memberName.startsWith(thisNsPrefix) && !actionNames.has(memberName)) {
|
|
2339
|
+
feedback.warn(
|
|
2340
|
+
"Sequence '%s' contains action '%s' which is in the same namespace but not part of the deployment",
|
|
2341
|
+
seq.name,
|
|
2342
|
+
memberName
|
|
2343
|
+
);
|
|
2344
|
+
}
|
|
2345
|
+
}
|
|
2346
|
+
inProgress.delete(seqName);
|
|
2347
|
+
completed.add(seqName);
|
|
2348
|
+
seqDebug("adding %s to result", seqName);
|
|
2349
|
+
result.push(seq);
|
|
2350
|
+
return true;
|
|
2351
|
+
}
|
|
2352
|
+
async function deploySequences(todeploy) {
|
|
2353
|
+
try {
|
|
2354
|
+
todeploy.sequences = sortSequences(todeploy.sequences || [], todeploy);
|
|
2355
|
+
} catch (err) {
|
|
2356
|
+
return [wrapError(err, "sequences")];
|
|
2357
|
+
}
|
|
2358
|
+
const result = [];
|
|
2359
|
+
for (const seq of todeploy.sequences ?? []) {
|
|
2360
|
+
const components = seq.sequence.map(
|
|
2361
|
+
(action) => fqn(action, todeploy.credentials.namespace)
|
|
2362
|
+
);
|
|
2363
|
+
const exec = { kind: "sequence", components };
|
|
2364
|
+
result.push(
|
|
2365
|
+
await deployActionFromCodeOrSequence(
|
|
2366
|
+
seq,
|
|
2367
|
+
todeploy,
|
|
2368
|
+
void 0,
|
|
2369
|
+
exec,
|
|
2370
|
+
isCleanPkg(todeploy, seq.package)
|
|
2371
|
+
)
|
|
2372
|
+
);
|
|
2373
|
+
}
|
|
2374
|
+
return result;
|
|
2375
|
+
}
|
|
2376
|
+
function isCleanPkg(spec, pkgName) {
|
|
2377
|
+
if (spec.cleanNamespace) {
|
|
2378
|
+
return true;
|
|
2379
|
+
}
|
|
2380
|
+
const pkg = (spec.packages || []).find((pkg2) => pkg2.name === pkgName);
|
|
2381
|
+
return !!(pkg == null ? void 0 : pkg.clean);
|
|
2382
|
+
}
|
|
2383
|
+
function fqnFromActionSpec(spec, namespace) {
|
|
2384
|
+
let name = spec.name;
|
|
2385
|
+
if (spec.package && spec.package !== "default") {
|
|
2386
|
+
name = `${spec.package}/${name}`;
|
|
2387
|
+
}
|
|
2388
|
+
return `/${namespace}/${name}`;
|
|
2389
|
+
}
|
|
2390
|
+
function getAllActionFqns(spec, namespace) {
|
|
2391
|
+
const ans = /* @__PURE__ */ new Set();
|
|
2392
|
+
for (const pkg of spec.packages ?? []) {
|
|
2393
|
+
if (pkg.actions) {
|
|
2394
|
+
pkg.actions.forEach(
|
|
2395
|
+
(action) => ans.add(fqnFromActionSpec(action, namespace))
|
|
2396
|
+
);
|
|
2397
|
+
}
|
|
2398
|
+
}
|
|
2399
|
+
return ans;
|
|
2400
|
+
}
|
|
2401
|
+
function fqn(name, namespace) {
|
|
2402
|
+
if (name.startsWith("/")) {
|
|
2403
|
+
return name;
|
|
2404
|
+
}
|
|
2405
|
+
return `/${namespace}/${name}`;
|
|
2406
|
+
}
|
|
2407
|
+
function encodeParameters(normalParms, envParms) {
|
|
2408
|
+
let ans = [];
|
|
2409
|
+
if (normalParms) {
|
|
2410
|
+
ans = keyVal(normalParms);
|
|
2411
|
+
}
|
|
2412
|
+
if (envParms) {
|
|
2413
|
+
const envs = keyVal(envParms);
|
|
2414
|
+
envs.forEach((env) => {
|
|
2415
|
+
env.init = true;
|
|
2416
|
+
});
|
|
2417
|
+
ans = ans.concat(envs);
|
|
2418
|
+
}
|
|
2419
|
+
return ans;
|
|
2420
|
+
}
|
|
2421
|
+
function calculateActionExec(action, code) {
|
|
2422
|
+
const main2 = action.main ? action.main : void 0;
|
|
2423
|
+
if (action.docker) {
|
|
2424
|
+
return {
|
|
2425
|
+
code,
|
|
2426
|
+
binary: action.binary,
|
|
2427
|
+
kind: "blackbox",
|
|
2428
|
+
image: action.docker,
|
|
2429
|
+
main: main2
|
|
2430
|
+
};
|
|
2431
|
+
}
|
|
2432
|
+
return { code, binary: action.binary, kind: action.runtime, main: main2 };
|
|
2433
|
+
}
|
|
2434
|
+
async function deployActionFromCodeOrSequence(action, spec, code, sequence, pkgIsClean) {
|
|
2435
|
+
const name = getActionName(action);
|
|
2436
|
+
const { versions, flags, deployerAnnotation, owClient: wsk } = spec;
|
|
2437
|
+
const deployerAnnot = Object.assign({}, deployerAnnotation);
|
|
2438
|
+
debug5("deploying %s using %s", name, !sequence ? "code" : "sequence info");
|
|
2439
|
+
if (code && !action.runtime) {
|
|
2440
|
+
return Promise.resolve(
|
|
2441
|
+
wrapError(
|
|
2442
|
+
new Error(
|
|
2443
|
+
`Action '${name}' not deployed: runtime type could not be determined`
|
|
2444
|
+
),
|
|
2445
|
+
`action ${name}`
|
|
2446
|
+
)
|
|
2447
|
+
);
|
|
2448
|
+
}
|
|
2449
|
+
let digest;
|
|
2450
|
+
if (!sequence) {
|
|
2451
|
+
digest = digestAction(action, code);
|
|
2452
|
+
debug5("computed digest for %s", name);
|
|
2453
|
+
if (flags.incremental && versions.actionVersions && versions.actionVersions[name] && digest === versions.actionVersions[name].digest) {
|
|
2454
|
+
debug5("matched digest for %s", name);
|
|
2455
|
+
const actionVersions = {};
|
|
2456
|
+
actionVersions[name] = versions.actionVersions[name];
|
|
2457
|
+
return Promise.resolve(
|
|
2458
|
+
wrapSuccess(name, "action", true, actionVersions, void 0)
|
|
2459
|
+
);
|
|
2460
|
+
}
|
|
2461
|
+
debug5("recording digest for %s", name);
|
|
2462
|
+
deployerAnnot.digest = digest.substring(0, 8);
|
|
2463
|
+
}
|
|
2464
|
+
deployerAnnot.zipped = action.zipped;
|
|
2465
|
+
const annotations = Object.assign({}, action.annotations) || {};
|
|
2466
|
+
annotations.deployer = deployerAnnot;
|
|
2467
|
+
annotations.final = true;
|
|
2468
|
+
if (action.web === true) {
|
|
2469
|
+
annotations["web-export"] = true;
|
|
2470
|
+
annotations["raw-http"] = false;
|
|
2471
|
+
} else if (action.web === "raw") {
|
|
2472
|
+
annotations["web-export"] = true;
|
|
2473
|
+
annotations["raw-http"] = true;
|
|
2474
|
+
} else if (!action.web) {
|
|
2475
|
+
annotations["web-export"] = false;
|
|
2476
|
+
annotations["raw-http"] = false;
|
|
2477
|
+
}
|
|
2478
|
+
if (typeof action.webSecure === "string") {
|
|
2479
|
+
annotations["require-whisk-auth"] = action.webSecure;
|
|
2480
|
+
} else {
|
|
2481
|
+
annotations["require-whisk-auth"] = false;
|
|
2482
|
+
}
|
|
2483
|
+
let former;
|
|
2484
|
+
if (!action.clean && !pkgIsClean) {
|
|
2485
|
+
const options = { name, code: false };
|
|
2486
|
+
former = await wsk.actions.get(options).catch(() => void 0);
|
|
2487
|
+
}
|
|
2488
|
+
const oldAnnots = former && former.annotations ? makeDict(former.annotations) : {};
|
|
2489
|
+
const annotDict = Object.assign({}, oldAnnots, annotations);
|
|
2490
|
+
const params = encodeParameters(action.parameters, action.environment);
|
|
2491
|
+
const exec = sequence || calculateActionExec(action, code);
|
|
2492
|
+
const actionBody = {
|
|
2493
|
+
annotations: keyVal(annotDict),
|
|
2494
|
+
parameters: params,
|
|
2495
|
+
exec
|
|
2496
|
+
};
|
|
2497
|
+
if (action.limits) {
|
|
2498
|
+
actionBody.limits = action.limits;
|
|
2499
|
+
}
|
|
2500
|
+
const deployParams = { name, action: actionBody };
|
|
2501
|
+
try {
|
|
2502
|
+
const response = await wsk.actions.update(deployParams);
|
|
2503
|
+
let triggerResults = [];
|
|
2504
|
+
if (action.triggers) {
|
|
2505
|
+
triggerResults = await deployTriggers(
|
|
2506
|
+
action.triggers,
|
|
2507
|
+
name,
|
|
2508
|
+
spec.credentials
|
|
2509
|
+
);
|
|
2510
|
+
}
|
|
2511
|
+
const map = {};
|
|
2512
|
+
if (digest) {
|
|
2513
|
+
map[name] = { version: response.version, digest };
|
|
2514
|
+
}
|
|
2515
|
+
const namespace = response.namespace.split("/")[0];
|
|
2516
|
+
const success = wrapSuccess(name, "action", false, map, namespace);
|
|
2517
|
+
for (let i = 0; i < triggerResults.length; i++) {
|
|
2518
|
+
if (triggerResults[i] instanceof Error) {
|
|
2519
|
+
const err = triggerResults[i];
|
|
2520
|
+
err.context = `while deploying trigger '${action.triggers[i].name}'`;
|
|
2521
|
+
success.failures.push(triggerResults[i]);
|
|
2522
|
+
} else {
|
|
2523
|
+
success.successes.push(triggerResults[i]);
|
|
2524
|
+
}
|
|
2525
|
+
}
|
|
2526
|
+
return Promise.resolve(success);
|
|
2527
|
+
} catch (err) {
|
|
2528
|
+
return Promise.resolve(wrapError(err, `action '${name}'`));
|
|
2529
|
+
}
|
|
2530
|
+
}
|
|
2531
|
+
|
|
2532
|
+
// src/project-reader.ts
|
|
2533
|
+
var path5 = __toESM(require("path"));
|
|
2534
|
+
var fs6 = __toESM(require("fs"));
|
|
2535
|
+
|
|
2536
|
+
// src/finder-builder.ts
|
|
2537
|
+
var import_child_process = require("child_process");
|
|
2538
|
+
var path4 = __toESM(require("path"));
|
|
2539
|
+
var fs4 = __toESM(require("fs"));
|
|
2540
|
+
var yaml2 = __toESM(require("js-yaml"));
|
|
2541
|
+
var import_ignore = __toESM(require("ignore"));
|
|
2542
|
+
var import_axios3 = __toESM(require("axios"));
|
|
2543
|
+
var import_archiver = __toESM(require("archiver"));
|
|
2544
|
+
var import_touch = __toESM(require("touch"));
|
|
2545
|
+
var import_debug7 = __toESM(require("debug"));
|
|
2546
|
+
var memoryStreams = __toESM(require("memory-streams"));
|
|
2547
|
+
|
|
2548
|
+
// src/slice-reader.ts
|
|
2549
|
+
var path3 = __toESM(require("path"));
|
|
2550
|
+
var fs3 = __toESM(require("fs"));
|
|
2551
|
+
var import_debug6 = __toESM(require("debug"));
|
|
2552
|
+
var import_adm_zip = __toESM(require("adm-zip"));
|
|
2553
|
+
var rimraf = __toESM(require("rimraf"));
|
|
2554
|
+
var import_client_s3 = require("@aws-sdk/client-s3");
|
|
2555
|
+
var import_memory_streams = require("memory-streams");
|
|
2556
|
+
var debug6 = (0, import_debug6.default)("nim:deployer:slice-reader");
|
|
2557
|
+
var TEMP = process.platform === "win32" ? process.env.TEMP : "/tmp";
|
|
2558
|
+
var bucket = process.env.BUILDER_BUCKET_NAME;
|
|
2559
|
+
var endpoint = process.env.S3_ENDPOINT;
|
|
2560
|
+
var MAX_SLICE_UPLOAD_SIZE = parseInt(process.env.MAX_SLICE_UPLOAD_SIZE) || 64 * 1024 * 1024;
|
|
2561
|
+
var s3Client;
|
|
2562
|
+
function cacheArea() {
|
|
2563
|
+
return path3.join(TEMP, "slices");
|
|
2564
|
+
}
|
|
2565
|
+
function getS3Client() {
|
|
2566
|
+
if (!s3Client) {
|
|
2567
|
+
s3Client = new import_client_s3.S3Client({ endpoint, region: "us-east-1" });
|
|
2568
|
+
}
|
|
2569
|
+
return s3Client;
|
|
2570
|
+
}
|
|
2571
|
+
function pipe(input, output) {
|
|
2572
|
+
const toWait = new Promise(function(resolve5) {
|
|
2573
|
+
output.on("close", () => {
|
|
2574
|
+
resolve5(true);
|
|
2575
|
+
});
|
|
2576
|
+
output.on("finish", () => {
|
|
2577
|
+
resolve5(true);
|
|
2578
|
+
});
|
|
2579
|
+
});
|
|
2580
|
+
input.pipe(output);
|
|
2581
|
+
return toWait;
|
|
2582
|
+
}
|
|
2583
|
+
async function fetchSlice(sliceName) {
|
|
2584
|
+
const cache = path3.join(cacheArea(), sliceName);
|
|
2585
|
+
if (fs3.existsSync(cache)) {
|
|
2586
|
+
rimraf.sync(cache);
|
|
2587
|
+
}
|
|
2588
|
+
debug6("Making cache directory: %s", cache);
|
|
2589
|
+
fs3.mkdirSync(cache, { recursive: true });
|
|
2590
|
+
const s3 = getS3Client();
|
|
2591
|
+
const cmd = new import_client_s3.GetObjectCommand({ Bucket: bucket, Key: sliceName });
|
|
2592
|
+
const result = await s3.send(cmd);
|
|
2593
|
+
const content = result.Body;
|
|
2594
|
+
const destination = new import_memory_streams.WritableStream({
|
|
2595
|
+
highWaterMark: MAX_SLICE_UPLOAD_SIZE
|
|
2596
|
+
});
|
|
2597
|
+
await pipe(content, destination);
|
|
2598
|
+
const data = destination.toBuffer();
|
|
2599
|
+
const zip = new import_adm_zip.default(data);
|
|
2600
|
+
debug6("zip file has %d entries", zip.getEntries().length);
|
|
2601
|
+
for (const entry of zip.getEntries().filter((entry2) => !entry2.isDirectory)) {
|
|
2602
|
+
const target = path3.join(cache, entry.entryName);
|
|
2603
|
+
const parent = path3.dirname(target);
|
|
2604
|
+
if (!fs3.existsSync(parent)) {
|
|
2605
|
+
fs3.mkdirSync(parent, { recursive: true });
|
|
2606
|
+
}
|
|
2607
|
+
const mode = entry.attr >>> 16;
|
|
2608
|
+
debug6("storing %s", entry.entryName);
|
|
2609
|
+
fs3.writeFileSync(target, entry.getData(), { mode });
|
|
2610
|
+
}
|
|
2611
|
+
return cache;
|
|
2612
|
+
}
|
|
2613
|
+
async function deleteSlice(project) {
|
|
2614
|
+
const sliceName = path3.relative(cacheArea(), project.filePath);
|
|
2615
|
+
const s3 = getS3Client();
|
|
2616
|
+
const cmd = new import_client_s3.DeleteObjectCommand({ Bucket: bucket, Key: sliceName });
|
|
2617
|
+
await s3.send(cmd);
|
|
2618
|
+
}
|
|
2619
|
+
|
|
2620
|
+
// src/finder-builder.ts
|
|
2621
|
+
var openwhisk = require("openwhisk");
|
|
2622
|
+
var debug7 = (0, import_debug7.default)("nim:deployer:finder-builder");
|
|
2623
|
+
var zipDebug = (0, import_debug7.default)("nim:deployer:zip");
|
|
2624
|
+
var ZIP_TARGET = "__deployer__.zip";
|
|
2625
|
+
var BUILDER_NAMESPACE = process.env["TEST_BUILDER_NAMESPACE"] || "nimbella";
|
|
2626
|
+
var BUILDER_ACTION_STEM = `/${BUILDER_NAMESPACE}/builder/build_`;
|
|
2627
|
+
var GET_UPLOAD_URL = `/${BUILDER_NAMESPACE}/builder/getUploadUrl`;
|
|
2628
|
+
var CANNED_REMOTE_BUILD = `#!/bin/bash
|
|
2629
|
+
set -e
|
|
2630
|
+
/bin/defaultBuild %MAIN%
|
|
2631
|
+
`;
|
|
2632
|
+
function getBuildForAction(filepath, reader) {
|
|
2633
|
+
return readDirectory(filepath, reader).then(
|
|
2634
|
+
(items) => findSpecialFile(items, filepath, true, false)
|
|
2635
|
+
);
|
|
2636
|
+
}
|
|
2637
|
+
async function buildAllActions(spec) {
|
|
2638
|
+
const packages = spec.packages;
|
|
2639
|
+
if (!packages || packages.length === 0) {
|
|
2640
|
+
return void 0;
|
|
2641
|
+
}
|
|
2642
|
+
const pkgMap = mapPackages(packages);
|
|
2643
|
+
const promises = [];
|
|
2644
|
+
for (const pkg of packages) {
|
|
2645
|
+
if (pkg.actions && pkg.actions.length > 0 || pkg.binding) {
|
|
2646
|
+
const builtPackage = buildActionsOfPackage(pkg, spec);
|
|
2647
|
+
promises.push(builtPackage);
|
|
2648
|
+
}
|
|
2649
|
+
}
|
|
2650
|
+
if (promises.length === 0) {
|
|
2651
|
+
return void 0;
|
|
2652
|
+
}
|
|
2653
|
+
return Promise.all(promises).then((newpkgs) => {
|
|
2654
|
+
for (const pkg of newpkgs) {
|
|
2655
|
+
if (pkg) {
|
|
2656
|
+
pkgMap[pkg.name] = pkg;
|
|
2657
|
+
}
|
|
2658
|
+
}
|
|
2659
|
+
return Object.values(pkgMap);
|
|
2660
|
+
});
|
|
2661
|
+
}
|
|
2662
|
+
async function buildActionsOfPackage(pkg, spec) {
|
|
2663
|
+
var _a;
|
|
2664
|
+
const mustDeployPackage = pkg.name !== "default" && ((_a = pkg.actions) == null ? void 0 : _a.some(
|
|
2665
|
+
(action) => action.build === "remote" || action.build === "remote-default"
|
|
2666
|
+
));
|
|
2667
|
+
if (mustDeployPackage) {
|
|
2668
|
+
const pkgResult = await onlyDeployPackage(pkg, spec);
|
|
2669
|
+
if (pkgResult.failures.length > 0) {
|
|
2670
|
+
throw pkgResult.failures[0];
|
|
2671
|
+
}
|
|
2672
|
+
pkg.deployedDuringBuild = true;
|
|
2673
|
+
spec.deployerAnnotation.newSliceHandling = true;
|
|
2674
|
+
}
|
|
2675
|
+
const actionMap = mapActions(pkg.actions);
|
|
2676
|
+
let nobuilds = true;
|
|
2677
|
+
for (const action of pkg.actions || []) {
|
|
2678
|
+
if (action.build) {
|
|
2679
|
+
nobuilds = false;
|
|
2680
|
+
const builtAction = await buildAction(action, spec).catch((err) => {
|
|
2681
|
+
action.buildError = err;
|
|
2682
|
+
return action;
|
|
2683
|
+
});
|
|
2684
|
+
actionMap[action.name] = builtAction;
|
|
2685
|
+
}
|
|
2686
|
+
}
|
|
2687
|
+
if (nobuilds) {
|
|
2688
|
+
return void 0;
|
|
2689
|
+
}
|
|
2690
|
+
pkg.actions = Object.values(actionMap);
|
|
2691
|
+
return pkg;
|
|
2692
|
+
}
|
|
2693
|
+
function buildAction(action, spec) {
|
|
2694
|
+
if (!action.build) {
|
|
2695
|
+
return Promise.resolve(action);
|
|
2696
|
+
}
|
|
2697
|
+
debug7("building action %O", action);
|
|
2698
|
+
let actionDir;
|
|
2699
|
+
const { reader, flags, feedback, slice, buildEnv } = spec;
|
|
2700
|
+
switch (action.build) {
|
|
2701
|
+
case "build.sh":
|
|
2702
|
+
actionDir = makeLocal(reader, action.file);
|
|
2703
|
+
return scriptBuilder(
|
|
2704
|
+
"./build.sh",
|
|
2705
|
+
actionDir,
|
|
2706
|
+
action.displayFile,
|
|
2707
|
+
flags,
|
|
2708
|
+
buildEnv,
|
|
2709
|
+
slice,
|
|
2710
|
+
feedback
|
|
2711
|
+
).then(
|
|
2712
|
+
() => identifyActionFiles(
|
|
2713
|
+
action,
|
|
2714
|
+
flags.incremental,
|
|
2715
|
+
flags.verboseZip,
|
|
2716
|
+
reader,
|
|
2717
|
+
feedback
|
|
2718
|
+
)
|
|
2719
|
+
);
|
|
2720
|
+
case "build.cmd":
|
|
2721
|
+
actionDir = makeLocal(reader, action.file);
|
|
2722
|
+
return scriptBuilder(
|
|
2723
|
+
"build.cmd",
|
|
2724
|
+
actionDir,
|
|
2725
|
+
action.displayFile,
|
|
2726
|
+
flags,
|
|
2727
|
+
buildEnv,
|
|
2728
|
+
slice,
|
|
2729
|
+
feedback
|
|
2730
|
+
).then(
|
|
2731
|
+
() => identifyActionFiles(
|
|
2732
|
+
action,
|
|
2733
|
+
flags.incremental,
|
|
2734
|
+
flags.verboseZip,
|
|
2735
|
+
reader,
|
|
2736
|
+
feedback
|
|
2737
|
+
)
|
|
2738
|
+
);
|
|
2739
|
+
case "package.json":
|
|
2740
|
+
actionDir = makeLocal(reader, action.file);
|
|
2741
|
+
return npmBuilder(
|
|
2742
|
+
actionDir,
|
|
2743
|
+
action.displayFile,
|
|
2744
|
+
flags,
|
|
2745
|
+
buildEnv,
|
|
2746
|
+
slice,
|
|
2747
|
+
feedback
|
|
2748
|
+
).then(
|
|
2749
|
+
() => identifyActionFiles(
|
|
2750
|
+
action,
|
|
2751
|
+
flags.incremental,
|
|
2752
|
+
flags.verboseZip,
|
|
2753
|
+
reader,
|
|
2754
|
+
feedback
|
|
2755
|
+
)
|
|
2756
|
+
);
|
|
2757
|
+
case ".include":
|
|
2758
|
+
case "identify":
|
|
2759
|
+
return identifyActionFiles(
|
|
2760
|
+
action,
|
|
2761
|
+
flags.incremental,
|
|
2762
|
+
flags.verboseZip,
|
|
2763
|
+
reader,
|
|
2764
|
+
feedback
|
|
2765
|
+
);
|
|
2766
|
+
case "remote":
|
|
2767
|
+
case "remote-default":
|
|
2768
|
+
checkBuiltLocally(reader, action.file);
|
|
2769
|
+
return doRemoteActionBuild(action, spec);
|
|
2770
|
+
default:
|
|
2771
|
+
throw new Error("Unknown build type in ActionSpec: " + action.build);
|
|
2772
|
+
}
|
|
2773
|
+
}
|
|
2774
|
+
async function processInclude(includesPath, dirPath, reader, web) {
|
|
2775
|
+
debug7("processing includes from '%s'", includesPath);
|
|
2776
|
+
const items = await readFileAsList(includesPath, reader);
|
|
2777
|
+
const errMsg = checkIncludeItems(items, web);
|
|
2778
|
+
if (errMsg) {
|
|
2779
|
+
return Promise.reject(new Error(errMsg));
|
|
2780
|
+
}
|
|
2781
|
+
return processIncludeFileItems(items, dirPath, reader);
|
|
2782
|
+
}
|
|
2783
|
+
function makeLocal(reader, ...paths) {
|
|
2784
|
+
const project = reader.getFSLocation();
|
|
2785
|
+
if (!project) {
|
|
2786
|
+
throw new Error("invalid call to makeLocal");
|
|
2787
|
+
}
|
|
2788
|
+
return path4.resolve(project, ...paths);
|
|
2789
|
+
}
|
|
2790
|
+
async function processIncludeFileItems(items, dirPath, reader) {
|
|
2791
|
+
const complex = [];
|
|
2792
|
+
const simple = [];
|
|
2793
|
+
for (let item of items) {
|
|
2794
|
+
debug7("processing include item %s", item);
|
|
2795
|
+
if (item.startsWith("./") || item.startsWith(".\\")) {
|
|
2796
|
+
item = item.slice(2);
|
|
2797
|
+
}
|
|
2798
|
+
let oldPath = path4.join(dirPath, item);
|
|
2799
|
+
if (oldPath.endsWith("/") || oldPath.endsWith("\\")) {
|
|
2800
|
+
oldPath = oldPath.slice(0, -1);
|
|
2801
|
+
}
|
|
2802
|
+
debug7("Calculated oldPath '%s'", oldPath);
|
|
2803
|
+
const lstat2 = await reader.getPathKind(oldPath);
|
|
2804
|
+
if (!lstat2) {
|
|
2805
|
+
return Promise.reject(
|
|
2806
|
+
new Error(`${oldPath} is included for '${dirPath}' but does not exist`)
|
|
2807
|
+
);
|
|
2808
|
+
}
|
|
2809
|
+
let newPath;
|
|
2810
|
+
if (item.includes("..")) {
|
|
2811
|
+
newPath = path4.basename(item);
|
|
2812
|
+
} else {
|
|
2813
|
+
newPath = item;
|
|
2814
|
+
}
|
|
2815
|
+
const toElide = oldPath.length - newPath.length;
|
|
2816
|
+
debug7("Calculated newPath '%s' with elision %d", newPath, toElide);
|
|
2817
|
+
if (lstat2.isFile) {
|
|
2818
|
+
simple.push([oldPath, newPath]);
|
|
2819
|
+
} else if (lstat2.isDirectory) {
|
|
2820
|
+
const expanded = promiseFilesAndFilterFiles(oldPath, reader).then(
|
|
2821
|
+
(items2) => items2.map((item2) => [item2, item2.slice(toElide)])
|
|
2822
|
+
);
|
|
2823
|
+
debug7("Expanded directory '%s'", oldPath);
|
|
2824
|
+
complex.push(expanded);
|
|
2825
|
+
} else {
|
|
2826
|
+
return Promise.reject(
|
|
2827
|
+
new Error(`'${item}' is neither a file nor a directory`)
|
|
2828
|
+
);
|
|
2829
|
+
}
|
|
2830
|
+
}
|
|
2831
|
+
return Promise.all(complex.concat(Promise.resolve(simple))).then(
|
|
2832
|
+
(arrays) => arrays.reduce((prev, curr) => prev.concat(curr), [])
|
|
2833
|
+
);
|
|
2834
|
+
}
|
|
2835
|
+
async function identifyActionFiles(action, incremental, verboseZip, reader, feedback) {
|
|
2836
|
+
let includesPath = path4.join(action.file, ".include");
|
|
2837
|
+
if (!await reader.isExistingFile(includesPath)) {
|
|
2838
|
+
includesPath = path4.join(action.file, ".source");
|
|
2839
|
+
}
|
|
2840
|
+
if (await reader.isExistingFile(includesPath)) {
|
|
2841
|
+
return processInclude(includesPath, action.file, reader, false).then(
|
|
2842
|
+
(pairs) => {
|
|
2843
|
+
if (pairs.length === 0) {
|
|
2844
|
+
return Promise.reject(new Error(includesPath + " is empty"));
|
|
2845
|
+
} else if (pairs.length > 1) {
|
|
2846
|
+
return autozipBuilder(
|
|
2847
|
+
pairs,
|
|
2848
|
+
action,
|
|
2849
|
+
incremental,
|
|
2850
|
+
verboseZip,
|
|
2851
|
+
reader,
|
|
2852
|
+
feedback
|
|
2853
|
+
);
|
|
2854
|
+
} else {
|
|
2855
|
+
return singleFileBuilder(action, pairs[0][0]);
|
|
2856
|
+
}
|
|
2857
|
+
}
|
|
2858
|
+
);
|
|
2859
|
+
}
|
|
2860
|
+
return getIgnores(action.file, reader).then((ignore2) => {
|
|
2861
|
+
return promiseFilesAndFilterFiles(action.file, reader).then(
|
|
2862
|
+
(items) => {
|
|
2863
|
+
items = applyIgnores(action.file, items, ignore2);
|
|
2864
|
+
if (items.length === 0) {
|
|
2865
|
+
return Promise.reject(
|
|
2866
|
+
new Error(`Action '${getActionName(action)}' has no included files`)
|
|
2867
|
+
);
|
|
2868
|
+
} else if (items.length === 1) {
|
|
2869
|
+
return singleFileBuilder(action, items[0]);
|
|
2870
|
+
} else {
|
|
2871
|
+
const pairs = items.map((item) => {
|
|
2872
|
+
const shortName = item.substring(action.file.length + 1);
|
|
2873
|
+
return [item, shortName];
|
|
2874
|
+
});
|
|
2875
|
+
return autozipBuilder(
|
|
2876
|
+
pairs,
|
|
2877
|
+
action,
|
|
2878
|
+
incremental,
|
|
2879
|
+
verboseZip,
|
|
2880
|
+
reader,
|
|
2881
|
+
feedback
|
|
2882
|
+
);
|
|
2883
|
+
}
|
|
2884
|
+
}
|
|
2885
|
+
);
|
|
2886
|
+
});
|
|
2887
|
+
}
|
|
2888
|
+
function applyIgnores(basePath, items, ignore2) {
|
|
2889
|
+
const absolute = path4.isAbsolute(basePath);
|
|
2890
|
+
if (absolute) {
|
|
2891
|
+
items = items.map((item) => path4.relative(basePath, item));
|
|
2892
|
+
}
|
|
2893
|
+
items = ignore2.filter(items);
|
|
2894
|
+
if (absolute) {
|
|
2895
|
+
items = items.map((item) => path4.join(basePath, item));
|
|
2896
|
+
}
|
|
2897
|
+
return items;
|
|
2898
|
+
}
|
|
2899
|
+
function readFileAsList(file, reader) {
|
|
2900
|
+
return reader.readFileContents(file).then(
|
|
2901
|
+
(data) => String(data).split("\n").filter((line) => line && line.trim().length > 0).map((line) => line.trim())
|
|
2902
|
+
);
|
|
2903
|
+
}
|
|
2904
|
+
function getBuildForLibOrWeb(filepath, reader, lib) {
|
|
2905
|
+
if (!filepath) {
|
|
2906
|
+
return Promise.resolve(void 0);
|
|
2907
|
+
}
|
|
2908
|
+
return readDirectory(filepath, reader).then(
|
|
2909
|
+
(items) => findSpecialFile(items, filepath, false, lib)
|
|
2910
|
+
);
|
|
2911
|
+
}
|
|
2912
|
+
async function maybeBuildLib(spec) {
|
|
2913
|
+
function isRemote(build2) {
|
|
2914
|
+
return build2 === "remote" || build2 === "remote-default";
|
|
2915
|
+
}
|
|
2916
|
+
let shouldBuild = spec.slice;
|
|
2917
|
+
if (!shouldBuild && spec.packages) {
|
|
2918
|
+
pkgLoop:
|
|
2919
|
+
for (const pkg of spec.packages) {
|
|
2920
|
+
if (pkg.actions) {
|
|
2921
|
+
for (const action of pkg.actions) {
|
|
2922
|
+
shouldBuild = action.build && !isRemote(action.build);
|
|
2923
|
+
if (shouldBuild) {
|
|
2924
|
+
break pkgLoop;
|
|
2925
|
+
}
|
|
2926
|
+
}
|
|
2927
|
+
}
|
|
2928
|
+
}
|
|
2929
|
+
}
|
|
2930
|
+
if (shouldBuild) {
|
|
2931
|
+
let scriptPath;
|
|
2932
|
+
const displayPath = path4.join(getBestProjectName(spec), "lib");
|
|
2933
|
+
const { reader, flags, feedback, slice, buildEnv } = spec;
|
|
2934
|
+
switch (spec.libBuild) {
|
|
2935
|
+
case "build.sh":
|
|
2936
|
+
scriptPath = makeLocal(reader, "lib");
|
|
2937
|
+
return scriptBuilder(
|
|
2938
|
+
"./build.sh",
|
|
2939
|
+
scriptPath,
|
|
2940
|
+
displayPath,
|
|
2941
|
+
flags,
|
|
2942
|
+
buildEnv,
|
|
2943
|
+
slice,
|
|
2944
|
+
feedback
|
|
2945
|
+
);
|
|
2946
|
+
case "build.cmd":
|
|
2947
|
+
scriptPath = makeLocal(reader, "lib");
|
|
2948
|
+
return scriptBuilder(
|
|
2949
|
+
"build.cmd",
|
|
2950
|
+
scriptPath,
|
|
2951
|
+
displayPath,
|
|
2952
|
+
flags,
|
|
2953
|
+
buildEnv,
|
|
2954
|
+
slice,
|
|
2955
|
+
feedback
|
|
2956
|
+
);
|
|
2957
|
+
case "package.json":
|
|
2958
|
+
scriptPath = makeLocal(reader, "lib");
|
|
2959
|
+
return npmBuilder(
|
|
2960
|
+
scriptPath,
|
|
2961
|
+
displayPath,
|
|
2962
|
+
flags,
|
|
2963
|
+
buildEnv,
|
|
2964
|
+
slice,
|
|
2965
|
+
feedback
|
|
2966
|
+
);
|
|
2967
|
+
default:
|
|
2968
|
+
throw new Error(
|
|
2969
|
+
"Unknown or inappropriate build type for lib directory: " + spec.libBuild
|
|
2970
|
+
);
|
|
2971
|
+
}
|
|
2972
|
+
}
|
|
2973
|
+
}
|
|
2974
|
+
function checkBuiltLocally(reader, localPath) {
|
|
2975
|
+
const loc = reader.getFSLocation();
|
|
2976
|
+
if (!loc) {
|
|
2977
|
+
debug7(
|
|
2978
|
+
"checkBuiltLocally skipped because project reader does not use local file system"
|
|
2979
|
+
);
|
|
2980
|
+
return;
|
|
2981
|
+
}
|
|
2982
|
+
const filepath = path4.join(loc, localPath);
|
|
2983
|
+
debug7(
|
|
2984
|
+
"checking for local build artifacts in %s when remote build requested",
|
|
2985
|
+
filepath
|
|
2986
|
+
);
|
|
2987
|
+
if (fs4.existsSync(filepath) && fs4.lstatSync(filepath).isDirectory()) {
|
|
2988
|
+
debug7("%s exists and is a directory", filepath);
|
|
2989
|
+
const zipped = path4.join(filepath, ZIP_TARGET);
|
|
2990
|
+
const dotBuilt = path4.join(filepath, ".built");
|
|
2991
|
+
if (fs4.existsSync(zipped) || fs4.existsSync(dotBuilt)) {
|
|
2992
|
+
throw new Error(
|
|
2993
|
+
`Remote build is requested for '${filepath}' but it appears to have been built locally. Remove derived artifacts first.`
|
|
2994
|
+
);
|
|
2995
|
+
}
|
|
2996
|
+
debug7("did not find %s or %s", zipped, dotBuilt);
|
|
2997
|
+
}
|
|
2998
|
+
debug7("checkBuiltLocally passed");
|
|
2999
|
+
}
|
|
3000
|
+
function checkIncludeItems(items, web) {
|
|
3001
|
+
const legalDots = web ? "../lib" : "../../../lib";
|
|
3002
|
+
for (const item of items) {
|
|
3003
|
+
if (!item || item.length === 0) {
|
|
3004
|
+
continue;
|
|
3005
|
+
}
|
|
3006
|
+
if (path4.isAbsolute(item)) {
|
|
3007
|
+
return `Absolute paths are prohibited in an '.include' file`;
|
|
3008
|
+
}
|
|
3009
|
+
if (item.includes("..") && !item.startsWith(legalDots)) {
|
|
3010
|
+
return `Illegal use of '..' in an '.include' file`;
|
|
3011
|
+
}
|
|
3012
|
+
}
|
|
3013
|
+
return "";
|
|
3014
|
+
}
|
|
3015
|
+
async function checkRemoteBuildPreReqs(filepath, project, web) {
|
|
3016
|
+
debug7(`checking remote build pre-reqs for '${filepath}'`);
|
|
3017
|
+
const reader = project.reader;
|
|
3018
|
+
if ((await reader.getPathKind(filepath)).isDirectory) {
|
|
3019
|
+
const include = path4.join(filepath, ".include");
|
|
3020
|
+
if (await reader.isExistingFile(include)) {
|
|
3021
|
+
debug7(`found an .include file for '${filepath}'`);
|
|
3022
|
+
const items = await readFileAsList(include, reader);
|
|
3023
|
+
debug7(`read ${items.length} .include items for '${filepath}'`);
|
|
3024
|
+
const msg = checkIncludeItems(items, web);
|
|
3025
|
+
if (msg) {
|
|
3026
|
+
throw new Error(msg);
|
|
3027
|
+
}
|
|
3028
|
+
}
|
|
3029
|
+
}
|
|
3030
|
+
}
|
|
3031
|
+
async function doRemoteActionBuild(action, project) {
|
|
3032
|
+
await checkRemoteBuildPreReqs(action.file, project, false);
|
|
3033
|
+
const { zip, output, outputPromise } = makeProjectSliceZip(action.file);
|
|
3034
|
+
const pkgName = path4.basename(path4.dirname(action.file));
|
|
3035
|
+
const actionName = pkgName === "default" ? action.name : path4.join(pkgName, action.name);
|
|
3036
|
+
debug7("zipping action path %s for project slice", action.file);
|
|
3037
|
+
const generateRemote = defaultRemote(action);
|
|
3038
|
+
const runtime = await appendToZip(
|
|
3039
|
+
zip,
|
|
3040
|
+
action.file,
|
|
3041
|
+
project.reader,
|
|
3042
|
+
generateRemote
|
|
3043
|
+
);
|
|
3044
|
+
if (!action.runtime) {
|
|
3045
|
+
if (!runtime) {
|
|
3046
|
+
throw new Error(
|
|
3047
|
+
`Could not determine runtime for remote build of '${actionName}'. You may need to specify it in 'project.yml'`
|
|
3048
|
+
);
|
|
3049
|
+
}
|
|
3050
|
+
debug7("Setting runtime to %s for remote build", runtime);
|
|
3051
|
+
action.runtime = runtime;
|
|
3052
|
+
}
|
|
3053
|
+
if (project.libBuild) {
|
|
3054
|
+
await appendLibToZip(zip, "lib", project.reader);
|
|
3055
|
+
}
|
|
3056
|
+
const spec = makeConfigFromActionSpec(action, project, pkgName);
|
|
3057
|
+
debug7("converting slice spec to YAML: %O", spec);
|
|
3058
|
+
const { config, key } = encryptProjectConfig(yaml2.safeDump(spec));
|
|
3059
|
+
zip.append(config, { name: "project.yml" });
|
|
3060
|
+
debug7("finalizing zip for project slice");
|
|
3061
|
+
zip.finalize();
|
|
3062
|
+
debug7("zip finalized for project slice of action %s", getActionName(action));
|
|
3063
|
+
await outputPromise;
|
|
3064
|
+
debug7(
|
|
3065
|
+
"outputPromise settled for project slice of action %s",
|
|
3066
|
+
getActionName(action)
|
|
3067
|
+
);
|
|
3068
|
+
const toSend = output.toBuffer();
|
|
3069
|
+
debug7(
|
|
3070
|
+
"sending the remote build request for project %s and action %s",
|
|
3071
|
+
project.filePath,
|
|
3072
|
+
actionName
|
|
3073
|
+
);
|
|
3074
|
+
action.buildResult = await invokeRemoteBuilder(
|
|
3075
|
+
toSend,
|
|
3076
|
+
project.owClient,
|
|
3077
|
+
project.feedback,
|
|
3078
|
+
action,
|
|
3079
|
+
key
|
|
3080
|
+
);
|
|
3081
|
+
return action;
|
|
3082
|
+
}
|
|
3083
|
+
function defaultRemote(action) {
|
|
3084
|
+
if (action.build && action.build === "remote-default") {
|
|
3085
|
+
const main2 = action.main || "Main";
|
|
3086
|
+
const contents = CANNED_REMOTE_BUILD.replace("%MAIN%", main2);
|
|
3087
|
+
const actionName = action.name;
|
|
3088
|
+
return { contents, actionName };
|
|
3089
|
+
}
|
|
3090
|
+
return void 0;
|
|
3091
|
+
}
|
|
3092
|
+
async function appendToZip(zip, actionPath, reader, generateBuild) {
|
|
3093
|
+
const kind = await reader.getPathKind(actionPath);
|
|
3094
|
+
let analyzeForRuntime;
|
|
3095
|
+
if (kind.isFile) {
|
|
3096
|
+
if (generateBuild) {
|
|
3097
|
+
const parent = path4.dirname(actionPath);
|
|
3098
|
+
const simpleFile = path4.basename(actionPath);
|
|
3099
|
+
const name = path4.join(parent, generateBuild.actionName, simpleFile);
|
|
3100
|
+
const contents = await reader.readFileContents(actionPath);
|
|
3101
|
+
zip.append(contents, { name, mode: 438 });
|
|
3102
|
+
const buildFile = path4.join(parent, generateBuild.actionName, "build.sh");
|
|
3103
|
+
zip.append(generateBuild.contents, { name: buildFile, mode: 511 });
|
|
3104
|
+
} else {
|
|
3105
|
+
await appendAndCheck(zip, actionPath, actionPath, reader);
|
|
3106
|
+
}
|
|
3107
|
+
analyzeForRuntime = [actionPath];
|
|
3108
|
+
} else if (kind.isDirectory) {
|
|
3109
|
+
zipDebug("getting contents of directory %s for remote build slice", path4);
|
|
3110
|
+
const files = await promiseFilesAndFilterFiles(actionPath, reader);
|
|
3111
|
+
analyzeForRuntime = files;
|
|
3112
|
+
for (const file of files) {
|
|
3113
|
+
await appendAndCheck(zip, file, actionPath, reader);
|
|
3114
|
+
}
|
|
3115
|
+
if (generateBuild) {
|
|
3116
|
+
const buildFile = path4.join(actionPath, "build.sh");
|
|
3117
|
+
zip.append(generateBuild.contents, { name: buildFile, mode: 511 });
|
|
3118
|
+
}
|
|
3119
|
+
}
|
|
3120
|
+
return agreeOnRuntime(analyzeForRuntime);
|
|
3121
|
+
}
|
|
3122
|
+
async function appendLibToZip(zip, path7, reader) {
|
|
3123
|
+
zipDebug("getting contents of directory %s for remote build slice", path7);
|
|
3124
|
+
const files = await promiseFilesAndFilterFiles(path7, reader);
|
|
3125
|
+
for (const file of files) {
|
|
3126
|
+
await appendAndCheck(zip, file, path7, reader);
|
|
3127
|
+
}
|
|
3128
|
+
}
|
|
3129
|
+
async function appendAndCheck(zip, file, actionPath, reader) {
|
|
3130
|
+
const contents = await reader.readFileContents(file);
|
|
3131
|
+
let mode;
|
|
3132
|
+
if (file.endsWith(".sh") && process.platform === "win32") {
|
|
3133
|
+
mode = 511;
|
|
3134
|
+
} else {
|
|
3135
|
+
mode = (await reader.getPathKind(file)).mode;
|
|
3136
|
+
}
|
|
3137
|
+
debug7(`mode for ${file} is ${mode}`);
|
|
3138
|
+
zip.append(contents, { name: file, mode });
|
|
3139
|
+
zipDebug("zipped '%s' for remote build slice", file);
|
|
3140
|
+
}
|
|
3141
|
+
function makeConfigFromActionSpec(action, spec, pkgName) {
|
|
3142
|
+
debug7("converting action spec to sliced project.yml: %O", action);
|
|
3143
|
+
const {
|
|
3144
|
+
targetNamespace,
|
|
3145
|
+
cleanNamespace,
|
|
3146
|
+
parameters,
|
|
3147
|
+
environment: globalEnv,
|
|
3148
|
+
credentials,
|
|
3149
|
+
flags,
|
|
3150
|
+
deployerAnnotation,
|
|
3151
|
+
buildEnv
|
|
3152
|
+
} = spec;
|
|
3153
|
+
flags.remoteBuild = false;
|
|
3154
|
+
flags.buildEnv = void 0;
|
|
3155
|
+
const {
|
|
3156
|
+
name,
|
|
3157
|
+
runtime,
|
|
3158
|
+
main: main2,
|
|
3159
|
+
binary,
|
|
3160
|
+
zipped,
|
|
3161
|
+
web,
|
|
3162
|
+
webSecure,
|
|
3163
|
+
annotations,
|
|
3164
|
+
environment,
|
|
3165
|
+
limits,
|
|
3166
|
+
clean
|
|
3167
|
+
} = action;
|
|
3168
|
+
const newSpec = {
|
|
3169
|
+
targetNamespace,
|
|
3170
|
+
cleanNamespace,
|
|
3171
|
+
parameters,
|
|
3172
|
+
environment: globalEnv,
|
|
3173
|
+
credentials,
|
|
3174
|
+
flags,
|
|
3175
|
+
deployerAnnotation,
|
|
3176
|
+
buildEnv,
|
|
3177
|
+
slice: true
|
|
3178
|
+
};
|
|
3179
|
+
const newAction = {
|
|
3180
|
+
name,
|
|
3181
|
+
runtime,
|
|
3182
|
+
main: main2,
|
|
3183
|
+
binary,
|
|
3184
|
+
zipped,
|
|
3185
|
+
web,
|
|
3186
|
+
webSecure,
|
|
3187
|
+
annotations,
|
|
3188
|
+
parameters: action.parameters,
|
|
3189
|
+
environment,
|
|
3190
|
+
limits,
|
|
3191
|
+
clean
|
|
3192
|
+
};
|
|
3193
|
+
removeUndefined(newSpec);
|
|
3194
|
+
removeUndefined(newAction);
|
|
3195
|
+
const pkg = Object.assign(
|
|
3196
|
+
{},
|
|
3197
|
+
spec.packages.find((pkg2) => pkg2.name === pkgName)
|
|
3198
|
+
);
|
|
3199
|
+
pkg.actions = [newAction];
|
|
3200
|
+
pkg.deployedDuringBuild = false;
|
|
3201
|
+
newSpec.packages = [pkg];
|
|
3202
|
+
return newSpec;
|
|
3203
|
+
}
|
|
3204
|
+
function removeUndefined(obj) {
|
|
3205
|
+
for (const item in obj) {
|
|
3206
|
+
if (typeof obj[item] === "undefined") {
|
|
3207
|
+
delete obj[item];
|
|
3208
|
+
} else if (typeof obj[item] === "object") {
|
|
3209
|
+
obj[item] = removeUndefined(obj[item]);
|
|
3210
|
+
}
|
|
3211
|
+
}
|
|
3212
|
+
return obj;
|
|
3213
|
+
}
|
|
3214
|
+
function makeProjectSliceZip(context) {
|
|
3215
|
+
const output = new memoryStreams.WritableStream({
|
|
3216
|
+
highWaterMark: MAX_SLICE_UPLOAD_SIZE
|
|
3217
|
+
});
|
|
3218
|
+
const zip = (0, import_archiver.default)("zip");
|
|
3219
|
+
const outputPromise = new Promise(function(resolve5, reject) {
|
|
3220
|
+
zip.on("error", (err) => {
|
|
3221
|
+
debug7("zip error occurred: %O", err);
|
|
3222
|
+
reject(err);
|
|
3223
|
+
});
|
|
3224
|
+
output.on("close", () => {
|
|
3225
|
+
debug7("zipfile successfully closed");
|
|
3226
|
+
resolve5(void 0);
|
|
3227
|
+
});
|
|
3228
|
+
output.on("finish", () => {
|
|
3229
|
+
debug7("zipfile successfully finished");
|
|
3230
|
+
resolve5(void 0);
|
|
3231
|
+
});
|
|
3232
|
+
output.on("end", () => {
|
|
3233
|
+
debug7("zipfile data has been drained");
|
|
3234
|
+
});
|
|
3235
|
+
output.on("drain", () => {
|
|
3236
|
+
debug7("memory stream posted a drain event");
|
|
3237
|
+
reject(
|
|
3238
|
+
new Error(
|
|
3239
|
+
`Remote build upload for '${context}' is too large. Make sure the directory is free of derived artifacts`
|
|
3240
|
+
)
|
|
3241
|
+
);
|
|
3242
|
+
});
|
|
3243
|
+
zip.on("warning", (err) => {
|
|
3244
|
+
debug7("warning issued from archiver %O", err);
|
|
3245
|
+
if (err.code !== "ENOENT") {
|
|
3246
|
+
reject(err);
|
|
3247
|
+
}
|
|
3248
|
+
});
|
|
3249
|
+
});
|
|
3250
|
+
zip.pipe(output);
|
|
3251
|
+
return { output, zip, outputPromise };
|
|
3252
|
+
}
|
|
3253
|
+
function computeTag(action) {
|
|
3254
|
+
if (!action) {
|
|
3255
|
+
return "web";
|
|
3256
|
+
}
|
|
3257
|
+
if (action.package) {
|
|
3258
|
+
return `${action.package}_${action.name}`;
|
|
3259
|
+
}
|
|
3260
|
+
return action.name;
|
|
3261
|
+
}
|
|
3262
|
+
async function getUploadUrl(owClient, params, feedback) {
|
|
3263
|
+
var _a, _b;
|
|
3264
|
+
const invoked = await owClient.actions.invoke({
|
|
3265
|
+
name: GET_UPLOAD_URL,
|
|
3266
|
+
params
|
|
3267
|
+
});
|
|
3268
|
+
const tick = () => feedback.progress(
|
|
3269
|
+
`Waiting for permission to upload remote build for '${params.action}'`
|
|
3270
|
+
);
|
|
3271
|
+
const activation = await waitForActivation(
|
|
3272
|
+
invoked.activationId,
|
|
3273
|
+
owClient,
|
|
3274
|
+
tick,
|
|
3275
|
+
2 * 60
|
|
3276
|
+
);
|
|
3277
|
+
if (!activation) {
|
|
3278
|
+
throw new Error(
|
|
3279
|
+
`Timed out awaiting permission to upload remote build for '${params.action}'`
|
|
3280
|
+
);
|
|
3281
|
+
}
|
|
3282
|
+
if (!activation.response || !activation.response.success) {
|
|
3283
|
+
let err = "Failed to get remote build upload permission";
|
|
3284
|
+
const resultError = (_b = (_a = activation == null ? void 0 : activation.response) == null ? void 0 : _a.result) == null ? void 0 : _b.error;
|
|
3285
|
+
if (resultError) {
|
|
3286
|
+
const errMsg = typeof resultError === "string" ? resultError : resultError.message;
|
|
3287
|
+
if (typeof errMsg === "string") {
|
|
3288
|
+
const parts = errMsg.split("Error:");
|
|
3289
|
+
err = parts[parts.length - 1];
|
|
3290
|
+
}
|
|
3291
|
+
}
|
|
3292
|
+
const thrown = new Error(err);
|
|
3293
|
+
thrown.activation = JSON.stringify(activation, null, 2);
|
|
3294
|
+
throw thrown;
|
|
3295
|
+
}
|
|
3296
|
+
const result = activation.response.result;
|
|
3297
|
+
return { url: result.url, sliceName: result.sliceName };
|
|
3298
|
+
}
|
|
3299
|
+
async function invokeRemoteBuilder(zipped, owClient, feedback, action, encryptionKey) {
|
|
3300
|
+
const params = { action: computeTag(action) };
|
|
3301
|
+
debug7(`Invoking 'getUploadUrl'`);
|
|
3302
|
+
const { url, sliceName } = await getUploadUrl(owClient, params, feedback);
|
|
3303
|
+
if (!url || !sliceName) {
|
|
3304
|
+
const msg = `Unexpected response from getUploadUrl`;
|
|
3305
|
+
throw new Error(msg);
|
|
3306
|
+
}
|
|
3307
|
+
debug7("remote build url is %s", url);
|
|
3308
|
+
const axiosConfig = {
|
|
3309
|
+
maxBodyLength: MAX_SLICE_UPLOAD_SIZE,
|
|
3310
|
+
maxContentLength: MAX_SLICE_UPLOAD_SIZE
|
|
3311
|
+
};
|
|
3312
|
+
const result = await import_axios3.default.put(url, zipped, axiosConfig);
|
|
3313
|
+
if (result.status !== 200) {
|
|
3314
|
+
throw new Error(
|
|
3315
|
+
`Bad response [$result.status}] when uploading '${sliceName}' for remote build`
|
|
3316
|
+
);
|
|
3317
|
+
}
|
|
3318
|
+
debug7("axios put of url was successful");
|
|
3319
|
+
const kind = action ? action.runtime : "nodejs:default";
|
|
3320
|
+
const activityName = action ? `action '${getActionName(action)}'` : "web content";
|
|
3321
|
+
const runtime = (await canonicalRuntime(kind)).replace(":", "_");
|
|
3322
|
+
const buildActionName = `${BUILDER_ACTION_STEM}${runtime}`;
|
|
3323
|
+
debug7(
|
|
3324
|
+
`Invoking remote build action '${buildActionName}' for build '${path4.basename(
|
|
3325
|
+
sliceName
|
|
3326
|
+
)} of ${activityName}`
|
|
3327
|
+
);
|
|
3328
|
+
try {
|
|
3329
|
+
const invoked = await owClient.actions.invoke({
|
|
3330
|
+
name: buildActionName,
|
|
3331
|
+
params: { toBuild: sliceName, encryptionKey }
|
|
3332
|
+
});
|
|
3333
|
+
feedback.progress(
|
|
3334
|
+
`Submitted ${activityName} for remote building and deployment in runtime ${kind} (id: ${invoked.activationId})`
|
|
3335
|
+
);
|
|
3336
|
+
return invoked.activationId;
|
|
3337
|
+
} catch (err) {
|
|
3338
|
+
if (err.statusCode === 404) {
|
|
3339
|
+
throw new Error(
|
|
3340
|
+
`Remote build service is not available for runtime '${kind}' on this platform instance.`
|
|
3341
|
+
);
|
|
3342
|
+
} else if (err.statusCode >= 500 && err.statusCode <= 599) {
|
|
3343
|
+
throw new Error("Remote build service returned error status.");
|
|
3344
|
+
} else {
|
|
3345
|
+
throw err;
|
|
3346
|
+
}
|
|
3347
|
+
}
|
|
3348
|
+
}
|
|
3349
|
+
function readDirectory(filepath, reader) {
|
|
3350
|
+
return reader.readdir(filepath).then(filterFiles);
|
|
3351
|
+
}
|
|
3352
|
+
function findSpecialFile(items, filepath, isAction, isLib) {
|
|
3353
|
+
const files = items.filter((item) => !item.isDirectory);
|
|
3354
|
+
let buildDotSh = false;
|
|
3355
|
+
let buildDotCmd = false;
|
|
3356
|
+
let npm = false;
|
|
3357
|
+
let include = false;
|
|
3358
|
+
let ignore2 = false;
|
|
3359
|
+
for (const file of files) {
|
|
3360
|
+
if (file.name === "build.sh") {
|
|
3361
|
+
buildDotSh = true;
|
|
3362
|
+
} else if (file.name === "build.cmd") {
|
|
3363
|
+
buildDotCmd = true;
|
|
3364
|
+
} else if (file.name === "package.json") {
|
|
3365
|
+
npm = true;
|
|
3366
|
+
} else if (file.name === ".include" || file.name === ".source") {
|
|
3367
|
+
include = true;
|
|
3368
|
+
} else if (file.name === ".ignore") {
|
|
3369
|
+
ignore2 = true;
|
|
3370
|
+
}
|
|
3371
|
+
}
|
|
3372
|
+
if (include && ignore2) {
|
|
3373
|
+
throw new Error(
|
|
3374
|
+
`In ${filepath}: '.include' (or '.source') and '.ignore' may not both be present`
|
|
3375
|
+
);
|
|
3376
|
+
} else if (isAction && (files.length === 0 || ignore2 && files.length === 1)) {
|
|
3377
|
+
throw new Error(`Action directory ${filepath} has no files`);
|
|
3378
|
+
} else if (isLib && (include || ignore2)) {
|
|
3379
|
+
throw new Error(
|
|
3380
|
+
`'.include' and '.ignore' are not supported in the 'lib' directory`
|
|
3381
|
+
);
|
|
3382
|
+
}
|
|
3383
|
+
if (process.platform === "win32") {
|
|
3384
|
+
if (buildDotSh && !buildDotCmd) {
|
|
3385
|
+
throw new Error(
|
|
3386
|
+
`In ${filepath}: 'build.sh' won't run on this platform and no 'build.cmd' is provided`
|
|
3387
|
+
);
|
|
3388
|
+
}
|
|
3389
|
+
if (buildDotCmd) {
|
|
3390
|
+
return "build.cmd";
|
|
3391
|
+
}
|
|
3392
|
+
} else {
|
|
3393
|
+
if (!buildDotSh && buildDotCmd) {
|
|
3394
|
+
throw new Error(
|
|
3395
|
+
`In ${filepath}: 'build.cmd' won't run on this platform and no 'build.sh' is provided`
|
|
3396
|
+
);
|
|
3397
|
+
}
|
|
3398
|
+
if (buildDotSh) {
|
|
3399
|
+
return "build.sh";
|
|
3400
|
+
}
|
|
3401
|
+
}
|
|
3402
|
+
return npm ? "package.json" : include ? ".include" : "identify";
|
|
3403
|
+
}
|
|
3404
|
+
async function singleFileBuilder(action, file) {
|
|
3405
|
+
debug7("singleFileBuilder deploying '%s'", file);
|
|
3406
|
+
const newMeta = await actionFileToParts(file);
|
|
3407
|
+
delete newMeta.name;
|
|
3408
|
+
newMeta.web = true;
|
|
3409
|
+
const { binary, zipped } = newMeta;
|
|
3410
|
+
const newAction = Object.assign(newMeta, action, { file, binary, zipped });
|
|
3411
|
+
return Promise.resolve(newAction);
|
|
3412
|
+
}
|
|
3413
|
+
async function autozipBuilder(pairs, action, incremental, verboseZip, reader, feedback) {
|
|
3414
|
+
if (verboseZip) {
|
|
3415
|
+
feedback.progress("Zipping action contents in", action.file);
|
|
3416
|
+
} else {
|
|
3417
|
+
debug7("Zipping action contents in %s", action.file);
|
|
3418
|
+
}
|
|
3419
|
+
if (!action.runtime) {
|
|
3420
|
+
action.runtime = await agreeOnRuntime(pairs.map((pair) => pair[0]));
|
|
3421
|
+
}
|
|
3422
|
+
const targetZip = path4.join(action.file, ZIP_TARGET);
|
|
3423
|
+
const inMemory = reader.getFSLocation() === null;
|
|
3424
|
+
let output;
|
|
3425
|
+
if (!inMemory) {
|
|
3426
|
+
zipDebug("zipping to %s for action %s", targetZip, getActionName(action));
|
|
3427
|
+
const localTargetZip = makeLocal(reader, targetZip);
|
|
3428
|
+
pairs = pairs.map((pair) => [makeLocal(reader, pair[0]), pair[1]]);
|
|
3429
|
+
if (fs4.existsSync(localTargetZip)) {
|
|
3430
|
+
zipDebug("the file exists and will be either reused or deleted");
|
|
3431
|
+
if (incremental) {
|
|
3432
|
+
const metaFiles = [
|
|
3433
|
+
makeLocal(reader, action.file, ".include"),
|
|
3434
|
+
makeLocal(reader, action.file, ".ignore")
|
|
3435
|
+
].filter(fs4.existsSync);
|
|
3436
|
+
debug7(
|
|
3437
|
+
"checking whether to build a new zip for %s with metaFiles %o",
|
|
3438
|
+
getActionName(action),
|
|
3439
|
+
metaFiles
|
|
3440
|
+
);
|
|
3441
|
+
if (zipFileAppearsCurrent(
|
|
3442
|
+
localTargetZip,
|
|
3443
|
+
pairs.map((pair) => pair[0]).concat(metaFiles)
|
|
3444
|
+
)) {
|
|
3445
|
+
return singleFileBuilder(action, targetZip);
|
|
3446
|
+
}
|
|
3447
|
+
}
|
|
3448
|
+
zipDebug("deleting old target zip");
|
|
3449
|
+
fs4.unlinkSync(localTargetZip);
|
|
3450
|
+
}
|
|
3451
|
+
output = fs4.createWriteStream(localTargetZip);
|
|
3452
|
+
} else {
|
|
3453
|
+
zipDebug("zipping to memory buffer for action %s", getActionName(action));
|
|
3454
|
+
output = new memoryStreams.WritableStream({ highWaterMark: 1024 * 1024 });
|
|
3455
|
+
}
|
|
3456
|
+
const zip = (0, import_archiver.default)("zip");
|
|
3457
|
+
const outputPromise = new Promise(function(resolve5, reject) {
|
|
3458
|
+
zip.on("error", (err) => {
|
|
3459
|
+
zipDebug("zip error occurred: %O", err);
|
|
3460
|
+
reject(err);
|
|
3461
|
+
});
|
|
3462
|
+
output.on("close", () => {
|
|
3463
|
+
zipDebug("zipfile successfully closed");
|
|
3464
|
+
resolve5(void 0);
|
|
3465
|
+
});
|
|
3466
|
+
output.on("finish", () => {
|
|
3467
|
+
zipDebug("zipfile successfully finished");
|
|
3468
|
+
resolve5(void 0);
|
|
3469
|
+
});
|
|
3470
|
+
output.on("end", () => {
|
|
3471
|
+
zipDebug("zipfile data has been drained");
|
|
3472
|
+
});
|
|
3473
|
+
zip.on("warning", (err) => {
|
|
3474
|
+
zipDebug("warning issued from archiver %O", err);
|
|
3475
|
+
if (err.code !== "ENOENT") {
|
|
3476
|
+
reject(err);
|
|
3477
|
+
}
|
|
3478
|
+
});
|
|
3479
|
+
});
|
|
3480
|
+
zip.pipe(output);
|
|
3481
|
+
zipDebug("zipping %d files", pairs.length);
|
|
3482
|
+
for (const pair of pairs) {
|
|
3483
|
+
const [oldPath, newPath] = pair;
|
|
3484
|
+
const pathKind = await reader.getPathKind(oldPath);
|
|
3485
|
+
if (pathKind.symlink) {
|
|
3486
|
+
zip.symlink(newPath, pathKind.symlink);
|
|
3487
|
+
} else {
|
|
3488
|
+
const mode = pathKind.mode;
|
|
3489
|
+
const data = await reader.readFileContents(oldPath);
|
|
3490
|
+
zipDebug(
|
|
3491
|
+
"Zipping file with old path '%s', buffer length '%d', new path '%s', and mode %d",
|
|
3492
|
+
oldPath,
|
|
3493
|
+
data.length,
|
|
3494
|
+
newPath,
|
|
3495
|
+
mode
|
|
3496
|
+
);
|
|
3497
|
+
zip.append(data, { name: newPath, mode });
|
|
3498
|
+
zipDebug(
|
|
3499
|
+
"Zipped '%s' for action '%s', emitted %d",
|
|
3500
|
+
newPath,
|
|
3501
|
+
action.name,
|
|
3502
|
+
zip.pointer()
|
|
3503
|
+
);
|
|
3504
|
+
}
|
|
3505
|
+
}
|
|
3506
|
+
zipDebug("finalizing zip for action %s", action.name);
|
|
3507
|
+
zip.finalize();
|
|
3508
|
+
zipDebug("zip finalized for action %s", action.name);
|
|
3509
|
+
return outputPromise.then(() => {
|
|
3510
|
+
if (verboseZip) {
|
|
3511
|
+
feedback.progress("Zipping complete in", action.file);
|
|
3512
|
+
} else {
|
|
3513
|
+
debug7("zipping complete for %s", action.name);
|
|
3514
|
+
}
|
|
3515
|
+
if (inMemory) {
|
|
3516
|
+
const code = output.toBuffer().toString("base64");
|
|
3517
|
+
if (!code) {
|
|
3518
|
+
return Promise.reject(
|
|
3519
|
+
new Error("An error occurred in in-memory zipping")
|
|
3520
|
+
);
|
|
3521
|
+
}
|
|
3522
|
+
zipDebug(
|
|
3523
|
+
"in memory zipping complete with code of length %d",
|
|
3524
|
+
code.length
|
|
3525
|
+
);
|
|
3526
|
+
action.code = code;
|
|
3527
|
+
return singleFileBuilder(action, action.file);
|
|
3528
|
+
} else {
|
|
3529
|
+
return singleFileBuilder(action, targetZip);
|
|
3530
|
+
}
|
|
3531
|
+
});
|
|
3532
|
+
}
|
|
3533
|
+
function build(cmd, args, realPath, displayPath, infoMsg, errorTag, verbose, buildEnv, slice, feedback) {
|
|
3534
|
+
debug7("building with realPath=%s and displayPath=%s", realPath, displayPath);
|
|
3535
|
+
let result = "";
|
|
3536
|
+
let time = Date.now();
|
|
3537
|
+
function statusUpdate(data) {
|
|
3538
|
+
result += data.toString();
|
|
3539
|
+
const newTime = Date.now();
|
|
3540
|
+
if (newTime - time > 5e3) {
|
|
3541
|
+
time = newTime;
|
|
3542
|
+
feedback.progress("Still running", infoMsg, "in", displayPath);
|
|
3543
|
+
}
|
|
3544
|
+
}
|
|
3545
|
+
const env = buildEnv ? Object.assign({}, process.env, buildEnv) : process.env;
|
|
3546
|
+
return new Promise(function(resolve5, reject) {
|
|
3547
|
+
feedback.progress("Started running", infoMsg, "in", displayPath);
|
|
3548
|
+
const shell = process.platform === "win32" ? true : process.env.shell || "/bin/bash";
|
|
3549
|
+
const child = (0, import_child_process.spawn)(cmd, args, { cwd: realPath, shell, env });
|
|
3550
|
+
if (verbose && !slice) {
|
|
3551
|
+
child.stdout.on("data", (data) => feedback.progress(String(data)));
|
|
3552
|
+
child.stderr.on("data", (data) => feedback.warn(String(data)));
|
|
3553
|
+
} else {
|
|
3554
|
+
child.stdout.on("data", statusUpdate);
|
|
3555
|
+
child.stderr.on("data", statusUpdate);
|
|
3556
|
+
}
|
|
3557
|
+
child.on("close", (code) => {
|
|
3558
|
+
if (code !== 0) {
|
|
3559
|
+
if (!verbose || slice) {
|
|
3560
|
+
feedback.warn("Output of failed build in %s", realPath);
|
|
3561
|
+
feedback.warn(result);
|
|
3562
|
+
}
|
|
3563
|
+
reject(new Error(`'${errorTag}' exited with code ${code}`));
|
|
3564
|
+
} else {
|
|
3565
|
+
feedback.progress("Finished running", infoMsg, "in", displayPath);
|
|
3566
|
+
if (verbose && slice) {
|
|
3567
|
+
feedback.warn(result);
|
|
3568
|
+
}
|
|
3569
|
+
resolve5(void 0);
|
|
3570
|
+
}
|
|
3571
|
+
});
|
|
3572
|
+
child.on("error", (err) => {
|
|
3573
|
+
reject(err);
|
|
3574
|
+
});
|
|
3575
|
+
});
|
|
3576
|
+
}
|
|
3577
|
+
function scriptBuilder(script, realPath, displayPath, flags, buildEnv, slice, feedback) {
|
|
3578
|
+
if (flags.incremental && scriptAppearsBuilt(realPath)) {
|
|
3579
|
+
if (flags.verboseBuild) {
|
|
3580
|
+
feedback.progress(
|
|
3581
|
+
`Skipping build in ${displayPath} because the action was previously built`
|
|
3582
|
+
);
|
|
3583
|
+
}
|
|
3584
|
+
return Promise.resolve(true);
|
|
3585
|
+
}
|
|
3586
|
+
return build(
|
|
3587
|
+
script,
|
|
3588
|
+
[],
|
|
3589
|
+
realPath,
|
|
3590
|
+
displayPath,
|
|
3591
|
+
script,
|
|
3592
|
+
script,
|
|
3593
|
+
flags.verboseBuild,
|
|
3594
|
+
buildEnv,
|
|
3595
|
+
slice,
|
|
3596
|
+
feedback
|
|
3597
|
+
);
|
|
3598
|
+
}
|
|
3599
|
+
function scriptAppearsBuilt(filepath) {
|
|
3600
|
+
const toTest = path4.join(filepath, ".built");
|
|
3601
|
+
return fs4.existsSync(toTest);
|
|
3602
|
+
}
|
|
3603
|
+
function zipFileAppearsCurrent(zipfile, dependencies) {
|
|
3604
|
+
const ziptime = fs4.statSync(zipfile).mtimeMs;
|
|
3605
|
+
for (const dep of dependencies) {
|
|
3606
|
+
if (fs4.existsSync(dep)) {
|
|
3607
|
+
if (fs4.statSync(dep).mtimeMs > ziptime) {
|
|
3608
|
+
debug7("%s not considered current because %s is newer", zipfile, dep);
|
|
3609
|
+
return false;
|
|
3610
|
+
}
|
|
3611
|
+
} else {
|
|
3612
|
+
debug7("dependency %s doesn't exist", dep);
|
|
3613
|
+
return false;
|
|
3614
|
+
}
|
|
3615
|
+
}
|
|
3616
|
+
debug7("%s seems up to date so no re-zip", zipfile);
|
|
3617
|
+
return true;
|
|
3618
|
+
}
|
|
3619
|
+
function npmPackageAppearsBuilt(filepath) {
|
|
3620
|
+
const packageJson = path4.join(filepath, "package.json");
|
|
3621
|
+
const packageLockJson = path4.join(filepath, "package-lock.json");
|
|
3622
|
+
const yarnLock = path4.join(filepath, "yarn.lock");
|
|
3623
|
+
const nodeModules = path4.join(filepath, "node_modules");
|
|
3624
|
+
const packageJsonTime = fs4.statSync(packageJson).mtimeMs;
|
|
3625
|
+
const packageLockJsonTime = fs4.existsSync(packageLockJson) ? fs4.statSync(packageLockJson).mtimeMs : 0;
|
|
3626
|
+
const nodeModulesTime = fs4.existsSync(nodeModules) ? fs4.statSync(nodeModules).mtimeMs : 0;
|
|
3627
|
+
const yarnLockTime = fs4.existsSync(yarnLock) ? fs4.statSync(yarnLock).mtimeMs : 0;
|
|
3628
|
+
const lockTime = yarnLockTime > packageLockJsonTime ? yarnLockTime : packageLockJsonTime;
|
|
3629
|
+
return lockTime >= packageJsonTime && nodeModulesTime >= packageJsonTime;
|
|
3630
|
+
}
|
|
3631
|
+
function makeNpmPackageAppearBuilt(filepath) {
|
|
3632
|
+
const packageLockJson = path4.join(filepath, "package-lock.json");
|
|
3633
|
+
if (fs4.existsSync(packageLockJson))
|
|
3634
|
+
(0, import_touch.default)(packageLockJson);
|
|
3635
|
+
const yarnLock = path4.join(filepath, "yarn.lock");
|
|
3636
|
+
if (fs4.existsSync(yarnLock))
|
|
3637
|
+
(0, import_touch.default)(yarnLock);
|
|
3638
|
+
const nodeModules = path4.join(filepath, "node_modules");
|
|
3639
|
+
if (fs4.existsSync(nodeModules))
|
|
3640
|
+
(0, import_touch.default)(nodeModules);
|
|
3641
|
+
}
|
|
3642
|
+
function npmBuilder(filepath, displayPath, flags, buildEnv, slice, feedback) {
|
|
3643
|
+
debug7("Performing npm build for %s", filepath);
|
|
3644
|
+
const cmd = flags.yarn ? "yarn" : "npm";
|
|
3645
|
+
const npmRunBuild = buildScriptExists(filepath);
|
|
3646
|
+
const args = npmRunBuild ? ["install", "&&", cmd, "run", "build"] : ["install", "--production"];
|
|
3647
|
+
const infoMsg = [cmd, ...args].join(" ");
|
|
3648
|
+
if (flags.incremental) {
|
|
3649
|
+
debug7("Detected incremental build");
|
|
3650
|
+
const pkgBuilt = npmPackageAppearsBuilt(filepath);
|
|
3651
|
+
const scriptBuilt = scriptAppearsBuilt(filepath);
|
|
3652
|
+
const shouldSkip = npmRunBuild ? pkgBuilt && scriptBuilt : pkgBuilt;
|
|
3653
|
+
debug7(
|
|
3654
|
+
`npmRunBuild=${!!npmRunBuild}, npmPackageAppearsBuilt=${pkgBuilt}, scriptAppearsBuilt=${scriptBuilt}, shouldSkip=${shouldSkip}`
|
|
3655
|
+
);
|
|
3656
|
+
if (shouldSkip) {
|
|
3657
|
+
if (flags.verboseBuild) {
|
|
3658
|
+
feedback.progress(
|
|
3659
|
+
`Skipping '${infoMsg}' in ${filepath} because the previous build is still valid`
|
|
3660
|
+
);
|
|
3661
|
+
}
|
|
3662
|
+
return Promise.resolve(true);
|
|
3663
|
+
}
|
|
3664
|
+
} else {
|
|
3665
|
+
debug7("Build was not incremental");
|
|
3666
|
+
}
|
|
3667
|
+
return build(
|
|
3668
|
+
cmd,
|
|
3669
|
+
args,
|
|
3670
|
+
filepath,
|
|
3671
|
+
displayPath,
|
|
3672
|
+
infoMsg,
|
|
3673
|
+
`${cmd} install`,
|
|
3674
|
+
flags.verboseBuild,
|
|
3675
|
+
buildEnv,
|
|
3676
|
+
slice,
|
|
3677
|
+
feedback
|
|
3678
|
+
).then(() => makeNpmPackageAppearBuilt(filepath));
|
|
3679
|
+
}
|
|
3680
|
+
function buildScriptExists(filepath) {
|
|
3681
|
+
const contents = fs4.readFileSync(path4.join(filepath, "package.json"));
|
|
3682
|
+
try {
|
|
3683
|
+
const pj = JSON.parse(String(contents));
|
|
3684
|
+
return pj.scripts && pj.scripts.build;
|
|
3685
|
+
} catch {
|
|
3686
|
+
return false;
|
|
3687
|
+
}
|
|
3688
|
+
}
|
|
3689
|
+
function getIgnores(dir, reader) {
|
|
3690
|
+
const filePath = path4.join(dir, ".ignore");
|
|
3691
|
+
const fixedItems = [
|
|
3692
|
+
".ignore",
|
|
3693
|
+
"build.sh",
|
|
3694
|
+
"build.cmd",
|
|
3695
|
+
ZIP_TARGET,
|
|
3696
|
+
...getExclusionList()
|
|
3697
|
+
];
|
|
3698
|
+
return readFileAsList(filePath, reader).then((items) => {
|
|
3699
|
+
return (0, import_ignore.default)().add(items.concat(fixedItems));
|
|
3700
|
+
}).catch(() => {
|
|
3701
|
+
return (0, import_ignore.default)().add(fixedItems);
|
|
3702
|
+
});
|
|
3703
|
+
}
|
|
3704
|
+
|
|
3705
|
+
// src/project-reader.ts
|
|
3706
|
+
var import_debug9 = __toESM(require("debug"));
|
|
3707
|
+
|
|
3708
|
+
// src/file-reader.ts
|
|
3709
|
+
var fs5 = __toESM(require("fs"));
|
|
3710
|
+
var Path = __toESM(require("path"));
|
|
3711
|
+
var import_util4 = require("util");
|
|
3712
|
+
var import_debug8 = __toESM(require("debug"));
|
|
3713
|
+
var debug8 = (0, import_debug8.default)("nim:deployer:file-reader");
|
|
3714
|
+
var fs_readdir;
|
|
3715
|
+
var fs_readfile;
|
|
3716
|
+
var fs_lstat;
|
|
3717
|
+
var fs_realpath;
|
|
3718
|
+
var fs_readlink;
|
|
3719
|
+
function makeFileReader(basepath) {
|
|
3720
|
+
debug8("making file reader on basepath '%s'", basepath);
|
|
3721
|
+
fs_readdir = (0, import_util4.promisify)(fs5.readdir);
|
|
3722
|
+
fs_readfile = (0, import_util4.promisify)(fs5.readFile);
|
|
3723
|
+
fs_lstat = (0, import_util4.promisify)(fs5.lstat);
|
|
3724
|
+
fs_realpath = (0, import_util4.promisify)(fs5.realpath);
|
|
3725
|
+
fs_readlink = (0, import_util4.promisify)(fs5.readlink);
|
|
3726
|
+
return new FileProjectReader(basepath);
|
|
3727
|
+
}
|
|
3728
|
+
var FileProjectReader = class {
|
|
3729
|
+
constructor(basepath) {
|
|
3730
|
+
this.basepath = basepath;
|
|
3731
|
+
}
|
|
3732
|
+
getFSLocation() {
|
|
3733
|
+
return this.basepath;
|
|
3734
|
+
}
|
|
3735
|
+
async readdir(path7) {
|
|
3736
|
+
debug8("request to read directory '%s'", path7);
|
|
3737
|
+
path7 = Path.resolve(this.basepath, path7);
|
|
3738
|
+
path7 = await fs_realpath(path7);
|
|
3739
|
+
debug8("resolved to directory '%s", path7);
|
|
3740
|
+
const entries = await fs_readdir(path7, { withFileTypes: true });
|
|
3741
|
+
const results = entries.map(async (entry) => {
|
|
3742
|
+
let isFile, isDirectory, symlink;
|
|
3743
|
+
if (entry.isSymbolicLink()) {
|
|
3744
|
+
try {
|
|
3745
|
+
const fullName = await fs_realpath(Path.resolve(path7, entry.name));
|
|
3746
|
+
const stat = await fs_lstat(fullName);
|
|
3747
|
+
isFile = stat.isFile();
|
|
3748
|
+
isDirectory = stat.isDirectory();
|
|
3749
|
+
} catch (_) {
|
|
3750
|
+
symlink = await fs_readlink(Path.resolve(path7, entry.name));
|
|
3751
|
+
}
|
|
3752
|
+
} else {
|
|
3753
|
+
isFile = entry.isFile();
|
|
3754
|
+
isDirectory = entry.isDirectory();
|
|
3755
|
+
}
|
|
3756
|
+
return { name: entry.name, isDirectory, isFile, symlink, mode: 438 };
|
|
3757
|
+
});
|
|
3758
|
+
return Promise.all(results);
|
|
3759
|
+
}
|
|
3760
|
+
async readFileContents(path7) {
|
|
3761
|
+
debug8("request to read %s", path7);
|
|
3762
|
+
path7 = Path.resolve(this.basepath, path7);
|
|
3763
|
+
path7 = await fs_realpath(path7);
|
|
3764
|
+
return fs_readfile(path7);
|
|
3765
|
+
}
|
|
3766
|
+
isExistingFile(path7) {
|
|
3767
|
+
debug8("testing existence for file '%s'", path7);
|
|
3768
|
+
path7 = Path.resolve(this.basepath, path7);
|
|
3769
|
+
debug8("resolved to file '%s", path7);
|
|
3770
|
+
return fs_lstat(path7).then((stats) => {
|
|
3771
|
+
if (stats.isFile()) {
|
|
3772
|
+
debug8("file exists");
|
|
3773
|
+
return true;
|
|
3774
|
+
}
|
|
3775
|
+
debug8("path exists but is not a file");
|
|
3776
|
+
return false;
|
|
3777
|
+
}).catch(() => {
|
|
3778
|
+
debug8("lstat failed for path %s", path7);
|
|
3779
|
+
return false;
|
|
3780
|
+
});
|
|
3781
|
+
}
|
|
3782
|
+
async getPathKind(path7) {
|
|
3783
|
+
path7 = Path.resolve(this.basepath, path7);
|
|
3784
|
+
const stats = await fs_lstat(path7).catch(() => void 0);
|
|
3785
|
+
if (!stats) {
|
|
3786
|
+
return void 0;
|
|
3787
|
+
}
|
|
3788
|
+
let symlink;
|
|
3789
|
+
if (stats.isSymbolicLink()) {
|
|
3790
|
+
symlink = await fs_readlink(path7);
|
|
3791
|
+
}
|
|
3792
|
+
return {
|
|
3793
|
+
name: Path.basename(path7),
|
|
3794
|
+
isFile: stats.isFile(),
|
|
3795
|
+
isDirectory: stats.isDirectory(),
|
|
3796
|
+
symlink,
|
|
3797
|
+
mode: stats.mode
|
|
3798
|
+
};
|
|
3799
|
+
}
|
|
3800
|
+
};
|
|
3801
|
+
|
|
3802
|
+
// src/project-reader.ts
|
|
3803
|
+
var debug9 = (0, import_debug9.default)("nim:deployer:project-reader");
|
|
3804
|
+
var CONFIG_FILE = "project.yml";
|
|
3805
|
+
var LEGACY_CONFIG_FILE = "projectConfig.yml";
|
|
3806
|
+
var ENV_FILE = ".env";
|
|
3807
|
+
async function readTopLevel(filePath, env, buildEnv, includer, feedback, noTriggers) {
|
|
3808
|
+
debug9("readTopLevel with filePath:'%s'", filePath);
|
|
3809
|
+
debug9("feedback is %O", feedback);
|
|
3810
|
+
if (env && !fs6.existsSync(env)) {
|
|
3811
|
+
throw new Error(`The specified environment file '${env}' does not exist`);
|
|
3812
|
+
}
|
|
3813
|
+
if (buildEnv && !fs6.existsSync(buildEnv)) {
|
|
3814
|
+
throw new Error(
|
|
3815
|
+
`The specified environment file '${buildEnv}' does not exist`
|
|
3816
|
+
);
|
|
3817
|
+
}
|
|
3818
|
+
if (filePath.startsWith("slice:")) {
|
|
3819
|
+
debug9("fetching slice");
|
|
3820
|
+
filePath = await fetchSlice(filePath.replace("slice:", ""));
|
|
3821
|
+
if (!filePath) {
|
|
3822
|
+
throw new Error("Could not fetch slice");
|
|
3823
|
+
}
|
|
3824
|
+
}
|
|
3825
|
+
const reader = makeFileReader(filePath);
|
|
3826
|
+
const pkgDir = "packages";
|
|
3827
|
+
const libDir = "lib";
|
|
3828
|
+
return reader.readdir("").then((items) => {
|
|
3829
|
+
items = filterFiles(items);
|
|
3830
|
+
let config;
|
|
3831
|
+
let notconfig;
|
|
3832
|
+
let legacyConfig;
|
|
3833
|
+
let packages;
|
|
3834
|
+
const strays = [];
|
|
3835
|
+
let lib;
|
|
3836
|
+
for (const item of items) {
|
|
3837
|
+
if (item.isDirectory) {
|
|
3838
|
+
switch (item.name) {
|
|
3839
|
+
case pkgDir:
|
|
3840
|
+
packages = pkgDir;
|
|
3841
|
+
break;
|
|
3842
|
+
case libDir:
|
|
3843
|
+
lib = libDir;
|
|
3844
|
+
break;
|
|
3845
|
+
case ".nimbella":
|
|
3846
|
+
case ".deployed":
|
|
3847
|
+
break;
|
|
3848
|
+
default:
|
|
3849
|
+
strays.push(item.name);
|
|
3850
|
+
}
|
|
3851
|
+
} else if (!item.isDirectory && item.name === CONFIG_FILE) {
|
|
3852
|
+
config = item.name;
|
|
3853
|
+
} else if (!item.isDirectory && item.name === LEGACY_CONFIG_FILE) {
|
|
3854
|
+
legacyConfig = item.name;
|
|
3855
|
+
} else if (!item.isDirectory && (item.name.endsWith(".yml") || item.name.endsWith(".yaml"))) {
|
|
3856
|
+
notconfig = item.name;
|
|
3857
|
+
} else if (!env && !item.isDirectory && item.name === ENV_FILE) {
|
|
3858
|
+
env = path5.join(filePath, item.name);
|
|
3859
|
+
} else {
|
|
3860
|
+
strays.push(item.name);
|
|
3861
|
+
}
|
|
3862
|
+
}
|
|
3863
|
+
if (legacyConfig && !config) {
|
|
3864
|
+
config = legacyConfig;
|
|
3865
|
+
feedback.warn(
|
|
3866
|
+
`Warning: the name '${LEGACY_CONFIG_FILE}' is deprecated; please rename to '${CONFIG_FILE}' soon`
|
|
3867
|
+
);
|
|
3868
|
+
}
|
|
3869
|
+
if (notconfig && !config) {
|
|
3870
|
+
feedback.warn("Warning: found %s but no %s", notconfig, CONFIG_FILE);
|
|
3871
|
+
}
|
|
3872
|
+
const ans = {
|
|
3873
|
+
lib,
|
|
3874
|
+
packages,
|
|
3875
|
+
config,
|
|
3876
|
+
strays,
|
|
3877
|
+
filePath,
|
|
3878
|
+
env,
|
|
3879
|
+
buildEnv,
|
|
3880
|
+
includer,
|
|
3881
|
+
reader,
|
|
3882
|
+
feedback,
|
|
3883
|
+
noTriggers
|
|
3884
|
+
};
|
|
3885
|
+
debug9("readTopLevel returning %O", ans);
|
|
3886
|
+
return ans;
|
|
3887
|
+
});
|
|
3888
|
+
}
|
|
3889
|
+
async function buildStructureParts(topLevel) {
|
|
3890
|
+
const {
|
|
3891
|
+
lib,
|
|
3892
|
+
packages,
|
|
3893
|
+
config,
|
|
3894
|
+
strays,
|
|
3895
|
+
filePath,
|
|
3896
|
+
env,
|
|
3897
|
+
buildEnv,
|
|
3898
|
+
includer,
|
|
3899
|
+
reader,
|
|
3900
|
+
feedback,
|
|
3901
|
+
noTriggers
|
|
3902
|
+
} = topLevel;
|
|
3903
|
+
let configPart = await readConfig(
|
|
3904
|
+
config,
|
|
3905
|
+
env,
|
|
3906
|
+
buildEnv,
|
|
3907
|
+
filePath,
|
|
3908
|
+
includer,
|
|
3909
|
+
reader,
|
|
3910
|
+
feedback,
|
|
3911
|
+
noTriggers
|
|
3912
|
+
);
|
|
3913
|
+
const deployerAnnotation = configPart.deployerAnnotation || await getDeployerAnnotation(filePath);
|
|
3914
|
+
configPart = Object.assign(configPart, {
|
|
3915
|
+
strays,
|
|
3916
|
+
filePath,
|
|
3917
|
+
includer,
|
|
3918
|
+
reader,
|
|
3919
|
+
feedback,
|
|
3920
|
+
deployerAnnotation
|
|
3921
|
+
});
|
|
3922
|
+
const displayName = getBestProjectName(configPart);
|
|
3923
|
+
debug9("display path for actions is %O", displayName);
|
|
3924
|
+
const actionsPart = await buildActionsPart(
|
|
3925
|
+
packages,
|
|
3926
|
+
displayName,
|
|
3927
|
+
includer,
|
|
3928
|
+
reader
|
|
3929
|
+
);
|
|
3930
|
+
configPart.libBuild = await getBuildForLibOrWeb(lib, reader, true);
|
|
3931
|
+
return [actionsPart, configPart];
|
|
3932
|
+
}
|
|
3933
|
+
function assembleInitialStructure(parts) {
|
|
3934
|
+
debug9("Assembling structure from parts");
|
|
3935
|
+
const [actionsPart, configPart] = parts;
|
|
3936
|
+
const errPart = parts.find((part) => part.error);
|
|
3937
|
+
if (errPart) {
|
|
3938
|
+
return errPart;
|
|
3939
|
+
}
|
|
3940
|
+
const strays = (actionsPart.strays || []).concat(configPart.strays || []);
|
|
3941
|
+
configPart.strays = strays;
|
|
3942
|
+
configPart.packages = actionsPart.packages && configPart.packages ? mergePackages(actionsPart.packages, configPart.packages) : actionsPart.packages ? actionsPart.packages : configPart.packages ? configPart.packages : [];
|
|
3943
|
+
adjustWebExportFlags(configPart.packages);
|
|
3944
|
+
debug9("Result of assembly: %O", configPart);
|
|
3945
|
+
return configPart;
|
|
3946
|
+
}
|
|
3947
|
+
function mergePackages(fs8, config) {
|
|
3948
|
+
const merge = {};
|
|
3949
|
+
fs8.forEach((pkg) => {
|
|
3950
|
+
merge[pkg.name] = pkg;
|
|
3951
|
+
});
|
|
3952
|
+
config.forEach((pkg) => {
|
|
3953
|
+
const already = merge[pkg.name];
|
|
3954
|
+
if (already) {
|
|
3955
|
+
merge[pkg.name] = mergePackage(already, pkg);
|
|
3956
|
+
} else {
|
|
3957
|
+
(pkg.actions || []).forEach((action) => {
|
|
3958
|
+
action.package = pkg.name;
|
|
3959
|
+
});
|
|
3960
|
+
merge[pkg.name] = pkg;
|
|
3961
|
+
}
|
|
3962
|
+
});
|
|
3963
|
+
const ans = [];
|
|
3964
|
+
for (const name in merge) {
|
|
3965
|
+
ans.push(merge[name]);
|
|
3966
|
+
}
|
|
3967
|
+
return ans;
|
|
3968
|
+
}
|
|
3969
|
+
function mergePackage(fs8, config) {
|
|
3970
|
+
const fsActions = fs8.actions;
|
|
3971
|
+
const cfgActions = config.actions;
|
|
3972
|
+
const ans = Object.assign({}, fs8, config);
|
|
3973
|
+
if (fsActions && fsActions.length > 0) {
|
|
3974
|
+
if (cfgActions && cfgActions.length > 0) {
|
|
3975
|
+
ans.actions = mergeActions(fsActions, cfgActions, config.name);
|
|
3976
|
+
} else {
|
|
3977
|
+
ans.actions = fsActions;
|
|
3978
|
+
}
|
|
3979
|
+
} else {
|
|
3980
|
+
ans.actions = cfgActions;
|
|
3981
|
+
}
|
|
3982
|
+
return ans;
|
|
3983
|
+
}
|
|
3984
|
+
function adjustWebExportFlags(pkgs) {
|
|
3985
|
+
pkgs.forEach((pkg) => {
|
|
3986
|
+
if (pkg.actions) {
|
|
3987
|
+
pkg.actions.forEach((action) => {
|
|
3988
|
+
if (typeof action.web === "undefined") {
|
|
3989
|
+
action.web = typeof pkg.web === "undefined" ? true : pkg.web;
|
|
3990
|
+
}
|
|
3991
|
+
});
|
|
3992
|
+
}
|
|
3993
|
+
});
|
|
3994
|
+
}
|
|
3995
|
+
function mergeActions(fs8, config, pkgName) {
|
|
3996
|
+
const merge = {};
|
|
3997
|
+
fs8.forEach((action) => {
|
|
3998
|
+
merge[action.name] = action;
|
|
3999
|
+
});
|
|
4000
|
+
config.forEach((action) => {
|
|
4001
|
+
const already = merge[action.name];
|
|
4002
|
+
if (already) {
|
|
4003
|
+
merge[action.name] = mergeAction(already, action);
|
|
4004
|
+
} else {
|
|
4005
|
+
action.package = pkgName;
|
|
4006
|
+
merge[action.name] = action;
|
|
4007
|
+
}
|
|
4008
|
+
});
|
|
4009
|
+
const ans = [];
|
|
4010
|
+
for (const name in merge) {
|
|
4011
|
+
ans.push(merge[name]);
|
|
4012
|
+
}
|
|
4013
|
+
return ans;
|
|
4014
|
+
}
|
|
4015
|
+
function mergeAction(fs8, config) {
|
|
4016
|
+
debug9("Action from filesystem: %O", fs8);
|
|
4017
|
+
debug9("Action from config: %O", config);
|
|
4018
|
+
const result = Object.assign({}, fs8, config);
|
|
4019
|
+
debug9("Result of merge: %O", result);
|
|
4020
|
+
return result;
|
|
4021
|
+
}
|
|
4022
|
+
function buildActionsPart(pkgsdir, displayPath, includer, reader) {
|
|
4023
|
+
if (!pkgsdir) {
|
|
4024
|
+
return Promise.resolve(emptyStructure());
|
|
4025
|
+
} else {
|
|
4026
|
+
return buildPkgArray(
|
|
4027
|
+
pkgsdir,
|
|
4028
|
+
displayPath + "/packages",
|
|
4029
|
+
includer,
|
|
4030
|
+
reader
|
|
4031
|
+
).then((values) => {
|
|
4032
|
+
const [strays, pkgs] = values;
|
|
4033
|
+
return { web: [], packages: pkgs, strays };
|
|
4034
|
+
});
|
|
4035
|
+
}
|
|
4036
|
+
}
|
|
4037
|
+
function buildPkgArray(pkgsDir, displayPath, includer, reader) {
|
|
4038
|
+
debug9("Building package array");
|
|
4039
|
+
return reader.readdir(pkgsDir).then((items) => {
|
|
4040
|
+
items = filterFiles(items);
|
|
4041
|
+
const strays = items.filter((dirent) => !dirent.isDirectory).map((dirent) => dirent.name);
|
|
4042
|
+
const pkgNames = items.filter((dirent) => dirent.isDirectory).map((dirent) => dirent.name);
|
|
4043
|
+
const rdrs = [];
|
|
4044
|
+
for (const name of pkgNames) {
|
|
4045
|
+
if (includer.isPackageIncluded(name, false)) {
|
|
4046
|
+
const pkgPath = path5.join(pkgsDir, name);
|
|
4047
|
+
rdrs.push(
|
|
4048
|
+
readPackage(
|
|
4049
|
+
pkgPath,
|
|
4050
|
+
path5.join(displayPath, name),
|
|
4051
|
+
name,
|
|
4052
|
+
includer,
|
|
4053
|
+
reader
|
|
4054
|
+
)
|
|
4055
|
+
);
|
|
4056
|
+
}
|
|
4057
|
+
}
|
|
4058
|
+
return Promise.all([Promise.resolve(strays), Promise.all(rdrs)]);
|
|
4059
|
+
});
|
|
4060
|
+
}
|
|
4061
|
+
async function readPackage(pkgPath, displayPath, pkgName, includer, reader) {
|
|
4062
|
+
debug9(
|
|
4063
|
+
"reading information for package '%s' with display path '%s'",
|
|
4064
|
+
pkgPath,
|
|
4065
|
+
displayPath
|
|
4066
|
+
);
|
|
4067
|
+
return reader.readdir(pkgPath).then(async (items) => {
|
|
4068
|
+
items = filterFiles(items);
|
|
4069
|
+
const promises = [];
|
|
4070
|
+
const seen = /* @__PURE__ */ new Map();
|
|
4071
|
+
for (const item of items) {
|
|
4072
|
+
const file = path5.join(pkgPath, item.name);
|
|
4073
|
+
const displayFile = path5.join(displayPath, item.name);
|
|
4074
|
+
debug9("item %s has display path %s", item.name, displayFile);
|
|
4075
|
+
if (!item.isDirectory) {
|
|
4076
|
+
const { name, runtime, binary, zipped } = await actionFileToParts(
|
|
4077
|
+
item.name
|
|
4078
|
+
);
|
|
4079
|
+
if (!includer.isActionIncluded(pkgName, name))
|
|
4080
|
+
continue;
|
|
4081
|
+
const before = seen.get(name);
|
|
4082
|
+
if (before) {
|
|
4083
|
+
throw duplicateName(name, before, runtime);
|
|
4084
|
+
}
|
|
4085
|
+
seen.set(name, runtime);
|
|
4086
|
+
promises.push(
|
|
4087
|
+
Promise.resolve({
|
|
4088
|
+
name,
|
|
4089
|
+
file,
|
|
4090
|
+
displayFile,
|
|
4091
|
+
runtime,
|
|
4092
|
+
binary,
|
|
4093
|
+
zipped,
|
|
4094
|
+
package: pkgName
|
|
4095
|
+
})
|
|
4096
|
+
);
|
|
4097
|
+
} else if (item.isDirectory) {
|
|
4098
|
+
if (!includer.isActionIncluded(pkgName, item.name))
|
|
4099
|
+
continue;
|
|
4100
|
+
const before = seen.get(item.name);
|
|
4101
|
+
if (before) {
|
|
4102
|
+
throw duplicateName(item.name, before, "*");
|
|
4103
|
+
}
|
|
4104
|
+
seen.set(item.name, "*");
|
|
4105
|
+
promises.push(
|
|
4106
|
+
getBuildForAction(file, reader).then((build2) => {
|
|
4107
|
+
return {
|
|
4108
|
+
name: item.name,
|
|
4109
|
+
file,
|
|
4110
|
+
displayFile,
|
|
4111
|
+
build: build2,
|
|
4112
|
+
package: pkgName
|
|
4113
|
+
};
|
|
4114
|
+
})
|
|
4115
|
+
);
|
|
4116
|
+
}
|
|
4117
|
+
}
|
|
4118
|
+
return Promise.all(promises);
|
|
4119
|
+
}).then((actions) => {
|
|
4120
|
+
return { name: pkgName, actions, shared: false };
|
|
4121
|
+
});
|
|
4122
|
+
}
|
|
4123
|
+
function duplicateName(actionName, formerUse, newUse) {
|
|
4124
|
+
const former = formerUse === "*" ? "as a directory" : `with runtime '${formerUse}'`;
|
|
4125
|
+
const present = newUse === "*" ? "as a directory" : `with runtime '${newUse}'`;
|
|
4126
|
+
return new Error(
|
|
4127
|
+
`The action name '${actionName}' appears twice, once ${former} and once ${present}`
|
|
4128
|
+
);
|
|
4129
|
+
}
|
|
4130
|
+
async function readConfig(configFile, envPath, buildEnvPath, filePath, includer, reader, feedback, noTriggers) {
|
|
4131
|
+
if (!configFile) {
|
|
4132
|
+
debug9("No config file found");
|
|
4133
|
+
const ans = Object.assign({}, emptyStructure());
|
|
4134
|
+
return Promise.resolve(ans);
|
|
4135
|
+
}
|
|
4136
|
+
debug9("Reading config file");
|
|
4137
|
+
const config = loadProjectConfig(
|
|
4138
|
+
configFile,
|
|
4139
|
+
envPath,
|
|
4140
|
+
buildEnvPath,
|
|
4141
|
+
filePath,
|
|
4142
|
+
reader,
|
|
4143
|
+
feedback,
|
|
4144
|
+
noTriggers
|
|
4145
|
+
).then((config2) => trimConfigWithIncluder(config2, includer)).catch((err) => errorStructure(err));
|
|
4146
|
+
debug9("Config contents: %O", config);
|
|
4147
|
+
return config;
|
|
4148
|
+
}
|
|
4149
|
+
function trimConfigWithIncluder(config, includer) {
|
|
4150
|
+
if (config.packages) {
|
|
4151
|
+
const newPkgs = [];
|
|
4152
|
+
for (const pkg of config.packages) {
|
|
4153
|
+
if (includer.isPackageIncluded(pkg.name, false)) {
|
|
4154
|
+
if (pkg.actions) {
|
|
4155
|
+
pkg.actions = pkg.actions.filter(
|
|
4156
|
+
(action) => includer.isActionIncluded(pkg.name, action.name)
|
|
4157
|
+
);
|
|
4158
|
+
}
|
|
4159
|
+
newPkgs.push(pkg);
|
|
4160
|
+
}
|
|
4161
|
+
}
|
|
4162
|
+
config.packages = newPkgs;
|
|
4163
|
+
}
|
|
4164
|
+
return config;
|
|
4165
|
+
}
|
|
4166
|
+
|
|
4167
|
+
// src/includer.ts
|
|
4168
|
+
var import_debug10 = __toESM(require("debug"));
|
|
4169
|
+
var debug10 = (0, import_debug10.default)("nim:deployer:includer");
|
|
4170
|
+
function makeIncluder(include, exclude) {
|
|
4171
|
+
const includes = include ? include.split(",") : void 0;
|
|
4172
|
+
const excludes = exclude ? exclude.split(",") : void 0;
|
|
4173
|
+
const ans = new IncluderImpl(includes, excludes);
|
|
4174
|
+
debug10("constructed includer: %O", ans);
|
|
4175
|
+
return ans;
|
|
4176
|
+
}
|
|
4177
|
+
var IncluderImpl = class {
|
|
4178
|
+
constructor(includes, excludes) {
|
|
4179
|
+
this.isExcludingOnly = false;
|
|
4180
|
+
this.includedPackages = /* @__PURE__ */ new Set();
|
|
4181
|
+
this.excludedPackages = /* @__PURE__ */ new Set();
|
|
4182
|
+
this.includedActions = /* @__PURE__ */ new Map();
|
|
4183
|
+
this.excludedActions = /* @__PURE__ */ new Map();
|
|
4184
|
+
this.isPackageIncluded = (pkg, all) => {
|
|
4185
|
+
const nominallyIncluded = this.includedPackages.has(pkg) || this.isExcludingOnly && !this.excludedPackages.has(pkg);
|
|
4186
|
+
if (all) {
|
|
4187
|
+
return nominallyIncluded && !this.excludedActions.has(pkg);
|
|
4188
|
+
} else {
|
|
4189
|
+
return nominallyIncluded || this.includedActions.has(pkg);
|
|
4190
|
+
}
|
|
4191
|
+
};
|
|
4192
|
+
this.isActionIncluded = (pkg, action) => {
|
|
4193
|
+
if (this.isActionInMap(pkg, action, this.includedActions)) {
|
|
4194
|
+
return true;
|
|
4195
|
+
}
|
|
4196
|
+
if (this.excludedPackages.has(pkg) || this.isActionInMap(pkg, action, this.excludedActions)) {
|
|
4197
|
+
return false;
|
|
4198
|
+
}
|
|
4199
|
+
return this.isExcludingOnly || this.includedPackages.has(pkg);
|
|
4200
|
+
};
|
|
4201
|
+
this.isIncludingEverything = () => {
|
|
4202
|
+
return this.isExcludingOnly && this.includedActions.size === 0 && this.includedPackages.size === 0;
|
|
4203
|
+
};
|
|
4204
|
+
if (!includes) {
|
|
4205
|
+
this.isExcludingOnly = true;
|
|
4206
|
+
} else {
|
|
4207
|
+
for (let token of includes) {
|
|
4208
|
+
if (token.endsWith("/")) {
|
|
4209
|
+
token = token.slice(0, -1);
|
|
4210
|
+
}
|
|
4211
|
+
const [pkg, action] = token.split("/");
|
|
4212
|
+
if (action) {
|
|
4213
|
+
this.addToMap(pkg, action, this.includedActions);
|
|
4214
|
+
} else {
|
|
4215
|
+
this.includedPackages.add(pkg);
|
|
4216
|
+
}
|
|
4217
|
+
}
|
|
4218
|
+
}
|
|
4219
|
+
if (excludes) {
|
|
4220
|
+
for (let token of excludes) {
|
|
4221
|
+
if (token.endsWith("/")) {
|
|
4222
|
+
token = token.slice(0, -1);
|
|
4223
|
+
}
|
|
4224
|
+
const [pkg, action] = token.split("/");
|
|
4225
|
+
if (action) {
|
|
4226
|
+
this.addToMap(pkg, action, this.excludedActions);
|
|
4227
|
+
} else {
|
|
4228
|
+
this.excludedPackages.add(pkg);
|
|
4229
|
+
}
|
|
4230
|
+
}
|
|
4231
|
+
}
|
|
4232
|
+
}
|
|
4233
|
+
addToMap(pkg, action, map) {
|
|
4234
|
+
let set = map.get(pkg);
|
|
4235
|
+
if (!set) {
|
|
4236
|
+
set = /* @__PURE__ */ new Set();
|
|
4237
|
+
map.set(pkg, set);
|
|
4238
|
+
}
|
|
4239
|
+
set.add(action);
|
|
4240
|
+
}
|
|
4241
|
+
isActionInMap(pkg, action, map) {
|
|
4242
|
+
const set = map.get(pkg);
|
|
4243
|
+
if (!set) {
|
|
4244
|
+
return false;
|
|
4245
|
+
}
|
|
4246
|
+
return set.has(action);
|
|
4247
|
+
}
|
|
4248
|
+
};
|
|
4249
|
+
|
|
4250
|
+
// src/api.ts
|
|
4251
|
+
var import_debug11 = __toESM(require("debug"));
|
|
4252
|
+
var openwhisk2 = require("openwhisk");
|
|
4253
|
+
var debug11 = (0, import_debug11.default)("nim:deployer:api");
|
|
4254
|
+
function initializeAPI(userAgent) {
|
|
4255
|
+
const result = {};
|
|
4256
|
+
for (const item in process.env) {
|
|
4257
|
+
if (item.startsWith("__OW_")) {
|
|
4258
|
+
result[item] = process.env[item];
|
|
4259
|
+
delete process.env[item];
|
|
4260
|
+
}
|
|
4261
|
+
}
|
|
4262
|
+
process.env.__OW_USER_AGENT = userAgent;
|
|
4263
|
+
if (result.__OW_NAMESPACE) {
|
|
4264
|
+
process.env.savedOW_NAMESPACE = result.__OW_NAMESPACE;
|
|
4265
|
+
}
|
|
4266
|
+
if (result.__OW_API_HOST) {
|
|
4267
|
+
process.env.savedOW_API_HOST = result.__OW_API_HOST;
|
|
4268
|
+
}
|
|
4269
|
+
if (result.__OW_API_KEY) {
|
|
4270
|
+
process.env.savedOW_API_KEY = result.__OW_API_KEY;
|
|
4271
|
+
}
|
|
4272
|
+
return result;
|
|
4273
|
+
}
|
|
4274
|
+
function getUserAgent() {
|
|
4275
|
+
const ans = process.env.__OW_USER_AGENT;
|
|
4276
|
+
return ans || "nimbella-cli";
|
|
4277
|
+
}
|
|
4278
|
+
async function deployProject(path7, credentials, flags) {
|
|
4279
|
+
debug11("deployProject invoked with incremental %s", flags.incremental);
|
|
4280
|
+
return readPrepareAndBuild(path7, credentials, flags).then((spec) => {
|
|
4281
|
+
if (spec.error) {
|
|
4282
|
+
debug11("An error was caught prior to %O:", spec.error);
|
|
4283
|
+
return Promise.resolve(wrapError(spec.error, void 0));
|
|
4284
|
+
}
|
|
4285
|
+
return deploy(spec);
|
|
4286
|
+
});
|
|
4287
|
+
}
|
|
4288
|
+
function readPrepareAndBuild(path7, credentials, flags, feedback) {
|
|
4289
|
+
return readAndPrepare(path7, credentials, flags, feedback).then(
|
|
4290
|
+
(spec) => spec.error ? spec : buildProject(spec)
|
|
4291
|
+
);
|
|
4292
|
+
}
|
|
4293
|
+
function readAndPrepare(path7, credentials, flags, feedback) {
|
|
4294
|
+
const includer = makeIncluder(flags.include, flags.exclude);
|
|
4295
|
+
return readProject(
|
|
4296
|
+
path7,
|
|
4297
|
+
flags.env,
|
|
4298
|
+
flags.buildEnv,
|
|
4299
|
+
includer,
|
|
4300
|
+
flags.remoteBuild,
|
|
4301
|
+
feedback,
|
|
4302
|
+
flags.noTriggers
|
|
4303
|
+
).then(
|
|
4304
|
+
(spec) => spec.error ? spec : prepareToDeploy(spec, credentials, flags)
|
|
4305
|
+
);
|
|
4306
|
+
}
|
|
4307
|
+
function deploy(todeploy) {
|
|
4308
|
+
debug11("Starting deploy");
|
|
4309
|
+
return cleanOrLoadVersions(todeploy).then(doDeploy).then((results) => {
|
|
4310
|
+
const statusDir = writeProjectStatus(
|
|
4311
|
+
todeploy.filePath,
|
|
4312
|
+
results,
|
|
4313
|
+
todeploy.includer.isIncludingEverything()
|
|
4314
|
+
);
|
|
4315
|
+
if (statusDir && !todeploy.slice) {
|
|
4316
|
+
todeploy.feedback.progress(
|
|
4317
|
+
`Deployment status recorded in '${statusDir}'`
|
|
4318
|
+
);
|
|
4319
|
+
}
|
|
4320
|
+
if (!results.namespace && todeploy.credentials) {
|
|
4321
|
+
results.namespace = todeploy.credentials.namespace;
|
|
4322
|
+
}
|
|
4323
|
+
debug11("deploy results are: %O", results);
|
|
4324
|
+
return results;
|
|
4325
|
+
});
|
|
4326
|
+
}
|
|
4327
|
+
async function readProject(projectPath, envPath, buildEnvPath, includer, requestRemote, feedback = new DefaultFeedback(), noTriggers = false) {
|
|
4328
|
+
debug11(
|
|
4329
|
+
"Starting readProject, projectPath=%s, envPath=%s",
|
|
4330
|
+
projectPath,
|
|
4331
|
+
envPath
|
|
4332
|
+
);
|
|
4333
|
+
let ans;
|
|
4334
|
+
try {
|
|
4335
|
+
const topLevel = await readTopLevel(
|
|
4336
|
+
projectPath,
|
|
4337
|
+
envPath,
|
|
4338
|
+
buildEnvPath,
|
|
4339
|
+
includer,
|
|
4340
|
+
feedback,
|
|
4341
|
+
noTriggers
|
|
4342
|
+
);
|
|
4343
|
+
const parts = await buildStructureParts(topLevel);
|
|
4344
|
+
ans = assembleInitialStructure(parts);
|
|
4345
|
+
} catch (err) {
|
|
4346
|
+
return errorStructure(err);
|
|
4347
|
+
}
|
|
4348
|
+
if (ans.error) {
|
|
4349
|
+
return ans;
|
|
4350
|
+
}
|
|
4351
|
+
debug11("evaluating the just-read project: %O", ans);
|
|
4352
|
+
let needsLocalBuilds;
|
|
4353
|
+
try {
|
|
4354
|
+
needsLocalBuilds = await checkBuildingRequirements(ans, requestRemote);
|
|
4355
|
+
debug11("needsLocalBuilds=%s", needsLocalBuilds);
|
|
4356
|
+
} catch (err) {
|
|
4357
|
+
return errorStructure(err);
|
|
4358
|
+
}
|
|
4359
|
+
if (needsLocalBuilds && ans.reader.getFSLocation() === null) {
|
|
4360
|
+
debug11(
|
|
4361
|
+
"project '%s' will be re-read and cached because it is covered by a non-file-system reader and needs local building",
|
|
4362
|
+
projectPath
|
|
4363
|
+
);
|
|
4364
|
+
try {
|
|
4365
|
+
const topLevel = await readTopLevel(
|
|
4366
|
+
projectPath,
|
|
4367
|
+
envPath,
|
|
4368
|
+
buildEnvPath,
|
|
4369
|
+
includer,
|
|
4370
|
+
feedback,
|
|
4371
|
+
noTriggers
|
|
4372
|
+
);
|
|
4373
|
+
const parts = await buildStructureParts(topLevel);
|
|
4374
|
+
ans = assembleInitialStructure(parts);
|
|
4375
|
+
} catch (err) {
|
|
4376
|
+
return errorStructure(err);
|
|
4377
|
+
}
|
|
4378
|
+
}
|
|
4379
|
+
return ans;
|
|
4380
|
+
}
|
|
4381
|
+
async function buildProject(project) {
|
|
4382
|
+
debug11("Starting buildProject with spec %O", project);
|
|
4383
|
+
if (project.libBuild && isRealBuild(project.libBuild)) {
|
|
4384
|
+
try {
|
|
4385
|
+
await maybeBuildLib(project);
|
|
4386
|
+
} catch (err) {
|
|
4387
|
+
return errorStructure(err);
|
|
4388
|
+
}
|
|
4389
|
+
}
|
|
4390
|
+
const actionPromise = buildAllActions(project);
|
|
4391
|
+
if (actionPromise) {
|
|
4392
|
+
return actionPromise.then((packages) => {
|
|
4393
|
+
project.packages = packages;
|
|
4394
|
+
return project;
|
|
4395
|
+
}).catch((err) => errorStructure(err));
|
|
4396
|
+
} else {
|
|
4397
|
+
return Promise.resolve(project);
|
|
4398
|
+
}
|
|
4399
|
+
}
|
|
4400
|
+
async function prepareToDeploy(inputSpec, credentials, flags) {
|
|
4401
|
+
debug11("Starting prepare with spec: %O", inputSpec);
|
|
4402
|
+
if (inputSpec.slice) {
|
|
4403
|
+
debug11("Retrieving credentials and flags from spec for slice");
|
|
4404
|
+
credentials = inputSpec.credentials;
|
|
4405
|
+
if (process.env.__OW_API_HOST) {
|
|
4406
|
+
credentials.ow.apihost = process.env.__OW_API_HOST;
|
|
4407
|
+
} else if (process.env.savedOW_API_HOST) {
|
|
4408
|
+
credentials.ow.apihost = process.env.savedOW_API_HOST;
|
|
4409
|
+
}
|
|
4410
|
+
flags = inputSpec.flags;
|
|
4411
|
+
}
|
|
4412
|
+
const owOptions = {
|
|
4413
|
+
api_key: flags.auth,
|
|
4414
|
+
apihost: flags.apiHost,
|
|
4415
|
+
ignore_certs: flags.insecure
|
|
4416
|
+
};
|
|
4417
|
+
if (!credentials) {
|
|
4418
|
+
debug11("Finding credentials locally");
|
|
4419
|
+
let namespace;
|
|
4420
|
+
if (inputSpec.targetNamespace) {
|
|
4421
|
+
namespace = inputSpec.targetNamespace;
|
|
4422
|
+
}
|
|
4423
|
+
if (namespace) {
|
|
4424
|
+
debug11("Retrieving specific credentials for namespace %s", namespace);
|
|
4425
|
+
credentials = await getCredentialsForNamespace(
|
|
4426
|
+
namespace,
|
|
4427
|
+
owOptions.apihost
|
|
4428
|
+
);
|
|
4429
|
+
} else {
|
|
4430
|
+
let badCredentials;
|
|
4431
|
+
debug11("Attempting to get credentials for current namespace");
|
|
4432
|
+
credentials = await getCredentials().catch((err) => {
|
|
4433
|
+
badCredentials = err;
|
|
4434
|
+
return void 0;
|
|
4435
|
+
});
|
|
4436
|
+
if (badCredentials) {
|
|
4437
|
+
debug11(
|
|
4438
|
+
"Could not get credentials, returning error structure with %O",
|
|
4439
|
+
badCredentials
|
|
4440
|
+
);
|
|
4441
|
+
return errorStructure(badCredentials);
|
|
4442
|
+
}
|
|
4443
|
+
}
|
|
4444
|
+
}
|
|
4445
|
+
debug11("owOptions: %O", owOptions);
|
|
4446
|
+
debug11("credentials.ow: %O", credentials.ow);
|
|
4447
|
+
const wskoptions = {
|
|
4448
|
+
api_key: owOptions.api_key || credentials.ow.api_key,
|
|
4449
|
+
apihost: owOptions.apihost || credentials.ow.apihost,
|
|
4450
|
+
ignore_certs: owOptions.ignore_certs || credentials.ow.ignore_certs
|
|
4451
|
+
};
|
|
4452
|
+
debug11('wskoptions" %O', wskoptions);
|
|
4453
|
+
inputSpec.credentials = credentials;
|
|
4454
|
+
debug11("prepareToDeploy merging flags: %O", flags);
|
|
4455
|
+
inputSpec.flags = flags;
|
|
4456
|
+
debug11("Options merged");
|
|
4457
|
+
debug11("Auth sufficiency established");
|
|
4458
|
+
inputSpec.owClient = openwhisk2(wskoptions);
|
|
4459
|
+
if (!credentials.namespace) {
|
|
4460
|
+
credentials.namespace = await getTargetNamespace(inputSpec.owClient);
|
|
4461
|
+
} else {
|
|
4462
|
+
await isTargetNamespaceValid(inputSpec.owClient, credentials.namespace);
|
|
4463
|
+
}
|
|
4464
|
+
debug11("Target namespace validated");
|
|
4465
|
+
debug11("Sensitive project/namespace guard passed");
|
|
4466
|
+
debug11("returning spec %O", inputSpec);
|
|
4467
|
+
return Promise.resolve(inputSpec);
|
|
4468
|
+
}
|
|
4469
|
+
async function wipeNamespace(credentials) {
|
|
4470
|
+
debug11(
|
|
4471
|
+
"Requested wipe-namespace function with host %s and auth %s",
|
|
4472
|
+
credentials.ow.apihost,
|
|
4473
|
+
credentials.ow.api_key
|
|
4474
|
+
);
|
|
4475
|
+
const init = {
|
|
4476
|
+
apihost: credentials.ow.apihost,
|
|
4477
|
+
api_key: credentials.ow.api_key
|
|
4478
|
+
};
|
|
4479
|
+
const client = openwhisk2(init);
|
|
4480
|
+
debug11("Client opened");
|
|
4481
|
+
return wipe(client, credentials);
|
|
4482
|
+
}
|
|
4483
|
+
async function wipePackage(name, host, auth, credentials) {
|
|
4484
|
+
debug11(
|
|
4485
|
+
"wipePackage invoked with name='%s', host='%s', auth='%s",
|
|
4486
|
+
name,
|
|
4487
|
+
host,
|
|
4488
|
+
auth
|
|
4489
|
+
);
|
|
4490
|
+
const init = { apihost: host, api_key: auth };
|
|
4491
|
+
const client = openwhisk2(init);
|
|
4492
|
+
return cleanPackage(client, credentials, name, void 0);
|
|
4493
|
+
}
|
|
4494
|
+
|
|
4495
|
+
// src/watch.ts
|
|
4496
|
+
var fs7 = __toESM(require("fs"));
|
|
4497
|
+
var chokidar = __toESM(require("chokidar"));
|
|
4498
|
+
function watch2(project, cmdFlags, creds, logger) {
|
|
4499
|
+
logger.log(`Watching '${project}' [use Control-C to terminate]`);
|
|
4500
|
+
let watcher;
|
|
4501
|
+
const reset = async () => {
|
|
4502
|
+
if (watcher) {
|
|
4503
|
+
await watcher.close();
|
|
4504
|
+
}
|
|
4505
|
+
};
|
|
4506
|
+
const watch3 = () => {
|
|
4507
|
+
watcher = chokidar.watch(project, {
|
|
4508
|
+
ignoreInitial: true,
|
|
4509
|
+
followSymlinks: false,
|
|
4510
|
+
usePolling: false,
|
|
4511
|
+
useFsEvents: false
|
|
4512
|
+
});
|
|
4513
|
+
watcher.on("all", async (event, filename) => {
|
|
4514
|
+
if (!isExcluded(filename)) {
|
|
4515
|
+
await fireDeploy(
|
|
4516
|
+
project,
|
|
4517
|
+
filename,
|
|
4518
|
+
cmdFlags,
|
|
4519
|
+
creds,
|
|
4520
|
+
logger,
|
|
4521
|
+
reset,
|
|
4522
|
+
watch3,
|
|
4523
|
+
event
|
|
4524
|
+
);
|
|
4525
|
+
}
|
|
4526
|
+
});
|
|
4527
|
+
};
|
|
4528
|
+
watch3();
|
|
4529
|
+
}
|
|
4530
|
+
async function fireDeploy(project, filename, cmdFlags, creds, logger, reset, watch3, event) {
|
|
4531
|
+
if (event === "addDir") {
|
|
4532
|
+
return;
|
|
4533
|
+
}
|
|
4534
|
+
if (event === "add" && isSymlink(filename)) {
|
|
4535
|
+
return;
|
|
4536
|
+
}
|
|
4537
|
+
await reset();
|
|
4538
|
+
logger.log(`
|
|
4539
|
+
Deploying '${project}' due to change in '${filename}'`);
|
|
4540
|
+
let error = false;
|
|
4541
|
+
const result = await deployProject2(
|
|
4542
|
+
project,
|
|
4543
|
+
cmdFlags,
|
|
4544
|
+
creds,
|
|
4545
|
+
true,
|
|
4546
|
+
logger
|
|
4547
|
+
).catch((err) => {
|
|
4548
|
+
logger.displayError("", err);
|
|
4549
|
+
error = true;
|
|
4550
|
+
});
|
|
4551
|
+
if (error || !result) {
|
|
4552
|
+
return;
|
|
4553
|
+
}
|
|
4554
|
+
logger.log("Deployment complete. Resuming watch.\n");
|
|
4555
|
+
await delay(200).then(() => watch3());
|
|
4556
|
+
}
|
|
4557
|
+
function isSymlink(filename) {
|
|
4558
|
+
try {
|
|
4559
|
+
const stat = fs7.lstatSync(filename);
|
|
4560
|
+
return stat.isSymbolicLink();
|
|
4561
|
+
} catch {
|
|
4562
|
+
return false;
|
|
4563
|
+
}
|
|
4564
|
+
}
|
|
4565
|
+
|
|
4566
|
+
// src/main.ts
|
|
4567
|
+
var path6 = __toESM(require("path"));
|
|
4568
|
+
var import_yargs_parser = __toESM(require("yargs-parser"));
|
|
4569
|
+
var import_http = require("http");
|
|
4570
|
+
var import_debug12 = __toESM(require("debug"));
|
|
4571
|
+
|
|
4572
|
+
// src/version.ts
|
|
4573
|
+
var version = "5.0.18";
|
|
4574
|
+
|
|
4575
|
+
// src/main.ts
|
|
4576
|
+
var verboseError = (0, import_debug12.default)("nim:error");
|
|
4577
|
+
var DefaultLogger = class {
|
|
4578
|
+
log(msg = "", ...args) {
|
|
4579
|
+
console.log(msg, ...args);
|
|
4580
|
+
}
|
|
4581
|
+
handleError(msg, err) {
|
|
4582
|
+
if (err)
|
|
4583
|
+
throw err;
|
|
4584
|
+
msg = improveErrorMsg(msg, err);
|
|
4585
|
+
throw new Error(msg);
|
|
4586
|
+
}
|
|
4587
|
+
displayError(msg, err) {
|
|
4588
|
+
msg = improveErrorMsg(msg, err);
|
|
4589
|
+
verboseError("%O", err);
|
|
4590
|
+
const bang = process.platform === "win32" ? "\xBB" : "\u203A";
|
|
4591
|
+
console.log(bang + " Error: " + msg);
|
|
4592
|
+
}
|
|
4593
|
+
exit(code) {
|
|
4594
|
+
process.exit(code);
|
|
4595
|
+
}
|
|
4596
|
+
logJSON(entity) {
|
|
4597
|
+
console.log(JSON.stringify(entity, null, 2));
|
|
4598
|
+
}
|
|
4599
|
+
logTable(data, _columns, _options = {}) {
|
|
4600
|
+
console.log(JSON.stringify(data, null, 2));
|
|
4601
|
+
}
|
|
4602
|
+
logOutput(json, msgs) {
|
|
4603
|
+
for (const msg of msgs) {
|
|
4604
|
+
console.log(msg);
|
|
4605
|
+
}
|
|
4606
|
+
console.log(JSON.stringify(json, null, 2));
|
|
4607
|
+
}
|
|
4608
|
+
};
|
|
4609
|
+
var CaptureLogger = class {
|
|
4610
|
+
constructor() {
|
|
4611
|
+
this.captured = [];
|
|
4612
|
+
this.errors = [];
|
|
4613
|
+
}
|
|
4614
|
+
log(msg = "", ...args) {
|
|
4615
|
+
const msgs = String(msg).split("\n");
|
|
4616
|
+
for (const msg2 of msgs) {
|
|
4617
|
+
this.captured.push(msg2, ...args);
|
|
4618
|
+
}
|
|
4619
|
+
}
|
|
4620
|
+
handleError(msg, err) {
|
|
4621
|
+
if (err)
|
|
4622
|
+
throw err;
|
|
4623
|
+
msg = improveErrorMsg(msg, err);
|
|
4624
|
+
throw new Error(msg);
|
|
4625
|
+
}
|
|
4626
|
+
displayError(msg, err) {
|
|
4627
|
+
msg = improveErrorMsg(msg, err);
|
|
4628
|
+
this.errors.push(msg);
|
|
4629
|
+
}
|
|
4630
|
+
exit(_code) {
|
|
4631
|
+
}
|
|
4632
|
+
logJSON(entity) {
|
|
4633
|
+
this.entity = entity;
|
|
4634
|
+
}
|
|
4635
|
+
logTable(data, _columns, _options = {}) {
|
|
4636
|
+
this.table = data;
|
|
4637
|
+
}
|
|
4638
|
+
logOutput(json, msgs) {
|
|
4639
|
+
this.entity = json;
|
|
4640
|
+
this.captured = msgs;
|
|
4641
|
+
}
|
|
4642
|
+
};
|
|
4643
|
+
var LoggerFeedback = class {
|
|
4644
|
+
constructor(logger) {
|
|
4645
|
+
this.logger = logger;
|
|
4646
|
+
}
|
|
4647
|
+
warn(msg, ...args) {
|
|
4648
|
+
this.logger.log(String(msg), ...args);
|
|
4649
|
+
}
|
|
4650
|
+
progress(msg, ...args) {
|
|
4651
|
+
if (this.warnOnly)
|
|
4652
|
+
return;
|
|
4653
|
+
this.logger.log(String(msg), ...args);
|
|
4654
|
+
}
|
|
4655
|
+
};
|
|
4656
|
+
async function flush() {
|
|
4657
|
+
process.stdout.once("drain", () => process.exit(0));
|
|
4658
|
+
}
|
|
4659
|
+
function handleError(err) {
|
|
4660
|
+
console.error(err);
|
|
4661
|
+
process.exit(1);
|
|
4662
|
+
}
|
|
4663
|
+
var parsing = {
|
|
4664
|
+
string: ["env", "build-env", "apihost", "auth", "include", "exclude"],
|
|
4665
|
+
boolean: [
|
|
4666
|
+
"insecure",
|
|
4667
|
+
"verbose-build",
|
|
4668
|
+
"verbose-zip",
|
|
4669
|
+
"yarn",
|
|
4670
|
+
"remote-build",
|
|
4671
|
+
"incremental",
|
|
4672
|
+
"json",
|
|
4673
|
+
"no-triggers"
|
|
4674
|
+
],
|
|
4675
|
+
configuration: {
|
|
4676
|
+
"parse-positional-numbers": false,
|
|
4677
|
+
"unknown-options-as-args": true,
|
|
4678
|
+
"boolean-negation": false
|
|
4679
|
+
}
|
|
4680
|
+
};
|
|
4681
|
+
function main() {
|
|
4682
|
+
return runCommand(process.argv.slice(2), new DefaultLogger());
|
|
4683
|
+
}
|
|
4684
|
+
async function runCommand(inputArgs, logger) {
|
|
4685
|
+
const parsed = (0, import_yargs_parser.default)(inputArgs, parsing);
|
|
4686
|
+
const args = parsed._;
|
|
4687
|
+
const badFlags = args.filter((arg) => arg.startsWith("-"));
|
|
4688
|
+
if (badFlags.length > 0) {
|
|
4689
|
+
logger.handleError(`unknown flag(s): [${badFlags}]`);
|
|
4690
|
+
}
|
|
4691
|
+
if (args.length != 2 && args[0] !== "version") {
|
|
4692
|
+
logger.handleError(
|
|
4693
|
+
"exactly two non-flag tokens are required: the command, and the project"
|
|
4694
|
+
);
|
|
4695
|
+
}
|
|
4696
|
+
const [cmd, project] = args;
|
|
4697
|
+
const {
|
|
4698
|
+
env,
|
|
4699
|
+
buildEnv,
|
|
4700
|
+
apihost,
|
|
4701
|
+
auth,
|
|
4702
|
+
include,
|
|
4703
|
+
exclude,
|
|
4704
|
+
insecure,
|
|
4705
|
+
verboseBuild,
|
|
4706
|
+
verboseZip,
|
|
4707
|
+
yarn,
|
|
4708
|
+
remoteBuild,
|
|
4709
|
+
incremental,
|
|
4710
|
+
json,
|
|
4711
|
+
noTriggers
|
|
4712
|
+
} = parsed;
|
|
4713
|
+
const flags = {
|
|
4714
|
+
env,
|
|
4715
|
+
buildEnv,
|
|
4716
|
+
apiHost: apihost,
|
|
4717
|
+
auth,
|
|
4718
|
+
include,
|
|
4719
|
+
exclude,
|
|
4720
|
+
insecure,
|
|
4721
|
+
verboseBuild,
|
|
4722
|
+
verboseZip,
|
|
4723
|
+
yarn,
|
|
4724
|
+
remoteBuild,
|
|
4725
|
+
incremental,
|
|
4726
|
+
json,
|
|
4727
|
+
noTriggers
|
|
4728
|
+
};
|
|
4729
|
+
switch (cmd) {
|
|
4730
|
+
case "deploy":
|
|
4731
|
+
await doDeploy2(project, flags, logger);
|
|
4732
|
+
break;
|
|
4733
|
+
case "get-metadata":
|
|
4734
|
+
await doGetMetadata(project, flags, logger);
|
|
4735
|
+
break;
|
|
4736
|
+
case "watch":
|
|
4737
|
+
await doWatch(project, flags, logger);
|
|
4738
|
+
break;
|
|
4739
|
+
case "version":
|
|
4740
|
+
logger.log(version);
|
|
4741
|
+
break;
|
|
4742
|
+
default:
|
|
4743
|
+
logger.handleError(`unknown command: ${cmd}`);
|
|
4744
|
+
}
|
|
4745
|
+
}
|
|
4746
|
+
async function doDeploy2(project, flags, logger) {
|
|
4747
|
+
const { insecure, apiHost: apihost, auth } = flags;
|
|
4748
|
+
const creds = await processCredentials(insecure, apihost, auth);
|
|
4749
|
+
await deployProject2(project, flags, creds, false, logger);
|
|
4750
|
+
}
|
|
4751
|
+
async function doGetMetadata(project, flags, logger) {
|
|
4752
|
+
const includer = makeIncluder(flags.include, flags.exclude);
|
|
4753
|
+
const result = await readProject(
|
|
4754
|
+
project,
|
|
4755
|
+
flags.env,
|
|
4756
|
+
void 0,
|
|
4757
|
+
includer,
|
|
4758
|
+
false,
|
|
4759
|
+
void 0,
|
|
4760
|
+
flags.noTriggers
|
|
4761
|
+
);
|
|
4762
|
+
if (result.error && !result.unresolvedVariables) {
|
|
4763
|
+
logger.displayError("", result.error);
|
|
4764
|
+
logger.exit(1);
|
|
4765
|
+
}
|
|
4766
|
+
if (result.packages && !result.unresolvedVariables) {
|
|
4767
|
+
for (const pkg of result.packages) {
|
|
4768
|
+
if (pkg.actions) {
|
|
4769
|
+
for (const action of pkg.actions) {
|
|
4770
|
+
action.runtime = await getRuntimeForAction(action, result.reader);
|
|
4771
|
+
}
|
|
4772
|
+
}
|
|
4773
|
+
}
|
|
4774
|
+
}
|
|
4775
|
+
renameActionsToFunctions(result);
|
|
4776
|
+
logger.logJSON(result);
|
|
4777
|
+
}
|
|
4778
|
+
async function doWatch(project, flags, logger) {
|
|
4779
|
+
const { insecure, apiHost: apihost, auth } = flags;
|
|
4780
|
+
const creds = await processCredentials(insecure, apihost, auth);
|
|
4781
|
+
watch2(project, flags, creds, logger);
|
|
4782
|
+
}
|
|
4783
|
+
async function processCredentials(ignore_certs, apihost, auth) {
|
|
4784
|
+
const owOptions = { ignore_certs };
|
|
4785
|
+
if (apihost) {
|
|
4786
|
+
owOptions.apihost = parseAPIHost(apihost);
|
|
4787
|
+
}
|
|
4788
|
+
if (auth) {
|
|
4789
|
+
owOptions.api_key = auth;
|
|
4790
|
+
}
|
|
4791
|
+
let creds;
|
|
4792
|
+
if (apihost && auth) {
|
|
4793
|
+
creds = {
|
|
4794
|
+
namespace: void 0,
|
|
4795
|
+
ow: owOptions,
|
|
4796
|
+
do_token: process.env.DO_API_TOKEN
|
|
4797
|
+
};
|
|
4798
|
+
}
|
|
4799
|
+
return creds;
|
|
4800
|
+
}
|
|
4801
|
+
function parseAPIHost(host) {
|
|
4802
|
+
if (!host) {
|
|
4803
|
+
return void 0;
|
|
4804
|
+
}
|
|
4805
|
+
if (host.includes(":")) {
|
|
4806
|
+
return host;
|
|
4807
|
+
}
|
|
4808
|
+
if (host.includes(".")) {
|
|
4809
|
+
return "https://" + host;
|
|
4810
|
+
}
|
|
4811
|
+
return "https://" + host + ".doserverless.co";
|
|
4812
|
+
}
|
|
4813
|
+
async function deployProject2(project, cmdFlags, creds, watching, logger) {
|
|
4814
|
+
let feedback;
|
|
4815
|
+
if (project.startsWith("slice:") || cmdFlags.json) {
|
|
4816
|
+
feedback = new LoggerFeedback(new CaptureLogger());
|
|
4817
|
+
feedback.warnOnly = true;
|
|
4818
|
+
} else {
|
|
4819
|
+
feedback = new LoggerFeedback(logger);
|
|
4820
|
+
}
|
|
4821
|
+
let todeploy = await readAndPrepare(project, creds, cmdFlags, feedback);
|
|
4822
|
+
if (!todeploy) {
|
|
4823
|
+
return false;
|
|
4824
|
+
} else if (todeploy.error && !cmdFlags.json) {
|
|
4825
|
+
logger.displayError("", todeploy.error);
|
|
4826
|
+
return false;
|
|
4827
|
+
}
|
|
4828
|
+
if (!watching && !todeploy.slice && !cmdFlags.json) {
|
|
4829
|
+
displayHeader(project, todeploy.credentials, logger);
|
|
4830
|
+
}
|
|
4831
|
+
todeploy = await buildProject(todeploy);
|
|
4832
|
+
if (todeploy.error && !cmdFlags.json) {
|
|
4833
|
+
logger.displayError("", todeploy.error);
|
|
4834
|
+
return false;
|
|
4835
|
+
}
|
|
4836
|
+
const result = await deploy(todeploy);
|
|
4837
|
+
if (cmdFlags.json || todeploy.slice) {
|
|
4838
|
+
const success = displayJSONResult(result, logger, feedback, todeploy.slice);
|
|
4839
|
+
if (success && todeploy.slice) {
|
|
4840
|
+
await deleteSlice(todeploy);
|
|
4841
|
+
}
|
|
4842
|
+
return success;
|
|
4843
|
+
}
|
|
4844
|
+
return displayResult(result, watching, logger);
|
|
4845
|
+
}
|
|
4846
|
+
function displayHeader(project, creds, logger) {
|
|
4847
|
+
let namespaceClause = "";
|
|
4848
|
+
if (creds && creds.namespace) {
|
|
4849
|
+
namespaceClause = `
|
|
4850
|
+
to namespace '${creds.namespace}'`;
|
|
4851
|
+
}
|
|
4852
|
+
let hostClause = "";
|
|
4853
|
+
if (creds && creds.ow.apihost) {
|
|
4854
|
+
hostClause = `
|
|
4855
|
+
on host '${creds.ow.apihost}'`;
|
|
4856
|
+
}
|
|
4857
|
+
const projectPath = path6.resolve(project);
|
|
4858
|
+
logger.log(`Deploying '${projectPath}'${namespaceClause}${hostClause}`);
|
|
4859
|
+
}
|
|
4860
|
+
function displayJSONResult(outcome, logger, feedback, slice) {
|
|
4861
|
+
const transcript = feedback.logger.captured;
|
|
4862
|
+
const result = { transcript, outcome };
|
|
4863
|
+
if (slice) {
|
|
4864
|
+
let replaceErrors = function(_key, value) {
|
|
4865
|
+
if (value instanceof Error) {
|
|
4866
|
+
const error = {};
|
|
4867
|
+
Object.getOwnPropertyNames(value).forEach(function(key) {
|
|
4868
|
+
error[key] = value[key];
|
|
4869
|
+
});
|
|
4870
|
+
return error;
|
|
4871
|
+
}
|
|
4872
|
+
return value;
|
|
4873
|
+
};
|
|
4874
|
+
const toDisplay = JSON.stringify(result, replaceErrors);
|
|
4875
|
+
logger.log(toDisplay);
|
|
4876
|
+
} else {
|
|
4877
|
+
logger.logJSON(result);
|
|
4878
|
+
}
|
|
4879
|
+
return outcome.failures.length === 0;
|
|
4880
|
+
}
|
|
4881
|
+
function displayResult(result, _watching, logger) {
|
|
4882
|
+
let success = true;
|
|
4883
|
+
if (result.successes.length === 0 && result.failures.length === 0) {
|
|
4884
|
+
logger.log("\nNothing deployed");
|
|
4885
|
+
} else {
|
|
4886
|
+
logger.log("");
|
|
4887
|
+
const actions = [];
|
|
4888
|
+
const triggers = [];
|
|
4889
|
+
const packages = [];
|
|
4890
|
+
let skippedActions = 0;
|
|
4891
|
+
let skippedTriggers = 0;
|
|
4892
|
+
let skippedPackages = 0;
|
|
4893
|
+
for (const success2 of result.successes) {
|
|
4894
|
+
if (success2.kind === "action") {
|
|
4895
|
+
if (success2.skipped) {
|
|
4896
|
+
skippedActions++;
|
|
4897
|
+
} else {
|
|
4898
|
+
const name = success2.name;
|
|
4899
|
+
actions.push(name);
|
|
4900
|
+
}
|
|
4901
|
+
} else if (success2.kind === "trigger") {
|
|
4902
|
+
if (success2.skipped) {
|
|
4903
|
+
skippedTriggers++;
|
|
4904
|
+
} else {
|
|
4905
|
+
triggers.push(success2.name);
|
|
4906
|
+
}
|
|
4907
|
+
} else if (success2.kind === "binding") {
|
|
4908
|
+
if (success2.skipped) {
|
|
4909
|
+
skippedPackages++;
|
|
4910
|
+
} else {
|
|
4911
|
+
packages.push(success2.name);
|
|
4912
|
+
}
|
|
4913
|
+
}
|
|
4914
|
+
}
|
|
4915
|
+
if (actions.length > 0) {
|
|
4916
|
+
logger.log(
|
|
4917
|
+
"Deployed functions ('doctl sls fn get <funcName> --url' for URL):"
|
|
4918
|
+
);
|
|
4919
|
+
for (const action of actions) {
|
|
4920
|
+
logger.log(` - ${action}`);
|
|
4921
|
+
}
|
|
4922
|
+
}
|
|
4923
|
+
if (skippedActions > 0) {
|
|
4924
|
+
logger.log(`Skipped ${skippedActions} unchanged functions`);
|
|
4925
|
+
}
|
|
4926
|
+
if (triggers.length > 0) {
|
|
4927
|
+
logger.log("Deployed triggers:");
|
|
4928
|
+
for (const trigger of triggers) {
|
|
4929
|
+
logger.log(` - ${trigger}`);
|
|
4930
|
+
}
|
|
4931
|
+
}
|
|
4932
|
+
if (skippedTriggers > 0) {
|
|
4933
|
+
logger.log(`Skipped ${skippedTriggers} triggers`);
|
|
4934
|
+
}
|
|
4935
|
+
if (packages.length > 0) {
|
|
4936
|
+
logger.log("Deployed bound packages:");
|
|
4937
|
+
for (const pkg of packages) {
|
|
4938
|
+
logger.log(` - ${pkg}`);
|
|
4939
|
+
}
|
|
4940
|
+
}
|
|
4941
|
+
if (skippedPackages > 0) {
|
|
4942
|
+
logger.log(`Skipped ${skippedPackages} bound packages`);
|
|
4943
|
+
}
|
|
4944
|
+
if (result.failures.length > 0) {
|
|
4945
|
+
success = false;
|
|
4946
|
+
logger.log("Failures:");
|
|
4947
|
+
for (const err of result.failures) {
|
|
4948
|
+
success = false;
|
|
4949
|
+
const context = err.context;
|
|
4950
|
+
if (context) {
|
|
4951
|
+
logger.displayError(`While deploying ${context}`, err);
|
|
4952
|
+
} else {
|
|
4953
|
+
logger.displayError("", err);
|
|
4954
|
+
}
|
|
4955
|
+
}
|
|
4956
|
+
}
|
|
4957
|
+
}
|
|
4958
|
+
return success;
|
|
4959
|
+
}
|
|
4960
|
+
function improveErrorMsg(msg, err) {
|
|
4961
|
+
const getStatusCode = (code) => `${code} ${import_http.STATUS_CODES[code] || ""}`.trim();
|
|
4962
|
+
let pretty = "";
|
|
4963
|
+
if (err) {
|
|
4964
|
+
pretty = err.message || "";
|
|
4965
|
+
if (err.name === "OpenWhiskError") {
|
|
4966
|
+
if (err.error && err.error.error) {
|
|
4967
|
+
pretty = err.error.error.toLowerCase();
|
|
4968
|
+
if (err.statusCode)
|
|
4969
|
+
pretty = `${pretty} (${getStatusCode(err.statusCode)})`;
|
|
4970
|
+
else if (err.error.code)
|
|
4971
|
+
pretty = `${pretty} (${err.error.code})`;
|
|
4972
|
+
} else if (err.statusCode) {
|
|
4973
|
+
pretty = getStatusCode(err.statusCode);
|
|
4974
|
+
}
|
|
4975
|
+
}
|
|
4976
|
+
}
|
|
4977
|
+
if ((pretty || "").toString().trim()) {
|
|
4978
|
+
msg = msg ? `${msg}: ${pretty}` : pretty;
|
|
4979
|
+
}
|
|
4980
|
+
if (!msg) {
|
|
4981
|
+
if (err.status) {
|
|
4982
|
+
msg = getStatusCode(err.status);
|
|
4983
|
+
} else {
|
|
4984
|
+
msg = "unknown error";
|
|
4985
|
+
}
|
|
4986
|
+
}
|
|
4987
|
+
return msg;
|
|
4988
|
+
}
|
|
4989
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
4990
|
+
0 && (module.exports = {
|
|
4991
|
+
API_ENDPOINT,
|
|
4992
|
+
CaptureLogger,
|
|
4993
|
+
DefaultFeedback,
|
|
4994
|
+
DefaultLogger,
|
|
4995
|
+
SYSTEM_EXCLUDE_PATTERNS,
|
|
4996
|
+
addCredentialAndSave,
|
|
4997
|
+
authPersister,
|
|
4998
|
+
buildProject,
|
|
4999
|
+
canonicalRuntime,
|
|
5000
|
+
defaultRuntime,
|
|
5001
|
+
delay,
|
|
5002
|
+
deleteAction,
|
|
5003
|
+
deleteSlice,
|
|
5004
|
+
deploy,
|
|
5005
|
+
deployProject,
|
|
5006
|
+
emptyStructure,
|
|
5007
|
+
fileExtensionForRuntime,
|
|
5008
|
+
flush,
|
|
5009
|
+
forgetNamespace,
|
|
5010
|
+
fromPlatform,
|
|
5011
|
+
getApiHosts,
|
|
5012
|
+
getBestProjectName,
|
|
5013
|
+
getCredentialDict,
|
|
5014
|
+
getCredentialList,
|
|
5015
|
+
getCredentials,
|
|
5016
|
+
getCredentialsForNamespace,
|
|
5017
|
+
getCredentialsFromEnvironment,
|
|
5018
|
+
getCurrentNamespace,
|
|
5019
|
+
getExclusionList,
|
|
5020
|
+
getRuntimeForAction,
|
|
5021
|
+
getRuntimes,
|
|
5022
|
+
getUserAgent,
|
|
5023
|
+
handleError,
|
|
5024
|
+
initializeAPI,
|
|
5025
|
+
invokeWebSecure,
|
|
5026
|
+
isBinaryFileExtension,
|
|
5027
|
+
isExcluded,
|
|
5028
|
+
isValidRuntime,
|
|
5029
|
+
load,
|
|
5030
|
+
main,
|
|
5031
|
+
makeIncluder,
|
|
5032
|
+
nimbellaDir,
|
|
5033
|
+
prepareToDeploy,
|
|
5034
|
+
readAndPrepare,
|
|
5035
|
+
readPrepareAndBuild,
|
|
5036
|
+
readProject,
|
|
5037
|
+
renameActionsToFunctions,
|
|
5038
|
+
renamePackage,
|
|
5039
|
+
runCommand,
|
|
5040
|
+
runtimeForFileExtension,
|
|
5041
|
+
runtimeForZipMid,
|
|
5042
|
+
switchNamespace,
|
|
5043
|
+
wipeNamespace,
|
|
5044
|
+
wipePackage,
|
|
5045
|
+
writeSliceResult,
|
|
5046
|
+
wskRequest
|
|
5047
|
+
});
|
|
5048
|
+
//# sourceMappingURL=index.js.map
|