navy 6.0.0 → 7.0.0-alpha.2
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/__tests__/config-provider.js +75 -0
- package/lib/__tests__/config.js +130 -0
- package/lib/__tests__/driver-logging.js +148 -0
- package/lib/__tests__/driver.js +19 -0
- package/lib/__tests__/errors.js +49 -0
- package/lib/__tests__/http-proxy.js +214 -0
- package/lib/__tests__/index.js +25 -0
- package/lib/__tests__/service.js +16 -0
- package/lib/cli/__tests__/develop.js +239 -0
- package/lib/cli/__tests__/external-ip.js +68 -0
- package/lib/cli/__tests__/health.js +257 -0
- package/lib/cli/__tests__/https.js +210 -0
- package/lib/cli/__tests__/import.js +110 -0
- package/lib/cli/__tests__/index.js +118 -0
- package/lib/cli/__tests__/lan-ip.js +90 -0
- package/lib/cli/__tests__/launch.js +179 -0
- package/lib/cli/__tests__/live.js +155 -0
- package/lib/cli/__tests__/local-ip.js +72 -0
- package/lib/cli/__tests__/logs.js +52 -0
- package/lib/cli/__tests__/open.js +65 -0
- package/lib/cli/__tests__/program.js +472 -0
- package/lib/cli/__tests__/ps.js +345 -0
- package/lib/cli/__tests__/refresh-config.js +95 -0
- package/lib/cli/__tests__/run.js +54 -0
- package/lib/cli/__tests__/status.js +204 -0
- package/lib/cli/__tests__/updates.js +243 -0
- package/lib/cli/__tests__/wait-for-healthy.js +134 -0
- package/lib/cli/config/__tests__/index.js +275 -0
- package/lib/cli/config/__tests__/wrapper.js +53 -0
- package/lib/cli/config/index.js +19 -37
- package/lib/cli/config/wrapper.js +0 -6
- package/lib/cli/develop.js +7 -21
- package/lib/cli/doctor/__tests__/clean-compose-files.js +78 -0
- package/lib/cli/doctor/__tests__/index.js +67 -0
- package/lib/cli/doctor/__tests__/invalid-compose-config.js +103 -0
- package/lib/cli/doctor/__tests__/invalid-state.js +83 -0
- package/lib/cli/doctor/__tests__/util.js +91 -0
- package/lib/cli/doctor/clean-compose-files.js +5 -13
- package/lib/cli/doctor/index.js +0 -12
- package/lib/cli/doctor/invalid-compose-config.js +0 -4
- package/lib/cli/doctor/invalid-state.js +0 -6
- package/lib/cli/doctor/util.js +0 -10
- package/lib/cli/external-ip.js +0 -4
- package/lib/cli/health.js +0 -12
- package/lib/cli/https.js +9 -25
- package/lib/cli/import.js +0 -12
- package/lib/cli/index.js +0 -9
- package/lib/cli/lan-ip.js +2 -8
- package/lib/cli/launch.js +0 -9
- package/lib/cli/live.js +6 -16
- package/lib/cli/local-ip.js +2 -7
- package/lib/cli/logs.js +0 -3
- package/lib/cli/open.js +2 -7
- package/lib/cli/program.js +73 -101
- package/lib/cli/ps.js +1 -21
- package/lib/cli/refresh-config.js +0 -7
- package/lib/cli/run.js +0 -3
- package/lib/cli/status.js +0 -11
- package/lib/cli/updates.js +0 -22
- package/lib/cli/util/__tests__/get-or-initialise-navy.js +66 -0
- package/lib/cli/util/__tests__/import.js +123 -0
- package/lib/cli/util/__tests__/index.js +17 -0
- package/lib/cli/util/__tests__/merge-action-options.js +47 -0
- package/lib/cli/util/__tests__/reconfigure.js +78 -0
- package/lib/cli/util/get-or-initialise-navy.js +0 -7
- package/lib/cli/util/import.js +0 -9
- package/lib/cli/util/index.js +0 -2
- package/lib/cli/util/merge-action-options.js +20 -0
- package/lib/cli/util/reconfigure.js +0 -4
- package/lib/cli/wait-for-healthy.js +0 -21
- package/lib/client/registry/__tests__/get-credentials.js +62 -0
- package/lib/client/registry/__tests__/get-endpoint.js +124 -0
- package/lib/client/registry/__tests__/get-fat-manifest.js +67 -0
- package/lib/client/registry/__tests__/get-token.js +66 -0
- package/lib/client/registry/__tests__/helpers.js +26 -0
- package/lib/client/registry/get-credentials.js +3 -9
- package/lib/client/registry/get-endpoint.js +29 -63
- package/lib/client/registry/get-fat-manifest.js +2 -9
- package/lib/client/registry/get-token.js +2 -13
- package/lib/client/registry/helpers.js +0 -4
- package/lib/config-provider.js +0 -12
- package/lib/config-providers/filesystem/__tests__/index.js +176 -0
- package/lib/config-providers/filesystem/index.js +5 -23
- package/lib/config-providers/npm/__tests__/index.js +226 -0
- package/lib/config-providers/npm/__tests__/util.js +1 -2
- package/lib/config-providers/npm/index.js +12 -35
- package/lib/config-providers/npm/util.js +0 -3
- package/lib/config.js +4 -19
- package/lib/domain/__tests__/container-image.js +81 -0
- package/lib/domain/__tests__/oci-api-specification.js +23 -0
- package/lib/domain/container-image.js +8 -21
- package/lib/domain/oci-api-specification.js +3 -5
- package/lib/driver-logging.js +0 -19
- package/lib/driver.js +0 -4
- package/lib/drivers/docker-compose/__tests__/client.js +249 -0
- package/lib/drivers/docker-compose/__tests__/index.js +430 -0
- package/lib/drivers/docker-compose/client.js +0 -16
- package/lib/drivers/docker-compose/index.js +7 -49
- package/lib/errors.js +0 -10
- package/lib/http-proxy.js +28 -23
- package/lib/index.js +1 -9
- package/lib/middleware/__tests__/add-service-proxy-config.js +258 -0
- package/lib/middleware/__tests__/develop.js +120 -0
- package/lib/middleware/__tests__/helpers.js +154 -0
- package/lib/middleware/__tests__/port-override.js +125 -0
- package/lib/middleware/__tests__/set-env-vars.js +94 -0
- package/lib/middleware/__tests__/set-image.js +76 -0
- package/lib/middleware/__tests__/set-logging-driver.js +94 -0
- package/lib/middleware/__tests__/tag-override.js +92 -0
- package/lib/middleware/add-service-proxy-config.js +8 -16
- package/lib/middleware/develop.js +2 -5
- package/lib/middleware/helpers.js +6 -12
- package/lib/middleware/port-override.js +5 -8
- package/lib/middleware/set-env-vars.js +6 -6
- package/lib/middleware/set-image.js +4 -5
- package/lib/middleware/set-logging-driver.js +6 -6
- package/lib/middleware/tag-override.js +4 -6
- package/lib/navy/__tests__/default-middleware.js +40 -0
- package/lib/navy/__tests__/index.js +1612 -0
- package/lib/navy/__tests__/middleware.js +71 -0
- package/lib/navy/__tests__/plugin-interface.js +121 -0
- package/lib/navy/__tests__/state.js +103 -0
- package/lib/navy/__tests__/util.js +24 -0
- package/lib/navy/default-middleware.js +0 -10
- package/lib/navy/index.js +83 -138
- package/lib/navy/middleware.js +0 -6
- package/lib/navy/plugin-interface.js +2 -10
- package/lib/navy/state.js +12 -24
- package/lib/navy/util.js +0 -1
- package/lib/service.js +2 -3
- package/lib/util/__tests__/exec-async.js +83 -0
- package/lib/util/__tests__/external-ip.js +97 -2
- package/lib/util/__tests__/get-lan-ip.js +46 -0
- package/lib/util/__tests__/has-update.js +136 -0
- package/lib/util/__tests__/https.js +301 -0
- package/lib/util/__tests__/navyrc.js +45 -0
- package/lib/util/__tests__/service-host.js +63 -5
- package/lib/util/__tests__/table.js +44 -0
- package/lib/util/docker-client.js +2 -10
- package/lib/util/exec-async.js +0 -4
- package/lib/util/external-ip.js +8 -12
- package/lib/util/fs.js +1 -6
- package/lib/util/get-lan-ip.js +0 -5
- package/lib/util/has-update.js +2 -14
- package/lib/util/https.js +11 -55
- package/lib/util/navyrc.js +0 -5
- package/lib/util/service-host.js +0 -17
- package/lib/util/table.js +0 -6
- package/package.json +14 -13
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
var _chai = require("chai");
|
|
5
|
+
var _sinon = _interopRequireDefault(require("sinon"));
|
|
6
|
+
var _util = require("../util");
|
|
7
|
+
/* eslint-env mocha */
|
|
8
|
+
|
|
9
|
+
describe('cli/doctor/util', function () {
|
|
10
|
+
let sandbox;
|
|
11
|
+
let consoleLogStub;
|
|
12
|
+
beforeEach(function () {
|
|
13
|
+
sandbox = _sinon.default.createSandbox();
|
|
14
|
+
consoleLogStub = sandbox.stub(console, 'log');
|
|
15
|
+
});
|
|
16
|
+
afterEach(function () {
|
|
17
|
+
sandbox.restore();
|
|
18
|
+
});
|
|
19
|
+
describe('fix', function () {
|
|
20
|
+
it('should throw an invariant violation when no callback is provided', async function () {
|
|
21
|
+
let caught;
|
|
22
|
+
try {
|
|
23
|
+
await (0, _util.fix)('a message');
|
|
24
|
+
} catch (err) {
|
|
25
|
+
caught = err;
|
|
26
|
+
}
|
|
27
|
+
(0, _chai.expect)(caught).to.be.an('error');
|
|
28
|
+
(0, _chai.expect)(caught.message).to.contain('DOCTOR_FIX_NO_PARAMS');
|
|
29
|
+
});
|
|
30
|
+
it('should print the formatted message and call the callback', async function () {
|
|
31
|
+
const callback = sandbox.stub().resolves();
|
|
32
|
+
await (0, _util.fix)('Found %s, removing', 'env-1', callback);
|
|
33
|
+
(0, _chai.expect)(consoleLogStub.calledOnce).to.equal(true);
|
|
34
|
+
const printed = consoleLogStub.firstCall.args[0];
|
|
35
|
+
(0, _chai.expect)(printed).to.contain('Found env-1, removing');
|
|
36
|
+
(0, _chai.expect)(callback.calledOnce).to.equal(true);
|
|
37
|
+
});
|
|
38
|
+
it('should await the callback before resolving', async function () {
|
|
39
|
+
let resolved = false;
|
|
40
|
+
const callback = sandbox.stub().callsFake(() => new Promise(resolve => {
|
|
41
|
+
setImmediate(() => {
|
|
42
|
+
resolved = true;
|
|
43
|
+
resolve();
|
|
44
|
+
});
|
|
45
|
+
}));
|
|
46
|
+
await (0, _util.fix)('msg', callback);
|
|
47
|
+
(0, _chai.expect)(resolved).to.equal(true);
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
describe('start', function () {
|
|
51
|
+
it('should log a dimmed message with arrow prefix', function () {
|
|
52
|
+
(0, _util.start)('Doing thing');
|
|
53
|
+
(0, _chai.expect)(consoleLogStub.calledOnce).to.equal(true);
|
|
54
|
+
const printed = consoleLogStub.getCalls().map(c => c.args.join(' ')).join(' ');
|
|
55
|
+
(0, _chai.expect)(printed).to.contain('----->');
|
|
56
|
+
(0, _chai.expect)(printed).to.contain('Doing thing');
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
describe('catchInvariant', function () {
|
|
60
|
+
it('should call the catch callback when fn throws an Invariant Violation matching the code', async function () {
|
|
61
|
+
const catchCallback = sandbox.stub().resolves();
|
|
62
|
+
const err = new Error('MY_CODE: failure happened');
|
|
63
|
+
err.name = 'Invariant Violation';
|
|
64
|
+
await (0, _util.catchInvariant)('MY_CODE', async () => {
|
|
65
|
+
throw err;
|
|
66
|
+
}, catchCallback);
|
|
67
|
+
(0, _chai.expect)(catchCallback.calledOnce).to.equal(true);
|
|
68
|
+
});
|
|
69
|
+
it('should not call the catch callback when fn throws a non-invariant error', async function () {
|
|
70
|
+
const catchCallback = sandbox.stub().resolves();
|
|
71
|
+
await (0, _util.catchInvariant)('MY_CODE', async () => {
|
|
72
|
+
throw new Error('some other error');
|
|
73
|
+
}, catchCallback);
|
|
74
|
+
(0, _chai.expect)(catchCallback.called).to.equal(false);
|
|
75
|
+
});
|
|
76
|
+
it('should not call the catch callback when invariant code does not match', async function () {
|
|
77
|
+
const catchCallback = sandbox.stub().resolves();
|
|
78
|
+
const err = new Error('OTHER_CODE: failure');
|
|
79
|
+
err.name = 'Invariant Violation';
|
|
80
|
+
await (0, _util.catchInvariant)('MY_CODE', async () => {
|
|
81
|
+
throw err;
|
|
82
|
+
}, catchCallback);
|
|
83
|
+
(0, _chai.expect)(catchCallback.called).to.equal(false);
|
|
84
|
+
});
|
|
85
|
+
it('should not call the catch callback when fn resolves without throwing', async function () {
|
|
86
|
+
const catchCallback = sandbox.stub().resolves();
|
|
87
|
+
await (0, _util.catchInvariant)('MY_CODE', async () => undefined, catchCallback);
|
|
88
|
+
(0, _chai.expect)(catchCallback.called).to.equal(false);
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
});
|
|
@@ -1,33 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.default = _default;
|
|
9
|
-
|
|
10
|
-
var _bluebird = _interopRequireDefault(require("bluebird"));
|
|
11
|
-
|
|
12
8
|
var _path = _interopRequireDefault(require("path"));
|
|
13
|
-
|
|
9
|
+
var _fs = require("fs");
|
|
14
10
|
var _ = require("../../");
|
|
15
|
-
|
|
16
11
|
var _util = require("./util");
|
|
17
|
-
|
|
18
12
|
var _state = require("../../navy/state");
|
|
19
|
-
|
|
20
13
|
var _util2 = require("../../navy/util");
|
|
21
|
-
|
|
22
14
|
async function _default() {
|
|
23
|
-
const rimraf = _bluebird.default.promisify(require('rimraf'));
|
|
24
|
-
|
|
25
15
|
(0, _util.start)('Cleaning temporary Docker Compose files');
|
|
26
16
|
const navyNames = await (0, _.getLaunchedNavyNames)();
|
|
27
17
|
await Promise.all(navyNames.map(async navyName => {
|
|
28
18
|
const navyPath = (0, _state.pathToNavy)((0, _util2.normaliseNavyName)(navyName));
|
|
29
|
-
await
|
|
19
|
+
await _fs.promises.rm(_path.default.join(navyPath, 'docker-compose.tmp.yml'), {
|
|
20
|
+
recursive: true,
|
|
21
|
+
force: true
|
|
22
|
+
});
|
|
30
23
|
}));
|
|
31
24
|
}
|
|
32
|
-
|
|
33
25
|
module.exports = exports.default;
|
package/lib/cli/doctor/index.js
CHANGED
|
@@ -1,23 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.default = _default;
|
|
9
|
-
|
|
10
8
|
var _chalk = _interopRequireDefault(require("chalk"));
|
|
11
|
-
|
|
12
9
|
var _cleanComposeFiles = _interopRequireDefault(require("./clean-compose-files"));
|
|
13
|
-
|
|
14
10
|
var _invalidState = _interopRequireDefault(require("./invalid-state"));
|
|
15
|
-
|
|
16
11
|
var _invalidComposeConfig = _interopRequireDefault(require("./invalid-compose-config"));
|
|
17
|
-
|
|
18
12
|
async function run(fns) {
|
|
19
13
|
const errors = [];
|
|
20
|
-
|
|
21
14
|
for (const fn of fns) {
|
|
22
15
|
try {
|
|
23
16
|
await fn();
|
|
@@ -25,20 +18,16 @@ async function run(fns) {
|
|
|
25
18
|
errors.push(ex);
|
|
26
19
|
}
|
|
27
20
|
}
|
|
28
|
-
|
|
29
21
|
return errors;
|
|
30
22
|
}
|
|
31
|
-
|
|
32
23
|
async function _default() {
|
|
33
24
|
const errors = await run([_cleanComposeFiles.default, _invalidState.default, _invalidComposeConfig.default]);
|
|
34
|
-
|
|
35
25
|
if (errors.length > 0) {
|
|
36
26
|
console.log(_chalk.default.yellow('There were some issues'));
|
|
37
27
|
console.log();
|
|
38
28
|
errors.forEach(error => console.log(error.stack));
|
|
39
29
|
return;
|
|
40
30
|
}
|
|
41
|
-
|
|
42
31
|
console.log();
|
|
43
32
|
console.log(_chalk.default.green(' ✔ Finished tests'));
|
|
44
33
|
console.log();
|
|
@@ -46,5 +35,4 @@ async function _default() {
|
|
|
46
35
|
console.log(' If you still have problems, please open an issue at https://github.com/moneyhub/navy/issues/new');
|
|
47
36
|
console.log();
|
|
48
37
|
}
|
|
49
|
-
|
|
50
38
|
module.exports = exports.default;
|
|
@@ -4,11 +4,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = _default;
|
|
7
|
-
|
|
8
7
|
var _ = require("../../");
|
|
9
|
-
|
|
10
8
|
var _util = require("./util");
|
|
11
|
-
|
|
12
9
|
async function _default() {
|
|
13
10
|
(0, _util.start)('Checking for Navies with invalid/no compose config');
|
|
14
11
|
const navies = await (0, _.getLaunchedNavies)();
|
|
@@ -22,5 +19,4 @@ async function _default() {
|
|
|
22
19
|
});
|
|
23
20
|
}));
|
|
24
21
|
}
|
|
25
|
-
|
|
26
22
|
module.exports = exports.default;
|
|
@@ -4,24 +4,19 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = _default;
|
|
7
|
-
|
|
8
7
|
var _ = require("../../");
|
|
9
|
-
|
|
10
8
|
var _util = require("./util");
|
|
11
|
-
|
|
12
9
|
async function _default() {
|
|
13
10
|
(0, _util.start)('Checking for dangling Navies');
|
|
14
11
|
const navies = await (0, _.getLaunchedNavies)();
|
|
15
12
|
await Promise.all(navies.map(async navy => {
|
|
16
13
|
const configProvider = await navy.getConfigProvider();
|
|
17
|
-
|
|
18
14
|
if (!configProvider) {
|
|
19
15
|
await (0, _util.fix)('Found Navy without config provider %s, removing', navy.name, async () => {
|
|
20
16
|
await navy.delete();
|
|
21
17
|
});
|
|
22
18
|
return;
|
|
23
19
|
}
|
|
24
|
-
|
|
25
20
|
if (await configProvider.isDangling()) {
|
|
26
21
|
await (0, _util.fix)('Found dangling Navy %s (invalid config), removing', navy.name, async () => {
|
|
27
22
|
await navy.destroy();
|
|
@@ -29,5 +24,4 @@ async function _default() {
|
|
|
29
24
|
}
|
|
30
25
|
}));
|
|
31
26
|
}
|
|
32
|
-
|
|
33
27
|
module.exports = exports.default;
|
package/lib/cli/doctor/util.js
CHANGED
|
@@ -1,33 +1,24 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.start = exports.fix = exports.catchInvariant = void 0;
|
|
9
|
-
|
|
10
8
|
var _util = _interopRequireDefault(require("util"));
|
|
11
|
-
|
|
12
9
|
var _invariant = _interopRequireDefault(require("invariant"));
|
|
13
|
-
|
|
14
10
|
var _chalk = _interopRequireDefault(require("chalk"));
|
|
15
|
-
|
|
16
11
|
const fix = async (message, ...params) => {
|
|
17
12
|
(0, _invariant.default)(params.length > 0, "DOCTOR_FIX_NO_PARAMS: Expected params to be passed to doctor fix");
|
|
18
13
|
const fixCallback = params[params.length - 1];
|
|
19
14
|
console.log(_chalk.default.yellow('----->', _util.default.format(message, ...params.slice(0, -1))));
|
|
20
15
|
await fixCallback();
|
|
21
16
|
};
|
|
22
|
-
|
|
23
17
|
exports.fix = fix;
|
|
24
|
-
|
|
25
18
|
const start = message => {
|
|
26
19
|
console.log(_chalk.default.dim('----->', message));
|
|
27
20
|
};
|
|
28
|
-
|
|
29
21
|
exports.start = start;
|
|
30
|
-
|
|
31
22
|
const catchInvariant = async (code, fn, catchCallback) => {
|
|
32
23
|
try {
|
|
33
24
|
await fn();
|
|
@@ -37,5 +28,4 @@ const catchInvariant = async (code, fn, catchCallback) => {
|
|
|
37
28
|
}
|
|
38
29
|
}
|
|
39
30
|
};
|
|
40
|
-
|
|
41
31
|
exports.catchInvariant = catchInvariant;
|
package/lib/cli/external-ip.js
CHANGED
|
@@ -4,15 +4,11 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
7
|
var _config = require("../config");
|
|
9
|
-
|
|
10
8
|
var _externalIp = require("../util/external-ip");
|
|
11
|
-
|
|
12
9
|
var _default = async () => {
|
|
13
10
|
const config = await (0, _config.getConfig)();
|
|
14
11
|
console.log(await (0, _externalIp.getExternalIP)(config.externalIP));
|
|
15
12
|
};
|
|
16
|
-
|
|
17
13
|
exports.default = _default;
|
|
18
14
|
module.exports = exports.default;
|
package/lib/cli/health.js
CHANGED
|
@@ -1,45 +1,33 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.default = _default;
|
|
9
|
-
|
|
10
8
|
var _chalk = _interopRequireDefault(require("chalk"));
|
|
11
|
-
|
|
12
9
|
var _ = require("../");
|
|
13
|
-
|
|
14
10
|
var _table = _interopRequireDefault(require("../util/table"));
|
|
15
|
-
|
|
16
11
|
function getStatus(service, state) {
|
|
17
12
|
const health = service.raw && service.raw.State.Health;
|
|
18
|
-
|
|
19
13
|
if (!health) {
|
|
20
14
|
return '-';
|
|
21
15
|
}
|
|
22
|
-
|
|
23
16
|
const statusString = health.Status === 'healthy' ? _chalk.default.green('✔ Healthy') : _chalk.default.red('• Unhealthy');
|
|
24
17
|
return statusString;
|
|
25
18
|
}
|
|
26
|
-
|
|
27
19
|
function getHistory(service, state) {
|
|
28
20
|
const health = service.raw && service.raw.State.Health;
|
|
29
|
-
|
|
30
21
|
if (!health) {
|
|
31
22
|
return '-';
|
|
32
23
|
}
|
|
33
|
-
|
|
34
24
|
const history = health.Log;
|
|
35
25
|
return history.map(record => record.ExitCode === 0 ? _chalk.default.green('█') : _chalk.default.red('x')).join(' ');
|
|
36
26
|
}
|
|
37
|
-
|
|
38
27
|
async function _default(opts) {
|
|
39
28
|
const navy = (0, _.getNavy)(opts.navy);
|
|
40
29
|
const ps = await navy.ps();
|
|
41
30
|
const state = await navy.getState();
|
|
42
31
|
console.log((0, _table.default)([['NAME', 'STATUS', 'HISTORY'], ...ps.map(service => [service.name, getStatus(service, state), getHistory(service, state)])]));
|
|
43
32
|
}
|
|
44
|
-
|
|
45
33
|
module.exports = exports.default;
|
package/lib/cli/https.js
CHANGED
|
@@ -1,75 +1,60 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.default = _default;
|
|
9
|
-
|
|
10
8
|
var _chalk = _interopRequireDefault(require("chalk"));
|
|
11
|
-
|
|
12
9
|
var _errors = require("../errors");
|
|
13
|
-
|
|
14
10
|
var _navy = require("../navy");
|
|
15
|
-
|
|
16
11
|
var _config = require("../config");
|
|
17
|
-
|
|
18
12
|
var _httpProxy = require("../http-proxy");
|
|
19
|
-
|
|
20
13
|
var _https = require("../util/https");
|
|
21
|
-
|
|
22
14
|
var _fs = _interopRequireDefault(require("fs"));
|
|
23
|
-
|
|
24
15
|
async function _default(services, opts) {
|
|
25
16
|
const tlsRootCaDir = (0, _config.getConfig)().tlsRootCaDir || _config.DEFAULT_TLS_ROOT_CA_DIR;
|
|
26
|
-
|
|
27
17
|
const configDir = (0, _config.getConfigDir)();
|
|
28
|
-
|
|
29
18
|
if (opts.disable) {
|
|
30
19
|
await (0, _https.removeCert)(opts);
|
|
20
|
+
|
|
21
|
+
// Guard isInitialised so `--disable` still works when the navy has
|
|
22
|
+
// never been launched (otherwise getNavyFile throws).
|
|
23
|
+
const navy = await (0, _navy.getNavy)(opts.navy);
|
|
24
|
+
const navyFile = (await navy.isInitialised()) ? await navy.getNavyFile() : undefined;
|
|
31
25
|
await (0, _httpProxy.reconfigureHTTPProxy)({
|
|
32
|
-
restart: true
|
|
26
|
+
restart: true,
|
|
27
|
+
navyFile
|
|
33
28
|
});
|
|
34
29
|
console.log();
|
|
35
30
|
console.log(_chalk.default.green(`✅ HTTPS for service ${opts.disable} is now disabled`));
|
|
36
31
|
console.log();
|
|
37
32
|
return;
|
|
38
33
|
}
|
|
39
|
-
|
|
40
34
|
if (!services || services.length === 0) {
|
|
41
35
|
if (!_fs.default.existsSync(`${configDir}/tls-certs`)) return;
|
|
42
|
-
|
|
43
36
|
const files = _fs.default.readdirSync(`${configDir}/tls-certs`);
|
|
44
|
-
|
|
45
37
|
const urls = files.filter(file => file.endsWith('.crt')).map(crt => {
|
|
46
38
|
return `https://${crt.replace('.crt', '')}`;
|
|
47
39
|
});
|
|
48
|
-
|
|
49
40
|
for (const url of urls) {
|
|
50
41
|
console.log(`${url}`);
|
|
51
42
|
}
|
|
52
|
-
|
|
53
43
|
return;
|
|
54
44
|
}
|
|
55
|
-
|
|
56
45
|
if (!_fs.default.existsSync(`${tlsRootCaDir}/ca.crt`) || !_fs.default.existsSync(`${tlsRootCaDir}/ca.key`)) {
|
|
57
46
|
await (0, _https.generateRootCa)();
|
|
58
47
|
}
|
|
59
|
-
|
|
60
48
|
const navy = await (0, _navy.getNavy)(opts.navy);
|
|
61
49
|
await navy.ensurePluginsLoaded();
|
|
62
50
|
const availableServices = await navy.getAvailableServiceNames();
|
|
63
51
|
const httpsReadyServices = [];
|
|
64
|
-
|
|
65
52
|
for (const service of services) {
|
|
66
53
|
if (!availableServices.includes(service)) {
|
|
67
54
|
console.log(`❌ ${service} not found, skipping`);
|
|
68
55
|
continue;
|
|
69
56
|
}
|
|
70
|
-
|
|
71
57
|
const serviceUrl = await navy.url(service);
|
|
72
|
-
|
|
73
58
|
try {
|
|
74
59
|
await (0, _https.createCert)({
|
|
75
60
|
serviceUrl
|
|
@@ -80,13 +65,12 @@ async function _default(services, opts) {
|
|
|
80
65
|
throw new _errors.NavyError(`Could not generate TLS cert for ${service}`);
|
|
81
66
|
}
|
|
82
67
|
}
|
|
83
|
-
|
|
84
68
|
await (0, _httpProxy.reconfigureHTTPProxy)({
|
|
85
|
-
restart: true
|
|
69
|
+
restart: true,
|
|
70
|
+
navyFile: await navy.getNavyFile()
|
|
86
71
|
});
|
|
87
72
|
console.log();
|
|
88
73
|
console.log(_chalk.default.green(`✅ Service(s) ${httpsReadyServices.join(', ')} now accessible via HTTPS🔒`));
|
|
89
74
|
console.log();
|
|
90
75
|
}
|
|
91
|
-
|
|
92
76
|
module.exports = exports.default;
|
package/lib/cli/import.js
CHANGED
|
@@ -1,38 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.default = _default;
|
|
9
|
-
|
|
10
8
|
var _path = _interopRequireDefault(require("path"));
|
|
11
|
-
|
|
12
9
|
var _chalk = _interopRequireDefault(require("chalk"));
|
|
13
|
-
|
|
14
10
|
var _fs = _interopRequireDefault(require("../util/fs"));
|
|
15
|
-
|
|
16
11
|
var _ = require("../");
|
|
17
|
-
|
|
18
12
|
var _configProvider = require("../config-provider");
|
|
19
|
-
|
|
20
13
|
var _util = require("./util");
|
|
21
|
-
|
|
22
14
|
async function _default(opts) {
|
|
23
15
|
const navy = (0, _.getNavy)(opts.navy);
|
|
24
|
-
|
|
25
16
|
const boatAsciiArt = _fs.default.readFileSync(_path.default.join(__dirname, '../../resources/sailing-boat.txt')).toString();
|
|
26
|
-
|
|
27
17
|
const initialiseOpts = await (0, _configProvider.getImportOptionsForCLI)(opts);
|
|
28
18
|
await (0, _util.importNavy)(navy, initialiseOpts);
|
|
29
19
|
console.log(` You can now use ${_chalk.default.bold('navy')} commands from any directory to control this Navy.`);
|
|
30
20
|
console.log();
|
|
31
|
-
|
|
32
21
|
if (process.stdout.isTTY) {
|
|
33
22
|
console.log(boatAsciiArt);
|
|
34
23
|
console.log();
|
|
35
24
|
}
|
|
36
25
|
}
|
|
37
|
-
|
|
38
26
|
module.exports = exports.default;
|
package/lib/cli/index.js
CHANGED
|
@@ -1,19 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
var _package = _interopRequireDefault(require("../../package.json"));
|
|
6
|
-
|
|
7
5
|
var _program = _interopRequireDefault(require("./program"));
|
|
8
|
-
|
|
9
6
|
var _errors = require("../errors");
|
|
10
|
-
|
|
11
7
|
const debug = require('debug')('navy:cli');
|
|
12
|
-
|
|
13
8
|
_program.default.version(_package.default.version);
|
|
14
|
-
|
|
15
9
|
_program.default.command('help').alias('*').action(() => _program.default.help());
|
|
16
|
-
|
|
17
10
|
try {
|
|
18
11
|
_program.default.parse(process.argv);
|
|
19
12
|
} catch (ex) {
|
|
@@ -23,9 +16,7 @@ try {
|
|
|
23
16
|
throw ex;
|
|
24
17
|
}
|
|
25
18
|
}
|
|
26
|
-
|
|
27
19
|
debug('Invoked CLI action');
|
|
28
|
-
|
|
29
20
|
if (_program.default.args.length === 0) {
|
|
30
21
|
_program.default.help();
|
|
31
22
|
}
|
package/lib/cli/lan-ip.js
CHANGED
|
@@ -1,23 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.default = _default;
|
|
9
|
-
|
|
10
8
|
var _chalk = _interopRequireDefault(require("chalk"));
|
|
11
|
-
|
|
12
9
|
var _getLanIp = require("../util/get-lan-ip");
|
|
13
|
-
|
|
14
10
|
var _config = require("../config");
|
|
15
|
-
|
|
16
11
|
var _reconfigure = require("./util/reconfigure");
|
|
17
|
-
|
|
18
12
|
async function _default(navy) {
|
|
19
13
|
const lanIP = await (0, _getLanIp.getLANIP)();
|
|
20
|
-
await (0, _config.setConfig)({
|
|
14
|
+
await (0, _config.setConfig)({
|
|
15
|
+
...(0, _config.getConfig)(),
|
|
21
16
|
externalIP: lanIP
|
|
22
17
|
});
|
|
23
18
|
await (0, _reconfigure.reconfigureAllNavies)();
|
|
@@ -25,5 +20,4 @@ async function _default(navy) {
|
|
|
25
20
|
console.log(_chalk.default.green(` ✔ Now using your LAN IP address (${lanIP})`));
|
|
26
21
|
console.log();
|
|
27
22
|
}
|
|
28
|
-
|
|
29
23
|
module.exports = exports.default;
|
package/lib/cli/launch.js
CHANGED
|
@@ -1,18 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.default = _default;
|
|
9
|
-
|
|
10
8
|
var _inquirer = _interopRequireDefault(require("inquirer"));
|
|
11
|
-
|
|
12
9
|
var _util = require("./util");
|
|
13
|
-
|
|
14
10
|
var _driverLogging = require("../driver-logging");
|
|
15
|
-
|
|
16
11
|
const SELECTED_WEIGHT = 100; // make sure selected services appear at the top
|
|
17
12
|
|
|
18
13
|
async function _default(services, opts) {
|
|
@@ -22,7 +17,6 @@ async function _default(services, opts) {
|
|
|
22
17
|
const serviceNames = await navy.getAvailableServiceNames();
|
|
23
18
|
const launchedServiceNames = await navy.getLaunchedServiceNames();
|
|
24
19
|
const selectedServiceNames = launchedServiceNames.length > 0 ? launchedServiceNames : navyFile.launchDefaults || [];
|
|
25
|
-
|
|
26
20
|
if (!services || services.length === 0) {
|
|
27
21
|
const choices = serviceNames.sort(name => selectedServiceNames.indexOf(name) === -1 ? SELECTED_WEIGHT : -1).map(name => ({
|
|
28
22
|
name,
|
|
@@ -38,15 +32,12 @@ async function _default(services, opts) {
|
|
|
38
32
|
}]);
|
|
39
33
|
services = selectedServices;
|
|
40
34
|
}
|
|
41
|
-
|
|
42
35
|
if (services.length === 0) {
|
|
43
36
|
return;
|
|
44
37
|
}
|
|
45
|
-
|
|
46
38
|
await navy.emitAsync('cli.before.launch');
|
|
47
39
|
(0, _driverLogging.startDriverLogging)('Launching services...');
|
|
48
40
|
await navy.launch(services);
|
|
49
41
|
(0, _driverLogging.stopDriverLogging)();
|
|
50
42
|
}
|
|
51
|
-
|
|
52
43
|
module.exports = exports.default;
|
package/lib/cli/live.js
CHANGED
|
@@ -1,46 +1,37 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.default = _default;
|
|
9
|
-
|
|
10
8
|
var _chalk = _interopRequireDefault(require("chalk"));
|
|
11
|
-
|
|
12
9
|
var _ = require("../");
|
|
13
|
-
|
|
14
10
|
var _errors = require("../errors");
|
|
15
|
-
|
|
16
11
|
var _navyrc = _interopRequireDefault(require("../util/navyrc"));
|
|
17
|
-
|
|
18
12
|
async function _default(service, opts) {
|
|
19
13
|
const navy = (0, _.getNavy)(opts.navy);
|
|
20
14
|
const cwd = process.cwd();
|
|
21
15
|
const navyRc = await (0, _navyrc.default)(cwd);
|
|
22
|
-
|
|
23
16
|
if (navyRc && !navyRc.services) {
|
|
24
17
|
throw new _errors.NavyError(`No valid .navyrc file was found in "${cwd}"`);
|
|
25
18
|
}
|
|
26
|
-
|
|
27
19
|
if (navyRc && navyRc.services.length > 1 && !service) {
|
|
28
20
|
throw new _errors.NavyError('Multiple service mappings are defined in .navyrc, you need to explicitly specify what service to develop');
|
|
29
21
|
}
|
|
30
|
-
|
|
31
22
|
if (navyRc && !service) {
|
|
32
23
|
service = navyRc.services[0];
|
|
33
24
|
}
|
|
34
|
-
|
|
35
25
|
const state = (await navy.getState()) || {};
|
|
36
|
-
|
|
37
26
|
if (!state || !state.services || !state.services[service] || !state.services[service]._develop) {
|
|
38
27
|
return console.log(_chalk.default.dim(`Nothing to do, ${service} is not in development`));
|
|
39
28
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
services: {
|
|
43
|
-
|
|
29
|
+
await navy.saveState({
|
|
30
|
+
...state,
|
|
31
|
+
services: {
|
|
32
|
+
...state.services,
|
|
33
|
+
[service]: {
|
|
34
|
+
...state.services[service],
|
|
44
35
|
_develop: undefined
|
|
45
36
|
}
|
|
46
37
|
}
|
|
@@ -51,5 +42,4 @@ async function _default(service, opts) {
|
|
|
51
42
|
});
|
|
52
43
|
console.log(`${service} is no longer in development`);
|
|
53
44
|
}
|
|
54
|
-
|
|
55
45
|
module.exports = exports.default;
|
package/lib/cli/local-ip.js
CHANGED
|
@@ -1,20 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.default = _default;
|
|
9
|
-
|
|
10
8
|
var _chalk = _interopRequireDefault(require("chalk"));
|
|
11
|
-
|
|
12
9
|
var _config = require("../config");
|
|
13
|
-
|
|
14
10
|
var _reconfigure = require("./util/reconfigure");
|
|
15
|
-
|
|
16
11
|
async function _default(navy) {
|
|
17
|
-
await (0, _config.setConfig)({
|
|
12
|
+
await (0, _config.setConfig)({
|
|
13
|
+
...(0, _config.getConfig)(),
|
|
18
14
|
externalIP: '127.0.0.1'
|
|
19
15
|
});
|
|
20
16
|
await (0, _reconfigure.reconfigureAllNavies)();
|
|
@@ -22,5 +18,4 @@ async function _default(navy) {
|
|
|
22
18
|
console.log(_chalk.default.green(' ✔ Now using your local IP address (127.0.0.1)'));
|
|
23
19
|
console.log();
|
|
24
20
|
}
|
|
25
|
-
|
|
26
21
|
module.exports = exports.default;
|
package/lib/cli/logs.js
CHANGED
|
@@ -4,12 +4,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = _default;
|
|
7
|
-
|
|
8
7
|
var _ = require("../");
|
|
9
|
-
|
|
10
8
|
async function _default(services, opts) {
|
|
11
9
|
const env = (0, _.getNavy)(opts.navy);
|
|
12
10
|
await env.spawnLogStream(services);
|
|
13
11
|
}
|
|
14
|
-
|
|
15
12
|
module.exports = exports.default;
|