This is an automated email from the ASF dual-hosted git repository.

rabbah 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 179ef4b  support custom docker host IPs via the DOCKER_HOST_IP 
environment variable (#69)
179ef4b is described below

commit 179ef4bc2f5e8ea3154004cf15d430eb20dfd92d
Author: Alexander Klimetschek <[email protected]>
AuthorDate: Wed Jul 15 10:17:09 2020 -0700

    support custom docker host IPs via the DOCKER_HOST_IP environment variable 
(#69)
---
 src/invoker.js      |  3 ++-
 test/nodejs.test.js | 21 +++++++++++++++++++++
 test/test.js        |  1 +
 3 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/src/invoker.js b/src/invoker.js
index 0fcd536..f39c747 100644
--- a/src/invoker.js
+++ b/src/invoker.js
@@ -273,7 +273,8 @@ class OpenWhiskInvoker {
 
         const containerRuntimePort = `${RUNTIME_PORT}/tcp`;
         const hostRuntimePort = await getPort();
-        this.containerURL = `http://0.0.0.0:${hostRuntimePort}`;
+        const ipAddress = process.env.DOCKER_HOST_IP || "0.0.0.0";
+        this.containerURL = `http://${ipAddress}:${hostRuntimePort}`;
         const containerDebugPort = `${this.debug.internalPort}/tcp`;
 
         const createContainerConfig = {
diff --git a/test/nodejs.test.js b/test/nodejs.test.js
index 625e276..7369529 100644
--- a/test/nodejs.test.js
+++ b/test/nodejs.test.js
@@ -576,6 +576,27 @@ describe('nodejs', function() {
         test.assertAllNocksInvoked();
     });
 
+    it("should run an action with custom DOCKER_HOST_IP env var set", async 
function() {
+        test.mockActionAndInvocation(
+            "myaction",
+            `function main(params) {
+                return {
+                    msg: 'CORRECT',
+                    input: params.input
+                }
+            }`,
+            { input: "test-input" },
+            { msg: "CORRECT", input: "test-input" }
+        );
+
+        // 0.0.0.0 (default) or 127.0.0.1 should work if we are on the docker 
host
+        process.env.DOCKER_HOST_IP = "127.0.0.1";
+
+        await wskdebug(`myaction -p ${test.port}`);
+
+        test.assertAllNocksInvoked();
+    });
+
     // TODO: test -l livereload connection
 
     // TODO: test agents - conditions (unit test agent code locally)
diff --git a/test/test.js b/test/test.js
index 0aaeed6..3d501ea 100644
--- a/test/test.js
+++ b/test/test.js
@@ -55,6 +55,7 @@ async function beforeEach() {
 
 function afterEach() {
     delete process.env.WSK_CONFIG_FILE;
+    delete process.env.DOCKER_HOST_IP;
     nock.cleanAll();
 
     // restore working dir from beforeEach()

Reply via email to