support custom docker host IPs via the DOCKER_HOST_IP environment variable (#69)
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 @@
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 @@
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 @@
function afterEach() {
delete process.env.WSK_CONFIG_FILE;
+ delete process.env.DOCKER_HOST_IP;
nock.cleanAll();
// restore working dir from beforeEach()