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.
- package/lib/cli/config/index.js +57 -241
- package/lib/cli/config/wrapper.js +12 -36
- package/lib/cli/develop.js +63 -167
- package/lib/cli/doctor/clean-compose-files.js +19 -73
- package/lib/cli/doctor/index.js +34 -154
- package/lib/cli/doctor/invalid-compose-config.js +20 -110
- package/lib/cli/doctor/invalid-state.js +22 -115
- package/lib/cli/doctor/util.js +26 -93
- package/lib/cli/external-ip.js +9 -39
- package/lib/cli/health.js +18 -67
- package/lib/cli/https.js +92 -0
- package/lib/cli/import.js +22 -59
- package/lib/cli/index.js +11 -17
- package/lib/cli/lan-ip.js +18 -60
- package/lib/cli/launch.js +46 -127
- package/lib/cli/live.js +37 -111
- package/lib/cli/local-ip.js +16 -53
- package/lib/cli/logs.js +7 -35
- package/lib/cli/open.js +11 -45
- package/lib/cli/program.js +145 -167
- package/lib/cli/ps.js +36 -105
- package/lib/cli/refresh-config.js +18 -62
- package/lib/cli/run.js +8 -39
- package/lib/cli/status.js +41 -201
- package/lib/cli/updates.js +68 -160
- package/lib/cli/util/get-or-initialise-navy.js +14 -57
- package/lib/cli/util/import.js +33 -83
- package/lib/cli/util/index.js +10 -12
- package/lib/cli/util/reconfigure.js +12 -102
- package/lib/cli/wait-for-healthy.js +53 -100
- package/lib/config-provider.js +25 -127
- package/lib/config-providers/filesystem/index.js +58 -235
- package/lib/config-providers/npm/__tests__/util.js +3 -6
- package/lib/config-providers/npm/index.js +60 -231
- package/lib/config-providers/npm/util.js +6 -9
- package/lib/config.js +39 -76
- package/lib/driver-logging.js +23 -28
- package/lib/driver.js +5 -7
- package/lib/drivers/docker-compose/client.js +64 -172
- package/lib/drivers/docker-compose/index.js +153 -464
- package/lib/errors.js +27 -61
- package/lib/http-proxy.js +72 -158
- package/lib/index.js +26 -29
- package/lib/middleware/add-service-proxy-config.js +76 -0
- package/lib/middleware/develop.js +9 -23
- package/lib/middleware/helpers.js +20 -25
- package/lib/middleware/port-override.js +15 -37
- package/lib/middleware/set-env-vars.js +14 -18
- package/lib/middleware/set-image.js +12 -18
- package/lib/middleware/set-logging-driver.js +14 -18
- package/lib/middleware/tag-override.js +11 -19
- package/lib/navy/default-middleware.js +13 -27
- package/lib/navy/index.js +438 -1761
- package/lib/navy/middleware.js +15 -100
- package/lib/navy/plugin-interface.js +28 -108
- package/lib/navy/state.js +58 -147
- package/lib/navy/util.js +2 -1
- package/lib/service.js +5 -3
- package/lib/util/__tests__/external-ip.js +20 -96
- package/lib/util/__tests__/registry-client.js +11 -24
- package/lib/util/__tests__/service-host.js +19 -116
- package/lib/util/docker-client.js +10 -13
- package/lib/util/exec-async.js +9 -27
- package/lib/util/external-ip.js +48 -126
- package/lib/util/fs.js +7 -6
- package/lib/util/get-lan-ip.js +15 -52
- package/lib/util/has-update.js +23 -73
- package/lib/util/https.js +213 -0
- package/lib/util/navyrc.js +12 -50
- package/lib/util/registry-client.js +41 -112
- package/lib/util/service-host.js +40 -129
- package/lib/util/table.js +11 -21
- package/package.json +14 -14
- package/LICENSE +0 -21
- package/lib/middleware/add-virtual-hosts.js +0 -147
|
@@ -1,17 +1,16 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
2
|
|
|
3
|
-
var _chai = require(
|
|
3
|
+
var _chai = require("chai");
|
|
4
4
|
|
|
5
|
-
var _registryClient = require(
|
|
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)({
|
|
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)(
|
|
64
|
-
|
|
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
|
-
|
|
1
|
+
"use strict";
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chai = require("chai");
|
|
4
4
|
|
|
5
|
-
var
|
|
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
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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
|
-
|
|
70
|
-
|
|
71
|
-
|
|
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
|
-
|
|
101
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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(
|
|
8
|
-
|
|
9
|
-
var _dockerode2 = _interopRequireDefault(_dockerode);
|
|
10
|
-
|
|
11
|
-
var _bluebird = require('bluebird');
|
|
10
|
+
var _dockerode = _interopRequireDefault(require("dockerode"));
|
|
12
11
|
|
|
13
|
-
var
|
|
12
|
+
var _bluebird = _interopRequireDefault(require("bluebird"));
|
|
14
13
|
|
|
15
|
-
|
|
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 =
|
|
17
|
+
var _default = dockerClient;
|
|
18
|
+
exports.default = _default;
|
|
22
19
|
module.exports = exports.default;
|
package/lib/util/exec-async.js
CHANGED
|
@@ -1,45 +1,27 @@
|
|
|
1
|
-
|
|
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(
|
|
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
|
-
|
|
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.
|
|
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);
|
package/lib/util/external-ip.js
CHANGED
|
@@ -1,134 +1,56 @@
|
|
|
1
|
-
|
|
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.
|
|
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
|
-
|
|
11
|
+
var _dns = _interopRequireDefault(require("dns"));
|
|
70
12
|
|
|
71
|
-
|
|
72
|
-
if (!process.env.NAVY_EXTERNAL_IP) {
|
|
73
|
-
_context2.next = 5;
|
|
74
|
-
break;
|
|
75
|
-
}
|
|
13
|
+
const IPV4_FAMILY = 4;
|
|
76
14
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
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
|
-
}
|
|
121
|
-
})
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
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
|
-
|
|
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(
|
|
8
|
-
|
|
9
|
-
var _bluebird2 = _interopRequireDefault(_bluebird);
|
|
10
|
+
var _bluebird = _interopRequireDefault(require("bluebird"));
|
|
10
11
|
|
|
11
|
-
|
|
12
|
+
var _default = _bluebird.default.promisifyAll(require('fs'));
|
|
12
13
|
|
|
13
|
-
exports.default =
|
|
14
|
+
exports.default = _default;
|
|
14
15
|
module.exports = exports.default;
|
package/lib/util/get-lan-ip.js
CHANGED
|
@@ -1,61 +1,24 @@
|
|
|
1
|
-
|
|
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 =
|
|
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
|
|
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
|
-
|
|
34
|
-
});
|
|
35
|
-
});
|
|
12
|
+
var _os = _interopRequireDefault(require("os"));
|
|
36
13
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
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
|
-
|
|
21
|
+
return resolve(addr);
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
}
|