@nrwl/nx-cloud 15.3.1 → 15.3.3-beta.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/lib/core/api/error-reporter.api.js +36 -1
- package/lib/core/api/run-group.api.js +73 -1
- package/lib/core/api/run-group.api.js.map +1 -1
- package/lib/core/commands/record-output.js +6 -2
- package/lib/core/commands/record-output.js.map +1 -1
- package/lib/core/commands/upload-and-show-run-details.js +2 -1
- package/lib/core/commands/upload-and-show-run-details.js.map +1 -1
- package/lib/core/file-storage/file-storage.js +1 -1
- package/lib/core/file-storage/file-storage.js.map +1 -1
- package/lib/core/runners/cloud-enabled/cloud-enabled-life-cycle.js +93 -1
- package/lib/core/runners/cloud-enabled/cloud-enabled.runner.js +320 -1
- package/lib/core/runners/cloud-enabled/cloud-enabled.runner.js.map +1 -1
- package/lib/core/runners/cloud-enabled/cloud-remote-cache.js +133 -1
- package/lib/core/runners/cloud-enabled/cloud-run.api.js +168 -1
- package/lib/core/runners/cloud-enabled/id-generator.js +16 -1
- package/lib/core/runners/distributed-agent/distributed-agent.api.js +93 -1
- package/lib/core/runners/distributed-agent/distributed-agent.impl.js +157 -1
- package/lib/core/runners/distributed-agent/execute-tasks.js +114 -1
- package/lib/core/runners/distributed-agent/invoke-tasks-using-nx-imperative-api.js +58 -1
- package/lib/core/runners/distributed-agent/invoke-tasks-using-run-many.js +97 -1
- package/lib/core/runners/distributed-execution/distributed-execution.api.d.ts +1 -1
- package/lib/core/runners/distributed-execution/distributed-execution.api.js +152 -1
- package/lib/core/runners/distributed-execution/distributed-execution.api.js.map +1 -1
- package/lib/core/runners/distributed-execution/distributed-execution.runner.js +118 -1
- package/lib/core/runners/distributed-execution/process-task.js +45 -1
- package/lib/core/runners/distributed-execution/process-tasks.js +67 -1
- package/lib/core/runners/distributed-execution/split-task-graph-into-stages.js +37 -1
- package/lib/core/runners/distributed-execution/task-graph-creator.js +100 -1
- package/lib/utilities/environment.js +8 -2
- package/lib/utilities/environment.js.map +1 -1
- package/lib/utilities/is-private-cloud.d.ts +1 -0
- package/lib/utilities/is-private-cloud.js +30 -0
- package/lib/utilities/is-private-cloud.js.map +1 -0
- package/package.json +1 -1
|
@@ -1 +1,58 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.invokeTasksUsingNxImperativeApi = void 0;
|
|
13
|
+
const { initTasksRunner } = require('../../../utilities/nx-imports');
|
|
14
|
+
const parser = require("yargs-parser");
|
|
15
|
+
const serializer_overrides_1 = require("../../../utilities/serializer-overrides");
|
|
16
|
+
function invokeTasksUsingNxImperativeApi(options) {
|
|
17
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
18
|
+
const tasksRunner = yield initTasksRunner(options);
|
|
19
|
+
return (executionId, tasksToExecute, parallel) => __awaiter(this, void 0, void 0, function* () {
|
|
20
|
+
const tasks = tasksToExecute.map((t) => {
|
|
21
|
+
const params = parser(t.params, {
|
|
22
|
+
configuration: {
|
|
23
|
+
'camel-case-expansion': false,
|
|
24
|
+
'dot-notation': true,
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
const unparsed = (0, serializer_overrides_1.unparse)(params);
|
|
28
|
+
if (params._.length == 0) {
|
|
29
|
+
delete params._;
|
|
30
|
+
}
|
|
31
|
+
return {
|
|
32
|
+
id: t.taskId,
|
|
33
|
+
target: {
|
|
34
|
+
project: t.projectName,
|
|
35
|
+
target: t.target,
|
|
36
|
+
configuration: t.configuration,
|
|
37
|
+
},
|
|
38
|
+
overrides: Object.assign(Object.assign({}, params), { __overrides_unparsed__: unparsed }),
|
|
39
|
+
};
|
|
40
|
+
});
|
|
41
|
+
process.env.NX_CACHE_FAILURES = 'true'; // this is only requires because of how we do uploads
|
|
42
|
+
process.env.NX_CLOUD_DISTRIBUTED_EXECUTION_ID = executionId;
|
|
43
|
+
process.env.NX_STREAM_OUTPUT = 'true';
|
|
44
|
+
process.env.NX_PREFIX_OUTPUT = 'true';
|
|
45
|
+
const r = yield tasksRunner.invoke({ tasks, parallel });
|
|
46
|
+
const completedTasks = Object.values(r.taskGraph.tasks);
|
|
47
|
+
return {
|
|
48
|
+
completedTasks: completedTasks.map((t) => ({
|
|
49
|
+
taskId: t.id,
|
|
50
|
+
hash: t.hash,
|
|
51
|
+
})),
|
|
52
|
+
completedStatusCode: r.status,
|
|
53
|
+
};
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
exports.invokeTasksUsingNxImperativeApi = invokeTasksUsingNxImperativeApi;
|
|
58
|
+
//# sourceMappingURL=invoke-tasks-using-nx-imperative-api.js.map
|
|
@@ -1 +1,97 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.invokeTasksUsingRunMany = void 0;
|
|
13
|
+
const environment_1 = require("../../../utilities/environment");
|
|
14
|
+
const child_process_1 = require("child_process");
|
|
15
|
+
const fs_1 = require("fs");
|
|
16
|
+
const { output } = require('../../../utilities/nx-imports');
|
|
17
|
+
function invokeTasksUsingRunMany(options) {
|
|
18
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
19
|
+
const readCompleted = completedTasksReader(options);
|
|
20
|
+
return function invokeTasksUsingRunMany(executionId, tasksToExecute, parallel) {
|
|
21
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
22
|
+
let completedStatusCode = 0;
|
|
23
|
+
const completedTasks = [];
|
|
24
|
+
for (const g of groupByTarget(tasksToExecute)) {
|
|
25
|
+
const config = g.configuration
|
|
26
|
+
? `--configuration=${g.configuration}`
|
|
27
|
+
: ``;
|
|
28
|
+
const parallelStr = parallel > 1 ? ` --parallel --max-parallel=${parallel}` : ``;
|
|
29
|
+
// TODO use pnpx or yarn when needed
|
|
30
|
+
const command = `npx nx run-many --target=${g.target} ${config} --projects=${g.projects.join(',')} ${g.params}${parallelStr}`;
|
|
31
|
+
if (environment_1.VERBOSE_LOGGING) {
|
|
32
|
+
output.note({
|
|
33
|
+
title: `Executing: '${command}'`,
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
try {
|
|
37
|
+
(0, child_process_1.execSync)(command, {
|
|
38
|
+
stdio: ['ignore', 'inherit', 'inherit'],
|
|
39
|
+
env: Object.assign(Object.assign({}, process.env), { NX_CACHE_FAILURES: 'true', NX_CLOUD_DISTRIBUTED_EXECUTION_ID: executionId, NX_STREAM_OUTPUT: 'true', NX_PREFIX_OUTPUT: 'true' }),
|
|
40
|
+
});
|
|
41
|
+
completedTasks.push(...readCompleted(executionId));
|
|
42
|
+
}
|
|
43
|
+
catch (e) {
|
|
44
|
+
if (e.status === environment_1.DISTRIBUTED_TASK_EXECUTION_INTERNAL_ERROR_STATUS_CODE) {
|
|
45
|
+
throw e;
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
completedStatusCode = 1;
|
|
49
|
+
completedTasks.push(...readCompleted(executionId));
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return { completedStatusCode, completedTasks };
|
|
54
|
+
});
|
|
55
|
+
};
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
exports.invokeTasksUsingRunMany = invokeTasksUsingRunMany;
|
|
59
|
+
function groupByTarget(tasks) {
|
|
60
|
+
const res = [];
|
|
61
|
+
tasks.forEach((t) => {
|
|
62
|
+
const r = res.find((rr) => rr.target === t.target && rr.configuration === t.configuration);
|
|
63
|
+
if (r) {
|
|
64
|
+
r.projects.push(t.projectName);
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
res.push({
|
|
68
|
+
target: t.target,
|
|
69
|
+
projects: [t.projectName],
|
|
70
|
+
params: t.params,
|
|
71
|
+
configuration: t.configuration,
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
return res;
|
|
76
|
+
}
|
|
77
|
+
function completedTasksReader(options) {
|
|
78
|
+
const cacheDirectory = (0, environment_1.getNxCacheDirectory)(options);
|
|
79
|
+
return (distributedExecutionId) => {
|
|
80
|
+
const errorMessage = `Command execution failed (distributed task execution: ${distributedExecutionId}). Tasks hashes haven\'t been recorded.`;
|
|
81
|
+
let completedTasks;
|
|
82
|
+
try {
|
|
83
|
+
const taskHashesFile = `${cacheDirectory}/tasks-hashes-${distributedExecutionId}`;
|
|
84
|
+
completedTasks = JSON.parse((0, fs_1.readFileSync)(taskHashesFile).toString());
|
|
85
|
+
// remove it such that if the next command crashes we don't read an obsolete file
|
|
86
|
+
(0, fs_1.unlinkSync)(taskHashesFile);
|
|
87
|
+
}
|
|
88
|
+
catch (e) {
|
|
89
|
+
throw new Error(errorMessage);
|
|
90
|
+
}
|
|
91
|
+
if (completedTasks.length == 0) {
|
|
92
|
+
throw new Error(errorMessage);
|
|
93
|
+
}
|
|
94
|
+
return completedTasks;
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
//# sourceMappingURL=invoke-tasks-using-run-many.js.map
|
|
@@ -5,6 +5,6 @@ export declare class DistributedExecutionApi {
|
|
|
5
5
|
constructor(options: CloudTaskRunnerOptions);
|
|
6
6
|
start(params: any): Promise<string>;
|
|
7
7
|
status(id: string): Promise<any>;
|
|
8
|
-
completeRunGroupWithError(branch: string | null, runGroup: string, ciExecutionId: string | null, ciExecutionEnv: string, error: string): Promise<void>;
|
|
8
|
+
completeRunGroupWithError(branch: string | null, runGroup: string | null, ciExecutionId: string | null, ciExecutionEnv: string, error: string | null): Promise<void>;
|
|
9
9
|
}
|
|
10
10
|
export declare function createStartRequest(branch: string | null, runGroup: string, ciExecutionId: string | null, ciExecutionEnv: string, task: Task[][], options: CloudTaskRunnerOptions): any;
|
|
@@ -1 +1,152 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.createStartRequest = exports.DistributedExecutionApi = void 0;
|
|
13
|
+
const axios_1 = require("../../../utilities/axios");
|
|
14
|
+
const environment_1 = require("../../../utilities/environment");
|
|
15
|
+
const metric_logger_1 = require("../../../utilities/metric-logger");
|
|
16
|
+
const serializer_overrides_1 = require("../../../utilities/serializer-overrides");
|
|
17
|
+
const { output } = require('../../../utilities/nx-imports');
|
|
18
|
+
class DistributedExecutionApi {
|
|
19
|
+
constructor(options) {
|
|
20
|
+
this.apiAxiosInstance = (0, axios_1.createApiAxiosInstance)(options);
|
|
21
|
+
}
|
|
22
|
+
start(params) {
|
|
23
|
+
var _a;
|
|
24
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
25
|
+
const recorder = (0, metric_logger_1.createMetricRecorder)('dteStart');
|
|
26
|
+
let resp;
|
|
27
|
+
if (environment_1.VERBOSE_LOGGING) {
|
|
28
|
+
output.note({
|
|
29
|
+
title: 'Starting a distributed execution',
|
|
30
|
+
bodyLines: [JSON.stringify(params, null, 2)],
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
try {
|
|
34
|
+
resp = yield (0, axios_1.axiosMultipleTries)(() => this.apiAxiosInstance.post('/nx-cloud/executions/start', params));
|
|
35
|
+
recorder.recordMetric((0, metric_logger_1.mapRespToPerfEntry)(resp));
|
|
36
|
+
}
|
|
37
|
+
catch (e) {
|
|
38
|
+
recorder.recordMetric(((_a = e === null || e === void 0 ? void 0 : e.axiosException) === null || _a === void 0 ? void 0 : _a.response)
|
|
39
|
+
? (0, metric_logger_1.mapRespToPerfEntry)(e.axiosException.response)
|
|
40
|
+
: metric_logger_1.RUNNER_FAILURE_PERF_ENTRY);
|
|
41
|
+
throw e;
|
|
42
|
+
}
|
|
43
|
+
if (!resp.data.enabled) {
|
|
44
|
+
throw new Error(`Workspace is disabled. Cannot perform distributed task executions.`);
|
|
45
|
+
}
|
|
46
|
+
if (resp.data.error) {
|
|
47
|
+
throw new Error(resp.data.error);
|
|
48
|
+
}
|
|
49
|
+
return resp.data.id;
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
status(id) {
|
|
53
|
+
var _a;
|
|
54
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
55
|
+
const recorder = (0, metric_logger_1.createMetricRecorder)('dteStatus');
|
|
56
|
+
try {
|
|
57
|
+
const resp = yield (0, axios_1.axiosMultipleTries)(() => this.apiAxiosInstance.post('/nx-cloud/executions/status', {
|
|
58
|
+
id,
|
|
59
|
+
}));
|
|
60
|
+
recorder.recordMetric((0, metric_logger_1.mapRespToPerfEntry)(resp));
|
|
61
|
+
return resp.data;
|
|
62
|
+
}
|
|
63
|
+
catch (e) {
|
|
64
|
+
recorder.recordMetric(((_a = e === null || e === void 0 ? void 0 : e.axiosException) === null || _a === void 0 ? void 0 : _a.response)
|
|
65
|
+
? (0, metric_logger_1.mapRespToPerfEntry)(e.axiosException.response)
|
|
66
|
+
: metric_logger_1.RUNNER_FAILURE_PERF_ENTRY);
|
|
67
|
+
output.error({
|
|
68
|
+
title: e.message,
|
|
69
|
+
});
|
|
70
|
+
process.exit(1);
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
completeRunGroupWithError(branch, runGroup, ciExecutionId, ciExecutionEnv, error) {
|
|
75
|
+
var _a;
|
|
76
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
77
|
+
const recorder = (0, metric_logger_1.createMetricRecorder)('completeRunGroup');
|
|
78
|
+
if (environment_1.VERBOSE_LOGGING) {
|
|
79
|
+
output.note({
|
|
80
|
+
title: 'Completing with an error',
|
|
81
|
+
bodyLines: [
|
|
82
|
+
`ciExecutionId: ${ciExecutionId}`,
|
|
83
|
+
`ciExecutionEnv: ${ciExecutionEnv}`,
|
|
84
|
+
`runGroup: ${runGroup}`,
|
|
85
|
+
`error: ${error}`,
|
|
86
|
+
],
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
try {
|
|
90
|
+
const resp = yield (0, axios_1.axiosMultipleTries)(() => this.apiAxiosInstance.post('/nx-cloud/executions/complete-run-group', {
|
|
91
|
+
runGroup,
|
|
92
|
+
ciExecutionId,
|
|
93
|
+
ciExecutionEnv,
|
|
94
|
+
criticalErrorMessage: error,
|
|
95
|
+
}), 3);
|
|
96
|
+
recorder.recordMetric((0, metric_logger_1.mapRespToPerfEntry)(resp));
|
|
97
|
+
}
|
|
98
|
+
catch (e) {
|
|
99
|
+
recorder.recordMetric(((_a = e === null || e === void 0 ? void 0 : e.axiosException) === null || _a === void 0 ? void 0 : _a.response)
|
|
100
|
+
? (0, metric_logger_1.mapRespToPerfEntry)(e.axiosException.response)
|
|
101
|
+
: metric_logger_1.RUNNER_FAILURE_PERF_ENTRY);
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
exports.DistributedExecutionApi = DistributedExecutionApi;
|
|
107
|
+
function createStartRequest(branch, runGroup, ciExecutionId, ciExecutionEnv, task, options) {
|
|
108
|
+
const tasksToExecute = task.map((arr) => {
|
|
109
|
+
return arr.map((t) => {
|
|
110
|
+
return {
|
|
111
|
+
taskId: t.id,
|
|
112
|
+
hash: t.hash,
|
|
113
|
+
projectName: t.target.project,
|
|
114
|
+
target: t.target.target,
|
|
115
|
+
configuration: t.target.configuration || null,
|
|
116
|
+
params: (0, serializer_overrides_1.serializeOverrides)(t),
|
|
117
|
+
};
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
const request = {
|
|
121
|
+
command: (0, environment_1.parseCommand)(),
|
|
122
|
+
branch,
|
|
123
|
+
runGroup,
|
|
124
|
+
ciExecutionId,
|
|
125
|
+
ciExecutionEnv,
|
|
126
|
+
tasks: tasksToExecute,
|
|
127
|
+
maxParallel: calculateMaxParallel(options),
|
|
128
|
+
};
|
|
129
|
+
if (environment_1.NX_CLOUD_DISTRIBUTED_EXECUTION_AGENT_COUNT) {
|
|
130
|
+
request.agentCount = environment_1.NX_CLOUD_DISTRIBUTED_EXECUTION_AGENT_COUNT;
|
|
131
|
+
}
|
|
132
|
+
if (!environment_1.NX_CLOUD_DISTRIBUTED_EXECUTION_STOP_AGENTS_ON_FAILURE) {
|
|
133
|
+
request.stopAgentsOnFailure = false;
|
|
134
|
+
}
|
|
135
|
+
return request;
|
|
136
|
+
}
|
|
137
|
+
exports.createStartRequest = createStartRequest;
|
|
138
|
+
function calculateMaxParallel(options) {
|
|
139
|
+
if (options.parallel === 'false' || options.parallel === false) {
|
|
140
|
+
return 1;
|
|
141
|
+
}
|
|
142
|
+
else if (options.parallel === 'true' || options.parallel === true) {
|
|
143
|
+
return Number(options.maxParallel || 3);
|
|
144
|
+
}
|
|
145
|
+
else if (options.parallel === undefined) {
|
|
146
|
+
return options.maxParallel ? Number(options.maxParallel) : 3;
|
|
147
|
+
}
|
|
148
|
+
else {
|
|
149
|
+
return Number(options.parallel) || 3;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
//# sourceMappingURL=distributed-execution.api.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"distributed-execution.api.js","sourceRoot":"","sources":["../../../../../../../../libs/nx-packages/nx-cloud/lib/core/runners/distributed-execution/distributed-execution.api.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,oDAGkC;AAClC,gEAMwC;AACxC,oEAI0C;AAE1C,kFAA6E;AAE7E,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,+BAA+B,CAAC,CAAC;AAE5D,MAAa,uBAAuB;IAGlC,YAAY,OAA+B;QACzC,IAAI,CAAC,gBAAgB,GAAG,IAAA,8BAAsB,EAAC,OAAO,CAAC,CAAC;IAC1D,CAAC;IAEK,KAAK,CAAC,MAAW;;;YACrB,MAAM,QAAQ,GAAG,IAAA,oCAAoB,EAAC,UAAU,CAAC,CAAC;YAClD,IAAI,IAAI,CAAC;YAET,IAAI,6BAAe,EAAE;gBACnB,MAAM,CAAC,IAAI,CAAC;oBACV,KAAK,EAAE,kCAAkC;oBACzC,SAAS,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,CA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AM,EAAE;gBACf,QAAQ,CAAC,YAAY,CACnB,CAAA,MAAA,CAAC,aAAD,CAAC,uBAAD,CAAC,CAAE,cAAc,0CAAE,QAAQ;oBACzB,CAAC,CAAC,IAAA,kCAAkB,EAAC,CAAC,CAAC,cAAc,CAAC,QAAQ,CAAC;oBAC/C,CAAC,CAAC,yCAAyB,CAC9B,CAAC;gBAEF,MAAM,CAAC,KAAK,CAAC;oBACX,KAAK,EAAE,CAAC,CAAC,OAAO;iBACjB,CAAC,CAAC;gBACH,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;aACjB;;KACF;IAEK,yBAAyB,CAC7B,MAAqB,EACrB,
|
|
1
|
+
{"version":3,"file":"distributed-execution.api.js","sourceRoot":"","sources":["../../../../../../../../libs/nx-packages/nx-cloud/lib/core/runners/distributed-execution/distributed-execution.api.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,oDAGkC;AAClC,gEAMwC;AACxC,oEAI0C;AAE1C,kFAA6E;AAE7E,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,+BAA+B,CAAC,CAAC;AAE5D,MAAa,uBAAuB;IAGlC,YAAY,OAA+B;QACzC,IAAI,CAAC,gBAAgB,GAAG,IAAA,8BAAsB,EAAC,OAAO,CAAC,CAAC;IAC1D,CAAC;IAEK,KAAK,CAAC,MAAW;;;YACrB,MAAM,QAAQ,GAAG,IAAA,oCAAoB,EAAC,UAAU,CAAC,CAAC;YAClD,IAAI,IAAI,CAAC;YAET,IAAI,6BAAe,EAAE;gBACnB,MAAM,CAAC,IAAI,CAAC;oBACV,KAAK,EAAE,kCAAkC;oBACzC,SAAS,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;iBAC7C,CAAC,CAAC;aACJ;YACD,IAAI;gBACF,IAAI,GAAG,MAAM,IAAA,0BAAkB,EAAC,GAAG,EAAE,CACnC,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAA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WAAW,IAAI,CAAC,CAAC,CAAC;KACzC;SAAM,IAAI,OAAO,CAAC,QAAQ,KAAK,SAAS,EAAE;QACzC,OAAO,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;KAC9D;SAAM;QACL,OAAO,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;KACtC;AACH,CAAC"}
|
|
@@ -1 +1,118 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.nxCloudDistributedTasksRunner = void 0;
|
|
13
|
+
const environment_1 = require("../../../utilities/environment");
|
|
14
|
+
const metric_logger_1 = require("../../../utilities/metric-logger");
|
|
15
|
+
const error_reporter_api_1 = require("../../api/error-reporter.api");
|
|
16
|
+
const print_run_group_error_1 = require("../../error/print-run-group-error");
|
|
17
|
+
const e2e_encryption_1 = require("../../file-storage/e2e-encryption");
|
|
18
|
+
const file_storage_1 = require("../../file-storage/file-storage");
|
|
19
|
+
const distributed_execution_api_1 = require("./distributed-execution.api");
|
|
20
|
+
const split_task_graph_into_stages_1 = require("./split-task-graph-into-stages");
|
|
21
|
+
const task_graph_creator_1 = require("./task-graph-creator");
|
|
22
|
+
const process_tasks_1 = require("./process-tasks");
|
|
23
|
+
const dte_artifact_storage_1 = require("../../../utilities/dte-artifact-storage");
|
|
24
|
+
const { output } = require('../../../utilities/nx-imports');
|
|
25
|
+
class NoopLifeCycle {
|
|
26
|
+
scheduleTask(task) { }
|
|
27
|
+
startTask(task) { }
|
|
28
|
+
endTasks(tasks) { }
|
|
29
|
+
}
|
|
30
|
+
const nxCloudDistributedTasksRunner = (tasks, options, context) => __awaiter(void 0, void 0, void 0, function* () {
|
|
31
|
+
if (options.skipNxCache) {
|
|
32
|
+
output.warn({
|
|
33
|
+
title: `--skip-nx-cache is ignored when using distributed tasks execution (DTE).`,
|
|
34
|
+
bodyLine: [`DTE needs the cache to share files between agents.`],
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
if (environment_1.VERBOSE_LOGGING) {
|
|
38
|
+
output.note({
|
|
39
|
+
title: 'Starting distributed command execution',
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
options.lifeCycle = new NoopLifeCycle();
|
|
43
|
+
const branch = (0, environment_1.getBranch)();
|
|
44
|
+
const runGroup = (0, environment_1.getRunGroup)();
|
|
45
|
+
const ciExecutionId = (0, environment_1.getCIExecutionId)();
|
|
46
|
+
const ciExecutionEnv = (0, environment_1.getCIExecutionEnv)();
|
|
47
|
+
if (!(0, print_run_group_error_1.canDetectRunGroup)(runGroup, ciExecutionId)) {
|
|
48
|
+
(0, print_run_group_error_1.printRunGroupError)();
|
|
49
|
+
process.exit(1);
|
|
50
|
+
}
|
|
51
|
+
const encryption = new e2e_encryption_1.E2EEncryption(environment_1.ENCRYPTION_KEY || options.encryptionKey);
|
|
52
|
+
const errorReporter = new error_reporter_api_1.ErrorReporterApi(options);
|
|
53
|
+
const dteArtifactStorage = new dte_artifact_storage_1.DteArtifactStorage(new file_storage_1.FileStorage(encryption, errorReporter, options, 'dte-main'), (0, environment_1.getNxCacheDirectory)(options));
|
|
54
|
+
const api = new distributed_execution_api_1.DistributedExecutionApi(options);
|
|
55
|
+
attachSignalListenersToCompleteRunGroupOnError(api, branch, runGroup, ciExecutionId, ciExecutionEnv);
|
|
56
|
+
try {
|
|
57
|
+
const taskGraph = getTaskGraph(context, tasks, options);
|
|
58
|
+
const r = yield runDistributedExecution(api, options, dteArtifactStorage, branch, runGroup, ciExecutionId, ciExecutionEnv, taskGraph);
|
|
59
|
+
if (r.commandStatus === 0) {
|
|
60
|
+
output.success({
|
|
61
|
+
title: 'Successfully completed running the command.',
|
|
62
|
+
bodyLines: [`See run details at ${r.runUrl}`],
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
output.error({
|
|
67
|
+
title: 'Command execution failed.',
|
|
68
|
+
bodyLines: [`See run details at ${r.runUrl}`],
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
yield (0, metric_logger_1.submitRunMetrics)(options);
|
|
72
|
+
process.exit(r.commandStatus);
|
|
73
|
+
}
|
|
74
|
+
catch (e) {
|
|
75
|
+
output.error({
|
|
76
|
+
title: 'Unable to complete a run.',
|
|
77
|
+
bodyLines: [e.message],
|
|
78
|
+
});
|
|
79
|
+
if (e.axiosException) {
|
|
80
|
+
console.log(e.axiosException);
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
console.log(e);
|
|
84
|
+
}
|
|
85
|
+
try {
|
|
86
|
+
yield api.completeRunGroupWithError(branch, runGroup, ciExecutionId, ciExecutionEnv, `Main job terminated with an error: "${e.message}"`);
|
|
87
|
+
}
|
|
88
|
+
finally {
|
|
89
|
+
process.exit(1);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
exports.nxCloudDistributedTasksRunner = nxCloudDistributedTasksRunner;
|
|
94
|
+
function getTaskGraph(context, tasks, options) {
|
|
95
|
+
if (context.taskGraph) {
|
|
96
|
+
return context.taskGraph;
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
return (0, task_graph_creator_1.createTaskGraphCompat)(options, context.projectGraph, tasks);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
function attachSignalListenersToCompleteRunGroupOnError(api, branch, runGroup, ciExecutionId, ciExecutionEnv) {
|
|
103
|
+
process.on('SIGINT', () => __awaiter(this, void 0, void 0, function* () {
|
|
104
|
+
yield api.completeRunGroupWithError(branch, runGroup, ciExecutionId, ciExecutionEnv, 'Main job was terminated via SIGINT');
|
|
105
|
+
process.exit(1);
|
|
106
|
+
}));
|
|
107
|
+
process.on('SIGTERM', () => __awaiter(this, void 0, void 0, function* () {
|
|
108
|
+
yield api.completeRunGroupWithError(branch, runGroup, ciExecutionId, ciExecutionEnv, 'Main job was terminated via SIGTERM');
|
|
109
|
+
process.exit(1);
|
|
110
|
+
}));
|
|
111
|
+
}
|
|
112
|
+
function runDistributedExecution(api, options, dteArtifactStorage, branch, runGroup, ciExecutionId, ciExecutionEnv, taskGraph) {
|
|
113
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
114
|
+
const id = yield api.start((0, distributed_execution_api_1.createStartRequest)(branch, runGroup, ciExecutionId, ciExecutionEnv, (0, split_task_graph_into_stages_1.splitTasksIntoStages)(taskGraph), options));
|
|
115
|
+
return yield (0, process_tasks_1.processTasks)(api, dteArtifactStorage, id, Object.values(taskGraph.tasks));
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
//# sourceMappingURL=distributed-execution.runner.js.map
|
|
@@ -1 +1,45 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.processTask = void 0;
|
|
13
|
+
const environment_1 = require("../../../utilities/environment");
|
|
14
|
+
const serializer_overrides_1 = require("../../../utilities/serializer-overrides");
|
|
15
|
+
const { output } = require('../../../utilities/nx-imports');
|
|
16
|
+
function processTask(dteArtifactStorage, tasks, completedTask) {
|
|
17
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
18
|
+
if (environment_1.VERBOSE_LOGGING) {
|
|
19
|
+
output.note({
|
|
20
|
+
title: `Processing task ${completedTask.taskId}`,
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
const matchingTask = tasks.find((tt) => completedTask.taskId === tt.id);
|
|
24
|
+
if (!matchingTask) {
|
|
25
|
+
throw new Error(`Found unknown task: ${completedTask.taskId}`);
|
|
26
|
+
}
|
|
27
|
+
const terminalOutput = yield dteArtifactStorage.retrieveAndExtract(completedTask.hash, completedTask.url);
|
|
28
|
+
output.logCommand(getCommand(matchingTask));
|
|
29
|
+
process.stdout.write(terminalOutput);
|
|
30
|
+
output.addVerticalSeparator();
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
exports.processTask = processTask;
|
|
34
|
+
function getCommand(task) {
|
|
35
|
+
const config = task.target.configuration
|
|
36
|
+
? `:${task.target.configuration}`
|
|
37
|
+
: '';
|
|
38
|
+
return [
|
|
39
|
+
'nx',
|
|
40
|
+
'run',
|
|
41
|
+
`${task.target.project}:${task.target.target}${config}`,
|
|
42
|
+
(0, serializer_overrides_1.serializeOverrides)(task),
|
|
43
|
+
].join(' ');
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=process-task.js.map
|