@terascope/scripts 0.83.2 → 1.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/bin/ts-scripts.js +5 -4
- package/dist/src/cmds/bump-asset.d.ts +1 -1
- package/dist/src/cmds/bump-asset.d.ts.map +1 -1
- package/dist/src/cmds/bump-asset.js +9 -13
- package/dist/src/cmds/bump-asset.js.map +1 -1
- package/dist/src/cmds/bump.d.ts +1 -1
- package/dist/src/cmds/bump.d.ts.map +1 -1
- package/dist/src/cmds/bump.js +13 -17
- package/dist/src/cmds/bump.js.map +1 -1
- package/dist/src/cmds/docs.d.ts +1 -1
- package/dist/src/cmds/docs.d.ts.map +1 -1
- package/dist/src/cmds/docs.js +7 -8
- package/dist/src/cmds/docs.js.map +1 -1
- package/dist/src/cmds/images.d.ts +3 -3
- package/dist/src/cmds/images.d.ts.map +1 -1
- package/dist/src/cmds/images.js +5 -6
- package/dist/src/cmds/images.js.map +1 -1
- package/dist/src/cmds/k8s-env.d.ts +1 -1
- package/dist/src/cmds/k8s-env.d.ts.map +1 -1
- package/dist/src/cmds/k8s-env.js +5 -29
- package/dist/src/cmds/k8s-env.js.map +1 -1
- package/dist/src/cmds/publish.d.ts +3 -3
- package/dist/src/cmds/publish.d.ts.map +1 -1
- package/dist/src/cmds/publish.js +15 -16
- package/dist/src/cmds/publish.js.map +1 -1
- package/dist/src/cmds/sync.d.ts +2 -2
- package/dist/src/cmds/sync.d.ts.map +1 -1
- package/dist/src/cmds/sync.js +5 -6
- package/dist/src/cmds/sync.js.map +1 -1
- package/dist/src/cmds/test.d.ts +2 -2
- package/dist/src/cmds/test.d.ts.map +1 -1
- package/dist/src/cmds/test.js +17 -44
- package/dist/src/cmds/test.js.map +1 -1
- package/dist/src/command.js +21 -9
- package/dist/src/command.js.map +1 -1
- package/dist/src/helpers/args.d.ts +1 -1
- package/dist/src/helpers/args.d.ts.map +1 -1
- package/dist/src/helpers/args.js +18 -26
- package/dist/src/helpers/args.js.map +1 -1
- package/dist/src/helpers/bump/index.d.ts +2 -2
- package/dist/src/helpers/bump/index.d.ts.map +1 -1
- package/dist/src/helpers/bump/index.js +37 -69
- package/dist/src/helpers/bump/index.js.map +1 -1
- package/dist/src/helpers/bump/interfaces.d.ts +1 -1
- package/dist/src/helpers/bump/interfaces.d.ts.map +1 -1
- package/dist/src/helpers/bump/interfaces.js +2 -5
- package/dist/src/helpers/bump/interfaces.js.map +1 -1
- package/dist/src/helpers/bump/utils.d.ts +2 -2
- package/dist/src/helpers/bump/utils.d.ts.map +1 -1
- package/dist/src/helpers/bump/utils.js +35 -48
- package/dist/src/helpers/bump/utils.js.map +1 -1
- package/dist/src/helpers/config.d.ts +2 -1
- package/dist/src/helpers/config.d.ts.map +1 -1
- package/dist/src/helpers/config.js +117 -118
- package/dist/src/helpers/config.js.map +1 -1
- package/dist/src/helpers/doc-builder/index.d.ts +1 -1
- package/dist/src/helpers/doc-builder/index.d.ts.map +1 -1
- package/dist/src/helpers/doc-builder/index.js +14 -21
- package/dist/src/helpers/doc-builder/index.js.map +1 -1
- package/dist/src/helpers/doc-builder/overview.d.ts +1 -1
- package/dist/src/helpers/doc-builder/overview.d.ts.map +1 -1
- package/dist/src/helpers/doc-builder/overview.js +15 -25
- package/dist/src/helpers/doc-builder/overview.js.map +1 -1
- package/dist/src/helpers/doc-builder/sidebar.d.ts +1 -1
- package/dist/src/helpers/doc-builder/sidebar.d.ts.map +1 -1
- package/dist/src/helpers/doc-builder/sidebar.js +17 -24
- package/dist/src/helpers/doc-builder/sidebar.js.map +1 -1
- package/dist/src/helpers/doc-builder/typedoc.d.ts +1 -1
- package/dist/src/helpers/doc-builder/typedoc.d.ts.map +1 -1
- package/dist/src/helpers/doc-builder/typedoc.js +31 -38
- package/dist/src/helpers/doc-builder/typedoc.js.map +1 -1
- package/dist/src/helpers/hooks.d.ts +1 -1
- package/dist/src/helpers/hooks.d.ts.map +1 -1
- package/dist/src/helpers/hooks.js +7 -14
- package/dist/src/helpers/hooks.js.map +1 -1
- package/dist/src/helpers/images/index.d.ts +1 -1
- package/dist/src/helpers/images/index.d.ts.map +1 -1
- package/dist/src/helpers/images/index.js +25 -57
- package/dist/src/helpers/images/index.js.map +1 -1
- package/dist/src/helpers/images/interfaces.js +2 -5
- package/dist/src/helpers/images/interfaces.js.map +1 -1
- package/dist/src/helpers/interfaces.js +5 -8
- package/dist/src/helpers/interfaces.js.map +1 -1
- package/dist/src/helpers/k8s-env/index.d.ts +1 -1
- package/dist/src/helpers/k8s-env/index.d.ts.map +1 -1
- package/dist/src/helpers/k8s-env/index.js +51 -82
- package/dist/src/helpers/k8s-env/index.js.map +1 -1
- package/dist/src/helpers/k8s-env/interfaces.js +1 -2
- package/dist/src/helpers/k8s-env/k8s.js +49 -74
- package/dist/src/helpers/k8s-env/k8s.js.map +1 -1
- package/dist/src/helpers/kind.d.ts +1 -1
- package/dist/src/helpers/kind.d.ts.map +1 -1
- package/dist/src/helpers/kind.js +47 -51
- package/dist/src/helpers/kind.js.map +1 -1
- package/dist/src/helpers/mapper.js +1 -5
- package/dist/src/helpers/mapper.js.map +1 -1
- package/dist/src/helpers/misc.d.ts +1 -1
- package/dist/src/helpers/misc.d.ts.map +1 -1
- package/dist/src/helpers/misc.js +63 -80
- package/dist/src/helpers/misc.js.map +1 -1
- package/dist/src/helpers/packages.d.ts +1 -1
- package/dist/src/helpers/packages.d.ts.map +1 -1
- package/dist/src/helpers/packages.js +82 -129
- package/dist/src/helpers/packages.js.map +1 -1
- package/dist/src/helpers/publish/index.d.ts +1 -1
- package/dist/src/helpers/publish/index.d.ts.map +1 -1
- package/dist/src/helpers/publish/index.js +53 -60
- package/dist/src/helpers/publish/index.js.map +1 -1
- package/dist/src/helpers/publish/interfaces.js +4 -7
- package/dist/src/helpers/publish/interfaces.js.map +1 -1
- package/dist/src/helpers/publish/utils.d.ts +2 -2
- package/dist/src/helpers/publish/utils.d.ts.map +1 -1
- package/dist/src/helpers/publish/utils.js +32 -43
- package/dist/src/helpers/publish/utils.js.map +1 -1
- package/dist/src/helpers/scripts.d.ts +5 -4
- package/dist/src/helpers/scripts.d.ts.map +1 -1
- package/dist/src/helpers/scripts.js +124 -177
- package/dist/src/helpers/scripts.js.map +1 -1
- package/dist/src/helpers/signale.d.ts +2 -2
- package/dist/src/helpers/signale.d.ts.map +1 -1
- package/dist/src/helpers/signale.js +5 -6
- package/dist/src/helpers/signale.js.map +1 -1
- package/dist/src/helpers/sync/configs.d.ts +1 -1
- package/dist/src/helpers/sync/configs.d.ts.map +1 -1
- package/dist/src/helpers/sync/configs.js +8 -15
- package/dist/src/helpers/sync/configs.js.map +1 -1
- package/dist/src/helpers/sync/index.d.ts +1 -1
- package/dist/src/helpers/sync/index.d.ts.map +1 -1
- package/dist/src/helpers/sync/index.js +19 -46
- package/dist/src/helpers/sync/index.js.map +1 -1
- package/dist/src/helpers/sync/interfaces.js +2 -5
- package/dist/src/helpers/sync/interfaces.js.map +1 -1
- package/dist/src/helpers/sync/utils.d.ts +2 -2
- package/dist/src/helpers/sync/utils.d.ts.map +1 -1
- package/dist/src/helpers/sync/utils.js +51 -63
- package/dist/src/helpers/sync/utils.js.map +1 -1
- package/dist/src/helpers/test-runner/index.d.ts +2 -2
- package/dist/src/helpers/test-runner/index.d.ts.map +1 -1
- package/dist/src/helpers/test-runner/index.js +78 -86
- package/dist/src/helpers/test-runner/index.js.map +1 -1
- package/dist/src/helpers/test-runner/interfaces.d.ts +1 -1
- package/dist/src/helpers/test-runner/interfaces.d.ts.map +1 -1
- package/dist/src/helpers/test-runner/interfaces.js +1 -2
- package/dist/src/helpers/test-runner/services.d.ts +1 -1
- package/dist/src/helpers/test-runner/services.d.ts.map +1 -1
- package/dist/src/helpers/test-runner/services.js +159 -198
- package/dist/src/helpers/test-runner/services.js.map +1 -1
- package/dist/src/helpers/test-runner/tracker.d.ts +1 -1
- package/dist/src/helpers/test-runner/tracker.d.ts.map +1 -1
- package/dist/src/helpers/test-runner/tracker.js +29 -33
- package/dist/src/helpers/test-runner/tracker.js.map +1 -1
- package/dist/src/helpers/test-runner/utils.d.ts +3 -3
- package/dist/src/helpers/test-runner/utils.d.ts.map +1 -1
- package/dist/src/helpers/test-runner/utils.js +42 -78
- package/dist/src/helpers/test-runner/utils.js.map +1 -1
- package/dist/src/index.d.ts +6 -6
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +6 -22
- package/dist/src/index.js.map +1 -1
- package/package.json +4 -3
|
@@ -1,49 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
-
};
|
|
28
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.showState = exports.setAlias = exports.k8sStartService = exports.k8sStopService = exports.isKubectlInstalled = exports.isKindInstalled = exports.yarnPublish = exports.yarnPublishV2 = exports.mapToArgs = exports.getChangedFiles = exports.gitDiff = exports.getCommitHash = exports.saveAndZip = exports.pgrep = exports.deleteDockerImageCache = exports.loadThenDeleteImageFromCache = exports.dockerPush = exports.dockerBuild = exports.dockerContainerReady = exports.dockerRun = exports.remoteDockerImageExists = exports.dockerNetworkExists = exports.getContainerInfo = exports.getNodeVersionFromImage = exports.dockerTag = exports.dockerStop = exports.dockerPull = exports.runJest = exports.yarnRun = exports.setup = exports.build = exports.runTSScript = exports.fork = exports.exec = void 0;
|
|
30
|
-
const fs_1 = __importDefault(require("fs"));
|
|
31
|
-
const os_1 = __importDefault(require("os"));
|
|
32
|
-
const ms_1 = __importDefault(require("ms"));
|
|
33
|
-
const path_1 = __importDefault(require("path"));
|
|
34
|
-
const execa_1 = __importDefault(require("execa"));
|
|
35
|
-
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
36
|
-
const js_yaml_1 = __importDefault(require("js-yaml"));
|
|
37
|
-
const utils_1 = require("@terascope/utils");
|
|
38
|
-
const misc_1 = require("./misc");
|
|
39
|
-
const signale_1 = __importDefault(require("./signale"));
|
|
40
|
-
const config = __importStar(require("./config"));
|
|
41
|
-
const packages_1 = require("../helpers/packages");
|
|
42
|
-
const logger = (0, utils_1.debugLogger)('ts-scripts:cmd');
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import os from 'node:os';
|
|
3
|
+
import ms from 'ms';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import execa from 'execa';
|
|
6
|
+
import fse from 'fs-extra';
|
|
7
|
+
import yaml from 'js-yaml';
|
|
8
|
+
import { debugLogger, isString, get, pWhile, pDelay, TSError } from '@terascope/utils';
|
|
9
|
+
import { getRootDir } from './misc.js';
|
|
10
|
+
import signale from './signale.js';
|
|
11
|
+
import * as config from './config.js';
|
|
12
|
+
import { getE2eK8sDir } from '../helpers/packages.js';
|
|
13
|
+
const logger = debugLogger('ts-scripts:cmd');
|
|
43
14
|
function _exec(opts) {
|
|
44
15
|
let subprocess;
|
|
45
16
|
const options = {
|
|
46
|
-
cwd: opts.cwd ||
|
|
17
|
+
cwd: opts.cwd || getRootDir(),
|
|
47
18
|
env: opts.env,
|
|
48
19
|
preferLocal: true,
|
|
49
20
|
detached: opts.detached,
|
|
@@ -52,10 +23,10 @@ function _exec(opts) {
|
|
|
52
23
|
};
|
|
53
24
|
logger.debug('executing command', opts);
|
|
54
25
|
if (opts.args && opts.args.length) {
|
|
55
|
-
subprocess = (
|
|
26
|
+
subprocess = execa(opts.cmd, opts.args, options);
|
|
56
27
|
}
|
|
57
28
|
else {
|
|
58
|
-
subprocess = (
|
|
29
|
+
subprocess = execa(opts.cmd, options);
|
|
59
30
|
}
|
|
60
31
|
if (!subprocess) {
|
|
61
32
|
throw new Error(`Failed to execution ${opts.cmd}`);
|
|
@@ -68,7 +39,7 @@ function _exec(opts) {
|
|
|
68
39
|
}
|
|
69
40
|
return subprocess;
|
|
70
41
|
}
|
|
71
|
-
async function exec(opts, log = true) {
|
|
42
|
+
export async function exec(opts, log = true) {
|
|
72
43
|
try {
|
|
73
44
|
const env = { FORCE_COLOR: '0', ...opts.env };
|
|
74
45
|
const _opts = { ...opts };
|
|
@@ -87,8 +58,7 @@ async function exec(opts, log = true) {
|
|
|
87
58
|
throw new Error(err.message);
|
|
88
59
|
}
|
|
89
60
|
}
|
|
90
|
-
|
|
91
|
-
async function fork(opts) {
|
|
61
|
+
export async function fork(opts) {
|
|
92
62
|
try {
|
|
93
63
|
const env = {
|
|
94
64
|
FORCE_COLOR: config.FORCE_COLOR,
|
|
@@ -106,47 +76,42 @@ async function fork(opts) {
|
|
|
106
76
|
throw new Error(err.message);
|
|
107
77
|
}
|
|
108
78
|
}
|
|
109
|
-
|
|
110
|
-
async function runTSScript(cmd, args) {
|
|
79
|
+
export async function runTSScript(cmd, args) {
|
|
111
80
|
const scriptName = process.argv[1];
|
|
112
81
|
return fork({
|
|
113
82
|
cmd: scriptName,
|
|
114
83
|
args: [cmd, ...args],
|
|
115
84
|
});
|
|
116
85
|
}
|
|
117
|
-
|
|
118
|
-
async function build(pkgInfo) {
|
|
86
|
+
export async function build(pkgInfo) {
|
|
119
87
|
if (pkgInfo) {
|
|
120
|
-
const distDir =
|
|
121
|
-
if (
|
|
122
|
-
await
|
|
88
|
+
const distDir = path.join(pkgInfo.dir, 'dist');
|
|
89
|
+
if (fse.existsSync(distDir)) {
|
|
90
|
+
await fse.emptyDir(distDir);
|
|
123
91
|
}
|
|
124
92
|
await yarnRun('build', [], pkgInfo.dir);
|
|
125
93
|
return;
|
|
126
94
|
}
|
|
127
95
|
await yarnRun('build');
|
|
128
96
|
}
|
|
129
|
-
|
|
130
|
-
async function setup() {
|
|
97
|
+
export async function setup() {
|
|
131
98
|
await yarnRun('setup');
|
|
132
99
|
}
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
const
|
|
136
|
-
const
|
|
137
|
-
const hasScript = Boolean((0, utils_1.get)(pkgJSON, ['scripts', script]));
|
|
100
|
+
export async function yarnRun(script, args, cwd, env, log) {
|
|
101
|
+
const dir = cwd || getRootDir();
|
|
102
|
+
const pkgJSON = await fse.readJSON(path.join(dir, 'package.json'));
|
|
103
|
+
const hasScript = Boolean(get(pkgJSON, ['scripts', script]));
|
|
138
104
|
if (!hasScript)
|
|
139
105
|
return;
|
|
140
|
-
const _args = ['run', script, ...(args
|
|
106
|
+
const _args = ['run', script, ...(args ?? [])];
|
|
141
107
|
if (log) {
|
|
142
|
-
|
|
108
|
+
signale.info(`running yarn ${_args.join(' ')}...`);
|
|
143
109
|
}
|
|
144
110
|
await fork({
|
|
145
111
|
cmd: 'yarn', args: _args, cwd: dir, env
|
|
146
112
|
});
|
|
147
113
|
}
|
|
148
|
-
|
|
149
|
-
async function runJest(cwd, argsMap, env, extraArgs, debug) {
|
|
114
|
+
export async function runJest(cwd, argsMap, env, extraArgs, debug) {
|
|
150
115
|
const args = mapToArgs(argsMap);
|
|
151
116
|
if (extraArgs) {
|
|
152
117
|
extraArgs.forEach((extraArg) => {
|
|
@@ -160,7 +125,7 @@ async function runJest(cwd, argsMap, env, extraArgs, debug) {
|
|
|
160
125
|
});
|
|
161
126
|
}
|
|
162
127
|
if (debug) {
|
|
163
|
-
|
|
128
|
+
signale.debug(`executing: jest ${args.join(' ')}`);
|
|
164
129
|
}
|
|
165
130
|
await fork({
|
|
166
131
|
cmd: 'jest',
|
|
@@ -169,8 +134,7 @@ async function runJest(cwd, argsMap, env, extraArgs, debug) {
|
|
|
169
134
|
env,
|
|
170
135
|
});
|
|
171
136
|
}
|
|
172
|
-
|
|
173
|
-
async function dockerPull(image, timeout = 0) {
|
|
137
|
+
export async function dockerPull(image, timeout = 0) {
|
|
174
138
|
try {
|
|
175
139
|
await exec({
|
|
176
140
|
cmd: 'docker',
|
|
@@ -183,34 +147,30 @@ async function dockerPull(image, timeout = 0) {
|
|
|
183
147
|
throw err;
|
|
184
148
|
}
|
|
185
149
|
}
|
|
186
|
-
|
|
187
|
-
async function dockerStop(name) {
|
|
150
|
+
export async function dockerStop(name) {
|
|
188
151
|
await exec({
|
|
189
152
|
cmd: 'docker',
|
|
190
153
|
args: ['stop', name],
|
|
191
154
|
});
|
|
192
155
|
}
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
signale_1.default.pending(`Tagging image ${from} as ${to}`);
|
|
156
|
+
export async function dockerTag(from, to) {
|
|
157
|
+
signale.pending(`Tagging image ${from} as ${to}`);
|
|
196
158
|
await exec({
|
|
197
159
|
cmd: 'docker',
|
|
198
160
|
args: ['tag', from, to],
|
|
199
161
|
});
|
|
200
|
-
|
|
162
|
+
signale.success(`Image ${from} re-tagged as ${to}`);
|
|
201
163
|
}
|
|
202
|
-
|
|
203
|
-
async function getNodeVersionFromImage(image) {
|
|
164
|
+
export async function getNodeVersionFromImage(image) {
|
|
204
165
|
try {
|
|
205
|
-
const { stdout } = await (
|
|
166
|
+
const { stdout } = await execa('docker', ['run', image, 'node', '-v']);
|
|
206
167
|
return stdout;
|
|
207
168
|
}
|
|
208
169
|
catch (err) {
|
|
209
170
|
throw new Error(`Unable to get node version from image due to Error: ${err}`);
|
|
210
171
|
}
|
|
211
172
|
}
|
|
212
|
-
|
|
213
|
-
async function getContainerInfo(name) {
|
|
173
|
+
export async function getContainerInfo(name) {
|
|
214
174
|
const result = await exec({
|
|
215
175
|
cmd: 'docker',
|
|
216
176
|
args: ['ps', '--format={{json .}}', `--filter=name=${name}`],
|
|
@@ -219,23 +179,20 @@ async function getContainerInfo(name) {
|
|
|
219
179
|
return null;
|
|
220
180
|
return JSON.parse(result);
|
|
221
181
|
}
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
const subprocess = await execa_1.default.command(`docker network ls --format='{{json .Name}}' | grep '"${name}"'`, { reject: false });
|
|
182
|
+
export async function dockerNetworkExists(name) {
|
|
183
|
+
const subprocess = await execa.command(`docker network ls --format='{{json .Name}}' | grep '"${name}"'`, { reject: false });
|
|
225
184
|
return subprocess.exitCode > 0;
|
|
226
185
|
}
|
|
227
|
-
|
|
228
|
-
async function remoteDockerImageExists(image) {
|
|
186
|
+
export async function remoteDockerImageExists(image) {
|
|
229
187
|
try {
|
|
230
|
-
await dockerPull(image, (
|
|
188
|
+
await dockerPull(image, ms('30s'));
|
|
231
189
|
return true;
|
|
232
190
|
}
|
|
233
191
|
catch (err) {
|
|
234
192
|
return false;
|
|
235
193
|
}
|
|
236
194
|
}
|
|
237
|
-
|
|
238
|
-
async function dockerRun(opt, tag, ignoreMount, debug) {
|
|
195
|
+
export async function dockerRun(opt, tag, ignoreMount, debug) {
|
|
239
196
|
const args = ['run', '--rm'];
|
|
240
197
|
if (!opt.image) {
|
|
241
198
|
throw new Error('Missing required image option');
|
|
@@ -244,11 +201,13 @@ async function dockerRun(opt, tag, ignoreMount, debug) {
|
|
|
244
201
|
throw new Error('Missing required name option');
|
|
245
202
|
}
|
|
246
203
|
if (opt.mount && !ignoreMount) {
|
|
247
|
-
|
|
204
|
+
for (const mount of opt.mount) {
|
|
205
|
+
args.push('--mount', mount);
|
|
206
|
+
}
|
|
248
207
|
}
|
|
249
208
|
if (opt.ports && opt.ports.length) {
|
|
250
209
|
opt.ports.forEach((port) => {
|
|
251
|
-
if (
|
|
210
|
+
if (isString(port)) {
|
|
252
211
|
args.push('--publish', port);
|
|
253
212
|
}
|
|
254
213
|
else {
|
|
@@ -272,7 +231,7 @@ async function dockerRun(opt, tag, ignoreMount, debug) {
|
|
|
272
231
|
args.push('--network', opt.network);
|
|
273
232
|
}
|
|
274
233
|
args.push('--name', opt.name);
|
|
275
|
-
args.push(`${opt.image}:${tag
|
|
234
|
+
args.push(`${opt.image}:${tag ?? 'latest'}`);
|
|
276
235
|
if (opt.args) {
|
|
277
236
|
args.push(...opt.args);
|
|
278
237
|
}
|
|
@@ -280,9 +239,9 @@ async function dockerRun(opt, tag, ignoreMount, debug) {
|
|
|
280
239
|
let stderr;
|
|
281
240
|
let done = true;
|
|
282
241
|
if (debug) {
|
|
283
|
-
|
|
242
|
+
signale.debug(`executing: docker ${args.join(' ')}`);
|
|
284
243
|
}
|
|
285
|
-
const subprocess = (
|
|
244
|
+
const subprocess = execa('docker', args);
|
|
286
245
|
if (!subprocess || !subprocess.stderr) {
|
|
287
246
|
throw new Error('Failed to execute docker run');
|
|
288
247
|
}
|
|
@@ -306,10 +265,10 @@ async function dockerRun(opt, tag, ignoreMount, debug) {
|
|
|
306
265
|
done = true;
|
|
307
266
|
}
|
|
308
267
|
})();
|
|
309
|
-
const upFor = (
|
|
310
|
-
await
|
|
268
|
+
const upFor = ms('3s');
|
|
269
|
+
await pWhile(() => dockerContainerReady(opt.name, upFor, error), {
|
|
311
270
|
name: `Docker container up for 2m (${opt.name})`,
|
|
312
|
-
timeoutMs: (
|
|
271
|
+
timeoutMs: ms('2m')
|
|
313
272
|
});
|
|
314
273
|
if (error) {
|
|
315
274
|
if (stderr) {
|
|
@@ -325,17 +284,16 @@ async function dockerRun(opt, tag, ignoreMount, debug) {
|
|
|
325
284
|
if (stderr) {
|
|
326
285
|
process.stderr.write(stderr);
|
|
327
286
|
}
|
|
328
|
-
|
|
287
|
+
signale.error(error);
|
|
329
288
|
}
|
|
330
289
|
if (done && !subprocess.killed)
|
|
331
290
|
return;
|
|
332
291
|
subprocess.kill();
|
|
333
292
|
};
|
|
334
293
|
}
|
|
335
|
-
|
|
336
|
-
async function dockerContainerReady(name, upFor, error) {
|
|
294
|
+
export async function dockerContainerReady(name, upFor, error) {
|
|
337
295
|
if (error)
|
|
338
|
-
throw new
|
|
296
|
+
throw new TSError(error);
|
|
339
297
|
try {
|
|
340
298
|
const result = await exec({
|
|
341
299
|
cmd: 'docker',
|
|
@@ -343,20 +301,19 @@ async function dockerContainerReady(name, upFor, error) {
|
|
|
343
301
|
'ps', '--format', '"{{json .Status}}"', '--filter', `name=${name}`
|
|
344
302
|
]
|
|
345
303
|
});
|
|
346
|
-
const timeup = (
|
|
304
|
+
const timeup = ms(result.replace(/[(Up)\s"]+|/ig, ''));
|
|
347
305
|
if (!timeup)
|
|
348
306
|
return false;
|
|
349
307
|
return timeup >= upFor;
|
|
350
308
|
}
|
|
351
309
|
catch (err) {
|
|
352
|
-
await
|
|
310
|
+
await pDelay(1000);
|
|
353
311
|
return false;
|
|
354
312
|
}
|
|
355
313
|
}
|
|
356
|
-
|
|
357
|
-
async function dockerBuild(tag, cacheFrom, target, buildArgs, useDevFile) {
|
|
314
|
+
export async function dockerBuild(tag, cacheFrom, target, buildArgs, useDevFile) {
|
|
358
315
|
const cacheFromArgs = [];
|
|
359
|
-
cacheFrom
|
|
316
|
+
cacheFrom?.forEach((image) => {
|
|
360
317
|
cacheFromArgs.push('--cache-from', image);
|
|
361
318
|
});
|
|
362
319
|
const targetArgs = target ? ['--target', target] : [];
|
|
@@ -369,45 +326,47 @@ async function dockerBuild(tag, cacheFrom, target, buildArgs, useDevFile) {
|
|
|
369
326
|
args: ['build', ...cacheFromArgs, ...targetArgs, ...buildsArgs, '--tag', tag, ...dockerFilePath],
|
|
370
327
|
});
|
|
371
328
|
}
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
const subprocess = await execa_1.default.command(`docker push ${image}`, { reject: false });
|
|
329
|
+
export async function dockerPush(image) {
|
|
330
|
+
const subprocess = await execa.command(`docker push ${image}`, { reject: false });
|
|
375
331
|
if (subprocess.exitCode !== 0) {
|
|
376
332
|
throw new Error(`Unable to push docker image ${image}, ${subprocess.stderr}`);
|
|
377
333
|
}
|
|
378
334
|
}
|
|
379
|
-
|
|
335
|
+
async function dockerImageRm(image) {
|
|
336
|
+
const subprocess = await execa.command(`docker image rm ${image}`, { reject: false });
|
|
337
|
+
if (subprocess.exitCode !== 0) {
|
|
338
|
+
throw new Error(`Unable to remove docker image ${image}, ${subprocess.stderr}`);
|
|
339
|
+
}
|
|
340
|
+
}
|
|
380
341
|
/**
|
|
381
342
|
* Unzips and loads a Docker image from a Docker cache
|
|
382
343
|
* If successful the image will be deleted from the cache
|
|
383
344
|
* @param {string} imageName Name of the image to load
|
|
384
345
|
* @returns {Promise<boolean>} Whether or not the image loaded successfully
|
|
385
346
|
*/
|
|
386
|
-
async function loadThenDeleteImageFromCache(imageName) {
|
|
387
|
-
|
|
347
|
+
export async function loadThenDeleteImageFromCache(imageName) {
|
|
348
|
+
signale.time(`unzip and load ${imageName}`);
|
|
388
349
|
const fileName = imageName.trim().replace(/[/:]/g, '_');
|
|
389
|
-
const filePath =
|
|
390
|
-
if (!
|
|
391
|
-
|
|
350
|
+
const filePath = path.join(config.DOCKER_CACHE_PATH, `${fileName}.tar.gz`);
|
|
351
|
+
if (!fs.existsSync(filePath)) {
|
|
352
|
+
signale.error(`No file found at ${filePath}. Have you restored the cache?`);
|
|
392
353
|
return false;
|
|
393
354
|
}
|
|
394
|
-
const result = await
|
|
395
|
-
|
|
355
|
+
const result = await execa.command(`gunzip -c ${filePath} | docker load`, { shell: true });
|
|
356
|
+
signale.info('Result: ', result);
|
|
396
357
|
if (result.exitCode !== 0) {
|
|
397
|
-
|
|
358
|
+
signale.error(`Error loading ${filePath} to docker`);
|
|
398
359
|
return false;
|
|
399
360
|
}
|
|
400
|
-
|
|
401
|
-
|
|
361
|
+
fs.rmSync(filePath);
|
|
362
|
+
signale.timeEnd(`unzip and load ${imageName}`);
|
|
402
363
|
return true;
|
|
403
364
|
}
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
fs_extra_1.default.removeSync(config.DOCKER_CACHE_PATH);
|
|
365
|
+
export async function deleteDockerImageCache() {
|
|
366
|
+
signale.info(`Deleting Docker image cache at ${config.DOCKER_CACHE_PATH}`);
|
|
367
|
+
fse.removeSync(config.DOCKER_CACHE_PATH);
|
|
408
368
|
}
|
|
409
|
-
|
|
410
|
-
async function pgrep(name) {
|
|
369
|
+
export async function pgrep(name) {
|
|
411
370
|
const result = await exec({ cmd: 'ps', args: ['aux'] }, false);
|
|
412
371
|
if (!result) {
|
|
413
372
|
throw new Error('Invalid result from ps aux');
|
|
@@ -423,22 +382,22 @@ async function pgrep(name) {
|
|
|
423
382
|
}
|
|
424
383
|
return '';
|
|
425
384
|
}
|
|
426
|
-
exports.pgrep = pgrep;
|
|
427
385
|
/**
|
|
428
|
-
* Save a docker image as a tar.gz to a local directory
|
|
386
|
+
* Save a docker image as a tar.gz to a local directory.
|
|
387
|
+
* Then remove the image from docker
|
|
429
388
|
* @param {string} imageName Name of image to pull and save
|
|
430
389
|
* @param {string} imageSavePath Location where image will be saved and compressed.
|
|
431
390
|
* @returns void
|
|
432
391
|
*/
|
|
433
|
-
async function saveAndZip(imageName, imageSavePath) {
|
|
434
|
-
|
|
392
|
+
export async function saveAndZip(imageName, imageSavePath) {
|
|
393
|
+
signale.info(`Saving Docker image: ${imageName}`);
|
|
435
394
|
const fileName = imageName.replace(/[/:]/g, '_');
|
|
436
|
-
const filePath =
|
|
395
|
+
const filePath = path.join(imageSavePath, `${fileName}.tar`);
|
|
437
396
|
const command = `docker save ${imageName} | gzip > ${filePath}.gz`;
|
|
438
|
-
await
|
|
397
|
+
await execa.command(command, { shell: true });
|
|
398
|
+
await dockerImageRm(imageName);
|
|
439
399
|
}
|
|
440
|
-
|
|
441
|
-
async function getCommitHash() {
|
|
400
|
+
export async function getCommitHash() {
|
|
442
401
|
if (process.env.GIT_COMMIT_HASH)
|
|
443
402
|
return process.env.GIT_COMMIT_HASH;
|
|
444
403
|
if (config.SKIP_GIT_COMMANDS) {
|
|
@@ -446,8 +405,7 @@ async function getCommitHash() {
|
|
|
446
405
|
}
|
|
447
406
|
return exec({ cmd: 'git', args: ['rev-parse', '--short', 'HEAD'] });
|
|
448
407
|
}
|
|
449
|
-
|
|
450
|
-
async function gitDiff(files = []) {
|
|
408
|
+
export async function gitDiff(files = []) {
|
|
451
409
|
if (config.SKIP_GIT_COMMANDS)
|
|
452
410
|
return;
|
|
453
411
|
try {
|
|
@@ -458,8 +416,7 @@ async function gitDiff(files = []) {
|
|
|
458
416
|
logger.warn(e);
|
|
459
417
|
}
|
|
460
418
|
}
|
|
461
|
-
|
|
462
|
-
async function getChangedFiles(...files) {
|
|
419
|
+
export async function getChangedFiles(...files) {
|
|
463
420
|
if (config.SKIP_GIT_COMMANDS)
|
|
464
421
|
return [];
|
|
465
422
|
try {
|
|
@@ -482,8 +439,7 @@ async function getChangedFiles(...files) {
|
|
|
482
439
|
throw e;
|
|
483
440
|
}
|
|
484
441
|
}
|
|
485
|
-
|
|
486
|
-
function mapToArgs(input) {
|
|
442
|
+
export function mapToArgs(input) {
|
|
487
443
|
const args = [];
|
|
488
444
|
for (const [key, value] of Object.entries(input)) {
|
|
489
445
|
const vals = Array.isArray(value) ? value : [value];
|
|
@@ -496,11 +452,10 @@ function mapToArgs(input) {
|
|
|
496
452
|
}
|
|
497
453
|
return args.filter((str) => str != null && str !== '');
|
|
498
454
|
}
|
|
499
|
-
exports.mapToArgs = mapToArgs;
|
|
500
455
|
/**
|
|
501
456
|
* Yarn publish for version 2
|
|
502
457
|
*/
|
|
503
|
-
async function yarnPublishV2(pkgInfo, tag = 'latest') {
|
|
458
|
+
export async function yarnPublishV2(pkgInfo, tag = 'latest') {
|
|
504
459
|
await fork({
|
|
505
460
|
cmd: 'yarn',
|
|
506
461
|
args: [
|
|
@@ -515,8 +470,7 @@ async function yarnPublishV2(pkgInfo, tag = 'latest') {
|
|
|
515
470
|
}
|
|
516
471
|
});
|
|
517
472
|
}
|
|
518
|
-
|
|
519
|
-
async function yarnPublish(pkgInfo, tag = 'latest', registry = config.NPM_DEFAULT_REGISTRY) {
|
|
473
|
+
export async function yarnPublish(pkgInfo, tag = 'latest', registry = config.NPM_DEFAULT_REGISTRY) {
|
|
520
474
|
await fork({
|
|
521
475
|
cmd: 'yarn',
|
|
522
476
|
args: [
|
|
@@ -536,71 +490,67 @@ async function yarnPublish(pkgInfo, tag = 'latest', registry = config.NPM_DEFAUL
|
|
|
536
490
|
}
|
|
537
491
|
});
|
|
538
492
|
}
|
|
539
|
-
|
|
540
|
-
async function isKindInstalled() {
|
|
493
|
+
export async function isKindInstalled() {
|
|
541
494
|
try {
|
|
542
|
-
const subprocess = await
|
|
495
|
+
const subprocess = await execa.command('command -v kind');
|
|
543
496
|
return !!subprocess.stdout;
|
|
544
497
|
}
|
|
545
498
|
catch (err) {
|
|
546
499
|
return false;
|
|
547
500
|
}
|
|
548
501
|
}
|
|
549
|
-
|
|
550
|
-
async function isKubectlInstalled() {
|
|
502
|
+
export async function isKubectlInstalled() {
|
|
551
503
|
try {
|
|
552
|
-
const subprocess = await
|
|
504
|
+
const subprocess = await execa.command('command -v kubectl');
|
|
553
505
|
return !!subprocess.stdout;
|
|
554
506
|
}
|
|
555
507
|
catch (err) {
|
|
556
508
|
return false;
|
|
557
509
|
}
|
|
558
510
|
}
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
const e2eK8sDir = (0, packages_1.getE2eK8sDir)();
|
|
511
|
+
export async function k8sStopService(serviceName) {
|
|
512
|
+
const e2eK8sDir = getE2eK8sDir();
|
|
562
513
|
if (!e2eK8sDir) {
|
|
563
514
|
throw new Error('Missing k8s e2e test directory');
|
|
564
515
|
}
|
|
565
516
|
try {
|
|
566
517
|
// Any new service's yaml file must be named '<serviceName>Deployment.yaml'
|
|
567
518
|
const yamlFile = `${serviceName}Deployment.yaml`;
|
|
568
|
-
const subprocess = await
|
|
519
|
+
const subprocess = await execa.command(`kubectl delete -n services-dev1 -f ${path.join(e2eK8sDir, yamlFile)}`);
|
|
569
520
|
logger.debug(subprocess.stdout);
|
|
570
521
|
}
|
|
571
522
|
catch (err) {
|
|
572
523
|
// Do nothing. This should fail because no services should be up yet.
|
|
573
524
|
}
|
|
574
525
|
}
|
|
575
|
-
|
|
576
|
-
async function k8sStartService(serviceName, image, version, kind) {
|
|
526
|
+
export async function k8sStartService(serviceName, image, version, kind) {
|
|
577
527
|
// services that have an available k8s deployment yaml file
|
|
578
528
|
const availableServices = [
|
|
579
529
|
'elasticsearch', 'kafka', 'zookeeper', 'minio' // 'opensearch', 'rabbitmq'
|
|
580
530
|
];
|
|
581
531
|
if (!availableServices.includes(serviceName)) {
|
|
582
|
-
|
|
583
|
-
|
|
532
|
+
signale.error(`Service ${serviceName} is not available. No kubernetes deployment yaml file in 'e2e/k8s' directory.`);
|
|
533
|
+
signale.info(`Remove ${serviceName} from the services list by running 'unset TEST_${serviceName.toUpperCase()}' in your terminal.`);
|
|
584
534
|
await kind.destroyCluster();
|
|
585
535
|
process.exit(1);
|
|
586
536
|
}
|
|
587
537
|
// Any new service's yaml file must be named '<serviceName>Deployment.yaml'
|
|
588
538
|
const yamlFile = `${serviceName}Deployment.yaml`;
|
|
589
|
-
const e2eK8sDir =
|
|
539
|
+
const e2eK8sDir = getE2eK8sDir();
|
|
590
540
|
if (!e2eK8sDir) {
|
|
591
541
|
throw new Error('Missing k8s e2e test directory');
|
|
592
542
|
}
|
|
593
543
|
const imageString = `${image}:${version}`;
|
|
594
544
|
try {
|
|
595
|
-
const jsDoc =
|
|
545
|
+
const jsDoc = yaml.loadAll(fs.readFileSync(`${path.join(e2eK8sDir, yamlFile)}`, 'utf8'));
|
|
596
546
|
const deployment = jsDoc[0];
|
|
597
547
|
deployment.spec.template.spec.containers[0].image = imageString;
|
|
598
|
-
const updatedYaml = jsDoc.map((doc) =>
|
|
599
|
-
const tempDir =
|
|
600
|
-
|
|
601
|
-
const subprocess = await
|
|
548
|
+
const updatedYaml = jsDoc.map((doc) => yaml.dump(doc)).join('---\n');
|
|
549
|
+
const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'tempYaml'));
|
|
550
|
+
fs.writeFileSync(path.join(tempDir, `${serviceName}Deployment.yaml`), updatedYaml);
|
|
551
|
+
const subprocess = await execa.command(`kubectl create -n services-dev1 -f ${path.join(tempDir, `${serviceName}Deployment.yaml`)}`);
|
|
602
552
|
logger.debug(subprocess.stdout);
|
|
603
|
-
|
|
553
|
+
fs.rmSync(tempDir, { recursive: true, force: true });
|
|
604
554
|
}
|
|
605
555
|
catch (err) {
|
|
606
556
|
logger.error(`The service ${serviceName} could not be started: `, err);
|
|
@@ -609,7 +559,6 @@ async function k8sStartService(serviceName, image, version, kind) {
|
|
|
609
559
|
await waitForKafkaRunning();
|
|
610
560
|
}
|
|
611
561
|
}
|
|
612
|
-
exports.k8sStartService = k8sStartService;
|
|
613
562
|
function waitForKafkaRunning(timeoutMs = 120000) {
|
|
614
563
|
const endAt = Date.now() + timeoutMs;
|
|
615
564
|
const _waitForKafkaRunning = async () => {
|
|
@@ -618,45 +567,43 @@ function waitForKafkaRunning(timeoutMs = 120000) {
|
|
|
618
567
|
}
|
|
619
568
|
let kafkaRunning = false;
|
|
620
569
|
try {
|
|
621
|
-
const kubectlResponse = await
|
|
570
|
+
const kubectlResponse = await execa.command('kubectl -n services-dev1 get pods -l app.kubernetes.io/name=cpkafka -o=jsonpath="{.items[?(@.status.containerStatuses)].status.containerStatuses[0].ready}"');
|
|
622
571
|
const kafkaReady = kubectlResponse.stdout;
|
|
623
572
|
if (kafkaReady === '"true"') {
|
|
624
573
|
kafkaRunning = true;
|
|
625
574
|
}
|
|
626
575
|
}
|
|
627
576
|
catch (err) {
|
|
628
|
-
await
|
|
577
|
+
await pDelay(3000);
|
|
629
578
|
return _waitForKafkaRunning();
|
|
630
579
|
}
|
|
631
580
|
if (kafkaRunning) {
|
|
632
581
|
return;
|
|
633
582
|
}
|
|
634
|
-
await
|
|
583
|
+
await pDelay(3000);
|
|
635
584
|
return _waitForKafkaRunning();
|
|
636
585
|
};
|
|
637
586
|
return _waitForKafkaRunning();
|
|
638
587
|
}
|
|
639
|
-
async function setAlias(tsPort) {
|
|
640
|
-
let subprocess = await
|
|
588
|
+
export async function setAlias(tsPort) {
|
|
589
|
+
let subprocess = await execa.command('earl aliases remove k8s-e2e 2> /dev/null || true', { shell: true });
|
|
641
590
|
logger.debug(subprocess.stdout);
|
|
642
|
-
subprocess = await
|
|
591
|
+
subprocess = await execa.command(`earl aliases add k8s-e2e http://${config.HOST_IP}:${tsPort}`);
|
|
643
592
|
logger.debug(subprocess.stdout);
|
|
644
593
|
}
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
const subprocess = await execa_1.default.command('kubectl get deployments,po,svc --all-namespaces --show-labels -o wide');
|
|
594
|
+
export async function showState(tsPort) {
|
|
595
|
+
const subprocess = await execa.command('kubectl get deployments,po,svc --all-namespaces --show-labels -o wide');
|
|
648
596
|
logger.debug(subprocess.stdout);
|
|
649
597
|
logger.debug(await showESIndices());
|
|
650
598
|
logger.debug(await showAssets(tsPort));
|
|
651
599
|
}
|
|
652
|
-
exports.showState = showState;
|
|
653
600
|
async function showESIndices() {
|
|
654
|
-
const subprocess = await
|
|
601
|
+
const subprocess = await execa.command(`curl ${config.HOST_IP}:${config.ELASTICSEARCH_PORT}/_cat/indices?v`);
|
|
655
602
|
return subprocess.stdout;
|
|
656
603
|
}
|
|
657
604
|
async function showAssets(tsPort) {
|
|
658
605
|
try {
|
|
659
|
-
const subprocess = await
|
|
606
|
+
const subprocess = await execa.command(`curl ${config.HOST_IP}:${tsPort}/v1/assets`);
|
|
660
607
|
return subprocess.stdout;
|
|
661
608
|
}
|
|
662
609
|
catch (err) {
|