navy 4.1.2-rc.2 → 5.0.0

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.
Files changed (75) hide show
  1. package/lib/cli/config/index.js +57 -241
  2. package/lib/cli/config/wrapper.js +12 -36
  3. package/lib/cli/develop.js +63 -167
  4. package/lib/cli/doctor/clean-compose-files.js +19 -73
  5. package/lib/cli/doctor/index.js +34 -154
  6. package/lib/cli/doctor/invalid-compose-config.js +20 -110
  7. package/lib/cli/doctor/invalid-state.js +22 -115
  8. package/lib/cli/doctor/util.js +26 -93
  9. package/lib/cli/external-ip.js +9 -39
  10. package/lib/cli/health.js +18 -67
  11. package/lib/cli/https.js +92 -0
  12. package/lib/cli/import.js +22 -59
  13. package/lib/cli/index.js +11 -17
  14. package/lib/cli/lan-ip.js +18 -60
  15. package/lib/cli/launch.js +46 -127
  16. package/lib/cli/live.js +37 -111
  17. package/lib/cli/local-ip.js +16 -53
  18. package/lib/cli/logs.js +7 -35
  19. package/lib/cli/open.js +11 -45
  20. package/lib/cli/program.js +145 -167
  21. package/lib/cli/ps.js +36 -105
  22. package/lib/cli/refresh-config.js +18 -62
  23. package/lib/cli/run.js +8 -39
  24. package/lib/cli/status.js +41 -201
  25. package/lib/cli/updates.js +68 -160
  26. package/lib/cli/util/get-or-initialise-navy.js +14 -57
  27. package/lib/cli/util/import.js +33 -83
  28. package/lib/cli/util/index.js +10 -12
  29. package/lib/cli/util/reconfigure.js +12 -102
  30. package/lib/cli/wait-for-healthy.js +53 -100
  31. package/lib/config-provider.js +25 -127
  32. package/lib/config-providers/filesystem/index.js +58 -235
  33. package/lib/config-providers/npm/__tests__/util.js +3 -6
  34. package/lib/config-providers/npm/index.js +60 -231
  35. package/lib/config-providers/npm/util.js +6 -9
  36. package/lib/config.js +39 -76
  37. package/lib/driver-logging.js +23 -28
  38. package/lib/driver.js +5 -7
  39. package/lib/drivers/docker-compose/client.js +64 -172
  40. package/lib/drivers/docker-compose/index.js +153 -464
  41. package/lib/errors.js +27 -61
  42. package/lib/http-proxy.js +72 -158
  43. package/lib/index.js +26 -29
  44. package/lib/middleware/add-service-proxy-config.js +76 -0
  45. package/lib/middleware/develop.js +9 -23
  46. package/lib/middleware/helpers.js +20 -25
  47. package/lib/middleware/port-override.js +15 -37
  48. package/lib/middleware/set-env-vars.js +14 -18
  49. package/lib/middleware/set-image.js +12 -18
  50. package/lib/middleware/set-logging-driver.js +14 -18
  51. package/lib/middleware/tag-override.js +11 -19
  52. package/lib/navy/default-middleware.js +13 -27
  53. package/lib/navy/index.js +438 -1761
  54. package/lib/navy/middleware.js +15 -100
  55. package/lib/navy/plugin-interface.js +28 -108
  56. package/lib/navy/state.js +58 -147
  57. package/lib/navy/util.js +2 -1
  58. package/lib/service.js +5 -3
  59. package/lib/util/__tests__/external-ip.js +20 -96
  60. package/lib/util/__tests__/registry-client.js +11 -24
  61. package/lib/util/__tests__/service-host.js +19 -116
  62. package/lib/util/docker-client.js +10 -13
  63. package/lib/util/exec-async.js +9 -27
  64. package/lib/util/external-ip.js +48 -126
  65. package/lib/util/fs.js +7 -6
  66. package/lib/util/get-lan-ip.js +15 -52
  67. package/lib/util/has-update.js +23 -73
  68. package/lib/util/https.js +213 -0
  69. package/lib/util/navyrc.js +12 -50
  70. package/lib/util/registry-client.js +41 -112
  71. package/lib/util/service-host.js +40 -129
  72. package/lib/util/table.js +11 -21
  73. package/package.json +14 -14
  74. package/LICENSE +0 -21
  75. package/lib/middleware/add-virtual-hosts.js +0 -147
