@nosana/node 1.0.7 → 1.0.8-rc

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/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nosana/node",
3
- "version": "1.0.7",
3
+ "version": "1.0.8-rc",
4
4
  "description": "",
5
5
  "bin": {
6
6
  "nosana-node": "./dist/src/index.js"
@@ -50,6 +50,7 @@ export interface TaskLog {
50
50
  }
51
51
  export type OperationData = {
52
52
  host?: string;
53
+ container_ip?: string;
53
54
  endpoint?: {
54
55
  [key: string]: string;
55
56
  };
@@ -197,6 +198,7 @@ export default class TaskManager {
197
198
  setResult: (opId: string, key: string, value: any) => void;
198
199
  setResults: (opId: string, values: Record<string, any>) => void;
199
200
  setHost: (opId: string, host: string) => void;
201
+ setContainerIp: (opId: string, ip: string) => void;
200
202
  setDefaults: (flowId: string, project: string, jobDefinition: JobDefinition) => void;
201
203
  rehydrateEndpointsForOperation: (flowId: string, project: string, jobDefinition: JobDefinition, opId: string) => void;
202
204
  getByPath: (opId: string, path: string) => any;
@@ -13,7 +13,7 @@ import { createDependencyMap } from './executions/createDependencyMap.js';
13
13
  import { getCurrentGroup, getCurrentGroupStatus, getGroupStatus, getOperationsStatus, getOperationStatus, } from './operations/getOperationsInfos.js';
14
14
  import { addLog, getAllLogs, getLogsByGroup, getLogsByOp, subscribe, unsubscribe, } from './loggers/logManager.js';
15
15
  import { moveTaskManagerGroupOperations } from './operations/moveTaskManagerGroupOperation.js';
16
- import { setResult, setResults, setHost, setDefaults, rehydrateEndpointsForOperation, getByPath, resolveLiteralsInString, interpolate, interpolateOperation, transformCollections, } from './globalStore/index.js';
16
+ import { setResult, setResults, setHost, setDefaults, setContainerIp, rehydrateEndpointsForOperation, getByPath, resolveLiteralsInString, interpolate, interpolateOperation, transformCollections, } from './globalStore/index.js';
17
17
  import { configs } from '../../configs/configs.js';
18
18
  import { getSDK } from '../../sdk/index.js';
19
19
  export const StopReasons = {
@@ -155,6 +155,7 @@ export default class TaskManager {
155
155
  this.setResult = setResult.bind(this);
156
156
  this.setResults = setResults.bind(this);
157
157
  this.setHost = setHost.bind(this);
158
+ this.setContainerIp = setContainerIp.bind(this);
158
159
  this.setDefaults = setDefaults.bind(this);
159
160
  this.rehydrateEndpointsForOperation =
160
161
  rehydrateEndpointsForOperation.bind(this);
@@ -1,6 +1,7 @@
1
1
  export { setResult } from './setResult.js';
2
2
  export { setResults } from './setResults.js';
3
3
  export { setHost } from './setHost.js';
4
+ export { setContainerIp } from './setContainerIp.js';
4
5
  export { setDefaults, rehydrateEndpointsForOperation } from './setDefaults.js';
5
6
  export { getByPath } from './getByPath.js';
6
7
  export { resolveLiteralsInString } from './resolveLiteralsInString.js';
@@ -1,6 +1,7 @@
1
1
  export { setResult } from './setResult.js';
2
2
  export { setResults } from './setResults.js';
3
3
  export { setHost } from './setHost.js';
4
+ export { setContainerIp } from './setContainerIp.js';
4
5
  export { setDefaults, rehydrateEndpointsForOperation } from './setDefaults.js';
5
6
  export { getByPath } from './getByPath.js';
6
7
  export { resolveLiteralsInString } from './resolveLiteralsInString.js';
@@ -0,0 +1,2 @@
1
+ import TaskManager from '../TaskManager.js';
2
+ export declare function setContainerIp(this: TaskManager, opId: string, internalIp: string): void;
@@ -0,0 +1,9 @@
1
+ export function setContainerIp(opId, internalIp) {
2
+ const op = (this.globalOpStore[opId] ??= {});
3
+ op.container_ip = internalIp;
4
+ // Host updated; attempt endpoint rehydration for this op
5
+ const flow = this.repository.getFlow(this.job);
6
+ if (flow) {
7
+ this.rehydrateEndpointsForOperation(flow.id, flow.project, flow.jobDefinition, opId);
8
+ }
9
+ }
@@ -136,6 +136,9 @@ export async function runTaskManagerOperation(flow, op, dependent) {
136
136
  emitter.on('updateOpHost', (body) => {
137
137
  this.setHost(op.id, body.name);
138
138
  });
139
+ emitter.on('setContainerInternalIp', (ip) => {
140
+ this.setContainerIp(op.id, ip);
141
+ });
139
142
  /**
140
143
  * Subscribes to the 'start' event, which marks the official beginning of an operation’s execution.
141
144
  *
@@ -212,7 +212,7 @@ export class Provider {
212
212
  const resourceVolumes = await this.resourceManager.getResourceVolumes(op.args.resources ?? [], controller);
213
213
  volumes.push(...resourceVolumes);
214
214
  }
215
- container = await this.containerOrchestration.runFlowContainer(op.args.image ?? flow.jobDefinition.global?.image, {
215
+ const createContainerOptions = {
216
216
  name,
217
217
  cmd,
218
218
  env,
@@ -225,8 +225,22 @@ export class Provider {
225
225
  aliases,
226
226
  restart_policy: op.args.restart_policy,
227
227
  runtime: op.args.trusted_execution_env
228
- });
228
+ };
229
+ if (op.args.trusted_execution_env) {
230
+ await this.containerOrchestration.pullImage("busybox");
231
+ await this.resourceManager.images.setImage("busybox");
232
+ await this.containerOrchestration.runFlowContainer("busybox", {
233
+ name: `bridge-${name}`,
234
+ cmd: ['sleep', 'infinity'],
235
+ });
236
+ createContainerOptions.bind_network_to_container = `bridge-${name}`;
237
+ }
238
+ container = await this.containerOrchestration.runFlowContainer(op.args.image ?? flow.jobDefinition.global?.image, createContainerOptions);
239
+ const info = await container.inspect();
229
240
  emitter.emit('updateOpState', { providerId: container.id });
241
+ if (info.NetworkSettings?.Networks["NOSANA_GATEWAY"].IPAddress) {
242
+ emitter.emit('setContainerInternalIp', info.NetworkSettings.Networks["NOSANA_GATEWAY"].IPAddress);
243
+ }
230
244
  stateManager = new ContainerStateManager(container, controller, emitter, op.args.restart_policy);
231
245
  await stateManager.startMonitoring();
232
246
  if (isOpExposed(op)) {
@@ -277,8 +291,10 @@ export class Provider {
277
291
  try {
278
292
  const index = getOpStateIndex(flow.jobDefinition.ops, op.id);
279
293
  const name = flow.id + '-' + index;
280
- const opContainer = await this.containerOrchestration.getContainerByName(name);
281
- const frpcContainer = await this.containerOrchestration.getContainerByName('frpc-' + name);
294
+ const [opContainer, getSupportContainers] = await Promise.all([
295
+ this.containerOrchestration.getContainerByName(name),
296
+ this.containerOrchestration.getContainersByName([`frpc-${name}`, `bridge-${name}`]),
297
+ ]);
282
298
  if (opContainer) {
283
299
  const info = await this.containerOrchestration.stopAndDeleteContainer(opContainer.id);
284
300
  if (info) {
@@ -289,8 +305,8 @@ export class Provider {
289
305
  });
290
306
  }
291
307
  }
292
- if (frpcContainer) {
293
- await this.containerOrchestration.stopAndDeleteContainer(frpcContainer.id);
308
+ if (getSupportContainers) {
309
+ await Promise.all(getSupportContainers.map((container) => this.containerOrchestration.stopAndDeleteContainer(container.id)));
294
310
  }
295
311
  await this.containerOrchestration.deleteNetwork(name);
296
312
  if (flow.jobDefinition.ops[index]
@@ -1,3 +1,3 @@
1
1
  import { ContainerCreateOptions } from "dockerode";
2
2
  import { RunContainerArgs } from "../interface";
3
- export declare function createDockerRunOptions(image: string, { name, cmd, gpu, volumes, env, work_dir, entrypoint, aliases, restart_policy, runtime }: RunContainerArgs, gpuOption: string): ContainerCreateOptions;
3
+ export declare function createDockerRunOptions(image: string, { name, cmd, gpu, volumes, env, work_dir, entrypoint, aliases, restart_policy, runtime, bind_network_to_container }: RunContainerArgs, gpuOption: string): ContainerCreateOptions;
@@ -10,7 +10,7 @@ function parseRestartPolicy(restart_policy) {
10
10
  }
11
11
  return undefined;
12
12
  }
13
- export function createDockerRunOptions(image, { name, cmd, gpu, volumes, env, work_dir, entrypoint, aliases, restart_policy, runtime }, gpuOption) {
13
+ export function createDockerRunOptions(image, { name, cmd, gpu, volumes, env, work_dir, entrypoint, aliases, restart_policy, runtime, bind_network_to_container }, gpuOption) {
14
14
  const devices = [];
15
15
  if (gpu) {
16
16
  devices.push({
@@ -37,11 +37,13 @@ export function createDockerRunOptions(image, { name, cmd, gpu, volumes, env, wo
37
37
  Image: image,
38
38
  WorkingDir: work_dir,
39
39
  Entrypoint: entrypoint,
40
- NetworkingConfig: {
41
- EndpointsConfig: {
42
- NOSANA_GATEWAY: aliases ? { Aliases: aliases } : {},
43
- },
44
- },
40
+ ...(!bind_network_to_container ? {
41
+ NetworkingConfig: {
42
+ EndpointsConfig: {
43
+ NOSANA_GATEWAY: aliases ? { Aliases: aliases } : {},
44
+ },
45
+ }
46
+ } : {}),
45
47
  HostConfig: {
46
48
  ExtraHosts: [
47
49
  'host.docker.internal:8.8.8.8',
@@ -53,7 +55,7 @@ export function createDockerRunOptions(image, { name, cmd, gpu, volumes, env, wo
53
55
  Type: 'volume',
54
56
  ReadOnly: readonly || false,
55
57
  })),
56
- NetworkMode: 'bridge',
58
+ NetworkMode: bind_network_to_container ? bind_network_to_container : 'bridge',
57
59
  DeviceRequests: devices,
58
60
  ...(runtime === 'SEV-SNP' ? {
59
61
  Devices: [
@@ -22,6 +22,7 @@ export type RunContainerArgs = {
22
22
  restart_policy?: RestartPolicy;
23
23
  aliases?: string[] | undefined;
24
24
  runtime?: string;
25
+ bind_network_to_container?: string;
25
26
  };
26
27
  export interface ContainerOrchestrationInterface {
27
28
  teeRuntime?: string;
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@nosana/node",
3
- "version": "1.0.7",
3
+ "version": "1.0.8-rc",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "@nosana/node",
9
- "version": "1.0.7",
9
+ "version": "1.0.8-rc",
10
10
  "license": "ISC",
11
11
  "dependencies": {
12
12
  "@coral-xyz/anchor": "^0.28.1-beta.1",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nosana/node",
3
- "version": "1.0.7",
3
+ "version": "1.0.8-rc",
4
4
  "description": "",
5
5
  "bin": {
6
6
  "nosana-node": "./dist/src/index.js"