@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.
Files changed (47) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/dist/cjs/src/assetManager.d.ts +2 -1
  3. package/dist/cjs/src/assetManager.js +3 -2
  4. package/dist/cjs/src/containerManager.d.ts +6 -3
  5. package/dist/cjs/src/containerManager.js +96 -18
  6. package/dist/cjs/src/instanceManager.js +15 -8
  7. package/dist/cjs/src/operatorManager.d.ts +3 -2
  8. package/dist/cjs/src/progressListener.d.ts +8 -1
  9. package/dist/cjs/src/progressListener.js +12 -1
  10. package/dist/cjs/src/repositoryManager.js +3 -2
  11. package/dist/cjs/src/taskManager.d.ts +2 -0
  12. package/dist/cjs/src/taskManager.js +9 -0
  13. package/dist/cjs/src/types.d.ts +0 -19
  14. package/dist/cjs/src/utils/BlockInstanceRunner.js +15 -3
  15. package/dist/cjs/src/utils/commandLineUtils.d.ts +2 -1
  16. package/dist/cjs/src/utils/commandLineUtils.js +7 -1
  17. package/dist/cjs/src/utils/utils.d.ts +3 -3
  18. package/dist/cjs/src/utils/utils.js +2 -1
  19. package/dist/esm/src/assetManager.d.ts +2 -1
  20. package/dist/esm/src/assetManager.js +3 -2
  21. package/dist/esm/src/containerManager.d.ts +6 -3
  22. package/dist/esm/src/containerManager.js +96 -18
  23. package/dist/esm/src/instanceManager.js +15 -8
  24. package/dist/esm/src/operatorManager.d.ts +3 -2
  25. package/dist/esm/src/progressListener.d.ts +8 -1
  26. package/dist/esm/src/progressListener.js +12 -1
  27. package/dist/esm/src/repositoryManager.js +3 -2
  28. package/dist/esm/src/taskManager.d.ts +2 -0
  29. package/dist/esm/src/taskManager.js +9 -0
  30. package/dist/esm/src/types.d.ts +0 -19
  31. package/dist/esm/src/utils/BlockInstanceRunner.js +15 -3
  32. package/dist/esm/src/utils/commandLineUtils.d.ts +2 -1
  33. package/dist/esm/src/utils/commandLineUtils.js +7 -1
  34. package/dist/esm/src/utils/utils.d.ts +3 -3
  35. package/dist/esm/src/utils/utils.js +2 -1
  36. package/package.json +14 -13
  37. package/src/assetManager.ts +5 -4
  38. package/src/containerManager.ts +110 -23
  39. package/src/instanceManager.ts +16 -10
  40. package/src/operatorManager.ts +2 -3
  41. package/src/progressListener.ts +15 -1
  42. package/src/repositoryManager.ts +5 -3
  43. package/src/taskManager.ts +11 -0
  44. package/src/types.ts +0 -19
  45. package/src/utils/BlockInstanceRunner.ts +21 -15
  46. package/src/utils/commandLineUtils.ts +10 -2
  47. package/src/utils/utils.ts +4 -4
