@terascope/scripts 0.83.3 → 1.0.1
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 +1 -1
- package/dist/src/helpers/config.d.ts.map +1 -1
- package/dist/src/helpers/config.js +117 -125
- 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 +2 -2
- package/dist/src/helpers/scripts.d.ts.map +1 -1
- package/dist/src/helpers/scripts.js +119 -178
- 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 +149 -192
- 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 +9 -8
|
@@ -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,48 +76,47 @@ 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
|
-
|
|
150
|
-
|
|
114
|
+
export async function runJest(cwd, argsMap, env, extraArgs, debug) {
|
|
115
|
+
// When running jest in yarn3 PnP with ESM we must call 'yarn jest <...args>'
|
|
116
|
+
// to prevent module not found errors. Therefore we will call fork with the yarn
|
|
117
|
+
// command and set jest to the first argument.
|
|
118
|
+
const args = ['jest'];
|
|
119
|
+
args.push(...mapToArgs(argsMap));
|
|
151
120
|
if (extraArgs) {
|
|
152
121
|
extraArgs.forEach((extraArg) => {
|
|
153
122
|
if (extraArg.startsWith('-') && args.includes(extraArg)) {
|
|
@@ -160,17 +129,16 @@ async function runJest(cwd, argsMap, env, extraArgs, debug) {
|
|
|
160
129
|
});
|
|
161
130
|
}
|
|
162
131
|
if (debug) {
|
|
163
|
-
|
|
132
|
+
signale.debug(`executing: jest ${args.join(' ')}`);
|
|
164
133
|
}
|
|
165
134
|
await fork({
|
|
166
|
-
cmd: '
|
|
135
|
+
cmd: 'yarn',
|
|
167
136
|
cwd,
|
|
168
137
|
args,
|
|
169
138
|
env,
|
|
170
139
|
});
|
|
171
140
|
}
|
|
172
|
-
|
|
173
|
-
async function dockerPull(image, timeout = 0) {
|
|
141
|
+
export async function dockerPull(image, timeout = 0) {
|
|
174
142
|
try {
|
|
175
143
|
await exec({
|
|
176
144
|
cmd: 'docker',
|
|
@@ -183,34 +151,30 @@ async function dockerPull(image, timeout = 0) {
|
|
|
183
151
|
throw err;
|
|
184
152
|
}
|
|
185
153
|
}
|
|
186
|
-
|
|
187
|
-
async function dockerStop(name) {
|
|
154
|
+
export async function dockerStop(name) {
|
|
188
155
|
await exec({
|
|
189
156
|
cmd: 'docker',
|
|
190
157
|
args: ['stop', name],
|
|
191
158
|
});
|
|
192
159
|
}
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
signale_1.default.pending(`Tagging image ${from} as ${to}`);
|
|
160
|
+
export async function dockerTag(from, to) {
|
|
161
|
+
signale.pending(`Tagging image ${from} as ${to}`);
|
|
196
162
|
await exec({
|
|
197
163
|
cmd: 'docker',
|
|
198
164
|
args: ['tag', from, to],
|
|
199
165
|
});
|
|
200
|
-
|
|
166
|
+
signale.success(`Image ${from} re-tagged as ${to}`);
|
|
201
167
|
}
|
|
202
|
-
|
|
203
|
-
async function getNodeVersionFromImage(image) {
|
|
168
|
+
export async function getNodeVersionFromImage(image) {
|
|
204
169
|
try {
|
|
205
|
-
const { stdout } = await (
|
|
170
|
+
const { stdout } = await execa('docker', ['run', image, 'node', '-v']);
|
|
206
171
|
return stdout;
|
|
207
172
|
}
|
|
208
173
|
catch (err) {
|
|
209
174
|
throw new Error(`Unable to get node version from image due to Error: ${err}`);
|
|
210
175
|
}
|
|
211
176
|
}
|
|
212
|
-
|
|
213
|
-
async function getContainerInfo(name) {
|
|
177
|
+
export async function getContainerInfo(name) {
|
|
214
178
|
const result = await exec({
|
|
215
179
|
cmd: 'docker',
|
|
216
180
|
args: ['ps', '--format={{json .}}', `--filter=name=${name}`],
|
|
@@ -219,23 +183,20 @@ async function getContainerInfo(name) {
|
|
|
219
183
|
return null;
|
|
220
184
|
return JSON.parse(result);
|
|
221
185
|
}
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
const subprocess = await execa_1.default.command(`docker network ls --format='{{json .Name}}' | grep '"${name}"'`, { reject: false });
|
|
186
|
+
export async function dockerNetworkExists(name) {
|
|
187
|
+
const subprocess = await execa.command(`docker network ls --format='{{json .Name}}' | grep '"${name}"'`, { reject: false });
|
|
225
188
|
return subprocess.exitCode > 0;
|
|
226
189
|
}
|
|
227
|
-
|
|
228
|
-
async function remoteDockerImageExists(image) {
|
|
190
|
+
export async function remoteDockerImageExists(image) {
|
|
229
191
|
try {
|
|
230
|
-
await dockerPull(image, (
|
|
192
|
+
await dockerPull(image, ms('30s'));
|
|
231
193
|
return true;
|
|
232
194
|
}
|
|
233
195
|
catch (err) {
|
|
234
196
|
return false;
|
|
235
197
|
}
|
|
236
198
|
}
|
|
237
|
-
|
|
238
|
-
async function dockerRun(opt, tag, ignoreMount, debug) {
|
|
199
|
+
export async function dockerRun(opt, tag, ignoreMount, debug) {
|
|
239
200
|
const args = ['run', '--rm'];
|
|
240
201
|
if (!opt.image) {
|
|
241
202
|
throw new Error('Missing required image option');
|
|
@@ -250,7 +211,7 @@ async function dockerRun(opt, tag, ignoreMount, debug) {
|
|
|
250
211
|
}
|
|
251
212
|
if (opt.ports && opt.ports.length) {
|
|
252
213
|
opt.ports.forEach((port) => {
|
|
253
|
-
if (
|
|
214
|
+
if (isString(port)) {
|
|
254
215
|
args.push('--publish', port);
|
|
255
216
|
}
|
|
256
217
|
else {
|
|
@@ -274,7 +235,7 @@ async function dockerRun(opt, tag, ignoreMount, debug) {
|
|
|
274
235
|
args.push('--network', opt.network);
|
|
275
236
|
}
|
|
276
237
|
args.push('--name', opt.name);
|
|
277
|
-
args.push(`${opt.image}:${tag
|
|
238
|
+
args.push(`${opt.image}:${tag ?? 'latest'}`);
|
|
278
239
|
if (opt.args) {
|
|
279
240
|
args.push(...opt.args);
|
|
280
241
|
}
|
|
@@ -282,9 +243,9 @@ async function dockerRun(opt, tag, ignoreMount, debug) {
|
|
|
282
243
|
let stderr;
|
|
283
244
|
let done = true;
|
|
284
245
|
if (debug) {
|
|
285
|
-
|
|
246
|
+
signale.debug(`executing: docker ${args.join(' ')}`);
|
|
286
247
|
}
|
|
287
|
-
const subprocess = (
|
|
248
|
+
const subprocess = execa('docker', args);
|
|
288
249
|
if (!subprocess || !subprocess.stderr) {
|
|
289
250
|
throw new Error('Failed to execute docker run');
|
|
290
251
|
}
|
|
@@ -308,10 +269,10 @@ async function dockerRun(opt, tag, ignoreMount, debug) {
|
|
|
308
269
|
done = true;
|
|
309
270
|
}
|
|
310
271
|
})();
|
|
311
|
-
const upFor = (
|
|
312
|
-
await
|
|
272
|
+
const upFor = ms('3s');
|
|
273
|
+
await pWhile(() => dockerContainerReady(opt.name, upFor, error), {
|
|
313
274
|
name: `Docker container up for 2m (${opt.name})`,
|
|
314
|
-
timeoutMs: (
|
|
275
|
+
timeoutMs: ms('2m')
|
|
315
276
|
});
|
|
316
277
|
if (error) {
|
|
317
278
|
if (stderr) {
|
|
@@ -327,17 +288,16 @@ async function dockerRun(opt, tag, ignoreMount, debug) {
|
|
|
327
288
|
if (stderr) {
|
|
328
289
|
process.stderr.write(stderr);
|
|
329
290
|
}
|
|
330
|
-
|
|
291
|
+
signale.error(error);
|
|
331
292
|
}
|
|
332
293
|
if (done && !subprocess.killed)
|
|
333
294
|
return;
|
|
334
295
|
subprocess.kill();
|
|
335
296
|
};
|
|
336
297
|
}
|
|
337
|
-
|
|
338
|
-
async function dockerContainerReady(name, upFor, error) {
|
|
298
|
+
export async function dockerContainerReady(name, upFor, error) {
|
|
339
299
|
if (error)
|
|
340
|
-
throw new
|
|
300
|
+
throw new TSError(error);
|
|
341
301
|
try {
|
|
342
302
|
const result = await exec({
|
|
343
303
|
cmd: 'docker',
|
|
@@ -345,20 +305,19 @@ async function dockerContainerReady(name, upFor, error) {
|
|
|
345
305
|
'ps', '--format', '"{{json .Status}}"', '--filter', `name=${name}`
|
|
346
306
|
]
|
|
347
307
|
});
|
|
348
|
-
const timeup = (
|
|
308
|
+
const timeup = ms(result.replace(/[(Up)\s"]+|/ig, ''));
|
|
349
309
|
if (!timeup)
|
|
350
310
|
return false;
|
|
351
311
|
return timeup >= upFor;
|
|
352
312
|
}
|
|
353
313
|
catch (err) {
|
|
354
|
-
await
|
|
314
|
+
await pDelay(1000);
|
|
355
315
|
return false;
|
|
356
316
|
}
|
|
357
317
|
}
|
|
358
|
-
|
|
359
|
-
async function dockerBuild(tag, cacheFrom, target, buildArgs, useDevFile) {
|
|
318
|
+
export async function dockerBuild(tag, cacheFrom, target, buildArgs, useDevFile) {
|
|
360
319
|
const cacheFromArgs = [];
|
|
361
|
-
cacheFrom
|
|
320
|
+
cacheFrom?.forEach((image) => {
|
|
362
321
|
cacheFromArgs.push('--cache-from', image);
|
|
363
322
|
});
|
|
364
323
|
const targetArgs = target ? ['--target', target] : [];
|
|
@@ -371,16 +330,14 @@ async function dockerBuild(tag, cacheFrom, target, buildArgs, useDevFile) {
|
|
|
371
330
|
args: ['build', ...cacheFromArgs, ...targetArgs, ...buildsArgs, '--tag', tag, ...dockerFilePath],
|
|
372
331
|
});
|
|
373
332
|
}
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
const subprocess = await execa_1.default.command(`docker push ${image}`, { reject: false });
|
|
333
|
+
export async function dockerPush(image) {
|
|
334
|
+
const subprocess = await execa.command(`docker push ${image}`, { reject: false });
|
|
377
335
|
if (subprocess.exitCode !== 0) {
|
|
378
336
|
throw new Error(`Unable to push docker image ${image}, ${subprocess.stderr}`);
|
|
379
337
|
}
|
|
380
338
|
}
|
|
381
|
-
exports.dockerPush = dockerPush;
|
|
382
339
|
async function dockerImageRm(image) {
|
|
383
|
-
const subprocess = await
|
|
340
|
+
const subprocess = await execa.command(`docker image rm ${image}`, { reject: false });
|
|
384
341
|
if (subprocess.exitCode !== 0) {
|
|
385
342
|
throw new Error(`Unable to remove docker image ${image}, ${subprocess.stderr}`);
|
|
386
343
|
}
|
|
@@ -391,31 +348,29 @@ async function dockerImageRm(image) {
|
|
|
391
348
|
* @param {string} imageName Name of the image to load
|
|
392
349
|
* @returns {Promise<boolean>} Whether or not the image loaded successfully
|
|
393
350
|
*/
|
|
394
|
-
async function loadThenDeleteImageFromCache(imageName) {
|
|
395
|
-
|
|
351
|
+
export async function loadThenDeleteImageFromCache(imageName) {
|
|
352
|
+
signale.time(`unzip and load ${imageName}`);
|
|
396
353
|
const fileName = imageName.trim().replace(/[/:]/g, '_');
|
|
397
|
-
const filePath =
|
|
398
|
-
if (!
|
|
399
|
-
|
|
354
|
+
const filePath = path.join(config.DOCKER_CACHE_PATH, `${fileName}.tar.gz`);
|
|
355
|
+
if (!fs.existsSync(filePath)) {
|
|
356
|
+
signale.error(`No file found at ${filePath}. Have you restored the cache?`);
|
|
400
357
|
return false;
|
|
401
358
|
}
|
|
402
|
-
const result = await
|
|
403
|
-
|
|
359
|
+
const result = await execa.command(`gunzip -c ${filePath} | docker load`, { shell: true });
|
|
360
|
+
signale.info('Result: ', result);
|
|
404
361
|
if (result.exitCode !== 0) {
|
|
405
|
-
|
|
362
|
+
signale.error(`Error loading ${filePath} to docker`);
|
|
406
363
|
return false;
|
|
407
364
|
}
|
|
408
|
-
|
|
409
|
-
|
|
365
|
+
fs.rmSync(filePath);
|
|
366
|
+
signale.timeEnd(`unzip and load ${imageName}`);
|
|
410
367
|
return true;
|
|
411
368
|
}
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
fs_extra_1.default.removeSync(config.DOCKER_CACHE_PATH);
|
|
369
|
+
export async function deleteDockerImageCache() {
|
|
370
|
+
signale.info(`Deleting Docker image cache at ${config.DOCKER_CACHE_PATH}`);
|
|
371
|
+
fse.removeSync(config.DOCKER_CACHE_PATH);
|
|
416
372
|
}
|
|
417
|
-
|
|
418
|
-
async function pgrep(name) {
|
|
373
|
+
export async function pgrep(name) {
|
|
419
374
|
const result = await exec({ cmd: 'ps', args: ['aux'] }, false);
|
|
420
375
|
if (!result) {
|
|
421
376
|
throw new Error('Invalid result from ps aux');
|
|
@@ -431,7 +386,6 @@ async function pgrep(name) {
|
|
|
431
386
|
}
|
|
432
387
|
return '';
|
|
433
388
|
}
|
|
434
|
-
exports.pgrep = pgrep;
|
|
435
389
|
/**
|
|
436
390
|
* Save a docker image as a tar.gz to a local directory.
|
|
437
391
|
* Then remove the image from docker
|
|
@@ -439,16 +393,15 @@ exports.pgrep = pgrep;
|
|
|
439
393
|
* @param {string} imageSavePath Location where image will be saved and compressed.
|
|
440
394
|
* @returns void
|
|
441
395
|
*/
|
|
442
|
-
async function saveAndZip(imageName, imageSavePath) {
|
|
443
|
-
|
|
396
|
+
export async function saveAndZip(imageName, imageSavePath) {
|
|
397
|
+
signale.info(`Saving Docker image: ${imageName}`);
|
|
444
398
|
const fileName = imageName.replace(/[/:]/g, '_');
|
|
445
|
-
const filePath =
|
|
399
|
+
const filePath = path.join(imageSavePath, `${fileName}.tar`);
|
|
446
400
|
const command = `docker save ${imageName} | gzip > ${filePath}.gz`;
|
|
447
|
-
await
|
|
401
|
+
await execa.command(command, { shell: true });
|
|
448
402
|
await dockerImageRm(imageName);
|
|
449
403
|
}
|
|
450
|
-
|
|
451
|
-
async function getCommitHash() {
|
|
404
|
+
export async function getCommitHash() {
|
|
452
405
|
if (process.env.GIT_COMMIT_HASH)
|
|
453
406
|
return process.env.GIT_COMMIT_HASH;
|
|
454
407
|
if (config.SKIP_GIT_COMMANDS) {
|
|
@@ -456,8 +409,7 @@ async function getCommitHash() {
|
|
|
456
409
|
}
|
|
457
410
|
return exec({ cmd: 'git', args: ['rev-parse', '--short', 'HEAD'] });
|
|
458
411
|
}
|
|
459
|
-
|
|
460
|
-
async function gitDiff(files = []) {
|
|
412
|
+
export async function gitDiff(files = []) {
|
|
461
413
|
if (config.SKIP_GIT_COMMANDS)
|
|
462
414
|
return;
|
|
463
415
|
try {
|
|
@@ -468,8 +420,7 @@ async function gitDiff(files = []) {
|
|
|
468
420
|
logger.warn(e);
|
|
469
421
|
}
|
|
470
422
|
}
|
|
471
|
-
|
|
472
|
-
async function getChangedFiles(...files) {
|
|
423
|
+
export async function getChangedFiles(...files) {
|
|
473
424
|
if (config.SKIP_GIT_COMMANDS)
|
|
474
425
|
return [];
|
|
475
426
|
try {
|
|
@@ -492,8 +443,7 @@ async function getChangedFiles(...files) {
|
|
|
492
443
|
throw e;
|
|
493
444
|
}
|
|
494
445
|
}
|
|
495
|
-
|
|
496
|
-
function mapToArgs(input) {
|
|
446
|
+
export function mapToArgs(input) {
|
|
497
447
|
const args = [];
|
|
498
448
|
for (const [key, value] of Object.entries(input)) {
|
|
499
449
|
const vals = Array.isArray(value) ? value : [value];
|
|
@@ -506,11 +456,10 @@ function mapToArgs(input) {
|
|
|
506
456
|
}
|
|
507
457
|
return args.filter((str) => str != null && str !== '');
|
|
508
458
|
}
|
|
509
|
-
exports.mapToArgs = mapToArgs;
|
|
510
459
|
/**
|
|
511
460
|
* Yarn publish for version 2
|
|
512
461
|
*/
|
|
513
|
-
async function yarnPublishV2(pkgInfo, tag = 'latest') {
|
|
462
|
+
export async function yarnPublishV2(pkgInfo, tag = 'latest') {
|
|
514
463
|
await fork({
|
|
515
464
|
cmd: 'yarn',
|
|
516
465
|
args: [
|
|
@@ -525,8 +474,7 @@ async function yarnPublishV2(pkgInfo, tag = 'latest') {
|
|
|
525
474
|
}
|
|
526
475
|
});
|
|
527
476
|
}
|
|
528
|
-
|
|
529
|
-
async function yarnPublish(pkgInfo, tag = 'latest', registry = config.NPM_DEFAULT_REGISTRY) {
|
|
477
|
+
export async function yarnPublish(pkgInfo, tag = 'latest', registry = config.NPM_DEFAULT_REGISTRY) {
|
|
530
478
|
await fork({
|
|
531
479
|
cmd: 'yarn',
|
|
532
480
|
args: [
|
|
@@ -546,71 +494,67 @@ async function yarnPublish(pkgInfo, tag = 'latest', registry = config.NPM_DEFAUL
|
|
|
546
494
|
}
|
|
547
495
|
});
|
|
548
496
|
}
|
|
549
|
-
|
|
550
|
-
async function isKindInstalled() {
|
|
497
|
+
export async function isKindInstalled() {
|
|
551
498
|
try {
|
|
552
|
-
const subprocess = await
|
|
499
|
+
const subprocess = await execa.command('command -v kind');
|
|
553
500
|
return !!subprocess.stdout;
|
|
554
501
|
}
|
|
555
502
|
catch (err) {
|
|
556
503
|
return false;
|
|
557
504
|
}
|
|
558
505
|
}
|
|
559
|
-
|
|
560
|
-
async function isKubectlInstalled() {
|
|
506
|
+
export async function isKubectlInstalled() {
|
|
561
507
|
try {
|
|
562
|
-
const subprocess = await
|
|
508
|
+
const subprocess = await execa.command('command -v kubectl');
|
|
563
509
|
return !!subprocess.stdout;
|
|
564
510
|
}
|
|
565
511
|
catch (err) {
|
|
566
512
|
return false;
|
|
567
513
|
}
|
|
568
514
|
}
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
const e2eK8sDir = (0, packages_1.getE2eK8sDir)();
|
|
515
|
+
export async function k8sStopService(serviceName) {
|
|
516
|
+
const e2eK8sDir = getE2eK8sDir();
|
|
572
517
|
if (!e2eK8sDir) {
|
|
573
518
|
throw new Error('Missing k8s e2e test directory');
|
|
574
519
|
}
|
|
575
520
|
try {
|
|
576
521
|
// Any new service's yaml file must be named '<serviceName>Deployment.yaml'
|
|
577
522
|
const yamlFile = `${serviceName}Deployment.yaml`;
|
|
578
|
-
const subprocess = await
|
|
523
|
+
const subprocess = await execa.command(`kubectl delete -n services-dev1 -f ${path.join(e2eK8sDir, yamlFile)}`);
|
|
579
524
|
logger.debug(subprocess.stdout);
|
|
580
525
|
}
|
|
581
526
|
catch (err) {
|
|
582
527
|
// Do nothing. This should fail because no services should be up yet.
|
|
583
528
|
}
|
|
584
529
|
}
|
|
585
|
-
|
|
586
|
-
async function k8sStartService(serviceName, image, version, kind) {
|
|
530
|
+
export async function k8sStartService(serviceName, image, version, kind) {
|
|
587
531
|
// services that have an available k8s deployment yaml file
|
|
588
532
|
const availableServices = [
|
|
589
533
|
'elasticsearch', 'kafka', 'zookeeper', 'minio' // 'opensearch', 'rabbitmq'
|
|
590
534
|
];
|
|
591
535
|
if (!availableServices.includes(serviceName)) {
|
|
592
|
-
|
|
593
|
-
|
|
536
|
+
signale.error(`Service ${serviceName} is not available. No kubernetes deployment yaml file in 'e2e/k8s' directory.`);
|
|
537
|
+
signale.info(`Remove ${serviceName} from the services list by running 'unset TEST_${serviceName.toUpperCase()}' in your terminal.`);
|
|
594
538
|
await kind.destroyCluster();
|
|
595
539
|
process.exit(1);
|
|
596
540
|
}
|
|
597
541
|
// Any new service's yaml file must be named '<serviceName>Deployment.yaml'
|
|
598
542
|
const yamlFile = `${serviceName}Deployment.yaml`;
|
|
599
|
-
const e2eK8sDir =
|
|
543
|
+
const e2eK8sDir = getE2eK8sDir();
|
|
600
544
|
if (!e2eK8sDir) {
|
|
601
545
|
throw new Error('Missing k8s e2e test directory');
|
|
602
546
|
}
|
|
603
547
|
const imageString = `${image}:${version}`;
|
|
604
548
|
try {
|
|
605
|
-
const jsDoc =
|
|
549
|
+
const jsDoc = yaml.loadAll(fs.readFileSync(`${path.join(e2eK8sDir, yamlFile)}`, 'utf8'));
|
|
606
550
|
const deployment = jsDoc[0];
|
|
607
551
|
deployment.spec.template.spec.containers[0].image = imageString;
|
|
608
|
-
const updatedYaml = jsDoc.map((doc) =>
|
|
609
|
-
const tempDir =
|
|
610
|
-
|
|
611
|
-
const subprocess = await
|
|
552
|
+
const updatedYaml = jsDoc.map((doc) => yaml.dump(doc)).join('---\n');
|
|
553
|
+
const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'tempYaml'));
|
|
554
|
+
fs.writeFileSync(path.join(tempDir, `${serviceName}Deployment.yaml`), updatedYaml);
|
|
555
|
+
const subprocess = await execa.command(`kubectl create -n services-dev1 -f ${path.join(tempDir, `${serviceName}Deployment.yaml`)}`);
|
|
612
556
|
logger.debug(subprocess.stdout);
|
|
613
|
-
|
|
557
|
+
fs.rmSync(tempDir, { recursive: true, force: true });
|
|
614
558
|
}
|
|
615
559
|
catch (err) {
|
|
616
560
|
logger.error(`The service ${serviceName} could not be started: `, err);
|
|
@@ -619,7 +563,6 @@ async function k8sStartService(serviceName, image, version, kind) {
|
|
|
619
563
|
await waitForKafkaRunning();
|
|
620
564
|
}
|
|
621
565
|
}
|
|
622
|
-
exports.k8sStartService = k8sStartService;
|
|
623
566
|
function waitForKafkaRunning(timeoutMs = 120000) {
|
|
624
567
|
const endAt = Date.now() + timeoutMs;
|
|
625
568
|
const _waitForKafkaRunning = async () => {
|
|
@@ -628,45 +571,43 @@ function waitForKafkaRunning(timeoutMs = 120000) {
|
|
|
628
571
|
}
|
|
629
572
|
let kafkaRunning = false;
|
|
630
573
|
try {
|
|
631
|
-
const kubectlResponse = await
|
|
574
|
+
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}"');
|
|
632
575
|
const kafkaReady = kubectlResponse.stdout;
|
|
633
576
|
if (kafkaReady === '"true"') {
|
|
634
577
|
kafkaRunning = true;
|
|
635
578
|
}
|
|
636
579
|
}
|
|
637
580
|
catch (err) {
|
|
638
|
-
await
|
|
581
|
+
await pDelay(3000);
|
|
639
582
|
return _waitForKafkaRunning();
|
|
640
583
|
}
|
|
641
584
|
if (kafkaRunning) {
|
|
642
585
|
return;
|
|
643
586
|
}
|
|
644
|
-
await
|
|
587
|
+
await pDelay(3000);
|
|
645
588
|
return _waitForKafkaRunning();
|
|
646
589
|
};
|
|
647
590
|
return _waitForKafkaRunning();
|
|
648
591
|
}
|
|
649
|
-
async function setAlias(tsPort) {
|
|
650
|
-
let subprocess = await
|
|
592
|
+
export async function setAlias(tsPort) {
|
|
593
|
+
let subprocess = await execa.command('earl aliases remove k8s-e2e 2> /dev/null || true', { shell: true });
|
|
651
594
|
logger.debug(subprocess.stdout);
|
|
652
|
-
subprocess = await
|
|
595
|
+
subprocess = await execa.command(`earl aliases add k8s-e2e http://${config.HOST_IP}:${tsPort}`);
|
|
653
596
|
logger.debug(subprocess.stdout);
|
|
654
597
|
}
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
const subprocess = await execa_1.default.command('kubectl get deployments,po,svc --all-namespaces --show-labels -o wide');
|
|
598
|
+
export async function showState(tsPort) {
|
|
599
|
+
const subprocess = await execa.command('kubectl get deployments,po,svc --all-namespaces --show-labels -o wide');
|
|
658
600
|
logger.debug(subprocess.stdout);
|
|
659
601
|
logger.debug(await showESIndices());
|
|
660
602
|
logger.debug(await showAssets(tsPort));
|
|
661
603
|
}
|
|
662
|
-
exports.showState = showState;
|
|
663
604
|
async function showESIndices() {
|
|
664
|
-
const subprocess = await
|
|
605
|
+
const subprocess = await execa.command(`curl ${config.HOST_IP}:${config.ELASTICSEARCH_PORT}/_cat/indices?v`);
|
|
665
606
|
return subprocess.stdout;
|
|
666
607
|
}
|
|
667
608
|
async function showAssets(tsPort) {
|
|
668
609
|
try {
|
|
669
|
-
const subprocess = await
|
|
610
|
+
const subprocess = await execa.command(`curl ${config.HOST_IP}:${tsPort}/v1/assets`);
|
|
670
611
|
return subprocess.stdout;
|
|
671
612
|
}
|
|
672
613
|
catch (err) {
|