hammerkit 1.4.0-beta.6 → 1.5.0-alpha.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/.devcontainer/Dockerfile +5 -0
- package/.devcontainer/devcontainer.json +40 -0
- package/Dockerfile +1 -1
- package/README.md +13 -86
- package/SUMMARY.md +43 -0
- package/build.schema.json +56 -2
- package/dist/cli.js +97 -0
- package/dist/cli.spec.js +5 -0
- package/dist/console/console-context-mock.js +11 -0
- package/dist/console/get-logger.js +23 -0
- package/dist/docker/pull.js +5 -5
- package/dist/docker/remove-container.js +21 -0
- package/dist/docker/stream.js +19 -21
- package/dist/docker/using-container.js +28 -0
- package/dist/environment/get-process-env.js +4 -4
- package/dist/environment/replace-env-variables.js +2 -3
- package/dist/executer/abort.js +13 -0
- package/dist/executer/check-readiness.js +25 -0
- package/dist/executer/create-scheduler-state.js +32 -0
- package/dist/executer/docker-node.js +123 -0
- package/dist/executer/docker-service.js +113 -0
- package/dist/executer/environment-mock.js +17 -0
- package/dist/executer/event-cache.js +165 -0
- package/dist/executer/execute-command.js +42 -0
- package/dist/executer/execute-docker.js +73 -223
- package/dist/executer/execute.spec.js +37 -37
- package/dist/executer/execution-steps.js +57 -0
- package/dist/executer/get-docker-executor.js +21 -20
- package/dist/executer/hierarchy-scheduler.js +94 -0
- package/dist/executer/kubernetes-service.js +64 -0
- package/dist/executer/label-values.js +65 -0
- package/dist/executer/local-node.js +57 -0
- package/dist/executer/print-container-options.js +17 -0
- package/dist/{logging/log-strategy.js → executer/process-item.js} +1 -1
- package/dist/executer/process-listener.js +3 -0
- package/dist/executer/process-manager.js +111 -0
- package/dist/executer/process-manager.spec.js +91 -0
- package/dist/executer/{executor.js → process.js} +1 -1
- package/dist/executer/{execute-result.js → readonly-state.js} +1 -1
- package/dist/executer/schedule.js +139 -0
- package/dist/executer/scheduler/check-for-loop.js +21 -0
- package/dist/executer/scheduler/enqueue-next.js +27 -0
- package/dist/{testing/test-context.js → executer/scheduler/node-state.js} +1 -1
- package/dist/executer/scheduler/scheduler-result.js +3 -0
- package/dist/executer/scheduler/scheduler-state.js +3 -0
- package/dist/executer/scheduler/service-state.js +3 -0
- package/dist/executer/service-dns.js +6 -0
- package/dist/executer/set-user-permission.js +16 -0
- package/dist/executer/start-node.js +59 -0
- package/dist/executer/state-listener.js +3 -0
- package/dist/executer/state.js +49 -0
- package/dist/executer/states.js +4 -129
- package/dist/executer/watch-node.js +57 -0
- package/dist/executer/watch-service.js +54 -0
- package/dist/executer/work-scope.js +10 -0
- package/dist/file/get-file-context-mock.js +1 -0
- package/dist/file/get-file-context-mock.spec.js +28 -27
- package/dist/file/get-file-context.js +73 -63
- package/dist/file/move-files.js +1 -1
- package/dist/get-work-context.js +29 -0
- package/dist/index.js +11 -10
- package/dist/log.js +209 -52
- package/dist/logging/grouped-logger.js +31 -19
- package/dist/logging/interactive-logger.js +20 -23
- package/dist/logging/live-logger.js +7 -17
- package/dist/optimizer/calculate-checksum.js +1 -1
- package/dist/optimizer/get-cache-directory.js +8 -13
- package/dist/optimizer/get-work-node-cache-stats.js +68 -21
- package/dist/optimizer/read-work-node-cache.js +2 -2
- package/dist/optimizer/work-node-cache-description.js +12 -11
- package/dist/optimizer/write-work-node-cache.js +9 -8
- package/dist/{executer/execution-context.js → parser/build-file-service.js} +1 -1
- package/dist/{optimizer → parser}/cache-method.js +0 -0
- package/dist/parser/get-build-file.js +1 -1
- package/dist/parser/parse-boolean.js +29 -0
- package/dist/parser/parse-boolean.spec.js +48 -0
- package/dist/parser/parse-build-file-references.js +2 -2
- package/dist/parser/parse-build-file-services.js +58 -0
- package/dist/parser/parse-build-file-task-command.js +6 -5
- package/dist/parser/parse-build-file-task-source.js +5 -5
- package/dist/parser/parse-build-file.js +29 -17
- package/dist/parser/parse-context.js +13 -0
- package/dist/parser/parse-envs.js +4 -3
- package/dist/parser/parse-healthcheck.js +28 -0
- package/dist/parser/parse-label-arguments.js +23 -0
- package/dist/parser/parse-service-selector.js +39 -0
- package/dist/parser/parse-string-array.js +6 -5
- package/dist/parser/parse-string-map.js +30 -0
- package/dist/parser/parse-string.js +20 -0
- package/dist/parser/read-build-file.js +16 -5
- package/dist/parser/read-env-file.js +7 -7
- package/dist/planner/utils/get-container-mounts.js +24 -0
- package/dist/planner/utils/normalize-path.js +17 -0
- package/dist/planner/utils/parse-work-node-mount.js +3 -14
- package/dist/planner/utils/parse-work-node-mount.spec.js +10 -10
- package/dist/planner/utils/parse-work-service-volume.js +21 -0
- package/dist/planner/utils/plan-work-command.js +1 -1
- package/dist/planner/utils/plan-work-dependency.js +29 -24
- package/dist/planner/utils/plan-work-node.js +203 -120
- package/dist/planner/utils/plan-work-nodes.js +60 -12
- package/dist/planner/utils/plan-work-tree.js +8 -4
- package/dist/planner/utils/plan-work-volume.js +25 -0
- package/dist/planner/validate.js +56 -8
- package/dist/planner/work-context.js +20 -0
- package/dist/planner/work-mount.js +3 -0
- package/dist/planner/work-node-id.js +4 -4
- package/dist/planner/work-node-id.spec.js +11 -8
- package/dist/planner/work-node-path.js +0 -1
- package/dist/planner/work-node-status.js +121 -18
- package/dist/planner/work-node.js +3 -3
- package/dist/planner/work-service-id.js +13 -0
- package/dist/planner/work-service-volume.js +3 -0
- package/dist/planner/work-service.js +6 -0
- package/dist/planner/work-services.js +3 -0
- package/dist/planner/work-volume.js +3 -0
- package/dist/program.js +155 -91
- package/dist/program.spec.js +20 -0
- package/dist/start-watch-processes.js +28 -0
- package/dist/testing/cli.js +73 -0
- package/dist/testing/create-build-file.js +1 -1
- package/dist/testing/example-test-suite.js +54 -0
- package/dist/testing/expect.js +30 -18
- package/dist/testing/get-logger.js +23 -0
- package/dist/testing/get-node.js +2 -2
- package/dist/testing/get-test-context.js +6 -5
- package/dist/testing/get-test-suite.js +2 -51
- package/dist/testing/integration/cache.spec.js +25 -28
- package/dist/testing/integration/cancellation.spec.js +19 -21
- package/dist/testing/integration/clean.spec.js +29 -13
- package/dist/testing/integration/cmd.spec.js +5 -8
- package/dist/testing/integration/concurrency.spec.js +8 -17
- package/dist/testing/integration/docker.spec.js +6 -9
- package/dist/testing/integration/env.spec.js +27 -34
- package/dist/testing/integration/error.spec.js +5 -9
- package/dist/testing/integration/extend.spec.js +32 -0
- package/dist/testing/integration/glob.spec.js +35 -28
- package/dist/testing/integration/include.spec.js +17 -16
- package/dist/testing/integration/invalid.spec.js +3 -2
- package/dist/testing/integration/invalid_loop.spec.js +13 -0
- package/dist/testing/integration/kubernetes.spec.js +15 -0
- package/dist/testing/integration/labels.spec.js +47 -0
- package/dist/testing/integration/local.spec.js +4 -7
- package/dist/testing/integration/monorepo.spec.js +6 -30
- package/dist/testing/integration/multi-line.spec.js +4 -4
- package/dist/testing/integration/program.spec.js +3 -10
- package/dist/testing/integration/reference.spec.js +10 -13
- package/dist/testing/integration/services.spec.js +14 -0
- package/dist/testing/integration/store.spec.js +42 -35
- package/dist/testing/integration/unknown.spec.js +4 -4
- package/dist/testing/integration/validate.spec.js +4 -4
- package/dist/testing/integration/watch.spec.js +25 -23
- package/dist/testing/lazy.js +17 -0
- package/dist/testing/start-watch-processes.js +29 -0
- package/dist/testing/test-suite-setup.js +3 -0
- package/dist/utils/abort-event.js +24 -0
- package/dist/utils/abortable-function.js +71 -0
- package/dist/utils/debouncer.spec.js +8 -8
- package/dist/utils/environment-config.js +13 -0
- package/dist/utils/fail-never.js +1 -1
- package/dist/utils/sleep.spec.js +3 -3
- package/package.json +24 -21
- package/dist/console/get-console-context-mock.js +0 -33
- package/dist/executer/clean.js +0 -22
- package/dist/executer/execute-local.js +0 -58
- package/dist/executer/execute.js +0 -95
- package/dist/executer/execution-context-event.js +0 -3
- package/dist/executer/execution-context-mock.js +0 -3
- package/dist/executer/executor-mock.js +0 -39
- package/dist/executer/get-environment-mock.js +0 -17
- package/dist/executer/get-execution-context-mock.js +0 -19
- package/dist/executer/get-local-executor.js +0 -22
- package/dist/executer/get-ready-work-nodes.js +0 -15
- package/dist/executer/restore.js +0 -22
- package/dist/executer/store.js +0 -23
- package/dist/logging/get-logger.js +0 -23
- package/dist/logging/message-to-console.js +0 -16
- package/dist/optimizer/optimize.js +0 -32
- package/dist/optimizer/work-node-description.js +0 -12
- package/dist/planner/utils/find-build-task.js +0 -18
- package/dist/testing/create-work-tree.js +0 -11
- package/dist/utils/defer.js +0 -57
- package/dist/utils/defer.spec.js +0 -76
|
@@ -2,24 +2,27 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const work_node_id_1 = require("./work-node-id");
|
|
4
4
|
const create_build_file_1 = require("../testing/create-build-file");
|
|
5
|
-
const get_environment_mock_1 = require("../executer/get-environment-mock");
|
|
6
5
|
const plan_work_node_1 = require("./utils/plan-work-node");
|
|
6
|
+
const work_context_1 = require("./work-context");
|
|
7
|
+
const environment_mock_1 = require("../executer/environment-mock");
|
|
7
8
|
async function compareTasks(firstTask, secondTask, expectEqual) {
|
|
8
|
-
const
|
|
9
|
-
const firstBuildFile = await create_build_file_1.createBuildFile(
|
|
9
|
+
const environment = (0, environment_mock_1.environmentMock)(process.cwd());
|
|
10
|
+
const firstBuildFile = await (0, create_build_file_1.createBuildFile)(environment, {
|
|
10
11
|
tasks: {
|
|
11
12
|
test: firstTask,
|
|
12
13
|
},
|
|
13
14
|
});
|
|
14
|
-
const secondBuildFile = await create_build_file_1.createBuildFile(
|
|
15
|
+
const secondBuildFile = await (0, create_build_file_1.createBuildFile)(environment, {
|
|
15
16
|
tasks: {
|
|
16
17
|
test: secondTask,
|
|
17
18
|
},
|
|
18
19
|
});
|
|
19
|
-
const
|
|
20
|
-
const
|
|
21
|
-
const
|
|
22
|
-
const
|
|
20
|
+
const firstContext = (0, work_context_1.createWorkContext)(firstBuildFile);
|
|
21
|
+
const firstMerged = (0, plan_work_node_1.planTask)(firstContext, (0, plan_work_node_1.findBuildTask)(firstContext, { taskName: 'test' }));
|
|
22
|
+
const secondContext = (0, work_context_1.createWorkContext)(secondBuildFile);
|
|
23
|
+
const secondMerged = (0, plan_work_node_1.planTask)(secondContext, (0, plan_work_node_1.findBuildTask)(secondContext, { taskName: 'test' }));
|
|
24
|
+
const firstNodeId = (0, work_node_id_1.getWorkNodeId)(firstMerged);
|
|
25
|
+
const secondNodeId = (0, work_node_id_1.getWorkNodeId)(secondMerged);
|
|
23
26
|
if (expectEqual) {
|
|
24
27
|
expect(firstNodeId).toEqual(secondNodeId);
|
|
25
28
|
}
|
|
@@ -1,31 +1,134 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
const log_1 = require("../log");
|
|
3
|
+
exports.statusConsole = exports.logContext = void 0;
|
|
5
4
|
const emitter_1 = require("../utils/emitter");
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
const work_node_1 = require("./work-node");
|
|
6
|
+
const environment_config_1 = require("../utils/environment-config");
|
|
7
|
+
const log_1 = require("../log");
|
|
8
|
+
const StatusBufferMax = (0, environment_config_1.getEnvironmentConfig)('STATUS_BUFFER_LIMIT', 300);
|
|
9
|
+
const ConsoleBufferMax = (0, environment_config_1.getEnvironmentConfig)('CONSOLE_BUFFER_LIMIT', 30);
|
|
10
|
+
function logContext(type, node) {
|
|
11
|
+
return {
|
|
12
|
+
type,
|
|
13
|
+
name: node.name,
|
|
14
|
+
id: node.id,
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
exports.logContext = logContext;
|
|
18
|
+
class BufferContext {
|
|
19
|
+
constructor(limit) {
|
|
20
|
+
this.limit = limit;
|
|
21
|
+
this.scopedBuffer = {};
|
|
22
|
+
this.buffer = [];
|
|
23
|
+
}
|
|
24
|
+
add(id, data) {
|
|
25
|
+
this.buffer.push(data);
|
|
26
|
+
if (id in this.scopedBuffer) {
|
|
27
|
+
const scopedBuffer = this.scopedBuffer[id];
|
|
28
|
+
scopedBuffer.push(data);
|
|
29
|
+
if (scopedBuffer.length > this.limit) {
|
|
30
|
+
const removedBuffer = this.buffer.splice(0, 1)[0];
|
|
31
|
+
const bufferIndex = this.buffer.indexOf(removedBuffer);
|
|
32
|
+
if (bufferIndex >= 0) {
|
|
33
|
+
this.buffer.splice(bufferIndex, 1);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
this.scopedBuffer[id] = [data];
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
current(id) {
|
|
42
|
+
if (!(id in this.scopedBuffer)) {
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
const value = this.scopedBuffer[id];
|
|
46
|
+
return value[value.length - 1];
|
|
47
|
+
}
|
|
48
|
+
get(id) {
|
|
49
|
+
if (id) {
|
|
50
|
+
return this.scopedBuffer[id] ?? [];
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
return this.buffer;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
function statusConsole() {
|
|
58
|
+
const statusBuffer = new BufferContext(StatusBufferMax);
|
|
59
|
+
const consoleBuffer = new BufferContext(ConsoleBufferMax);
|
|
60
|
+
const emit = (0, emitter_1.emitter)();
|
|
61
|
+
function addMessage(context, message) {
|
|
62
|
+
emit.emit(message);
|
|
63
|
+
if (message.type === 'console') {
|
|
64
|
+
consoleBuffer.add(context.id, message);
|
|
65
|
+
}
|
|
66
|
+
else if (log_1.isVerbose || message.level !== 'debug') {
|
|
67
|
+
statusBuffer.add(context.id, message);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
10
70
|
return {
|
|
11
|
-
|
|
12
|
-
return
|
|
71
|
+
task(task) {
|
|
72
|
+
return this.context(logContext('task', task));
|
|
73
|
+
},
|
|
74
|
+
service(service) {
|
|
75
|
+
return this.context(logContext('service', service));
|
|
76
|
+
},
|
|
77
|
+
from(node) {
|
|
78
|
+
if ((0, work_node_1.isWorkNode)(node)) {
|
|
79
|
+
return this.task(node);
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
return this.service(node);
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
context(context) {
|
|
86
|
+
return {
|
|
87
|
+
currentLog() {
|
|
88
|
+
return consoleBuffer.current(context.id);
|
|
89
|
+
},
|
|
90
|
+
current() {
|
|
91
|
+
return statusBuffer.current(context.id);
|
|
92
|
+
},
|
|
93
|
+
*logs() {
|
|
94
|
+
for (const log of consoleBuffer.get(context.id)) {
|
|
95
|
+
yield log;
|
|
96
|
+
}
|
|
97
|
+
},
|
|
98
|
+
*read() {
|
|
99
|
+
for (const log of statusBuffer.get(context.id)) {
|
|
100
|
+
yield log;
|
|
101
|
+
}
|
|
102
|
+
},
|
|
103
|
+
console(type, message) {
|
|
104
|
+
addMessage(context, {
|
|
105
|
+
type: 'console',
|
|
106
|
+
console: type,
|
|
107
|
+
message,
|
|
108
|
+
date: new Date(),
|
|
109
|
+
context,
|
|
110
|
+
});
|
|
111
|
+
},
|
|
112
|
+
write(level, message) {
|
|
113
|
+
addMessage(context, {
|
|
114
|
+
type: 'status',
|
|
115
|
+
message,
|
|
116
|
+
context,
|
|
117
|
+
level,
|
|
118
|
+
date: new Date(),
|
|
119
|
+
});
|
|
120
|
+
},
|
|
121
|
+
};
|
|
13
122
|
},
|
|
14
123
|
on(listener) {
|
|
15
124
|
return emit.on(listener);
|
|
16
125
|
},
|
|
17
|
-
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
current = log;
|
|
126
|
+
*read() {
|
|
127
|
+
for (const message of statusBuffer.get()) {
|
|
128
|
+
yield message;
|
|
21
129
|
}
|
|
22
|
-
emit.emit(log);
|
|
23
|
-
logs.push(log);
|
|
24
|
-
},
|
|
25
|
-
get current() {
|
|
26
|
-
return current;
|
|
27
130
|
},
|
|
28
131
|
};
|
|
29
132
|
}
|
|
30
|
-
exports.
|
|
133
|
+
exports.statusConsole = statusConsole;
|
|
31
134
|
//# sourceMappingURL=work-node-status.js.map
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.isWorkNode = exports.isContainerWorkNode = void 0;
|
|
4
4
|
const isContainerWorkNode = (val) => val.type === 'container';
|
|
5
5
|
exports.isContainerWorkNode = isContainerWorkNode;
|
|
6
|
-
const
|
|
7
|
-
exports.
|
|
6
|
+
const isWorkNode = (val) => val.type === 'container' || val.type === 'local';
|
|
7
|
+
exports.isWorkNode = isWorkNode;
|
|
8
8
|
//# sourceMappingURL=work-node.js.map
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getWorkServiceId = void 0;
|
|
4
|
+
const crypto_1 = require("crypto");
|
|
5
|
+
function getWorkServiceId(buildFile, service) {
|
|
6
|
+
const jsonData = JSON.stringify({
|
|
7
|
+
path: buildFile.path,
|
|
8
|
+
image: service.image,
|
|
9
|
+
});
|
|
10
|
+
return (0, crypto_1.createHash)('sha1').update(jsonData).digest('hex');
|
|
11
|
+
}
|
|
12
|
+
exports.getWorkServiceId = getWorkServiceId;
|
|
13
|
+
//# sourceMappingURL=work-service-id.js.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isContainerWorkService = void 0;
|
|
4
|
+
const isContainerWorkService = (svc) => 'image' in svc && svc.type === 'container-service';
|
|
5
|
+
exports.isContainerWorkService = isContainerWorkService;
|
|
6
|
+
//# sourceMappingURL=work-service.js.map
|
package/dist/program.js
CHANGED
|
@@ -1,75 +1,146 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getProgram = void 0;
|
|
3
|
+
exports.getProgram = exports.createCli = void 0;
|
|
4
4
|
const commander_1 = require("commander");
|
|
5
5
|
const path_1 = require("path");
|
|
6
|
-
const get_build_file_1 = require("./parser/get-build-file");
|
|
7
|
-
const plan_work_nodes_1 = require("./planner/utils/plan-work-nodes");
|
|
8
|
-
const execute_1 = require("./executer/execute");
|
|
9
|
-
const plan_work_tree_1 = require("./planner/utils/plan-work-tree");
|
|
10
|
-
const restore_1 = require("./executer/restore");
|
|
11
|
-
const store_1 = require("./executer/store");
|
|
12
|
-
const clean_1 = require("./executer/clean");
|
|
13
|
-
const validate_1 = require("./planner/validate");
|
|
14
|
-
const get_local_executor_1 = require("./executer/get-local-executor");
|
|
15
|
-
const get_docker_executor_1 = require("./executer/get-docker-executor");
|
|
16
|
-
const get_logger_1 = require("./logging/get-logger");
|
|
17
6
|
const ci_1 = require("./utils/ci");
|
|
18
|
-
const
|
|
7
|
+
const parse_label_arguments_1 = require("./parser/parse-label-arguments");
|
|
8
|
+
const cli_1 = require("./cli");
|
|
9
|
+
const get_build_file_1 = require("./parser/get-build-file");
|
|
10
|
+
const work_scope_1 = require("./executer/work-scope");
|
|
11
|
+
const get_work_context_1 = require("./get-work-context");
|
|
12
|
+
const log_1 = require("./log");
|
|
13
|
+
const label_values_1 = require("./executer/label-values");
|
|
14
|
+
async function createCli(fileName, environment, workScope) {
|
|
15
|
+
const buildFile = await (0, get_build_file_1.getBuildFile)(fileName, environment);
|
|
16
|
+
const workTree = (0, get_work_context_1.getWorkScope)(buildFile, workScope, environment);
|
|
17
|
+
return (0, cli_1.getCli)(workTree, environment);
|
|
18
|
+
}
|
|
19
|
+
exports.createCli = createCli;
|
|
20
|
+
function parseWorkScope(options) {
|
|
21
|
+
const scope = (0, work_scope_1.emptyWorkLabelScope)();
|
|
22
|
+
if (typeof options !== 'object') {
|
|
23
|
+
return scope;
|
|
24
|
+
}
|
|
25
|
+
if (options === undefined || options === null) {
|
|
26
|
+
return scope;
|
|
27
|
+
}
|
|
28
|
+
for (const [key, value] of Object.entries(options)) {
|
|
29
|
+
if (key === 'filter' && value instanceof Array) {
|
|
30
|
+
scope.filterLabels = (0, parse_label_arguments_1.parseLabelArguments)(value);
|
|
31
|
+
}
|
|
32
|
+
else if (key === 'exclude' && value instanceof Array) {
|
|
33
|
+
scope.excludeLabels = (0, parse_label_arguments_1.parseLabelArguments)(value);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return scope;
|
|
37
|
+
}
|
|
19
38
|
async function getProgram(environment, argv) {
|
|
20
39
|
const program = new commander_1.Command();
|
|
21
40
|
const args = [...argv];
|
|
22
41
|
const fileIndex = args.indexOf('--file');
|
|
23
|
-
const fileName = path_1.join(environment.cwd, fileIndex >= 0 ? args[fileIndex + 1] : 'build.yaml');
|
|
42
|
+
const fileName = (0, path_1.join)(environment.cwd, fileIndex >= 0 ? args[fileIndex + 1] : 'build.yaml');
|
|
24
43
|
if (fileIndex >= 0) {
|
|
25
44
|
args.splice(fileIndex, 2);
|
|
26
45
|
}
|
|
27
46
|
if (await environment.file.exists(fileName)) {
|
|
28
|
-
const buildFile = await get_build_file_1.getBuildFile(fileName, environment);
|
|
29
|
-
const workNodes = plan_work_nodes_1.planWorkNodes(buildFile);
|
|
30
|
-
const reservedCommands = ['clean', 'store', 'restore', 'validate'];
|
|
31
47
|
program
|
|
32
|
-
.command('
|
|
33
|
-
.description('
|
|
34
|
-
.
|
|
35
|
-
|
|
36
|
-
|
|
48
|
+
.command('ls')
|
|
49
|
+
.description('list all tasks')
|
|
50
|
+
.addOption(new commander_1.Option('-f, --filter <labels...>', 'filter task and services with labels'))
|
|
51
|
+
.addOption(new commander_1.Option('-e, --exclude <labels...>', 'exclude task and services with labels'))
|
|
52
|
+
.action(async (options) => {
|
|
53
|
+
const cli = await createCli(fileName, environment, parseWorkScope(options));
|
|
54
|
+
const items = cli.ls();
|
|
55
|
+
const tasks = items.filter(cli_1.isCliTask);
|
|
56
|
+
const services = items.filter(cli_1.isCliService);
|
|
57
|
+
if (services.length > 0) {
|
|
58
|
+
(0, log_1.printTitle)('Services');
|
|
59
|
+
for (const node of services) {
|
|
60
|
+
(0, log_1.printItem)(node.item);
|
|
61
|
+
(0, log_1.printProperty)('ports', node.item.ports.map((p) => `127.0.0.1:${p.hostPort} -> ${p.containerPort}`).join(', '));
|
|
62
|
+
if (node.item.type === 'kubernetes-service') {
|
|
63
|
+
(0, log_1.printProperty)('context', node.item.context);
|
|
64
|
+
(0, log_1.printProperty)('selector', `${node.item.selector.type}/${node.item.selector.name}`);
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
(0, log_1.printProperty)('image', node.item.image);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
37
70
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
process.exit(1);
|
|
71
|
+
if (tasks.length > 0 && services.length > 0) {
|
|
72
|
+
process.stdout.write('\n');
|
|
41
73
|
}
|
|
74
|
+
if (tasks.length > 0) {
|
|
75
|
+
(0, log_1.printTitle)('Tasks');
|
|
76
|
+
for (const node of tasks) {
|
|
77
|
+
(0, log_1.printItem)(node.item);
|
|
78
|
+
if (node.item.needs.length > 0) {
|
|
79
|
+
(0, log_1.printProperty)('needs', node.item.needs.map((d) => d.name).join(', '));
|
|
80
|
+
}
|
|
81
|
+
if (node.item.deps.length > 0) {
|
|
82
|
+
(0, log_1.printProperty)('deps', node.item.deps.map((d) => d.name).join(', '));
|
|
83
|
+
}
|
|
84
|
+
if (node.item.type === 'container') {
|
|
85
|
+
(0, log_1.printProperty)('image', node.item.image);
|
|
86
|
+
}
|
|
87
|
+
if (node.item.caching) {
|
|
88
|
+
(0, log_1.printProperty)('caching', node.item.caching);
|
|
89
|
+
}
|
|
90
|
+
if ((0, label_values_1.hasLabels)(node.item.labels)) {
|
|
91
|
+
(0, log_1.printProperty)('labels', `${Object.keys(node.item.labels)
|
|
92
|
+
.map((key) => `${key}=${node.item.labels[key].join(',')}`)
|
|
93
|
+
.join(' ')}`);
|
|
94
|
+
}
|
|
95
|
+
if (node.item.src.length > 0) {
|
|
96
|
+
(0, log_1.printProperty)('src', node.item.src.map((d) => (0, path_1.relative)(node.item.cwd, d.absolutePath)).join(' '));
|
|
97
|
+
}
|
|
98
|
+
if (node.item.generates.length > 0) {
|
|
99
|
+
(0, log_1.printProperty)('generates', node.item.generates.map((d) => (0, path_1.relative)(node.item.cwd, d.path)).join(' '));
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
process.stdout.write('\n');
|
|
104
|
+
});
|
|
105
|
+
program
|
|
106
|
+
.command('clean')
|
|
107
|
+
.description('clear task cache')
|
|
108
|
+
.addOption(new commander_1.Option('--service', 'clean data volumes of services'))
|
|
109
|
+
.addOption(new commander_1.Option('-f, --filter <labels...>', 'filter task and services with labels'))
|
|
110
|
+
.addOption(new commander_1.Option('-e, --exclude <labels...>', 'exclude task and services with labels'))
|
|
111
|
+
.action(async (options) => {
|
|
112
|
+
const cli = await createCli(fileName, environment, parseWorkScope(options));
|
|
113
|
+
await cli.clean({
|
|
114
|
+
service: options.service,
|
|
115
|
+
});
|
|
42
116
|
});
|
|
43
117
|
program
|
|
44
118
|
.command('store <path>')
|
|
45
119
|
.description('save task outputs into <path>')
|
|
46
|
-
.
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
environment.console.error(e);
|
|
52
|
-
process.exit(1);
|
|
53
|
-
}
|
|
120
|
+
.addOption(new commander_1.Option('-f, --filter <labels...>', 'filter task and services with labels'))
|
|
121
|
+
.addOption(new commander_1.Option('-e, --exclude <labels...>', 'exclude task and services with labels'))
|
|
122
|
+
.action(async (path, options) => {
|
|
123
|
+
const cli = await createCli(fileName, environment, parseWorkScope(options));
|
|
124
|
+
await cli.store((0, path_1.resolve)(path));
|
|
54
125
|
});
|
|
55
126
|
program
|
|
56
127
|
.command('restore <path>')
|
|
57
128
|
.description('restore task outputs from <path>')
|
|
58
|
-
.
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
environment.console.error(e);
|
|
64
|
-
process.exit(1);
|
|
65
|
-
}
|
|
129
|
+
.addOption(new commander_1.Option('-f, --filter <labels...>', 'filter task and services with labels'))
|
|
130
|
+
.addOption(new commander_1.Option('-e, --exclude <labels...>', 'exclude task and services with labels'))
|
|
131
|
+
.action(async (path, options) => {
|
|
132
|
+
const cli = await createCli(fileName, environment, parseWorkScope(options));
|
|
133
|
+
await cli.restore((0, path_1.resolve)(path));
|
|
66
134
|
});
|
|
67
135
|
program
|
|
68
136
|
.command('validate')
|
|
69
137
|
.description('validate build.yaml')
|
|
70
|
-
.
|
|
138
|
+
.addOption(new commander_1.Option('-f, --filter <labels...>', 'filter task and services with labels'))
|
|
139
|
+
.addOption(new commander_1.Option('-e, --exclude <labels...>', 'exclude task and services with labels'))
|
|
140
|
+
.action(async (options) => {
|
|
71
141
|
let errors = 0;
|
|
72
|
-
|
|
142
|
+
const cli = await createCli(fileName, environment, parseWorkScope(options));
|
|
143
|
+
for await (const validation of cli.validate()) {
|
|
73
144
|
if (validation.type === 'error') {
|
|
74
145
|
errors++;
|
|
75
146
|
environment.console.error(validation.message);
|
|
@@ -78,56 +149,46 @@ async function getProgram(environment, argv) {
|
|
|
78
149
|
environment.console.warn(validation.message);
|
|
79
150
|
}
|
|
80
151
|
}
|
|
81
|
-
if (errors
|
|
82
|
-
|
|
83
|
-
}
|
|
84
|
-
else {
|
|
85
|
-
process.exit(1);
|
|
152
|
+
if (errors !== 0) {
|
|
153
|
+
program.error('Detected errors in your build.yaml', { exitCode: 1 });
|
|
86
154
|
}
|
|
87
155
|
});
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
const result = await execute_1.execute(workTree, executionContext);
|
|
120
|
-
await logger.finish(workTree, result);
|
|
121
|
-
if (!result.success) {
|
|
122
|
-
process.exit(1);
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
catch (e) {
|
|
126
|
-
logger.abort(e);
|
|
127
|
-
process.exit(1);
|
|
128
|
-
}
|
|
156
|
+
program
|
|
157
|
+
.command('shutdown')
|
|
158
|
+
.description('end all container tasks/services')
|
|
159
|
+
.arguments('[task]')
|
|
160
|
+
.addOption(new commander_1.Option('-f, --filter <labels...>', 'filter task and services with labels'))
|
|
161
|
+
.addOption(new commander_1.Option('-e, --exclude <labels...>', 'exclude task and services with labels'))
|
|
162
|
+
.action(async (task, options) => {
|
|
163
|
+
const cli = await createCli(fileName, environment, task ? { taskName: task } : parseWorkScope(options));
|
|
164
|
+
cli.shutdown();
|
|
165
|
+
});
|
|
166
|
+
program
|
|
167
|
+
.command('exec', { isDefault: true })
|
|
168
|
+
.description('execute task(s)')
|
|
169
|
+
.arguments('[task]')
|
|
170
|
+
.addOption(new commander_1.Option('-f, --filter <labels...>', 'filter task and services with labels'))
|
|
171
|
+
.addOption(new commander_1.Option('-e, --exclude <labels...>', 'exclude task and services with labels'))
|
|
172
|
+
.addOption(new commander_1.Option('-c, --concurrency <number>', 'parallel worker count').argParser(parseInt).default(4))
|
|
173
|
+
.addOption(new commander_1.Option('-w, --watch', 'watch tasks').default(false))
|
|
174
|
+
.addOption(new commander_1.Option('-l, --log <mode>', 'log mode')
|
|
175
|
+
.default(ci_1.isCI ? 'live' : 'interactive')
|
|
176
|
+
.choices(['interactive', 'live', 'grouped']))
|
|
177
|
+
.addOption(new commander_1.Option('--cache <method>', 'caching method to compare')
|
|
178
|
+
.default(ci_1.isCI ? 'checksum' : 'modify-date')
|
|
179
|
+
.choices(['checksum', 'modify-date', 'none']))
|
|
180
|
+
.action(async (task, options) => {
|
|
181
|
+
const cli = await createCli(fileName, environment, task ? { taskName: task } : parseWorkScope(options));
|
|
182
|
+
const result = await cli.exec({
|
|
183
|
+
cacheDefault: options.cache,
|
|
184
|
+
watch: options.watch,
|
|
185
|
+
workers: options.concurrency,
|
|
186
|
+
logMode: options.log,
|
|
129
187
|
});
|
|
130
|
-
|
|
188
|
+
if (!result.success) {
|
|
189
|
+
program.error('Execution was not successful', { exitCode: 1 });
|
|
190
|
+
}
|
|
191
|
+
});
|
|
131
192
|
}
|
|
132
193
|
else {
|
|
133
194
|
if (fileIndex >= 0) {
|
|
@@ -153,7 +214,10 @@ tasks:
|
|
|
153
214
|
program.version(require('../package.json').version);
|
|
154
215
|
program.option('--verbose', 'log debugging information', false);
|
|
155
216
|
program.option('--file', 'set build file', 'build.yaml');
|
|
156
|
-
program.
|
|
217
|
+
program.configureOutput({
|
|
218
|
+
writeOut: (str) => environment.console.info(str),
|
|
219
|
+
writeErr: (str) => environment.console.error(str),
|
|
220
|
+
});
|
|
157
221
|
return { program, args };
|
|
158
222
|
}
|
|
159
223
|
exports.getProgram = getProgram;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const path_1 = require("path");
|
|
4
|
+
const program_1 = require("./program");
|
|
5
|
+
const environment_mock_1 = require("./executer/environment-mock");
|
|
6
|
+
describe('program', () => {
|
|
7
|
+
async function testCommand(commandArgs) {
|
|
8
|
+
const fileName = (0, path_1.join)(__dirname, '../examples/program');
|
|
9
|
+
const context = (0, environment_mock_1.environmentMock)(fileName);
|
|
10
|
+
const { program, args } = await (0, program_1.getProgram)(context, [process.argv[0], fileName, ...commandArgs]);
|
|
11
|
+
return program.exitOverride().parseAsync(args);
|
|
12
|
+
}
|
|
13
|
+
it('should run when cache is up to date and --no-cache arg is passed', async () => {
|
|
14
|
+
await testCommand(['example', '--cache', 'none']);
|
|
15
|
+
}, 120000);
|
|
16
|
+
it('should warn about invalid task name', async () => {
|
|
17
|
+
await expect(testCommand(['example2'])).rejects.toThrow();
|
|
18
|
+
});
|
|
19
|
+
});
|
|
20
|
+
//# sourceMappingURL=program.spec.js.map
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.startWatchProcesses = void 0;
|
|
4
|
+
const plan_work_nodes_1 = require("./planner/utils/plan-work-nodes");
|
|
5
|
+
const watch_node_1 = require("./executer/watch-node");
|
|
6
|
+
const work_service_1 = require("./planner/work-service");
|
|
7
|
+
const watch_service_1 = require("./executer/watch-service");
|
|
8
|
+
function startWatchProcesses(state, processManager, environment) {
|
|
9
|
+
for (const node of (0, plan_work_nodes_1.iterateWorkNodes)(state.current.node)) {
|
|
10
|
+
if (node.node.src.length > 0) {
|
|
11
|
+
if (node.node.continuous) {
|
|
12
|
+
environment.status.task(node.node).write('debug', 'do not start files watches for continuous task');
|
|
13
|
+
continue;
|
|
14
|
+
}
|
|
15
|
+
processManager.background({ type: 'task', id: node.node.id + '-watch', name: node.node.name }, (0, watch_node_1.watchNode)(node.node, state, processManager, environment));
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
for (const service of (0, plan_work_nodes_1.iterateWorkServices)(state.current.service)) {
|
|
19
|
+
if (!(0, work_service_1.isContainerWorkService)(service.service)) {
|
|
20
|
+
continue;
|
|
21
|
+
}
|
|
22
|
+
if (service.service.mounts.length > 0) {
|
|
23
|
+
processManager.background({ type: 'service', id: service.service.id + '-watch', name: service.service.name }, (0, watch_service_1.watchService)(service.service, state, processManager, environment));
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
exports.startWatchProcesses = startWatchProcesses;
|
|
28
|
+
//# sourceMappingURL=start-watch-processes.js.map
|