package/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ # [0.38.0](https://github.com/kapetacom/local-cluster-service/compare/v0.37.0...v0.38.0) (2024-02-24)
2
+
3
+
4
+ ### Features
5
+
6
+ * Add support for running local dockerfiles ([2ee08c5](https://github.com/kapetacom/local-cluster-service/commit/2ee08c58eb19666834262d8011c8f901957b5f63))
7
+
1
8
  # [0.37.0](https://github.com/kapetacom/local-cluster-service/compare/v0.36.1...v0.37.0) (2024-02-23)
2
9
 
3
10
 
@@ -4,6 +4,7 @@
4
4
  */
5
5
  import { Definition } from '@kapeta/local-cluster-config';
6
6
  import { BlockDefinition, BlockInstance, Plan } from '@kapeta/schemas';
7
+ import { Task } from './taskManager';
7
8
  import { SourceOfChange } from './types';
8
9
  export interface EnrichedAsset {
9
10
  ref: string;
@@ -31,7 +32,7 @@ declare class AssetManager {
31
32
  updateAsset(ref: string, yaml: Definition, sourceOfChange?: SourceOfChange): Promise<void>;
32
33
  importFile(filePath: string): Promise<EnrichedAsset[]>;
33
34
  unregisterAsset(ref: string): Promise<void>;
34
- installAsset(ref: string, wait?: boolean): Promise<import("./taskManager").Task<void>[] | undefined>;
35
+ installAsset(ref: string, wait?: boolean): Promise<Task<void>[] | undefined>;
35
36
  private cleanupUnusedProviders;
36
37
  private upgradeAllProviders;
37
38
  private maybeGenerateCode;
@@ -233,11 +233,12 @@ class AssetManager {
233
233
  return;
234
234
  }
235
235
  console.log('Installing updates', refs);
236
- const updateAll = async () => {
236
+ const updateAll = async (task) => {
237
+ const progressListener = new progressListener_1.TaskProgressListener(task);
237
238
  try {
238
239
  //We change to a temp dir to avoid issues with the current working directory
239
240
  process.chdir(node_os_1.default.tmpdir());
240
- await nodejs_registry_utils_1.Actions.install(new progressListener_1.ProgressListener(), refs, {});
241
+ await nodejs_registry_utils_1.Actions.install(progressListener, refs, {});
241
242
  await this.cleanupUnusedProviders();
242
243
  }
243
244
  catch (e) {
@@ -5,7 +5,9 @@
5
5
  /// <reference types="node" />
6
6
  import FSExtra from 'fs-extra';
7
7
  import Docker from 'dockerode';
8
- import { Health, InstanceInfo, LogEntry } from './types';
8
+ import { InstanceInfo, LogEntry } from './types';
9
+ import { Task } from './taskManager';
10
+ import { LocalInstanceHealth } from '@kapeta/schemas';
9
11
  type StringMap = {
10
12
  [key: string]: string;
11
13
  };
@@ -50,11 +52,11 @@ declare class ContainerManager {
50
52
  getContainerByName(containerName: string): Promise<ContainerInfo | undefined>;
51
53
  pull(image: string): Promise<boolean>;
52
54
  toDockerMounts(mounts: StringMap): DockerMounts[];
53
- toDockerHealth(health: Health): {
55
+ toDockerHealth(health: LocalInstanceHealth): {
54
56
  Test: string[];
55
57
  Interval: number;
56
58
  Timeout: number;
57
- Retries: number;
59
+ Retries: any;
58
60
  };
59
61
  private applyHash;
60
62
  ensureContainer(opts: any): Promise<Docker.Container>;
@@ -74,6 +76,7 @@ declare class ContainerManager {
74
76
  getLogs(instance: InstanceInfo): Promise<LogEntry[]>;
75
77
  stopLogListening(systemId: string, instanceId: string): Promise<void>;
76
78
  ensureLogListening(systemId: string, instanceId: string, handler: (log: LogEntry) => void): Promise<void>;
79
+ buildDockerImage(dockerFile: string, imageName: string): Task<void>;
77
80
  }
78
81
  declare class ClosableLogStream {
79
82
  private readonly stream;
@@ -207,14 +207,8 @@ class ContainerManager {
207
207
  return this._docker;
208
208
  }
209
209
  async getContainerByName(containerName) {
210
- const containers = await this.docker().listContainers({ all: true });
211
- const out = containers.find((container) => {
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 = await this.docker().getContainer(name);
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 === 0) {
834
- out.push({
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
- return out;
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 = types_1.InstanceStatus.STOPPED;
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.UNKNOWN,
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 = (newStatus === types_1.InstanceStatus.STOPPED && instance.status === types_1.InstanceStatus.FAILED) ||
626
- ([types_1.InstanceStatus.READY, types_1.InstanceStatus.UNHEALTHY].includes(newStatus) &&
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.FAILED, types_1.InstanceStatus.STOPPING].includes(newStatus)) {
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
- return types_1.InstanceStatus.STOPPED;
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, LocalImageOptions, OperatorInfo } from './types';
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(): LocalImageOptions;
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
- private emitLog;
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(new progressListener_1.ProgressListener(), [ref], {});
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
  }
@@ -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
- const dockerImage = localContainer.image;
162
- if (!dockerImage) {
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<import("../taskManager").Task<void> | null>;
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, PortInfo } from '../types';
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: PortInfo): {
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 = 'tcp';
49
+ port.type = schemas_1.LocalInstancePortType.TCP;
49
50
  }
50
51
  return port;
51
52
  }
@@ -4,6 +4,7 @@
4
4
  */
5
5
  import { Definition } from '@kapeta/local-cluster-config';
6
6
  import { BlockDefinition, BlockInstance, Plan } from '@kapeta/schemas';
7
+ import { Task } from './taskManager';
7
8
  import { SourceOfChange } from './types';
8
9
  export interface EnrichedAsset {
9
10
  ref: string;
@@ -31,7 +32,7 @@ declare class AssetManager {
31
32
  updateAsset(ref: string, yaml: Definition, sourceOfChange?: SourceOfChange): Promise<void>;
32
33
  importFile(filePath: string): Promise<EnrichedAsset[]>;
33
34
  unregisterAsset(ref: string): Promise<void>;
34
- installAsset(ref: string, wait?: boolean): Promise<import("./taskManager").Task<void>[] | undefined>;
35
+ installAsset(ref: string, wait?: boolean): Promise<Task<void>[] | undefined>;
35
36
  private cleanupUnusedProviders;
36
37
  private upgradeAllProviders;
37
38
  private maybeGenerateCode;
@@ -233,11 +233,12 @@ class AssetManager {
233
233
  return;
234
234
  }
235
235
  console.log('Installing updates', refs);
236
- const updateAll = async () => {
236
+ const updateAll = async (task) => {
237
+ const progressListener = new progressListener_1.TaskProgressListener(task);
237
238
  try {
238
239
  //We change to a temp dir to avoid issues with the current working directory
239
240
  process.chdir(node_os_1.default.tmpdir());
240
- await nodejs_registry_utils_1.Actions.install(new progressListener_1.ProgressListener(), refs, {});
241
+ await nodejs_registry_utils_1.Actions.install(progressListener, refs, {});
241
242
  await this.cleanupUnusedProviders();
242
243
  }
243
244
  catch (e) {
@@ -5,7 +5,9 @@
5
5
  /// <reference types="node" />
6
6
  import FSExtra from 'fs-extra';
7
7
  import Docker from 'dockerode';
8
- import { Health, InstanceInfo, LogEntry } from './types';
8
+ import { InstanceInfo, LogEntry } from './types';
9
+ import { Task } from './taskManager';
10
+ import { LocalInstanceHealth } from '@kapeta/schemas';
9
11
  type StringMap = {
10
12
  [key: string]: string;
11
13
  };
@@ -50,11 +52,11 @@ declare class ContainerManager {
50
52
  getContainerByName(containerName: string): Promise<ContainerInfo | undefined>;
51
53
  pull(image: string): Promise<boolean>;
52
54
  toDockerMounts(mounts: StringMap): DockerMounts[];
53
- toDockerHealth(health: Health): {
55
+ toDockerHealth(health: LocalInstanceHealth): {
54
56
  Test: string[];
55
57
  Interval: number;
56
58
  Timeout: number;
57
- Retries: number;
59
+ Retries: any;
58
60
  };
59
61
  private applyHash;
60
62
  ensureContainer(opts: any): Promise<Docker.Container>;
@@ -74,6 +76,7 @@ declare class ContainerManager {
74
76
  getLogs(instance: InstanceInfo): Promise<LogEntry[]>;
75
77
  stopLogListening(systemId: string, instanceId: string): Promise<void>;
76
78
  ensureLogListening(systemId: string, instanceId: string, handler: (log: LogEntry) => void): Promise<void>;
79
+ buildDockerImage(dockerFile: string, imageName: string): Task<void>;
77
80
  }
78
81
  declare class ClosableLogStream {
79
82
  private readonly stream;