@kapeta/local-cluster-service 0.37.0 → 0.38.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/CHANGELOG.md +7 -0
- package/dist/cjs/src/assetManager.d.ts +2 -1
- package/dist/cjs/src/assetManager.js +3 -2
- package/dist/cjs/src/containerManager.d.ts +6 -3
- package/dist/cjs/src/containerManager.js +96 -18
- package/dist/cjs/src/instanceManager.js +15 -8
- package/dist/cjs/src/operatorManager.d.ts +3 -2
- package/dist/cjs/src/progressListener.d.ts +8 -1
- package/dist/cjs/src/progressListener.js +12 -1
- package/dist/cjs/src/repositoryManager.js +3 -2
- package/dist/cjs/src/taskManager.d.ts +2 -0
- package/dist/cjs/src/taskManager.js +9 -0
- package/dist/cjs/src/types.d.ts +0 -19
- package/dist/cjs/src/utils/BlockInstanceRunner.js +15 -3
- package/dist/cjs/src/utils/commandLineUtils.d.ts +2 -1
- package/dist/cjs/src/utils/commandLineUtils.js +7 -1
- package/dist/cjs/src/utils/utils.d.ts +3 -3
- package/dist/cjs/src/utils/utils.js +2 -1
- package/dist/esm/src/assetManager.d.ts +2 -1
- package/dist/esm/src/assetManager.js +3 -2
- package/dist/esm/src/containerManager.d.ts +6 -3
- package/dist/esm/src/containerManager.js +96 -18
- package/dist/esm/src/instanceManager.js +15 -8
- package/dist/esm/src/operatorManager.d.ts +3 -2
- package/dist/esm/src/progressListener.d.ts +8 -1
- package/dist/esm/src/progressListener.js +12 -1
- package/dist/esm/src/repositoryManager.js +3 -2
- package/dist/esm/src/taskManager.d.ts +2 -0
- package/dist/esm/src/taskManager.js +9 -0
- package/dist/esm/src/types.d.ts +0 -19
- package/dist/esm/src/utils/BlockInstanceRunner.js +15 -3
- package/dist/esm/src/utils/commandLineUtils.d.ts +2 -1
- package/dist/esm/src/utils/commandLineUtils.js +7 -1
- package/dist/esm/src/utils/utils.d.ts +3 -3
- package/dist/esm/src/utils/utils.js +2 -1
- package/package.json +14 -13
- package/src/assetManager.ts +5 -4
- package/src/containerManager.ts +110 -23
- package/src/instanceManager.ts +16 -10
- package/src/operatorManager.ts +2 -3
- package/src/progressListener.ts +15 -1
- package/src/repositoryManager.ts +5 -3
- package/src/taskManager.ts +11 -0
- package/src/types.ts +0 -19
- package/src/utils/BlockInstanceRunner.ts +21 -15
- package/src/utils/commandLineUtils.ts +10 -2
- package/src/utils/utils.ts +4 -4
@@ -207,14 +207,8 @@ class ContainerManager {
|
|
207
207
|
return this._docker;
|
208
208
|
}
|
209
209
|
async getContainerByName(containerName) {
|
210
|
-
|
211
|
-
|
212
|
-
return container.Names.indexOf(`/${containerName}`) > -1;
|
213
|
-
});
|
214
|
-
if (out) {
|
215
|
-
return this.get(out.Id);
|
216
|
-
}
|
217
|
-
return undefined;
|
210
|
+
// The container can be fetched by name or by id using the same API call
|
211
|
+
return this.get(containerName);
|
218
212
|
}
|
219
213
|
async pull(image) {
|
220
214
|
let [imageName, tag] = image.split(/:/);
|
@@ -279,6 +273,10 @@ class ContainerManager {
|
|
279
273
|
};
|
280
274
|
}
|
281
275
|
const chunk = chunks[data.id];
|
276
|
+
if (data.stream) {
|
277
|
+
// Emit raw output to the task log
|
278
|
+
task.addLog(data.stream);
|
279
|
+
}
|
282
280
|
switch (data.status) {
|
283
281
|
case DockerPullEventTypes.PreparingPhase:
|
284
282
|
case DockerPullEventTypes.WaitingPhase:
|
@@ -520,7 +518,7 @@ class ContainerManager {
|
|
520
518
|
async get(name) {
|
521
519
|
let dockerContainer = null;
|
522
520
|
try {
|
523
|
-
dockerContainer =
|
521
|
+
dockerContainer = this.docker().getContainer(name);
|
524
522
|
await dockerContainer.stats();
|
525
523
|
}
|
526
524
|
catch (err) {
|
@@ -545,7 +543,7 @@ class ContainerManager {
|
|
545
543
|
},
|
546
544
|
];
|
547
545
|
}
|
548
|
-
return containerInfo.getLogs();
|
546
|
+
return await containerInfo.getLogs();
|
549
547
|
}
|
550
548
|
async stopLogListening(systemId, instanceId) {
|
551
549
|
const containerName = await (0, utils_1.getBlockInstanceContainerName)(systemId, instanceId);
|
@@ -616,6 +614,28 @@ class ContainerManager {
|
|
616
614
|
// Ignore
|
617
615
|
}
|
618
616
|
}
|
617
|
+
buildDockerImage(dockerFile, imageName) {
|
618
|
+
const taskName = `Building docker image: ${imageName}`;
|
619
|
+
const processor = async (task) => {
|
620
|
+
const timeStarted = Date.now();
|
621
|
+
const stream = await this.docker().buildImage({
|
622
|
+
context: path_1.default.dirname(dockerFile),
|
623
|
+
src: [path_1.default.basename(dockerFile)],
|
624
|
+
}, {
|
625
|
+
t: imageName,
|
626
|
+
dockerfile: path_1.default.basename(dockerFile),
|
627
|
+
});
|
628
|
+
await processJsonStream(`image:build:${imageName}`, stream, (data) => {
|
629
|
+
if (data.stream) {
|
630
|
+
// Emit raw output to the task log
|
631
|
+
task.addLog(data.stream);
|
632
|
+
}
|
633
|
+
});
|
634
|
+
};
|
635
|
+
return taskManager_1.taskManager.add(`docker:image:build:${imageName}`, processor, {
|
636
|
+
name: taskName,
|
637
|
+
});
|
638
|
+
}
|
619
639
|
}
|
620
640
|
function readLogBuffer(logBuffer) {
|
621
641
|
const out = [];
|
@@ -830,15 +850,73 @@ class ContainerInfo {
|
|
830
850
|
timestamps: true,
|
831
851
|
});
|
832
852
|
const out = readLogBuffer(logs);
|
833
|
-
if (out.length
|
834
|
-
out
|
835
|
-
time: Date.now(),
|
836
|
-
message: 'No logs found for container',
|
837
|
-
level: 'INFO',
|
838
|
-
source: 'stdout',
|
839
|
-
});
|
853
|
+
if (out.length > 0) {
|
854
|
+
return out;
|
840
855
|
}
|
841
|
-
|
856
|
+
const status = await this.status();
|
857
|
+
const healthLogs = status?.Health?.Log
|
858
|
+
? status?.Health?.Log.map((log) => {
|
859
|
+
return {
|
860
|
+
source: 'stdout',
|
861
|
+
level: log.ExitCode === 0 ? 'INFO' : 'ERROR',
|
862
|
+
time: Date.now(),
|
863
|
+
message: 'Health check: ' + log.Output,
|
864
|
+
};
|
865
|
+
})
|
866
|
+
: [];
|
867
|
+
if (status?.Running) {
|
868
|
+
return [
|
869
|
+
{
|
870
|
+
source: 'stdout',
|
871
|
+
level: 'INFO',
|
872
|
+
time: Date.now(),
|
873
|
+
message: 'Container is starting...',
|
874
|
+
},
|
875
|
+
...healthLogs,
|
876
|
+
];
|
877
|
+
}
|
878
|
+
if (status?.Restarting) {
|
879
|
+
return [
|
880
|
+
{
|
881
|
+
source: 'stdout',
|
882
|
+
level: 'INFO',
|
883
|
+
time: Date.now(),
|
884
|
+
message: 'Container is restarting...',
|
885
|
+
},
|
886
|
+
...healthLogs,
|
887
|
+
];
|
888
|
+
}
|
889
|
+
if (status?.Paused) {
|
890
|
+
return [
|
891
|
+
{
|
892
|
+
source: 'stdout',
|
893
|
+
level: 'INFO',
|
894
|
+
time: Date.now(),
|
895
|
+
message: 'Container is paused...',
|
896
|
+
},
|
897
|
+
...healthLogs,
|
898
|
+
];
|
899
|
+
}
|
900
|
+
if (status?.Error) {
|
901
|
+
return [
|
902
|
+
{
|
903
|
+
source: 'stderr',
|
904
|
+
level: 'ERROR',
|
905
|
+
time: Date.now(),
|
906
|
+
message: 'Container failed to start:\n' + status.Error,
|
907
|
+
},
|
908
|
+
...healthLogs,
|
909
|
+
];
|
910
|
+
}
|
911
|
+
return [
|
912
|
+
{
|
913
|
+
source: 'stdout',
|
914
|
+
level: 'INFO',
|
915
|
+
time: Date.now(),
|
916
|
+
message: 'Container not running',
|
917
|
+
...healthLogs,
|
918
|
+
},
|
919
|
+
];
|
842
920
|
}
|
843
921
|
}
|
844
922
|
exports.ContainerInfo = ContainerInfo;
|
@@ -212,7 +212,9 @@ class InstanceManager {
|
|
212
212
|
systemId = (0, nodejs_utils_1.normalizeKapetaUri)(systemId);
|
213
213
|
const instance = lodash_1.default.find(this._instances, { systemId, instanceId });
|
214
214
|
if (instance && instance.owner === types_1.InstanceOwner.EXTERNAL && instance.status !== types_1.InstanceStatus.STOPPED) {
|
215
|
-
instance.status
|
215
|
+
if (instance.status != types_1.InstanceStatus.FAILED) {
|
216
|
+
instance.status = types_1.InstanceStatus.STOPPED;
|
217
|
+
}
|
216
218
|
instance.pid = null;
|
217
219
|
instance.health = null;
|
218
220
|
socketManager_1.socketManager.emitSystemEvent(systemId, socketManager_1.EVENT_STATUS_CHANGED, instance);
|
@@ -501,8 +503,7 @@ class InstanceManager {
|
|
501
503
|
];
|
502
504
|
const out = await this.saveInternalInstance({
|
503
505
|
...instance,
|
504
|
-
type: types_1.InstanceType.
|
505
|
-
pid: null,
|
506
|
+
type: types_1.InstanceType.DOCKER,
|
506
507
|
health: null,
|
507
508
|
portType: DEFAULT_HEALTH_PORT_TYPE,
|
508
509
|
status: types_1.InstanceStatus.FAILED,
|
@@ -622,9 +623,8 @@ class InstanceManager {
|
|
622
623
|
}
|
623
624
|
if (instance.status !== newStatus) {
|
624
625
|
const oldStatus = instance.status;
|
625
|
-
const skipUpdate = (
|
626
|
-
|
627
|
-
instance.status === types_1.InstanceStatus.STOPPING) ||
|
626
|
+
const skipUpdate = ([types_1.InstanceStatus.READY, types_1.InstanceStatus.UNHEALTHY].includes(newStatus) &&
|
627
|
+
instance.status === types_1.InstanceStatus.STOPPING) ||
|
628
628
|
(newStatus === types_1.InstanceStatus.STOPPED &&
|
629
629
|
instance.status === types_1.InstanceStatus.STARTING &&
|
630
630
|
instance.desiredStatus === types_1.DesiredInstanceStatus.RUN);
|
@@ -637,7 +637,7 @@ class InstanceManager {
|
|
637
637
|
}
|
638
638
|
}
|
639
639
|
if (instance.desiredStatus === types_1.DesiredInstanceStatus.RUN &&
|
640
|
-
[types_1.InstanceStatus.STOPPED, types_1.InstanceStatus.
|
640
|
+
[types_1.InstanceStatus.STOPPED, types_1.InstanceStatus.STOPPING].includes(newStatus)) {
|
641
641
|
//If the instance is stopped but we want it to run, start it
|
642
642
|
try {
|
643
643
|
await this.start(instance.systemId, instance.instanceId);
|
@@ -708,10 +708,17 @@ class InstanceManager {
|
|
708
708
|
return types_1.InstanceStatus.READY;
|
709
709
|
}
|
710
710
|
if (statusType === 'created') {
|
711
|
+
if (state.ExitCode !== 0) {
|
712
|
+
// Failed during creation
|
713
|
+
return types_1.InstanceStatus.FAILED;
|
714
|
+
}
|
711
715
|
return types_1.InstanceStatus.STARTING;
|
712
716
|
}
|
713
717
|
if (statusType === 'exited' || statusType === 'dead') {
|
714
|
-
|
718
|
+
if (state.ExitCode === 0) {
|
719
|
+
return types_1.InstanceStatus.STOPPED;
|
720
|
+
}
|
721
|
+
return types_1.InstanceStatus.FAILED;
|
715
722
|
}
|
716
723
|
if (statusType === 'removing') {
|
717
724
|
return types_1.InstanceStatus.BUSY;
|
@@ -4,11 +4,12 @@
|
|
4
4
|
*/
|
5
5
|
import { DefinitionInfo } from '@kapeta/local-cluster-config';
|
6
6
|
import { ContainerInfo } from './containerManager';
|
7
|
-
import { EnvironmentType,
|
7
|
+
import { EnvironmentType, OperatorInfo } from './types';
|
8
|
+
import { LocalInstance } from '@kapeta/schemas';
|
8
9
|
declare class Operator {
|
9
10
|
private readonly _data;
|
10
11
|
constructor(data: DefinitionInfo);
|
11
|
-
getLocalData():
|
12
|
+
getLocalData(): LocalInstance;
|
12
13
|
getDefinitionInfo(): DefinitionInfo;
|
13
14
|
getCredentials(): any;
|
14
15
|
}
|
@@ -3,11 +3,13 @@
|
|
3
3
|
* SPDX-License-Identifier: BUSL-1.1
|
4
4
|
*/
|
5
5
|
/// <reference types="node" />
|
6
|
+
import { LogEntry } from './types';
|
7
|
+
import { Task } from './taskManager';
|
6
8
|
export declare class ProgressListener {
|
7
9
|
private readonly systemId;
|
8
10
|
private readonly instanceId;
|
9
11
|
constructor(systemId?: string, instanceId?: string);
|
10
|
-
|
12
|
+
protected emitLog(payload: Omit<LogEntry, 'time' | 'source'>): void;
|
11
13
|
run(command: string, directory?: string): Promise<{
|
12
14
|
exit: number;
|
13
15
|
signal: NodeJS.Signals | null;
|
@@ -22,3 +24,8 @@ export declare class ProgressListener {
|
|
22
24
|
info(msg: string, ...args: any[]): void;
|
23
25
|
debug(msg: string, ...args: any[]): void;
|
24
26
|
}
|
27
|
+
export declare class TaskProgressListener extends ProgressListener {
|
28
|
+
private readonly task;
|
29
|
+
constructor(task: Task);
|
30
|
+
protected emitLog(payload: Omit<LogEntry, 'time' | 'source'>): void;
|
31
|
+
}
|
@@ -4,7 +4,7 @@
|
|
4
4
|
* SPDX-License-Identifier: BUSL-1.1
|
5
5
|
*/
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
7
|
-
exports.ProgressListener = void 0;
|
7
|
+
exports.TaskProgressListener = exports.ProgressListener = void 0;
|
8
8
|
const nodejs_process_1 = require("@kapeta/nodejs-process");
|
9
9
|
const socketManager_1 = require("./socketManager");
|
10
10
|
const node_util_1 = require("node:util");
|
@@ -120,3 +120,14 @@ class ProgressListener {
|
|
120
120
|
}
|
121
121
|
}
|
122
122
|
exports.ProgressListener = ProgressListener;
|
123
|
+
class TaskProgressListener extends ProgressListener {
|
124
|
+
task;
|
125
|
+
constructor(task) {
|
126
|
+
super();
|
127
|
+
this.task = task;
|
128
|
+
}
|
129
|
+
emitLog(payload) {
|
130
|
+
this.task.addLog(payload.message, payload.level);
|
131
|
+
}
|
132
|
+
}
|
133
|
+
exports.TaskProgressListener = TaskProgressListener;
|
@@ -164,16 +164,17 @@ class RepositoryManager extends node_events_1.EventEmitter {
|
|
164
164
|
async scheduleInstallation(refs) {
|
165
165
|
//We make sure to only install one asset at a time - otherwise unexpected things might happen
|
166
166
|
const createInstaller = (ref) => {
|
167
|
-
return async () => {
|
167
|
+
return async (task) => {
|
168
168
|
if (await definitionsManager_1.definitionsManager.exists(ref)) {
|
169
169
|
return;
|
170
170
|
}
|
171
|
+
const progressListener = new progressListener_1.TaskProgressListener(task);
|
171
172
|
//console.log(`Installing asset: ${ref}`);
|
172
173
|
//Auto-install missing asset
|
173
174
|
try {
|
174
175
|
//We change to a temp dir to avoid issues with the current working directory
|
175
176
|
process.chdir(node_os_1.default.tmpdir());
|
176
|
-
await nodejs_registry_utils_1.Actions.install(
|
177
|
+
await nodejs_registry_utils_1.Actions.install(progressListener, [ref], {});
|
177
178
|
}
|
178
179
|
catch (e) {
|
179
180
|
console.error(`Failed to install asset: ${ref}`, e);
|
@@ -2,6 +2,7 @@
|
|
2
2
|
* Copyright 2023 Kapeta Inc.
|
3
3
|
* SPDX-License-Identifier: BUSL-1.1
|
4
4
|
*/
|
5
|
+
import { LogLevel } from './types';
|
5
6
|
export type TaskRunner<T> = (task: Task<T>) => Promise<T>;
|
6
7
|
export declare enum TaskStatus {
|
7
8
|
PENDING = "PENDING",
|
@@ -44,6 +45,7 @@ export declare class Task<T = void> implements TaskData<T> {
|
|
44
45
|
set errorMessage(errorMessage: string | undefined);
|
45
46
|
set metadata(metadata: TaskMetadata);
|
46
47
|
emitUpdate(): void;
|
48
|
+
addLog(log: string, level?: LogLevel): void;
|
47
49
|
wait(): Promise<T>;
|
48
50
|
toData(): {
|
49
51
|
id: string;
|
@@ -12,6 +12,7 @@ const socketManager_1 = require("./socketManager");
|
|
12
12
|
const EVENT_TASK_UPDATED = 'task-updated';
|
13
13
|
const EVENT_TASK_ADDED = 'task-added';
|
14
14
|
const EVENT_TASK_REMOVED = 'task-removed';
|
15
|
+
const EVENT_TASK_LOG = 'task-log';
|
15
16
|
var TaskStatus;
|
16
17
|
(function (TaskStatus) {
|
17
18
|
TaskStatus["PENDING"] = "PENDING";
|
@@ -54,6 +55,14 @@ class Task {
|
|
54
55
|
emitUpdate() {
|
55
56
|
socketManager_1.socketManager.emitGlobal(EVENT_TASK_UPDATED, this.toData());
|
56
57
|
}
|
58
|
+
addLog(log, level = 'INFO') {
|
59
|
+
socketManager_1.socketManager.emitGlobal(EVENT_TASK_LOG, {
|
60
|
+
id: this.id,
|
61
|
+
message: log,
|
62
|
+
level,
|
63
|
+
time: Date.now(),
|
64
|
+
});
|
65
|
+
}
|
57
66
|
async wait() {
|
58
67
|
return this.future.promise;
|
59
68
|
}
|
package/dist/esm/src/types.d.ts
CHANGED
@@ -66,25 +66,6 @@ export interface Health {
|
|
66
66
|
timeout?: number;
|
67
67
|
retries?: number;
|
68
68
|
}
|
69
|
-
export type PortInfo = {
|
70
|
-
port: number;
|
71
|
-
type: 'tcp' | 'udp';
|
72
|
-
} | number | string;
|
73
|
-
export type LocalImageOptions<Credentials = AnyMap, Options = AnyMap> = {
|
74
|
-
image: string;
|
75
|
-
ports: {
|
76
|
-
[key: string]: PortInfo;
|
77
|
-
};
|
78
|
-
credentials?: Credentials;
|
79
|
-
options?: Options;
|
80
|
-
cmd?: string;
|
81
|
-
env?: AnyMap;
|
82
|
-
health?: Health;
|
83
|
-
singleton?: boolean;
|
84
|
-
mounts?: {
|
85
|
-
[key: string]: string;
|
86
|
-
};
|
87
|
-
};
|
88
69
|
export type InstanceInfo = {
|
89
70
|
systemId: string;
|
90
71
|
instanceId: string;
|
@@ -19,6 +19,7 @@ const clusterService_1 = require("../clusterService");
|
|
19
19
|
const types_1 = require("../types");
|
20
20
|
const definitionsManager_1 = require("../definitionsManager");
|
21
21
|
const node_os_1 = __importDefault(require("node:os"));
|
22
|
+
const node_path_1 = __importDefault(require("node:path"));
|
22
23
|
const taskManager_1 = require("../taskManager");
|
23
24
|
const KAPETA_SYSTEM_ID = 'KAPETA_SYSTEM_ID';
|
24
25
|
const KAPETA_BLOCK_REF = 'KAPETA_BLOCK_REF';
|
@@ -144,6 +145,7 @@ class BlockInstanceRunner {
|
|
144
145
|
if (!assetVersion.definition.spec?.target?.kind) {
|
145
146
|
throw new Error('Missing target kind in block definition');
|
146
147
|
}
|
148
|
+
const realLocalPath = await fs_extra_1.default.realpath(baseDir);
|
147
149
|
const kindUri = (0, nodejs_utils_1.parseKapetaUri)(assetVersion.definition.kind);
|
148
150
|
const providerVersion = await getProvider(kindUri);
|
149
151
|
if (!providerVersion) {
|
@@ -158,10 +160,21 @@ class BlockInstanceRunner {
|
|
158
160
|
if (!localContainer) {
|
159
161
|
throw new Error(`Missing local container information from target: ${targetKindUri.id}`);
|
160
162
|
}
|
161
|
-
|
162
|
-
|
163
|
+
let dockerImage = localContainer.image;
|
164
|
+
const isDockerImage = !localContainer.type || localContainer.type.toLowerCase() === 'docker';
|
165
|
+
const isDockerFile = Boolean(localContainer.type && localContainer.type.toLowerCase() === 'dockerfile');
|
166
|
+
if (isDockerImage && !dockerImage) {
|
163
167
|
throw new Error(`Missing docker image information: ${JSON.stringify(localContainer)}`);
|
164
168
|
}
|
169
|
+
if (isDockerFile) {
|
170
|
+
dockerImage = blockInfo.fullName + ':local';
|
171
|
+
const dockerFile = node_path_1.default.join(realLocalPath, localContainer.file ?? 'Dockerfile');
|
172
|
+
if (!fs_extra_1.default.existsSync(dockerFile)) {
|
173
|
+
throw new Error(`Dockerfile not found at: ${dockerFile}`);
|
174
|
+
}
|
175
|
+
const task = containerManager_1.containerManager.buildDockerImage(dockerFile, blockInfo.fullName + ':local');
|
176
|
+
await task.wait();
|
177
|
+
}
|
165
178
|
const containerName = await (0, utils_1.getBlockInstanceContainerName)(this._systemId, blockInstance.id, targetKindUri.id);
|
166
179
|
const startCmd = localContainer.handlers?.onCreate ? localContainer.handlers.onCreate : '';
|
167
180
|
const dockerOpts = localContainer.options ?? {};
|
@@ -180,7 +193,6 @@ class BlockInstanceRunner {
|
|
180
193
|
if (localContainer.healthcheck) {
|
181
194
|
HealthCheck = containerManager_1.containerManager.toDockerHealth({ cmd: localContainer.healthcheck });
|
182
195
|
}
|
183
|
-
const realLocalPath = await fs_extra_1.default.realpath(baseDir);
|
184
196
|
const Mounts = containerManager_1.containerManager.toDockerMounts({
|
185
197
|
[workingDir]: (0, containerManager_1.toLocalBindVolume)(realLocalPath),
|
186
198
|
});
|
@@ -2,6 +2,7 @@
|
|
2
2
|
* Copyright 2023 Kapeta Inc.
|
3
3
|
* SPDX-License-Identifier: BUSL-1.1
|
4
4
|
*/
|
5
|
+
import { Task } from '../taskManager';
|
5
6
|
export declare function hasCLI(): Promise<boolean>;
|
6
|
-
export declare function ensureCLI(): Promise<
|
7
|
+
export declare function ensureCLI(): Promise<Task<void> | null>;
|
7
8
|
export declare function ensureCLICommands(): Promise<void>;
|
@@ -15,10 +15,16 @@ async function ensureCLI() {
|
|
15
15
|
if (await hasCLI()) {
|
16
16
|
return null;
|
17
17
|
}
|
18
|
-
return taskManager_1.taskManager.add(`cli:install`, () => {
|
18
|
+
return taskManager_1.taskManager.add(`cli:install`, (task) => {
|
19
19
|
const process = (0, nodejs_process_1.spawn)('npm', ['install', '-g', '@kapeta/kap'], {
|
20
20
|
shell: true,
|
21
21
|
});
|
22
|
+
process.process.stdout?.on('data', (data) => {
|
23
|
+
task.addLog(data.toString(), 'INFO');
|
24
|
+
});
|
25
|
+
process.process.stderr?.on('data', (data) => {
|
26
|
+
task.addLog(data.toString(), 'ERROR');
|
27
|
+
});
|
22
28
|
return process.wait();
|
23
29
|
}, {
|
24
30
|
name: `Installing Kapeta CLI`,
|
@@ -2,10 +2,10 @@
|
|
2
2
|
* Copyright 2023 Kapeta Inc.
|
3
3
|
* SPDX-License-Identifier: BUSL-1.1
|
4
4
|
*/
|
5
|
-
import { EntityList } from '@kapeta/schemas';
|
6
|
-
import { AnyMap
|
5
|
+
import { EntityList, LocalInstancePort } from '@kapeta/schemas';
|
6
|
+
import { AnyMap } from '../types';
|
7
7
|
export declare function getBlockInstanceContainerName(systemId: string, instanceId: string, blockType?: string): Promise<string>;
|
8
|
-
export declare function toPortInfo(port:
|
8
|
+
export declare function toPortInfo(port: LocalInstancePort): LocalInstancePort | {
|
9
9
|
port: number;
|
10
10
|
type: string;
|
11
11
|
};
|
@@ -11,6 +11,7 @@ exports.getResolvedConfiguration = exports.getBindHost = exports.isLinux = expor
|
|
11
11
|
const node_fs_1 = __importDefault(require("node:fs"));
|
12
12
|
const yaml_1 = __importDefault(require("yaml"));
|
13
13
|
const md5_1 = __importDefault(require("md5"));
|
14
|
+
const schemas_1 = require("@kapeta/schemas");
|
14
15
|
const lodash_1 = __importDefault(require("lodash"));
|
15
16
|
const types_1 = require("../types");
|
16
17
|
const local_cluster_config_1 = __importDefault(require("@kapeta/local-cluster-config"));
|
@@ -45,7 +46,7 @@ function toPortInfo(port) {
|
|
45
46
|
return { port: parseInt(`${port}`), type: 'tcp' };
|
46
47
|
}
|
47
48
|
if (!port.type) {
|
48
|
-
port.type =
|
49
|
+
port.type = schemas_1.LocalInstancePortType.TCP;
|
49
50
|
}
|
50
51
|
return port;
|
51
52
|
}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@kapeta/local-cluster-service",
|
3
|
-
"version": "0.
|
3
|
+
"version": "0.38.0",
|
4
4
|
"description": "Manages configuration, ports and service discovery for locally running Kapeta systems",
|
5
5
|
"type": "commonjs",
|
6
6
|
"exports": {
|
@@ -35,7 +35,8 @@
|
|
35
35
|
},
|
36
36
|
"scripts": {
|
37
37
|
"start": "node ./dist/cjs/start.js",
|
38
|
-
"dev": "
|
38
|
+
"dev": "npm run start:dev",
|
39
|
+
"start:dev": "nodemon -e js,ts,json ./start.ts",
|
39
40
|
"test": "jest",
|
40
41
|
"clean": "rm -rf ./dist",
|
41
42
|
"build:esm": "tsc --module nodenext --moduleResolution nodenext --outDir ./dist/esm && echo '{\"type\":\"module\"}' > ./dist/esm/package.json",
|
@@ -47,19 +48,19 @@
|
|
47
48
|
},
|
48
49
|
"homepage": "https://github.com/kapetacom/local-cluster-service#readme",
|
49
50
|
"dependencies": {
|
50
|
-
"@kapeta/codegen": "^1.
|
51
|
-
"@kapeta/kaplang-core": "^1.
|
51
|
+
"@kapeta/codegen": "^1.3.0",
|
52
|
+
"@kapeta/kaplang-core": "^1.11.2",
|
52
53
|
"@kapeta/local-cluster-config": "^0.4.0",
|
53
|
-
"@kapeta/nodejs-api-client": ">=0.
|
54
|
-
"@kapeta/nodejs-process": "
|
55
|
-
"@kapeta/nodejs-registry-utils": ">=0.
|
54
|
+
"@kapeta/nodejs-api-client": ">=0.2.0 <2",
|
55
|
+
"@kapeta/nodejs-process": "^1.2.0",
|
56
|
+
"@kapeta/nodejs-registry-utils": ">=0.10.0 <2",
|
56
57
|
"@kapeta/nodejs-utils": "<2",
|
57
|
-
"@kapeta/schemas": "^
|
58
|
-
"@kapeta/sdk-config": "^2.
|
59
|
-
"@kapeta/ui-web-components": "^3.0
|
60
|
-
"@kapeta/ui-web-plan-editor": "^2.
|
61
|
-
"@kapeta/ui-web-types": "^1.
|
62
|
-
"@kapeta/web-microfrontend": "^1",
|
58
|
+
"@kapeta/schemas": "^3.4.0",
|
59
|
+
"@kapeta/sdk-config": "^2.1.0",
|
60
|
+
"@kapeta/ui-web-components": "^3.1.0",
|
61
|
+
"@kapeta/ui-web-plan-editor": "^2.3.1",
|
62
|
+
"@kapeta/ui-web-types": "^1.3.1",
|
63
|
+
"@kapeta/web-microfrontend": "^1.2.5",
|
63
64
|
"@sentry/node": "^7.94.1",
|
64
65
|
"@types/dockerode": "^3.3.19",
|
65
66
|
"@types/stream-json": "^1.7.3",
|
package/src/assetManager.ts
CHANGED
@@ -8,13 +8,13 @@ import FS from 'fs-extra';
|
|
8
8
|
import YAML from 'yaml';
|
9
9
|
import { Definition, DefinitionInfo } from '@kapeta/local-cluster-config';
|
10
10
|
import { codeGeneratorManager } from './codeGeneratorManager';
|
11
|
-
import { ProgressListener } from './progressListener';
|
11
|
+
import { ProgressListener, TaskProgressListener } from './progressListener';
|
12
12
|
import { normalizeKapetaUri, parseKapetaUri } from '@kapeta/nodejs-utils';
|
13
13
|
import { repositoryManager } from './repositoryManager';
|
14
14
|
import { BlockDefinition, BlockInstance, Plan } from '@kapeta/schemas';
|
15
15
|
import { Actions } from '@kapeta/nodejs-registry-utils';
|
16
16
|
import { definitionsManager } from './definitionsManager';
|
17
|
-
import { taskManager } from './taskManager';
|
17
|
+
import { Task, taskManager } from './taskManager';
|
18
18
|
import { KIND_BLOCK_TYPE_EXECUTABLE, KIND_BLOCK_TYPE_OPERATOR, KIND_BLOCK_TYPE, SourceOfChange } from './types';
|
19
19
|
import { cacheManager } from './cacheManager';
|
20
20
|
import uuid from 'node-uuid';
|
@@ -308,11 +308,12 @@ class AssetManager {
|
|
308
308
|
}
|
309
309
|
|
310
310
|
console.log('Installing updates', refs);
|
311
|
-
const updateAll = async () => {
|
311
|
+
const updateAll = async (task: Task) => {
|
312
|
+
const progressListener = new TaskProgressListener(task);
|
312
313
|
try {
|
313
314
|
//We change to a temp dir to avoid issues with the current working directory
|
314
315
|
process.chdir(os.tmpdir());
|
315
|
-
await Actions.install(
|
316
|
+
await Actions.install(progressListener, refs, {});
|
316
317
|
await this.cleanupUnusedProviders();
|
317
318
|
} catch (e) {
|
318
319
|
console.error(`Failed to update assets: ${refs.join(',')}`, e);
|