@toa.io/cli 1.1.0-dev.15 → 1.1.0-dev.16
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/package.json +6 -6
- package/readme.md +8 -7
- package/src/commands/build.js +2 -6
- package/src/commands/push.js +19 -0
- package/src/commands/replay.js +11 -0
- package/src/handlers/.replay/build.js +67 -0
- package/src/handlers/.replay/command.js +35 -0
- package/src/handlers/.replay/dock.js +18 -0
- package/src/handlers/.replay/run.js +33 -0
- package/src/handlers/build.js +2 -2
- package/src/handlers/export/images.js +8 -0
- package/src/handlers/push.js +14 -0
- package/src/handlers/replay.js +8 -2
- package/src/program.js +1 -1
- package/src/util/find.js +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@toa.io/cli",
|
|
3
|
-
"version": "1.1.0-dev.
|
|
3
|
+
"version": "1.1.0-dev.16",
|
|
4
4
|
"description": "Toa CLI",
|
|
5
5
|
"author": "temich <tema.gurtovoy@gmail.com>",
|
|
6
6
|
"homepage": "https://github.com/toa-io/toa#readme",
|
|
@@ -23,12 +23,12 @@
|
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"@toa.io/console": "0.6.0",
|
|
26
|
-
"@toa.io/generic": "0.11.0-dev.
|
|
27
|
-
"@toa.io/kubernetes": "0.7.5-dev.
|
|
28
|
-
"@toa.io/norm": "1.0
|
|
29
|
-
"@toa.io/yaml": "0.7.6-dev.
|
|
26
|
+
"@toa.io/generic": "0.11.0-dev.16",
|
|
27
|
+
"@toa.io/kubernetes": "0.7.5-dev.16",
|
|
28
|
+
"@toa.io/norm": "1.1.0-dev.0",
|
|
29
|
+
"@toa.io/yaml": "0.7.6-dev.16",
|
|
30
30
|
"find-up": "5.0.0",
|
|
31
31
|
"yargs": "17.6.2"
|
|
32
32
|
},
|
|
33
|
-
"gitHead": "
|
|
33
|
+
"gitHead": "669be360acebac4dbe49735ec506127d9d0a05e3"
|
|
34
34
|
}
|
package/readme.md
CHANGED
|
@@ -26,11 +26,12 @@ format.
|
|
|
26
26
|
<dl>
|
|
27
27
|
<dt><code>toa replay [paths...]</code></dt>
|
|
28
28
|
<dd>
|
|
29
|
-
<code>paths</code>
|
|
30
|
-
<code>--integration</code>
|
|
31
|
-
<code>--component <id></code>
|
|
32
|
-
<code>--operation <name></code>
|
|
33
|
-
<code>--title <regexp></code>
|
|
29
|
+
<code>paths</code> Path(s) to component(s) or a context (default <code>.</code>).<br/>
|
|
30
|
+
<code>--integration</code> Replay integration tests only.<br/>
|
|
31
|
+
<code>--component <id></code> Replay samples for a specified component <code>id</code>.<br/>
|
|
32
|
+
<code>--operation <name></code> Replay samples for specified operation.<br/>
|
|
33
|
+
<code>--title <regexp></code> Regexp to match sample titles.<br/>
|
|
34
|
+
<code>--dock</code> Run in Docker. Applicable only for component samples.
|
|
34
35
|
</dd>
|
|
35
36
|
</dl>
|
|
36
37
|
|
|
@@ -39,7 +40,7 @@ format.
|
|
|
39
40
|
```shell
|
|
40
41
|
$ toa replay
|
|
41
42
|
$ toa replay ./path/to/component
|
|
42
|
-
$ toa replay ./components/a ./components/b
|
|
43
|
+
$ toa replay ./components/a ./components/b --dock
|
|
43
44
|
$ toa replay ./components/*
|
|
44
45
|
$ toa replay ./path/to/context
|
|
45
46
|
$ toa replay --title "should add numbers"
|
|
@@ -97,7 +98,7 @@ the context will be found and replayed sequentially.
|
|
|
97
98
|
</dt>
|
|
98
99
|
<dd>Run interactive shell inside a disposable pod.
|
|
99
100
|
|
|
100
|
-
<code>image</code>
|
|
101
|
+
<code>image</code> Docker image<br/>
|
|
101
102
|
</dd>
|
|
102
103
|
</dl>
|
|
103
104
|
|
package/src/commands/build.js
CHANGED
|
@@ -4,10 +4,6 @@ const { build } = require('../handlers/build')
|
|
|
4
4
|
|
|
5
5
|
const builder = (yargs) => {
|
|
6
6
|
yargs
|
|
7
|
-
.positional('environment', {
|
|
8
|
-
type: 'string',
|
|
9
|
-
desc: 'Deployment environment'
|
|
10
|
-
})
|
|
11
7
|
.option('path', {
|
|
12
8
|
alias: 'p',
|
|
13
9
|
group: 'Command options:',
|
|
@@ -17,7 +13,7 @@ const builder = (yargs) => {
|
|
|
17
13
|
})
|
|
18
14
|
}
|
|
19
15
|
|
|
20
|
-
exports.command = 'build
|
|
21
|
-
exports.desc = 'Build
|
|
16
|
+
exports.command = 'build'
|
|
17
|
+
exports.desc = 'Build Docker images'
|
|
22
18
|
exports.builder = builder
|
|
23
19
|
exports.handler = build
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const { push } = require('../handlers/push')
|
|
4
|
+
|
|
5
|
+
const builder = (yargs) => {
|
|
6
|
+
yargs
|
|
7
|
+
.option('path', {
|
|
8
|
+
alias: 'p',
|
|
9
|
+
group: 'Command options:',
|
|
10
|
+
type: 'string',
|
|
11
|
+
desc: 'Path to context',
|
|
12
|
+
default: '.'
|
|
13
|
+
})
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
exports.command = 'push'
|
|
17
|
+
exports.desc = 'Build and push Docker images'
|
|
18
|
+
exports.builder = builder
|
|
19
|
+
exports.handler = push
|
package/src/commands/replay.js
CHANGED
|
@@ -4,6 +4,10 @@
|
|
|
4
4
|
|
|
5
5
|
const { replay } = require('../handlers/replay')
|
|
6
6
|
|
|
7
|
+
/*
|
|
8
|
+
!!! OPTIONS MUST BE SYNCHRONIZED WITH ../handlers/.replay/args !!!
|
|
9
|
+
*/
|
|
10
|
+
|
|
7
11
|
const builder = (yargs) => {
|
|
8
12
|
yargs
|
|
9
13
|
.positional('paths', {
|
|
@@ -35,6 +39,13 @@ const builder = (yargs) => {
|
|
|
35
39
|
group: 'Command options:',
|
|
36
40
|
describe: 'Replay samples with titles matching given regexp'
|
|
37
41
|
})
|
|
42
|
+
.option('dock', {
|
|
43
|
+
alias: 'd',
|
|
44
|
+
type: 'boolean',
|
|
45
|
+
default: false,
|
|
46
|
+
group: 'Command options:',
|
|
47
|
+
describe: 'Replay inside Docker container'
|
|
48
|
+
})
|
|
38
49
|
}
|
|
39
50
|
|
|
40
51
|
exports.command = 'replay [paths...]'
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const { newid } = require('@toa.io/generic')
|
|
4
|
+
const { component: load } = require('@toa.io/norm')
|
|
5
|
+
const { deployment: { Factory } } = require('@toa.io/operations')
|
|
6
|
+
const runtime = require('@toa.io/runtime')
|
|
7
|
+
|
|
8
|
+
const find = require('../../util/find')
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @param {string[]} paths
|
|
12
|
+
* @return {Promise<string>}
|
|
13
|
+
*/
|
|
14
|
+
async function build (paths) {
|
|
15
|
+
const context = await createContext(/** @type {string[]} */ paths)
|
|
16
|
+
const factory = new Factory(context)
|
|
17
|
+
const registry = factory.registry()
|
|
18
|
+
|
|
19
|
+
await registry.build()
|
|
20
|
+
|
|
21
|
+
const composition = context.compositions[0].name
|
|
22
|
+
|
|
23
|
+
return `${context.name}/composition-${composition}`
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* @param {string[]} patterns
|
|
28
|
+
* @return {Promise<toa.norm.Context>}
|
|
29
|
+
*/
|
|
30
|
+
async function createContext (patterns) {
|
|
31
|
+
const paths = patterns.map((pattern) => find.components(pattern))
|
|
32
|
+
const components = await loadComponents(paths)
|
|
33
|
+
const rnd = newid().substring(0, 6)
|
|
34
|
+
const name = 'replay-' + rnd
|
|
35
|
+
|
|
36
|
+
return {
|
|
37
|
+
name: 'toa-temp',
|
|
38
|
+
runtime: {
|
|
39
|
+
version: runtime.version
|
|
40
|
+
},
|
|
41
|
+
registry: {
|
|
42
|
+
platforms: null
|
|
43
|
+
},
|
|
44
|
+
compositions: [{
|
|
45
|
+
name,
|
|
46
|
+
components
|
|
47
|
+
}]
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* @param {string[]} paths
|
|
53
|
+
* @return {Promise<toa.norm.Component[]>}
|
|
54
|
+
*/
|
|
55
|
+
async function loadComponents (paths) {
|
|
56
|
+
const components = []
|
|
57
|
+
|
|
58
|
+
for (const path of paths) {
|
|
59
|
+
const component = await load(path)
|
|
60
|
+
|
|
61
|
+
components.push(component)
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return components
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
exports.build = build
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @param {Record<string, any>} argv
|
|
5
|
+
*/
|
|
6
|
+
const command = (argv) => {
|
|
7
|
+
const values = pick(argv)
|
|
8
|
+
|
|
9
|
+
return format(values)
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function pick (argv) {
|
|
13
|
+
const { component, operation, integration, title } = argv
|
|
14
|
+
return { component, operation, integration, title }
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function format (values) {
|
|
18
|
+
const args = []
|
|
19
|
+
|
|
20
|
+
for (const [name, value] of Object.entries(values)) {
|
|
21
|
+
if (value === undefined) continue
|
|
22
|
+
|
|
23
|
+
args.push('--' + name)
|
|
24
|
+
|
|
25
|
+
if (typeof value !== 'boolean') args.push(`"${value}"`)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const argumentsString = args.join(' ')
|
|
29
|
+
|
|
30
|
+
return COMMAND + argumentsString
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const COMMAND = 'toa replay * '
|
|
34
|
+
|
|
35
|
+
exports.command = command
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const { build } = require('./build')
|
|
4
|
+
const { run } = require('./run')
|
|
5
|
+
const { command } = require('./command')
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @param {Record<string, string | string[] | boolean>} argv
|
|
9
|
+
* @return {Promise<void>}
|
|
10
|
+
*/
|
|
11
|
+
async function dock (argv) {
|
|
12
|
+
const repository = await build(argv.paths)
|
|
13
|
+
const cmd = command(argv)
|
|
14
|
+
|
|
15
|
+
await run(repository, cmd)
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
exports.dock = dock
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const { spawn, exec } = require('node:child_process')
|
|
4
|
+
const { promisify } = require('node:util')
|
|
5
|
+
|
|
6
|
+
const { promex } = require('@toa.io/generic')
|
|
7
|
+
|
|
8
|
+
const execute = promisify(exec)
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @param {string} repository
|
|
12
|
+
* @param {string} command
|
|
13
|
+
* @return {Promise<void>}
|
|
14
|
+
*/
|
|
15
|
+
async function run (repository, command) {
|
|
16
|
+
const imagesResult =
|
|
17
|
+
/** @type {{ stdout: string }} */
|
|
18
|
+
await execute(`docker images -q ${repository} | head -n 1`)
|
|
19
|
+
|
|
20
|
+
const id = imagesResult.stdout.trim()
|
|
21
|
+
const args = ['run', '--rm', id, 'sh', '-c', command]
|
|
22
|
+
const done = promex()
|
|
23
|
+
|
|
24
|
+
const running = await spawn('docker', args, { stdio: 'inherit' })
|
|
25
|
+
|
|
26
|
+
running.on('exit', done.resolve)
|
|
27
|
+
|
|
28
|
+
await done
|
|
29
|
+
|
|
30
|
+
await execute(`docker rmi ${id}`)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
exports.run = run
|
package/src/handlers/build.js
CHANGED
|
@@ -6,9 +6,9 @@ const { context: find } = require('../util/find')
|
|
|
6
6
|
|
|
7
7
|
const build = async (argv) => {
|
|
8
8
|
const path = find(argv.path)
|
|
9
|
-
const
|
|
9
|
+
const registry = await boot.registry(path)
|
|
10
10
|
|
|
11
|
-
await
|
|
11
|
+
await registry.build()
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
exports.build = build
|
|
@@ -13,4 +13,12 @@ const prepare = async (argv) => {
|
|
|
13
13
|
console.log(path)
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
+
// const prepare = async (argv) => {
|
|
17
|
+
// const context = find(argv.path)
|
|
18
|
+
// const registry = await boot.registry(context)
|
|
19
|
+
// const path = await registry.prepare(argv.target)
|
|
20
|
+
//
|
|
21
|
+
// console.log(path)
|
|
22
|
+
// }
|
|
23
|
+
|
|
16
24
|
exports.prepare = prepare
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const boot = require('@toa.io/boot')
|
|
4
|
+
|
|
5
|
+
const { context: find } = require('../util/find')
|
|
6
|
+
|
|
7
|
+
const push = async (argv) => {
|
|
8
|
+
const path = find(argv.path)
|
|
9
|
+
const registry = await boot.registry(path)
|
|
10
|
+
|
|
11
|
+
await registry.push()
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
exports.push = push
|
package/src/handlers/replay.js
CHANGED
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
3
|
const find = require('../util/find')
|
|
4
|
+
const { context, components } = require('@toa.io/userland/samples')
|
|
4
5
|
|
|
6
|
+
const { dock } = require('./.replay/dock')
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @param {Record<string, string | boolean>} argv
|
|
10
|
+
* @return {Promise<void>}
|
|
11
|
+
*/
|
|
5
12
|
async function replay (argv) {
|
|
6
|
-
|
|
7
|
-
const { context, components } = require('@toa.io/userland/samples')
|
|
13
|
+
if (argv.dock) return dock(argv)
|
|
8
14
|
|
|
9
15
|
/** @type {boolean} */
|
|
10
16
|
let ok
|
package/src/program.js
CHANGED
|
@@ -19,7 +19,7 @@ yargs(process.argv.slice(2))
|
|
|
19
19
|
.fail((msg, err) => {
|
|
20
20
|
const actual = err || new Error(msg)
|
|
21
21
|
|
|
22
|
-
console.error(
|
|
22
|
+
console.error(actual)
|
|
23
23
|
|
|
24
24
|
process.exit(actual.exitCode > 0 ? actual.exitCode : 1)
|
|
25
25
|
})
|
package/src/util/find.js
CHANGED
|
@@ -17,7 +17,7 @@ const find = (from, filename, test) => {
|
|
|
17
17
|
|
|
18
18
|
if (found.size === 0) {
|
|
19
19
|
if (test === true) return null
|
|
20
|
-
else throw new Error(`File '${filename}' is found in ${from.join(', ')}`)
|
|
20
|
+
else throw new Error(`File '${filename}' is not found in ${from.join(', ')}`)
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
return [...found]
|