You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwhisk.apache.org by al...@apache.org on 2020/04/15 01:27:04 UTC
[openwhisk-wskdebug] branch master updated: validate source path
etc. before async installation of agent
This is an automated email from the ASF dual-hosted git repository.
alexkli pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/openwhisk-wskdebug.git
The following commit(s) were added to refs/heads/master by this push:
new 9571e47 validate source path etc. before async installation of agent
9571e47 is described below
commit 9571e47777d12b666c9825324c1f12d0876243f6
Author: Alexander Klimetschek <ak...@adobe.com>
AuthorDate: Tue Apr 14 17:04:42 2020 -0700
validate source path etc. before async installation of agent
- separate OpenWhiskInvoker.prepare() phase for validation
- better error msg if sourcePath points to folder
- fix race condition on early error related shutdown
---
src/agentmgr.js | 7 +++++++
src/debugger.js | 12 +++++++-----
src/invoker.js | 35 +++++++++++++++++++----------------
src/kinds/nodejs/nodejs.js | 6 +++++-
4 files changed, 38 insertions(+), 22 deletions(-)
diff --git a/src/agentmgr.js b/src/agentmgr.js
index 4405b8d..f96c6fa 100644
--- a/src/agentmgr.js
+++ b/src/agentmgr.js
@@ -264,6 +264,8 @@ class AgentMgr {
}
async shutdown() {
+ this.shuttingDown = true;
+
try {
// make sure we finished creating the backup
await this.createBackup;
@@ -529,6 +531,11 @@ class AgentMgr {
// this is to support older openwhisks for which nodejs:default is less than version 8
const nodejs8 = await this.openwhiskSupports("nodejs8");
+ if (this.shuttingDown) {
+ // race condition on shutdown during startup due to errors
+ return;
+ }
+
await this.wsk.actions.update({
name: this.actionName,
action: {
diff --git a/src/debugger.js b/src/debugger.js
index 8e2fb42..879d497 100644
--- a/src/debugger.js
+++ b/src/debugger.js
@@ -71,16 +71,18 @@ class Debugger {
this.invoker = new OpenWhiskInvoker(this.actionName, actionMetadata, this.argv, this.wskProps, this.wsk);
try {
+ // run build initially (would be required by starting container)
+ if (this.argv.onBuild) {
+ console.info("=> Build:", this.argv.onBuild);
+ spawnSync(this.argv.onBuild, {shell: true, stdio: "inherit"});
+ }
+ await this.invoker.prepare();
+
// parallelize slower work using promises
// task 1 - start local container
const containerTask = (async () => {
const debugTask = debug.task();
- // run build initially (would be required by starting container)
- if (this.argv.onBuild) {
- console.info("=> Build:", this.argv.onBuild);
- spawnSync(this.argv.onBuild, {shell: true, stdio: "inherit"});
- }
// start container - get it up fast for VSCode to connect within its 10 seconds timeout
await this.invoker.startContainer();
diff --git a/src/invoker.js b/src/invoker.js
index 35fff0e..eed849a 100644
--- a/src/invoker.js
+++ b/src/invoker.js
@@ -119,15 +119,12 @@ class OpenWhiskInvoker {
return kinds.images[kind];
}
- async startContainer() {
+ async prepare() {
const action = this.action;
- // this must run after initial build was kicked off in Debugger.startSourceWatching()
- // so that built files are present
-
- // kind and image
+ // this must run after initial build was kicked off in Debugger so that built files are present
- // precendence:
+ // kind and image - precendence:
// 1. arguments (this.image)
// 2. action (action.exec.image)
// 3. defaults (kinds.images[kind])
@@ -138,7 +135,6 @@ class OpenWhiskInvoker {
throw new Error("Action is of kind 'blackbox', must specify kind using `--kind` argument.");
}
- // const runtime = kinds[kind] || {};
this.image = this.image || action.exec.image || await this.getImageForKind(kind);
if (!this.image) {
@@ -174,7 +170,7 @@ class OpenWhiskInvoker {
}
// limits
- const memory = (action.limits.memory || OPENWHISK_DEFAULTS.memory) * 1024 * 1024;
+ this.memory = (action.limits.memory || OPENWHISK_DEFAULTS.memory) * 1024 * 1024;
// source mounting
if (this.sourcePath) {
@@ -184,9 +180,15 @@ class OpenWhiskInvoker {
}
}
- const dockerArgsFromKind = resolveValue(this.debug.dockerArgs, this) || "";
- const dockerArgsFromUser = this.dockerArgs || "";
+ this.dockerArgsFromKind = resolveValue(this.debug.dockerArgs, this) || "";
+ this.dockerArgsFromUser = this.dockerArgs || "";
+
+ if (this.sourcePath && this.debug.mountAction) {
+ this.sourceMountAction = resolveValue(this.debug.mountAction, this);
+ }
+ }
+ async startContainer() {
let showDockerRunOutput = this.verbose;
// quick fail for missing requirements such as docker not running
@@ -220,11 +222,11 @@ class OpenWhiskInvoker {
-d
--name ${this.name()}
--rm
- -m ${memory}
+ -m ${this.memory}
-p ${RUNTIME_PORT}
-p ${this.debug.port}:${this.debug.internalPort}
- ${dockerArgsFromKind}
- ${dockerArgsFromUser}
+ ${this.dockerArgsFromKind}
+ ${this.dockerArgsFromUser}
${this.image}
${this.debug.command}
`,
@@ -262,12 +264,13 @@ class OpenWhiskInvoker {
async init(actionWithCode) {
let action;
- if (this.sourcePath && this.debug.mountAction) {
- action = resolveValue(this.debug.mountAction, this);
-
+ if (this.sourceMountAction) {
if (this.verbose) {
console.log(`Mounting sources onto local debug container: ${this.sourcePath}`);
}
+
+ action = this.sourceMountAction;
+
} else {
if (this.verbose) {
console.log(`Pushing action code to local debug container: ${this.action.name}`);
diff --git a/src/kinds/nodejs/nodejs.js b/src/kinds/nodejs/nodejs.js
index 38d6396..1791def 100644
--- a/src/kinds/nodejs/nodejs.js
+++ b/src/kinds/nodejs/nodejs.js
@@ -39,7 +39,7 @@ module.exports = {
let args = "";
if (invoker.sourceDir) {
if (!invoker.sourceFile) {
- throw new Error("[source-path] or --build-path must point to the action javascript source file, it cannot be a folder.");
+ throw new Error(`[source-path] or --build-path must point to a source file, it cannot be a folder: '${invoker.sourcePath}'`);
}
args += ` -v "${invoker.sourceDir}:${CODE_MOUNT}"`;
@@ -59,6 +59,10 @@ module.exports = {
mountAction: function(invoker) {
// bridge that mounts local source path
+ if (fs.statSync(invoker.sourcePath).isDirectory()) {
+ throw new Error(`[source-path] or --build-path must point to a source file, it cannot be a folder: '${invoker.sourcePath}'`);
+ }
+
// test if code uses commonjs require()
const isCommonJS = /(\s|=)require\(\s*['"`]/.test(fs.readFileSync(invoker.sourcePath));