@terascope/scripts 0.83.3 → 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 +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 +113 -176
- 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 +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');
|
|
@@ -250,7 +207,7 @@ async function dockerRun(opt, tag, ignoreMount, debug) {
|
|
|
250
207
|
}
|
|
251
208
|
if (opt.ports && opt.ports.length) {
|
|
252
209
|
opt.ports.forEach((port) => {
|
|
253
|
-
if (
|
|
210
|
+
if (isString(port)) {
|
|
254
211
|
args.push('--publish', port);
|
|
255
212
|
}
|
|
256
213
|
else {
|
|
@@ -274,7 +231,7 @@ async function dockerRun(opt, tag, ignoreMount, debug) {
|
|
|
274
231
|
args.push('--network', opt.network);
|
|
275
232
|
}
|
|
276
233
|
args.push('--name', opt.name);
|
|
277
|
-
args.push(`${opt.image}:${tag
|
|
234
|
+
args.push(`${opt.image}:${tag ?? 'latest'}`);
|
|
278
235
|
if (opt.args) {
|
|
279
236
|
args.push(...opt.args);
|
|
280
237
|
}
|
|
@@ -282,9 +239,9 @@ async function dockerRun(opt, tag, ignoreMount, debug) {
|
|
|
282
239
|
let stderr;
|
|
283
240
|
let done = true;
|
|
284
241
|
if (debug) {
|
|
285
|
-
|
|
242
|
+
signale.debug(`executing: docker ${args.join(' ')}`);
|
|
286
243
|
}
|
|
287
|
-
const subprocess = (
|
|
244
|
+
const subprocess = execa('docker', args);
|
|
288
245
|
if (!subprocess || !subprocess.stderr) {
|
|
289
246
|
throw new Error('Failed to execute docker run');
|
|
290
247
|
}
|
|
@@ -308,10 +265,10 @@ async function dockerRun(opt, tag, ignoreMount, debug) {
|
|
|
308
265
|
done = true;
|
|
309
266
|
}
|
|
310
267
|
})();
|
|
311
|
-
const upFor = (
|
|
312
|
-
await
|
|
268
|
+
const upFor = ms('3s');
|
|
269
|
+
await pWhile(() => dockerContainerReady(opt.name, upFor, error), {
|
|
313
270
|
name: `Docker container up for 2m (${opt.name})`,
|
|
314
|
-
timeoutMs: (
|
|
271
|
+
timeoutMs: ms('2m')
|
|
315
272
|
});
|
|
316
273
|
if (error) {
|
|
317
274
|
if (stderr) {
|
|
@@ -327,17 +284,16 @@ async function dockerRun(opt, tag, ignoreMount, debug) {
|
|
|
327
284
|
if (stderr) {
|
|
328
285
|
process.stderr.write(stderr);
|
|
329
286
|
}
|
|
330
|
-
|
|
287
|
+
signale.error(error);
|
|
331
288
|
}
|
|
332
289
|
if (done && !subprocess.killed)
|
|
333
290
|
return;
|
|
334
291
|
subprocess.kill();
|
|
335
292
|
};
|
|
336
293
|
}
|
|
337
|
-
|
|
338
|
-
async function dockerContainerReady(name, upFor, error) {
|
|
294
|
+
export async function dockerContainerReady(name, upFor, error) {
|
|
339
295
|
if (error)
|
|
340
|
-
throw new
|
|
296
|
+
throw new TSError(error);
|
|
341
297
|
try {
|
|
342
298
|
const result = await exec({
|
|
343
299
|
cmd: 'docker',
|
|
@@ -345,20 +301,19 @@ async function dockerContainerReady(name, upFor, error) {
|
|
|
345
301
|
'ps', '--format', '"{{json .Status}}"', '--filter', `name=${name}`
|
|
346
302
|
]
|
|
347
303
|
});
|
|
348
|
-
const timeup = (
|
|
304
|
+
const timeup = ms(result.replace(/[(Up)\s"]+|/ig, ''));
|
|
349
305
|
if (!timeup)
|
|
350
306
|
return false;
|
|
351
307
|
return timeup >= upFor;
|
|
352
308
|
}
|
|
353
309
|
catch (err) {
|
|
354
|
-
await
|
|
310
|
+
await pDelay(1000);
|
|
355
311
|
return false;
|
|
356
312
|
}
|
|
357
313
|
}
|
|
358
|
-
|
|
359
|
-
async function dockerBuild(tag, cacheFrom, target, buildArgs, useDevFile) {
|
|
314
|
+
export async function dockerBuild(tag, cacheFrom, target, buildArgs, useDevFile) {
|
|
360
315
|
const cacheFromArgs = [];
|
|
361
|
-
cacheFrom
|
|
316
|
+
cacheFrom?.forEach((image) => {
|
|
362
317
|
cacheFromArgs.push('--cache-from', image);
|
|
363
318
|
});
|
|
364
319
|
const targetArgs = target ? ['--target', target] : [];
|
|
@@ -371,16 +326,14 @@ async function dockerBuild(tag, cacheFrom, target, buildArgs, useDevFile) {
|
|
|
371
326
|
args: ['build', ...cacheFromArgs, ...targetArgs, ...buildsArgs, '--tag', tag, ...dockerFilePath],
|
|
372
327
|
});
|
|
373
328
|
}
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
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 });
|
|
377
331
|
if (subprocess.exitCode !== 0) {
|
|
378
332
|
throw new Error(`Unable to push docker image ${image}, ${subprocess.stderr}`);
|
|
379
333
|
}
|
|
380
334
|
}
|
|
381
|
-
exports.dockerPush = dockerPush;
|
|
382
335
|
async function dockerImageRm(image) {
|
|
383
|
-
const subprocess = await
|
|
336
|
+
const subprocess = await execa.command(`docker image rm ${image}`, { reject: false });
|
|
384
337
|
if (subprocess.exitCode !== 0) {
|
|
385
338
|
throw new Error(`Unable to remove docker image ${image}, ${subprocess.stderr}`);
|
|
386
339
|
}
|
|
@@ -391,31 +344,29 @@ async function dockerImageRm(image) {
|
|
|
391
344
|
* @param {string} imageName Name of the image to load
|
|
392
345
|
* @returns {Promise<boolean>} Whether or not the image loaded successfully
|
|
393
346
|
*/
|
|
394
|
-
async function loadThenDeleteImageFromCache(imageName) {
|
|
395
|
-
|
|
347
|
+
export async function loadThenDeleteImageFromCache(imageName) {
|
|
348
|
+
signale.time(`unzip and load ${imageName}`);
|
|
396
349
|
const fileName = imageName.trim().replace(/[/:]/g, '_');
|
|
397
|
-
const filePath =
|
|
398
|
-
if (!
|
|
399
|
-
|
|
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?`);
|
|
400
353
|
return false;
|
|
401
354
|
}
|
|
402
|
-
const result = await
|
|
403
|
-
|
|
355
|
+
const result = await execa.command(`gunzip -c ${filePath} | docker load`, { shell: true });
|
|
356
|
+
signale.info('Result: ', result);
|
|
404
357
|
if (result.exitCode !== 0) {
|
|
405
|
-
|
|
358
|
+
signale.error(`Error loading ${filePath} to docker`);
|
|
406
359
|
return false;
|
|
407
360
|
}
|
|
408
|
-
|
|
409
|
-
|
|
361
|
+
fs.rmSync(filePath);
|
|
362
|
+
signale.timeEnd(`unzip and load ${imageName}`);
|
|
410
363
|
return true;
|
|
411
364
|
}
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
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);
|
|
416
368
|
}
|
|
417
|
-
|
|
418
|
-
async function pgrep(name) {
|
|
369
|
+
export async function pgrep(name) {
|
|
419
370
|
const result = await exec({ cmd: 'ps', args: ['aux'] }, false);
|
|
420
371
|
if (!result) {
|
|
421
372
|
throw new Error('Invalid result from ps aux');
|
|
@@ -431,7 +382,6 @@ async function pgrep(name) {
|
|
|
431
382
|
}
|
|
432
383
|
return '';
|
|
433
384
|
}
|
|
434
|
-
exports.pgrep = pgrep;
|
|
435
385
|
/**
|
|
436
386
|
* Save a docker image as a tar.gz to a local directory.
|
|
437
387
|
* Then remove the image from docker
|
|
@@ -439,16 +389,15 @@ exports.pgrep = pgrep;
|
|
|
439
389
|
* @param {string} imageSavePath Location where image will be saved and compressed.
|
|
440
390
|
* @returns void
|
|
441
391
|
*/
|
|
442
|
-
async function saveAndZip(imageName, imageSavePath) {
|
|
443
|
-
|
|
392
|
+
export async function saveAndZip(imageName, imageSavePath) {
|
|
393
|
+
signale.info(`Saving Docker image: ${imageName}`);
|
|
444
394
|
const fileName = imageName.replace(/[/:]/g, '_');
|
|
445
|
-
const filePath =
|
|
395
|
+
const filePath = path.join(imageSavePath, `${fileName}.tar`);
|
|
446
396
|
const command = `docker save ${imageName} | gzip > ${filePath}.gz`;
|
|
447
|
-
await
|
|
397
|
+
await execa.command(command, { shell: true });
|
|
448
398
|
await dockerImageRm(imageName);
|
|
449
399
|
}
|
|
450
|
-
|
|
451
|
-
async function getCommitHash() {
|
|
400
|
+
export async function getCommitHash() {
|
|
452
401
|
if (process.env.GIT_COMMIT_HASH)
|
|
453
402
|
return process.env.GIT_COMMIT_HASH;
|
|
454
403
|
if (config.SKIP_GIT_COMMANDS) {
|
|
@@ -456,8 +405,7 @@ async function getCommitHash() {
|
|
|
456
405
|
}
|
|
457
406
|
return exec({ cmd: 'git', args: ['rev-parse', '--short', 'HEAD'] });
|
|
458
407
|
}
|
|
459
|
-
|
|
460
|
-
async function gitDiff(files = []) {
|
|
408
|
+
export async function gitDiff(files = []) {
|
|
461
409
|
if (config.SKIP_GIT_COMMANDS)
|
|
462
410
|
return;
|
|
463
411
|
try {
|
|
@@ -468,8 +416,7 @@ async function gitDiff(files = []) {
|
|
|
468
416
|
logger.warn(e);
|
|
469
417
|
}
|
|
470
418
|
}
|
|
471
|
-
|
|
472
|
-
async function getChangedFiles(...files) {
|
|
419
|
+
export async function getChangedFiles(...files) {
|
|
473
420
|
if (config.SKIP_GIT_COMMANDS)
|
|
474
421
|
return [];
|
|
475
422
|
try {
|
|
@@ -492,8 +439,7 @@ async function getChangedFiles(...files) {
|
|
|
492
439
|
throw e;
|
|
493
440
|
}
|
|
494
441
|
}
|
|
495
|
-
|
|
496
|
-
function mapToArgs(input) {
|
|
442
|
+
export function mapToArgs(input) {
|
|
497
443
|
const args = [];
|
|
498
444
|
for (const [key, value] of Object.entries(input)) {
|
|
499
445
|
const vals = Array.isArray(value) ? value : [value];
|
|
@@ -506,11 +452,10 @@ function mapToArgs(input) {
|
|
|
506
452
|
}
|
|
507
453
|
return args.filter((str) => str != null && str !== '');
|
|
508
454
|
}
|
|
509
|
-
exports.mapToArgs = mapToArgs;
|
|
510
455
|
/**
|
|
511
456
|
* Yarn publish for version 2
|
|
512
457
|
*/
|
|
513
|
-
async function yarnPublishV2(pkgInfo, tag = 'latest') {
|
|
458
|
+
export async function yarnPublishV2(pkgInfo, tag = 'latest') {
|
|
514
459
|
await fork({
|
|
515
460
|
cmd: 'yarn',
|
|
516
461
|
args: [
|
|
@@ -525,8 +470,7 @@ async function yarnPublishV2(pkgInfo, tag = 'latest') {
|
|
|
525
470
|
}
|
|
526
471
|
});
|
|
527
472
|
}
|
|
528
|
-
|
|
529
|
-
async function yarnPublish(pkgInfo, tag = 'latest', registry = config.NPM_DEFAULT_REGISTRY) {
|
|
473
|
+
export async function yarnPublish(pkgInfo, tag = 'latest', registry = config.NPM_DEFAULT_REGISTRY) {
|
|
530
474
|
await fork({
|
|
531
475
|
cmd: 'yarn',
|
|
532
476
|
args: [
|
|
@@ -546,71 +490,67 @@ async function yarnPublish(pkgInfo, tag = 'latest', registry = config.NPM_DEFAUL
|
|
|
546
490
|
}
|
|
547
491
|
});
|
|
548
492
|
}
|
|
549
|
-
|
|
550
|
-
async function isKindInstalled() {
|
|
493
|
+
export async function isKindInstalled() {
|
|
551
494
|
try {
|
|
552
|
-
const subprocess = await
|
|
495
|
+
const subprocess = await execa.command('command -v kind');
|
|
553
496
|
return !!subprocess.stdout;
|
|
554
497
|
}
|
|
555
498
|
catch (err) {
|
|
556
499
|
return false;
|
|
557
500
|
}
|
|
558
501
|
}
|
|
559
|
-
|
|
560
|
-
async function isKubectlInstalled() {
|
|
502
|
+
export async function isKubectlInstalled() {
|
|
561
503
|
try {
|
|
562
|
-
const subprocess = await
|
|
504
|
+
const subprocess = await execa.command('command -v kubectl');
|
|
563
505
|
return !!subprocess.stdout;
|
|
564
506
|
}
|
|
565
507
|
catch (err) {
|
|
566
508
|
return false;
|
|
567
509
|
}
|
|
568
510
|
}
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
const e2eK8sDir = (0, packages_1.getE2eK8sDir)();
|
|
511
|
+
export async function k8sStopService(serviceName) {
|
|
512
|
+
const e2eK8sDir = getE2eK8sDir();
|
|
572
513
|
if (!e2eK8sDir) {
|
|
573
514
|
throw new Error('Missing k8s e2e test directory');
|
|
574
515
|
}
|
|
575
516
|
try {
|
|
576
517
|
// Any new service's yaml file must be named '<serviceName>Deployment.yaml'
|
|
577
518
|
const yamlFile = `${serviceName}Deployment.yaml`;
|
|
578
|
-
const subprocess = await
|
|
519
|
+
const subprocess = await execa.command(`kubectl delete -n services-dev1 -f ${path.join(e2eK8sDir, yamlFile)}`);
|
|
579
520
|
logger.debug(subprocess.stdout);
|
|
580
521
|
}
|
|
581
522
|
catch (err) {
|
|
582
523
|
// Do nothing. This should fail because no services should be up yet.
|
|
583
524
|
}
|
|
584
525
|
}
|
|
585
|
-
|
|
586
|
-
async function k8sStartService(serviceName, image, version, kind) {
|
|
526
|
+
export async function k8sStartService(serviceName, image, version, kind) {
|
|
587
527
|
// services that have an available k8s deployment yaml file
|
|
588
528
|
const availableServices = [
|
|
589
529
|
'elasticsearch', 'kafka', 'zookeeper', 'minio' // 'opensearch', 'rabbitmq'
|
|
590
530
|
];
|
|
591
531
|
if (!availableServices.includes(serviceName)) {
|
|
592
|
-
|
|
593
|
-
|
|
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.`);
|
|
594
534
|
await kind.destroyCluster();
|
|
595
535
|
process.exit(1);
|
|
596
536
|
}
|
|
597
537
|
// Any new service's yaml file must be named '<serviceName>Deployment.yaml'
|
|
598
538
|
const yamlFile = `${serviceName}Deployment.yaml`;
|
|
599
|
-
const e2eK8sDir =
|
|
539
|
+
const e2eK8sDir = getE2eK8sDir();
|
|
600
540
|
if (!e2eK8sDir) {
|
|
601
541
|
throw new Error('Missing k8s e2e test directory');
|
|
602
542
|
}
|
|
603
543
|
const imageString = `${image}:${version}`;
|
|
604
544
|
try {
|
|
605
|
-
const jsDoc =
|
|
545
|
+
const jsDoc = yaml.loadAll(fs.readFileSync(`${path.join(e2eK8sDir, yamlFile)}`, 'utf8'));
|
|
606
546
|
const deployment = jsDoc[0];
|
|
607
547
|
deployment.spec.template.spec.containers[0].image = imageString;
|
|
608
|
-
const updatedYaml = jsDoc.map((doc) =>
|
|
609
|
-
const tempDir =
|
|
610
|
-
|
|
611
|
-
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`)}`);
|
|
612
552
|
logger.debug(subprocess.stdout);
|
|
613
|
-
|
|
553
|
+
fs.rmSync(tempDir, { recursive: true, force: true });
|
|
614
554
|
}
|
|
615
555
|
catch (err) {
|
|
616
556
|
logger.error(`The service ${serviceName} could not be started: `, err);
|
|
@@ -619,7 +559,6 @@ async function k8sStartService(serviceName, image, version, kind) {
|
|
|
619
559
|
await waitForKafkaRunning();
|
|
620
560
|
}
|
|
621
561
|
}
|
|
622
|
-
exports.k8sStartService = k8sStartService;
|
|
623
562
|
function waitForKafkaRunning(timeoutMs = 120000) {
|
|
624
563
|
const endAt = Date.now() + timeoutMs;
|
|
625
564
|
const _waitForKafkaRunning = async () => {
|
|
@@ -628,45 +567,43 @@ function waitForKafkaRunning(timeoutMs = 120000) {
|
|
|
628
567
|
}
|
|
629
568
|
let kafkaRunning = false;
|
|
630
569
|
try {
|
|
631
|
-
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}"');
|
|
632
571
|
const kafkaReady = kubectlResponse.stdout;
|
|
633
572
|
if (kafkaReady === '"true"') {
|
|
634
573
|
kafkaRunning = true;
|
|
635
574
|
}
|
|
636
575
|
}
|
|
637
576
|
catch (err) {
|
|
638
|
-
await
|
|
577
|
+
await pDelay(3000);
|
|
639
578
|
return _waitForKafkaRunning();
|
|
640
579
|
}
|
|
641
580
|
if (kafkaRunning) {
|
|
642
581
|
return;
|
|
643
582
|
}
|
|
644
|
-
await
|
|
583
|
+
await pDelay(3000);
|
|
645
584
|
return _waitForKafkaRunning();
|
|
646
585
|
};
|
|
647
586
|
return _waitForKafkaRunning();
|
|
648
587
|
}
|
|
649
|
-
async function setAlias(tsPort) {
|
|
650
|
-
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 });
|
|
651
590
|
logger.debug(subprocess.stdout);
|
|
652
|
-
subprocess = await
|
|
591
|
+
subprocess = await execa.command(`earl aliases add k8s-e2e http://${config.HOST_IP}:${tsPort}`);
|
|
653
592
|
logger.debug(subprocess.stdout);
|
|
654
593
|
}
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
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');
|
|
658
596
|
logger.debug(subprocess.stdout);
|
|
659
597
|
logger.debug(await showESIndices());
|
|
660
598
|
logger.debug(await showAssets(tsPort));
|
|
661
599
|
}
|
|
662
|
-
exports.showState = showState;
|
|
663
600
|
async function showESIndices() {
|
|
664
|
-
const subprocess = await
|
|
601
|
+
const subprocess = await execa.command(`curl ${config.HOST_IP}:${config.ELASTICSEARCH_PORT}/_cat/indices?v`);
|
|
665
602
|
return subprocess.stdout;
|
|
666
603
|
}
|
|
667
604
|
async function showAssets(tsPort) {
|
|
668
605
|
try {
|
|
669
|
-
const subprocess = await
|
|
606
|
+
const subprocess = await execa.command(`curl ${config.HOST_IP}:${tsPort}/v1/assets`);
|
|
670
607
|
return subprocess.stdout;
|
|
671
608
|
}
|
|
672
609
|
catch (err) {
|