@@ -1,17 +1,16 @@
1
- 'use strict';
1
+ "use strict";
2
2
 
3
- var _chai = require('chai');
3
+ var _chai = require("chai");
4
4
 
5
- var _registryClient = require('../registry-client');
5
+ var _registryClient = require("../registry-client");
6
6
 
7
7
  /* eslint-env mocha */
8
+
8
9
  /* eslint-disable no-unused-expressions */
9
- /* eslint-enable chai-friendly/no-unused-expressions */
10
10
 
11
+ /* eslint-enable chai-friendly/no-unused-expressions */
11
12
  describe('docker registry client', function () {
12
-
13
13
  describe('getAuthForRegistry', function () {
14
-
15
14
  beforeEach(function () {
16
15
  this.config = {
17
16
  auths: {
@@ -26,68 +25,56 @@ describe('docker registry client', function () {
26
25
  }
27
26
  };
28
27
  });
29
-
30
28
  it('should return the auth config for the given registry', function () {
31
29
  (0, _chai.expect)((0, _registryClient.getAuthForRegistry)('quay.io', this.config)).to.eql({
32
30
  auth: 'pretend-base64-of-username-and-password',
33
31
  email: 'test@navy.rocks'
34
32
  });
35
33
  });
36
-
37
34
  it('should return the auth config for Docker Hub if given', function () {
38
35
  (0, _chai.expect)((0, _registryClient.getAuthForRegistry)('registry-1.docker.io', this.config)).to.eql({
39
36
  auth: 'pretend-base64-of-username-and-password',
40
37
  email: 'test@navy.rocks'
41
38
  });
42
39
  });
43
-
44
40
  it('should return null if there is no authentication for the given registry', function () {
45
41
  (0, _chai.expect)((0, _registryClient.getAuthForRegistry)('foo.bar', this.config)).to.be.null;
46
42
  });
47
-
48
43
  it('should return null if there is no docker config', function () {
49
44
  (0, _chai.expect)((0, _registryClient.getAuthForRegistry)('foo.bar', null)).to.be.null;
50
45
  });
51
46
  });
52
-
53
47
  describe('credentialsFromAuth', function () {
54
-
55
48
  it('should return the username and password from base64 encoded auth', function () {
56
- (0, _chai.expect)((0, _registryClient.credentialsFromAuth)({ auth: 'YmFyOnBhc3N3b3Jk' })).to.eql({
49
+ (0, _chai.expect)((0, _registryClient.credentialsFromAuth)({
50
+ auth: 'YmFyOnBhc3N3b3Jk'
51
+ })).to.eql({
57
52
  username: 'bar',
58
53
  password: 'password'
59
54
  });
60
55
  });
61
-
62
56
  it('should throw invariant violation when auth is invalid base64', function () {
63
- (0, _chai.expect)(function () {
64
- return (0, _registryClient.credentialsFromAuth)({ auth: 'zjasj' });
65
- }).to.throw('Invalid base64 string in docker/config.json for registry authentication');
57
+ (0, _chai.expect)(() => (0, _registryClient.credentialsFromAuth)({
58
+ auth: 'zjasj'
59
+ })).to.throw('Invalid base64 string in docker/config.json for registry authentication');
66
60
  });
67
61
  });
68
-
69
62
  describe('registryFromImage', function () {
70
-
71
63
  it('should return the correct registry domain from the given image', function () {
72
64
  (0, _chai.expect)((0, _registryClient.registryFromImage)('quay.io/someorg/someimage')).to.equal('quay.io');
73
65
  });
74
-
75
66
  it('should return the correct registry domain from the given image with tag', function () {
76
67
  (0, _chai.expect)((0, _registryClient.registryFromImage)('quay.io/someorg/someimage:some-tag')).to.equal('quay.io');
77
68
  });
78
-
79
69
  it('should return the correct registry domain from the given image from docker hub', function () {
80
70
  (0, _chai.expect)((0, _registryClient.registryFromImage)('someuser/someimage')).to.equal('registry-1.docker.io');
81
71
  });
82
-
83
72
  it('should return the correct registry domain from the given image with tag from docker hub', function () {
84
73
  (0, _chai.expect)((0, _registryClient.registryFromImage)('someuser/someimage:some-tag')).to.equal('registry-1.docker.io');
85
74
  });
86
-
87
75
  it('should return the correct registry domain from the given library image from docker hub', function () {
88
76
  (0, _chai.expect)((0, _registryClient.registryFromImage)('someimage')).to.equal('registry-1.docker.io');
89
77
  });
90
-
91
78
  it('should return the correct registry domain from the given library image with tag from docker hub', function () {
92
79
  (0, _chai.expect)((0, _registryClient.registryFromImage)('someimage:some-tag')).to.equal('registry-1.docker.io');
93
80
  });
@@ -1,145 +1,48 @@
1
- 'use strict';
1
+ "use strict";
2
2
 
3
- var _regenerator = require('babel-runtime/regenerator');
3
+ var _chai = require("chai");
4
4
 
5
- var _regenerator2 = _interopRequireDefault(_regenerator);
6
-
7
- var _asyncToGenerator2 = require('babel-runtime/helpers/asyncToGenerator');
8
-
9
- var _asyncToGenerator3 = _interopRequireDefault(_asyncToGenerator2);
10
-
11
- var _chai = require('chai');
12
-
13
- var _serviceHost = require('../service-host');
14
-
15
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
5
+ var _serviceHost = require("../service-host");
16
6
 
17
7
  /* eslint-env mocha */
18
-
19
8
  describe('service-host', function () {
20
-
21
9
  describe('getNIPSubdomain', function () {
22
-
23
- it('should return an nip.io domain with the correct IP address', (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee() {
24
- return _regenerator2.default.wrap(function _callee$(_context) {
25
- while (1) {
26
- switch (_context.prev = _context.next) {
27
- case 0:
28
- _context.t0 = _chai.expect;
29
- _context.next = 3;
30
- return (0, _serviceHost.getNIPSubdomain)('192.168.1.10');
31
-
32
- case 3:
33
- _context.t1 = _context.sent;
34
- (0, _context.t0)(_context.t1).to.equal('192.168.1.10.nip.io');
35
-
36
- case 5:
37
- case 'end':
38
- return _context.stop();
39
- }
40
- }
41
- }, _callee, this);
42
- })));
43
-
44
- it('should fallback to localhost when a hostname is passed instead of an IP address', (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee2() {
45
- return _regenerator2.default.wrap(function _callee2$(_context2) {
46
- while (1) {
47
- switch (_context2.prev = _context2.next) {
48
- case 0:
49
- process.env.NAVY_EXTERNAL_IP = 'somehostname';
50
- _context2.t0 = _chai.expect;
51
- _context2.next = 4;
52
- return (0, _serviceHost.getNIPSubdomain)('somehostname');
53
-
54
- case 4:
55
- _context2.t1 = _context2.sent;
56
- (0, _context2.t0)(_context2.t1).to.equal('127.0.0.1.nip.io');
57
-
58
- case 6:
59
- case 'end':
60
- return _context2.stop();
61
- }
62
- }
63
- }, _callee2, this);
64
- })));
10
+ it('should return an nip.io domain with the correct IP address', async function () {
11
+ (0, _chai.expect)(await (0, _serviceHost.getNIPSubdomain)('192.168.1.10')).to.equal('192.168.1.10.nip.io');
12
+ });
13
+ it('should fallback to localhost when a hostname is passed instead of an IP address', async function () {
14
+ process.env.NAVY_EXTERNAL_IP = 'somehostname';
15
+ (0, _chai.expect)(await (0, _serviceHost.getNIPSubdomain)('somehostname')).to.equal('127.0.0.1.nip.io');
16
+ });
65
17
  });
66
-
67
18
  describe('createHostForService', function () {
68
-
69
- it('should return the correct host for a service', (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee3() {
70
- return _regenerator2.default.wrap(function _callee3$(_context3) {
71
- while (1) {
72
- switch (_context3.prev = _context3.next) {
73
- case 0:
74
- _context3.t0 = _chai.expect;
75
- _context3.next = 3;
76
- return (0, _serviceHost.createHostForService)('someservice', 'mynavy', '127.0.0.1');
77
-
78
- case 3:
79
- _context3.t1 = _context3.sent;
80
- (0, _context3.t0)(_context3.t1).to.equal('someservice.mynavy.127.0.0.1.nip.io');
81
- _context3.t2 = _chai.expect;
82
- _context3.next = 8;
83
- return (0, _serviceHost.createHostForService)('someservice', 'mynavy', '192.168.1.10');
84
-
85
- case 8:
86
- _context3.t3 = _context3.sent;
87
- (0, _context3.t2)(_context3.t3).to.equal('someservice.mynavy.192.168.1.10.nip.io');
88
-
89
- case 10:
90
- case 'end':
91
- return _context3.stop();
92
- }
93
- }
94
- }, _callee3, this);
95
- })));
19
+ it('should return the correct host for a service', async function () {
20
+ (0, _chai.expect)(await (0, _serviceHost.createHostForService)('someservice', 'mynavy', '127.0.0.1')).to.equal('someservice.mynavy.127.0.0.1.nip.io');
21
+ (0, _chai.expect)(await (0, _serviceHost.createHostForService)('someservice', 'mynavy', '192.168.1.10')).to.equal('someservice.mynavy.192.168.1.10.nip.io');
22
+ });
96
23
  });
97
-
98
24
  describe('createUrlForService', function () {
99
-
100
- it('should return the correct url for a service', (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee4() {
101
- return _regenerator2.default.wrap(function _callee4$(_context4) {
102
- while (1) {
103
- switch (_context4.prev = _context4.next) {
104
- case 0:
105
- _context4.t0 = _chai.expect;
106
- _context4.next = 3;
107
- return (0, _serviceHost.createUrlForService)('someservice', 'mynavy', '192.168.99.100');
108
-
109
- case 3:
110
- _context4.t1 = _context4.sent;
111
- (0, _context4.t0)(_context4.t1).to.equal('http://someservice.mynavy.192.168.99.100.nip.io');
112
-
113
- case 5:
114
- case 'end':
115
- return _context4.stop();
116
- }
117
- }
118
- }, _callee4, this);
119
- })));
25
+ it('should return the correct url for a service', async function () {
26
+ (0, _chai.expect)(await (0, _serviceHost.createUrlForService)('someservice', 'mynavy', '192.168.99.100')).to.equal('http://someservice.mynavy.192.168.99.100.nip.io');
27
+ });
120
28
  });
121
-
122
29
  describe('getUrlFromService', function () {
123
-
124
30
  it('should extract the host from service ENV config', function () {
125
- var service = {
31
+ const service = {
126
32
  raw: {
127
33
  Config: {
128
34
  Env: ['VIRTUAL_HOST=myservice.coolnavy.127.0.0.1.nip.io']
129
35
  }
130
36
  }
131
37
  };
132
-
133
38
  (0, _chai.expect)((0, _serviceHost.getUrlFromService)(service)).to.equal('http://myservice.coolnavy.127.0.0.1.nip.io');
134
39
  });
135
-
136
40
  it('should return null when the service object is not valid', function () {
137
- var service = {
41
+ const service = {
138
42
  raw: {
139
43
  Config: {}
140
44
  }
141
45
  };
142
-
143
46
  (0, _chai.expect)((0, _serviceHost.getUrlFromService)(service)).to.equal(null);
144
47
  (0, _chai.expect)((0, _serviceHost.getUrlFromService)(undefined)).to.equal(null);
145
48
  });
@@ -1,22 +1,19 @@
1
- 'use strict';
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
2
4
 
3
5
  Object.defineProperty(exports, "__esModule", {
4
6
  value: true
5
7
  });
8
+ exports.default = void 0;
6
9
 
7
- var _dockerode = require('dockerode');
8
-
9
- var _dockerode2 = _interopRequireDefault(_dockerode);
10
-
11
- var _bluebird = require('bluebird');
10
+ var _dockerode = _interopRequireDefault(require("dockerode"));
12
11
 
13
- var _bluebird2 = _interopRequireDefault(_bluebird);
12
+ var _bluebird = _interopRequireDefault(require("bluebird"));
14
13
 
15
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
16
-
17
- var dockerClient = new _dockerode2.default({
18
- Promise: _bluebird2.default
14
+ const dockerClient = new _dockerode.default({
15
+ Promise: _bluebird.default
19
16
  });
20
-
21
- exports.default = dockerClient;
17
+ var _default = dockerClient;
18
+ exports.default = _default;
22
19
  module.exports = exports.default;
@@ -1,45 +1,27 @@
1
- 'use strict';
1
+ "use strict";
2
2
 
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
-
7
- var _promise = require('babel-runtime/core-js/promise');
8
-
9
- var _promise2 = _interopRequireDefault(_promise);
10
-
11
6
  exports.execAsync = execAsync;
12
7
 
13
- var _child_process = require('child_process');
14
-
15
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
16
-
17
- var debug = require('debug')('navy:exec');
8
+ var _child_process = require("child_process");
18
9
 
19
- function execAsync(command) {
20
- var args = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
21
- var callback = arguments[2];
22
- var opts = arguments[3];
23
-
24
- return new _promise2.default(function (resolve, reject) {
25
- var cmd = command + ' ' + args.join(' ');
10
+ const debug = require('debug')('navy:exec');
26
11
 
12
+ function execAsync(command, args = [], callback, opts) {
13
+ return new Promise((resolve, reject) => {
14
+ const cmd = command + ' ' + args.join(' ');
27
15
  debug('Executing ' + cmd);
28
-
29
- var childProcess = (0, _child_process.exec)(cmd, opts, function (err, stdout, stderr) {
16
+ const childProcess = (0, _child_process.exec)(cmd, opts, (err, stdout, stderr) => {
30
17
  if (err) {
31
18
  reject(err);
32
19
  } else {
33
20
  resolve(stdout.toString());
34
21
  }
35
22
  });
36
-
37
- childProcess.stdout.on('data', function (line) {
38
- return debug('out: ' + line.toString());
39
- });
40
- childProcess.stderr.on('data', function (line) {
41
- return debug('err: ' + line.toString());
42
- });
23
+ childProcess.stdout.on('data', line => debug('out: ' + line.toString()));
24
+ childProcess.stderr.on('data', line => debug('err: ' + line.toString()));
43
25
 
44
26
  if (callback) {
45
27
  callback(childProcess);
@@ -1,134 +1,56 @@
1
- 'use strict';
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
2
4
 
3
5
  Object.defineProperty(exports, "__esModule", {
4
6
  value: true
5
7
  });
6
- exports.getExternalIP = exports.dnsLookup = undefined;
7
-
8
- var _regenerator = require('babel-runtime/regenerator');
9
-
10
- var _regenerator2 = _interopRequireDefault(_regenerator);
11
-
12
- var _promise = require('babel-runtime/core-js/promise');
13
-
14
- var _promise2 = _interopRequireDefault(_promise);
15
-
16
- var _asyncToGenerator2 = require('babel-runtime/helpers/asyncToGenerator');
17
-
18
- var _asyncToGenerator3 = _interopRequireDefault(_asyncToGenerator2);
19
-
20
- var dnsLookup = exports.dnsLookup = function () {
21
- var _ref = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee(hostname) {
22
- return _regenerator2.default.wrap(function _callee$(_context) {
23
- while (1) {
24
- switch (_context.prev = _context.next) {
25
- case 0:
26
- _context.next = 2;
27
- return new _promise2.default(function (resolve, reject) {
28
- _dns2.default.lookup(hostname, null, function (err, ip, ipFamily) {
29
- if (err || ipFamily !== IPV4_FAMILY) {
30
- reject(new Error('Failed to lookup hostname "' + hostname + '"'));
31
- } else {
32
- resolve(ip);
33
- }
34
- });
35
- });
36
-
37
- case 2:
38
- return _context.abrupt('return', _context.sent);
39
-
40
- case 3:
41
- case 'end':
42
- return _context.stop();
43
- }
44
- }
45
- }, _callee, this);
46
- }));
47
-
48
- return function dnsLookup(_x) {
49
- return _ref.apply(this, arguments);
50
- };
51
- }();
52
-
53
- var getExternalIP = exports.getExternalIP = function () {
54
- var _ref2 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee2(ipInConfig) {
55
- var dockerHost, ip;
56
- return _regenerator2.default.wrap(function _callee2$(_context2) {
57
- while (1) {
58
- switch (_context2.prev = _context2.next) {
59
- case 0:
60
- dockerHost = process.env.DOCKER_HOST;
61
-
62
- // DEPRECATED use NAVY_EXTERNAL_IP instead
63
-
64
- if (!process.env.NAVY_HOST) {
65
- _context2.next = 3;
66
- break;
67
- }
8
+ exports.dnsLookup = dnsLookup;
9
+ exports.getExternalIP = getExternalIP;
68
10
 
69
- return _context2.abrupt('return', process.env.NAVY_HOST);
11
+ var _dns = _interopRequireDefault(require("dns"));
70
12
 
71
- case 3:
72
- if (!process.env.NAVY_EXTERNAL_IP) {
73
- _context2.next = 5;
74
- break;
75
- }
13
+ const IPV4_FAMILY = 4;
76
14
 
77
- return _context2.abrupt('return', process.env.NAVY_EXTERNAL_IP);
78
-
79
- case 5:
80
- if (!ipInConfig) {
81
- _context2.next = 9;
82
- break;
83
- }
84
-
85
- _context2.next = 8;
86
- return dnsLookup(ipInConfig);
87
-
88
- case 8:
89
- return _context2.abrupt('return', _context2.sent);
90
-
91
- case 9:
92
- if (!(dockerHost && dockerHost.indexOf('tcp://') !== -1)) {
93
- _context2.next = 16;
94
- break;
95
- }
96
-
97
- // OSX with docker-machine, or a remote docker
98
- // dockerHost will be formatted like:
99
- // tcp://_._._._:_
100
- // We only care about the IP address
101
-
102
- ip = dockerHost.substring('tcp://'.length);
103
-
104
- ip = ip.substring(0, ip.lastIndexOf(':')).trim();
105
- _context2.next = 14;
106
- return dnsLookup(ip);
107
-
108
- case 14:
109
- ip = _context2.sent;
110
- return _context2.abrupt('return', ip);
111
-
112
- case 16:
113
- return _context2.abrupt('return', '127.0.0.1');
114
-
115
- case 17:
116
- case 'end':
117
- return _context2.stop();
118
- }
15
+ async function dnsLookup(hostname) {
16
+ return await new Promise((resolve, reject) => {
17
+ _dns.default.lookup(hostname, null, (err, ip, ipFamily) => {
18
+ if (err || ipFamily !== IPV4_FAMILY) {
19
+ reject(new Error('Failed to lookup hostname "' + hostname + '"'));
20
+ } else {
21
+ resolve(ip);
119
22
  }
120
- }, _callee2, this);
121
- }));
122
-
123
- return function getExternalIP(_x2) {
124
- return _ref2.apply(this, arguments);
125
- };
126
- }();
127
-
128
- var _dns = require('dns');
129
-
130
- var _dns2 = _interopRequireDefault(_dns);
131
-
132
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
133
-
134
- var IPV4_FAMILY = 4;
23
+ });
24
+ });
25
+ }
26
+
27
+ async function getExternalIP(ipInConfig) {
28
+ const dockerHost = process.env.DOCKER_HOST; // DEPRECATED use NAVY_EXTERNAL_IP instead
29
+
30
+ if (process.env.NAVY_HOST) {
31
+ return process.env.NAVY_HOST;
32
+ }
33
+
34
+ if (process.env.NAVY_EXTERNAL_IP) {
35
+ // Custom external IP
36
+ return process.env.NAVY_EXTERNAL_IP;
37
+ }
38
+
39
+ if (ipInConfig) {
40
+ return await dnsLookup(ipInConfig);
41
+ }
42
+
43
+ if (dockerHost && dockerHost.indexOf('tcp://') !== -1) {
44
+ // OSX with docker-machine, or a remote docker
45
+ // dockerHost will be formatted like:
46
+ // tcp://_._._._:_
47
+ // We only care about the IP address
48
+ let ip = dockerHost.substring('tcp://'.length);
49
+ ip = ip.substring(0, ip.lastIndexOf(':')).trim();
50
+ ip = await dnsLookup(ip);
51
+ return ip;
52
+ } // No custom docker host, assume localhost
53
+
54
+
55
+ return '127.0.0.1';
56
+ }
package/lib/util/fs.js CHANGED
@@ -1,14 +1,15 @@
1
- 'use strict';
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
2
4
 
3
5
  Object.defineProperty(exports, "__esModule", {
4
6
  value: true
5
7
  });
8
+ exports.default = void 0;
6
9
 
7
- var _bluebird = require('bluebird');
8
-
9
- var _bluebird2 = _interopRequireDefault(_bluebird);
10
+ var _bluebird = _interopRequireDefault(require("bluebird"));
10
11
 
11
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
12
+ var _default = _bluebird.default.promisifyAll(require('fs'));
12
13
 
13
- exports.default = _bluebird2.default.promisifyAll(require('fs'));
14
+ exports.default = _default;
14
15
  module.exports = exports.default;
@@ -1,61 +1,24 @@
1
- 'use strict';
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
2
4
 
3
5
  Object.defineProperty(exports, "__esModule", {
4
6
  value: true
5
7
  });
6
- exports.getLANIP = undefined;
7
-
8
- var _regenerator = require('babel-runtime/regenerator');
9
-
10
- var _regenerator2 = _interopRequireDefault(_regenerator);
11
-
12
- var _promise = require('babel-runtime/core-js/promise');
13
-
14
- var _promise2 = _interopRequireDefault(_promise);
15
-
16
- var _asyncToGenerator2 = require('babel-runtime/helpers/asyncToGenerator');
17
-
18
- var _asyncToGenerator3 = _interopRequireDefault(_asyncToGenerator2);
8
+ exports.getLANIP = getLANIP;
19
9
 
20
- var getLANIP = exports.getLANIP = function () {
21
- var _ref = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee() {
22
- return _regenerator2.default.wrap(function _callee$(_context) {
23
- while (1) {
24
- switch (_context.prev = _context.next) {
25
- case 0:
26
- _context.next = 2;
27
- return new _promise2.default(function (resolve, reject) {
28
- _dns2.default.lookup(_os2.default.hostname(), null, function (err, addr) {
29
- if (err) {
30
- return reject(err);
31
- }
10
+ var _dns = _interopRequireDefault(require("dns"));
32
11
 
33
- return resolve(addr);
34
- });
35
- });
12
+ var _os = _interopRequireDefault(require("os"));
36
13
 
37
- case 2:
38
- return _context.abrupt('return', _context.sent);
39
-
40
- case 3:
41
- case 'end':
42
- return _context.stop();
43
- }
14
+ async function getLANIP() {
15
+ return await new Promise((resolve, reject) => {
16
+ _dns.default.lookup(_os.default.hostname(), null, (err, addr) => {
17
+ if (err) {
18
+ return reject(err);
44
19
  }
45
- }, _callee, this);
46
- }));
47
-
48
- return function getLANIP() {
49
- return _ref.apply(this, arguments);
50
- };
51
- }();
52
-
53
- var _dns = require('dns');
54
-
55
- var _dns2 = _interopRequireDefault(_dns);
56
-
57
- var _os = require('os');
58
-
59
- var _os2 = _interopRequireDefault(_os);
60
20
 
61
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
21
+ return resolve(addr);
22
+ });
23
+ });
24
+ }