@di-framework/cli-plugin-platform 6.0.3 → 6.0.6

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 (69) hide show
  1. package/README.md +196 -21
  2. package/dist/args.d.ts +2 -1
  3. package/dist/args.js +9 -5
  4. package/dist/assets/http-adapter.js +111 -2
  5. package/dist/assets/platform/README.md +22 -6
  6. package/dist/assets/sqlite/BUILD-INFO.txt +1 -1
  7. package/dist/assets/wit/deps/wasi-clocks-0.2.12/package.wit +43 -0
  8. package/dist/assets/wit/deps/wasi-filesystem-0.2.12/package.wit +196 -0
  9. package/dist/assets/wit/deps/wasi-io-0.2.12/package.wit +66 -0
  10. package/dist/assets/wit/deps/wasi-logging/package.wit +36 -0
  11. package/dist/build.d.ts +3 -1
  12. package/dist/build.js +4 -2
  13. package/dist/command.js +31 -13
  14. package/dist/console/auth.d.ts +20 -0
  15. package/dist/console/auth.js +82 -0
  16. package/dist/console/catalog.d.ts +196 -0
  17. package/dist/console/catalog.js +821 -0
  18. package/dist/console/cluster.d.ts +30 -0
  19. package/dist/console/cluster.js +299 -0
  20. package/dist/console/errors.d.ts +10 -0
  21. package/dist/console/errors.js +32 -0
  22. package/dist/console/run.d.ts +18 -0
  23. package/dist/console/run.js +102 -0
  24. package/dist/console/server.d.ts +25 -0
  25. package/dist/console/server.js +668 -0
  26. package/dist/console/services.d.ts +47 -0
  27. package/dist/console/services.js +111 -0
  28. package/dist/console-ui/app.css +1 -0
  29. package/dist/console-ui/app.js +260 -0
  30. package/dist/console-ui/di-framework-mark.png +0 -0
  31. package/dist/console-ui/index.html +13 -0
  32. package/dist/deps.d.ts +2 -0
  33. package/dist/deps.js +5 -3
  34. package/dist/dev.js +10 -5
  35. package/dist/egress.d.ts +40 -0
  36. package/dist/egress.js +214 -0
  37. package/dist/host-interface.js +2 -1
  38. package/dist/index.d.ts +1 -0
  39. package/dist/index.js +1 -0
  40. package/dist/manifest.d.ts +7 -0
  41. package/dist/manifest.js +35 -8
  42. package/dist/node-compat/console.d.ts +18 -0
  43. package/dist/node-compat/console.js +42 -0
  44. package/dist/node-compat/env.js +6 -0
  45. package/dist/node-compat/events.d.ts +20 -0
  46. package/dist/node-compat/events.js +55 -0
  47. package/dist/node-compat/fetch-runtime.d.ts +39 -0
  48. package/dist/node-compat/fetch-runtime.js +106 -2
  49. package/dist/node-compat/fs-promises.d.ts +30 -0
  50. package/dist/node-compat/fs-promises.js +3 -0
  51. package/dist/node-compat/fs.d.ts +79 -0
  52. package/dist/node-compat/fs.js +112 -5
  53. package/dist/node-compat/net.d.ts +2 -1
  54. package/dist/node-compat/net.js +3 -1
  55. package/dist/node-compat/storage.d.ts +87 -0
  56. package/dist/node-compat/storage.js +244 -0
  57. package/dist/node-compat/stream.d.ts +24 -0
  58. package/dist/node-compat/stream.js +70 -0
  59. package/dist/platform.js +2 -4
  60. package/dist/project.d.ts +5 -0
  61. package/dist/project.js +4 -0
  62. package/dist/service.d.ts +21 -2
  63. package/dist/service.js +71 -5
  64. package/dist/target.js +6 -1
  65. package/dist/wit.d.ts +8 -0
  66. package/dist/wit.js +28 -0
  67. package/dist/workload.d.ts +45 -0
  68. package/dist/workload.js +98 -26
  69. package/package.json +14 -4
package/dist/service.js CHANGED
@@ -12,20 +12,38 @@ export const BACKING_SERVICE_API_VERSION = 'platform.di-framework.dev/v1alpha1';
12
12
  export const BACKING_SERVICE_KIND = 'BackingService';
13
13
  export const BACKING_SERVICE_RESOURCE = 'backingservices.platform.di-framework.dev';
14
14
  export const BACKING_SERVICE_CLASS_RESOURCE = 'backingserviceclasses.platform.di-framework.dev';
15
- export const SERVICE_TYPES = ['keyvalue', 'messaging', 'postgres'];
15
+ export const SERVICE_TYPES = ['keyvalue', 'messaging', 'blobstore', 'postgres', 'egress'];
16
16
  export const DEFAULT_SERVICE_CLASSES = {
17
17
  keyvalue: 'keyvalue-redis',
18
18
  messaging: 'messaging-nats',
19
+ blobstore: 'blobstore-nats',
19
20
  postgres: 'postgres-dedicated',
21
+ egress: 'egress-public',
22
+ };
23
+ export const DEFAULT_SERVICE_PROVIDERS = {
24
+ keyvalue: 'redis',
25
+ messaging: 'nats',
26
+ blobstore: 'nats',
27
+ postgres: 'postgres',
28
+ egress: 'platform',
20
29
  };
21
30
  export const DEFAULT_WAIT_TIMEOUT_MS = 120_000;
22
31
  export const WAIT_POLL_INTERVAL_MS = 2_000;
23
32
  const NAME_PATTERN = /^[a-z][a-z0-9]*(-[a-z0-9]+)*$/;
24
33
  const QUANTITY_PATTERN = /^[0-9]+(\.[0-9]+)?(m|Ki|Mi|Gi|Ti)?$/;
34
+ /** `host`, `*.suffix`, optionally with `:port`; matches the BackingService egress schema. */
35
+ const DESTINATION_PATTERN = /^(?:\*\.)?[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?)*(?::([0-9]{1,5}))?$/;
25
36
  const DELETION_POLICIES = ['Retain', 'Delete'];
26
37
  export function isServiceType(value) {
27
38
  return SERVICE_TYPES.includes(value);
28
39
  }
40
+ /** An egress destination: `host`, `*.suffix`, `host:port`, or `*.suffix:port`. */
41
+ export function isEgressDestination(value) {
42
+ const match = DESTINATION_PATTERN.exec(value);
43
+ if (match === null || value.length > 260)
44
+ return false;
45
+ return match[1] === undefined || (Number(match[1]) >= 1 && Number(match[1]) <= 65535);
46
+ }
29
47
  /** DNS-label rules aligned with the BackingService CRD metadata.name schema (max 40). */
30
48
  export function isBackingServiceName(value, max = 40) {
31
49
  return value.length >= 1 && value.length <= max && NAME_PATTERN.test(value);
@@ -35,15 +53,20 @@ export function serviceTypeDiscoveryText() {
35
53
  'Supported resource types:',
36
54
  ' keyvalue default class keyvalue-redis',
37
55
  ' messaging default class messaging-nats',
56
+ ' blobstore default class blobstore-nats',
38
57
  ' postgres default class postgres-dedicated',
58
+ ' egress default class egress-public (needs --destination)',
39
59
  '',
40
60
  'Usage: di-framework platform service create <type> --name=<name> [--class=<class>]',
61
+ ' di-framework platform service create egress <name> --destination <host[:port]> [--destination …]',
41
62
  'Discover classes: di-framework platform service classes',
42
63
  ];
43
64
  return `${lines.join('\n')}\n`;
44
65
  }
45
66
  export function buildBackingServiceManifest(options) {
46
67
  const spec = { type: options.type };
68
+ if (options.destinations !== undefined)
69
+ spec.destinations = [...options.destinations];
47
70
  if (options.className !== undefined)
48
71
  spec.className = options.className;
49
72
  if (options.parameters !== undefined && Object.keys(options.parameters).length > 0) {
@@ -70,6 +93,7 @@ export function parseServiceCreateArgs(args) {
70
93
  let timeoutMs = DEFAULT_WAIT_TIMEOUT_MS;
71
94
  let timeoutExplicit = false;
72
95
  const parameters = {};
96
+ const destinations = [];
73
97
  for (let position = 0; position < args.length; position++) {
74
98
  const token = args[position] ?? '';
75
99
  const nameOpt = matchOption(args, position, token, '--name');
@@ -162,6 +186,12 @@ export function parseServiceCreateArgs(args) {
162
186
  position = timeoutOpt.consumedThrough;
163
187
  continue;
164
188
  }
189
+ const destinationOpt = matchOption(args, position, token, '--destination');
190
+ if (destinationOpt) {
191
+ destinations.push(destinationOpt.value);
192
+ position = destinationOpt.consumedThrough;
193
+ continue;
194
+ }
165
195
  if (token === '--wait') {
166
196
  if (wait)
167
197
  invalidUsage('Option may be provided only once: --wait', '--wait');
@@ -172,7 +202,13 @@ export function parseServiceCreateArgs(args) {
172
202
  invalidUsage(`Unknown option: ${token}`, token, { command: 'platform service create' });
173
203
  }
174
204
  if (type !== undefined) {
175
- invalidUsage(`Unexpected argument: ${token}`, token, { command: 'platform service create' });
205
+ // `service create egress <name>`: the name may follow the type instead of --name.
206
+ if (name !== undefined)
207
+ invalidUsage(`Unexpected argument: ${token}`, token, {
208
+ command: 'platform service create',
209
+ });
210
+ name = token;
211
+ continue;
176
212
  }
177
213
  if (!isServiceType(token)) {
178
214
  invalidUsage(`Unknown service type "${token}". Supported types: ${SERVICE_TYPES.join(', ')}`, token, { command: 'platform service create', types: [...SERVICE_TYPES] });
@@ -190,6 +226,7 @@ export function parseServiceCreateArgs(args) {
190
226
  wait,
191
227
  timeoutMs,
192
228
  parameters: Object.keys(parameters).length > 0 ? parameters : undefined,
229
+ ...(destinations.length > 0 ? { destinations } : {}),
193
230
  };
194
231
  }
195
232
  export function parseServiceNameArgs(args, command) {
@@ -281,6 +318,22 @@ function validateSizing(parameters) {
281
318
  }
282
319
  }
283
320
  }
321
+ function validateDestinations(type, options) {
322
+ const command = { command: 'platform service create' };
323
+ if (type !== 'egress') {
324
+ if (options.destinations !== undefined)
325
+ invalidUsage('--destination applies only to egress services', '--destination', command);
326
+ return;
327
+ }
328
+ if (options.destinations === undefined)
329
+ invalidUsage('Missing required --destination for an egress service (host, *.suffix, host:port, or *.suffix:port)', '--destination', command);
330
+ for (const destination of options.destinations) {
331
+ if (!isEgressDestination(destination))
332
+ invalidUsage(`Invalid destination "${destination}". Use host, *.suffix, host:port, or *.suffix:port`, destination, command);
333
+ }
334
+ if (options.parameters !== undefined || options.deletionPolicy !== undefined)
335
+ invalidUsage('Egress services take no sizing or deletion-policy options', 'egress', command);
336
+ }
284
337
  function validateCreateOptions(options) {
285
338
  if (options.type === undefined) {
286
339
  throw new CommandFailure('INVALID_USAGE', `Missing service type.\n${serviceTypeDiscoveryText().trimEnd()}`, 2, {
@@ -301,6 +354,7 @@ function validateCreateOptions(options) {
301
354
  invalidUsage(`Invalid class name "${options.className}". Class names must be DNS labels of at most 40 characters`, options.className, { command: 'platform service create' });
302
355
  }
303
356
  validateSizing(options.parameters);
357
+ validateDestinations(options.type, options);
304
358
  return { type: options.type, name: options.name };
305
359
  }
306
360
  async function resolveServiceConnection(options, deps) {
@@ -374,6 +428,8 @@ export function summarizeService(document) {
374
428
  }
375
429
  : {}),
376
430
  ...(document.spec?.deletionPolicy ? { deletionPolicy: document.spec.deletionPolicy } : {}),
431
+ ...(document.spec?.destinations ? { destinations: document.spec.destinations } : {}),
432
+ ...(document.status?.approved ? { approved: document.status.approved } : {}),
377
433
  };
378
434
  }
379
435
  function formatServiceTable(services) {
@@ -385,7 +441,9 @@ function formatServiceTable(services) {
385
441
  service.type,
386
442
  service.className || '-',
387
443
  service.ready,
388
- service.endpoint ? `${service.endpoint.host}:${service.endpoint.port}` : '-',
444
+ service.endpoint
445
+ ? `${service.endpoint.host}:${service.endpoint.port}`
446
+ : (service.destinations?.join(',') ?? '-'),
389
447
  ]);
390
448
  const widths = headers.map((header, index) => Math.max(header.length, ...rows.map((row) => row[index]?.length ?? 0)));
391
449
  const line = (cells) => cells.map((cell, index) => cell.padEnd(widths[index] ?? 0)).join(' ');
@@ -406,6 +464,10 @@ function formatServiceDetail(summary) {
406
464
  }
407
465
  if (summary.deletionPolicy)
408
466
  lines.push(`Deletion policy: ${summary.deletionPolicy}`);
467
+ if (summary.destinations)
468
+ lines.push(`Destinations: ${summary.destinations.join(', ')}`);
469
+ if (summary.approved)
470
+ lines.push(`Approved: ${summary.approved.join(', ') || '-'}`);
409
471
  return `${lines.join('\n')}\n`;
410
472
  }
411
473
  function isServiceReady(document) {
@@ -476,6 +538,7 @@ export async function runWasmcloudServiceCreate(args, io, deps = DEFAULT_DEPS) {
476
538
  className: options.className,
477
539
  parameters: options.parameters,
478
540
  deletionPolicy: options.deletionPolicy,
541
+ destinations: options.destinations,
479
542
  });
480
543
  const dir = mkdtempSync(join(tmpdir(), 'di-backing-service-'));
481
544
  const path = join(dir, `${name}.json`);
@@ -520,6 +583,7 @@ export async function runWasmcloudServiceCreate(args, io, deps = DEFAULT_DEPS) {
520
583
  : {}),
521
584
  ...(options.parameters ? { parameters: options.parameters } : {}),
522
585
  ...(options.deletionPolicy ? { deletionPolicy: options.deletionPolicy } : {}),
586
+ ...(options.destinations ? { destinations: options.destinations } : {}),
523
587
  wait: options.wait,
524
588
  ready: summary.ready,
525
589
  ...(summary.endpoint ? { endpoint: summary.endpoint } : {}),
@@ -599,7 +663,9 @@ export async function runWasmcloudServiceDelete(args, io, deps = DEFAULT_DEPS) {
599
663
  let deletionPolicy;
600
664
  try {
601
665
  const existing = await getServiceDocument(connection, options.name, deps);
602
- deletionPolicy = existing.spec?.deletionPolicy ?? 'Retain';
666
+ // Egress provisions nothing, so there is nothing to retain.
667
+ if (existing.spec?.type !== 'egress')
668
+ deletionPolicy = existing.spec?.deletionPolicy ?? 'Retain';
603
669
  }
604
670
  catch (error) {
605
671
  if (error instanceof CommandFailure && error.code === 'WASMCLOUD_SERVICE_NOT_FOUND') {
@@ -653,7 +719,7 @@ export async function runWasmcloudServiceClasses(args, _io, deps = DEFAULT_DEPS)
653
719
  : SERVICE_TYPES.map((type) => ({
654
720
  name: DEFAULT_SERVICE_CLASSES[type],
655
721
  type,
656
- provider: type === 'postgres' ? 'postgres' : type === 'keyvalue' ? 'redis' : 'nats',
722
+ provider: DEFAULT_SERVICE_PROVIDERS[type],
657
723
  default: true,
658
724
  }));
659
725
  const headers = ['NAME', 'TYPE', 'PROVIDER', 'DEFAULT'];
package/dist/target.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { resolve } from 'node:path';
1
2
  import { CommandFailure } from '@di-framework/cli-extension';
2
3
  import { loadPlatformOutputs, resolvePlatformDirectory } from './platform.js';
3
4
  import { materializeRegistry } from './registry.js';
@@ -16,7 +17,11 @@ export async function resolveConnection(target, workspaceRoot, manifestPath, dep
16
17
  if (target.kind === 'managed') {
17
18
  return resolveManagedConnection(target, workspaceRoot, manifestPath, deps);
18
19
  }
19
- return resolveExternalConnection(target);
20
+ const connection = resolveExternalConnection(target);
21
+ // kubectl runs from the project directory; a relative kubeconfig (e.g. from
22
+ // ${KUBECONFIG}) means the directory the command was invoked from.
23
+ connection.kubeconfig = resolve(deps.cwd(), connection.kubeconfig);
24
+ return connection;
20
25
  }
21
26
  async function resolveManagedConnection(target, workspaceRoot, manifestPath, deps) {
22
27
  const platformRoot = resolvePlatformDirectory(target, workspaceRoot, manifestPath);
package/dist/wit.d.ts CHANGED
@@ -2,12 +2,18 @@
2
2
  export declare const COMPONENT_MODEL = "0.3";
3
3
  export declare const HTTP_ADAPTER_SOURCE = "http-adapter";
4
4
  export declare const NODE_COMPAT_SOURCE = "node-compat";
5
+ export declare const WASI_LOGGING_PACKAGE = "wasi:logging";
6
+ export declare const WASI_LOGGING_VERSION = "0.1.0-draft";
7
+ export declare const GUEST_CONSOLE_SOURCE = "guest-console";
5
8
  export declare const WASI_HTTP_PACKAGE = "wasi:http";
6
9
  export declare const WASI_HTTP_VERSION = "0.3.0";
7
10
  export declare const WASI_HTTP_INTERFACE = "handler";
8
11
  export declare const WASI_SOCKETS_PACKAGE = "wasi:sockets";
9
12
  export declare const WASI_SOCKETS_VERSION = "0.3.0";
10
13
  export declare const WASI_RANDOM_PACKAGE = "wasi:random";
14
+ /** The sync preview-2 filesystem: node:fs storage paths and the SQLite provider use it. */
15
+ export declare const WASI_FILESYSTEM_PACKAGE = "wasi:filesystem";
16
+ export declare const WASI_FILESYSTEM_VERSION = "0.2.12";
11
17
  export declare const WASI_RANDOM_VERSION = "0.3.0";
12
18
  export declare const QUEUE_ADAPTER_SOURCE = "queue-adapter";
13
19
  export declare const DI_QUEUES_PACKAGE = "di-framework:queues";
@@ -63,6 +69,8 @@ export declare function sqliteProjectRequirements(): WitRequirement[];
63
69
  * actually imports those specifiers.
64
70
  */
65
71
  export declare function runtimeRequirementsFromJavaScript(source: string): WitRequirement[];
72
+ /** Guest console lines; the host binds its logging plugin only when this is declared. */
73
+ export declare function guestLoggingRequirement(): WitRequirement;
66
74
  /** @deprecated Use {@link runtimeRequirementsFromJavaScript}. */
67
75
  export declare function socketRequirementsFromJavaScript(source: string): WitRequirement[];
68
76
  export declare function parsePackageId(id: string): {
package/dist/wit.js CHANGED
@@ -5,12 +5,18 @@ import { join } from 'node:path';
5
5
  export const COMPONENT_MODEL = '0.3';
6
6
  export const HTTP_ADAPTER_SOURCE = 'http-adapter';
7
7
  export const NODE_COMPAT_SOURCE = 'node-compat';
8
+ export const WASI_LOGGING_PACKAGE = 'wasi:logging';
9
+ export const WASI_LOGGING_VERSION = '0.1.0-draft';
10
+ export const GUEST_CONSOLE_SOURCE = 'guest-console';
8
11
  export const WASI_HTTP_PACKAGE = 'wasi:http';
9
12
  export const WASI_HTTP_VERSION = '0.3.0';
10
13
  export const WASI_HTTP_INTERFACE = 'handler';
11
14
  export const WASI_SOCKETS_PACKAGE = 'wasi:sockets';
12
15
  export const WASI_SOCKETS_VERSION = '0.3.0';
13
16
  export const WASI_RANDOM_PACKAGE = 'wasi:random';
17
+ /** The sync preview-2 filesystem: node:fs storage paths and the SQLite provider use it. */
18
+ export const WASI_FILESYSTEM_PACKAGE = 'wasi:filesystem';
19
+ export const WASI_FILESYSTEM_VERSION = '0.2.12';
14
20
  export const WASI_RANDOM_VERSION = '0.3.0';
15
21
  export const QUEUE_ADAPTER_SOURCE = 'queue-adapter';
16
22
  export const DI_QUEUES_PACKAGE = 'di-framework:queues';
@@ -103,6 +109,15 @@ export function runtimeRequirementsFromJavaScript(source) {
103
109
  source: NODE_COMPAT_SOURCE,
104
110
  });
105
111
  }
112
+ if (source.includes(`${WASI_FILESYSTEM_PACKAGE}/preopens@${WASI_FILESYSTEM_VERSION}`)) {
113
+ requirements.push({
114
+ package: WASI_FILESYSTEM_PACKAGE,
115
+ version: WASI_FILESYSTEM_VERSION,
116
+ interfaces: ['types', 'preopens'],
117
+ direction: 'import',
118
+ source: NODE_COMPAT_SOURCE,
119
+ });
120
+ }
106
121
  if (source.includes('wasi:clocks/monotonic-clock@0.3.0')) {
107
122
  requirements.push({
108
123
  package: 'wasi:clocks',
@@ -112,6 +127,9 @@ export function runtimeRequirementsFromJavaScript(source) {
112
127
  source: NODE_COMPAT_SOURCE,
113
128
  });
114
129
  }
130
+ if (source.includes(`${WASI_LOGGING_PACKAGE}/logging@${WASI_LOGGING_VERSION}`)) {
131
+ requirements.push(guestLoggingRequirement());
132
+ }
115
133
  if (source.includes('wasi:cli/environment@0.3.0')) {
116
134
  requirements.push({
117
135
  package: 'wasi:cli',
@@ -132,6 +150,16 @@ export function runtimeRequirementsFromJavaScript(source) {
132
150
  }
133
151
  return requirements;
134
152
  }
153
+ /** Guest console lines; the host binds its logging plugin only when this is declared. */
154
+ export function guestLoggingRequirement() {
155
+ return {
156
+ package: WASI_LOGGING_PACKAGE,
157
+ version: WASI_LOGGING_VERSION,
158
+ interfaces: ['logging'],
159
+ direction: 'import',
160
+ source: GUEST_CONSOLE_SOURCE,
161
+ };
162
+ }
135
163
  /** @deprecated Use {@link runtimeRequirementsFromJavaScript}. */
136
164
  export function socketRequirementsFromJavaScript(source) {
137
165
  return runtimeRequirementsFromJavaScript(source);
@@ -17,11 +17,56 @@ export declare const HOST_STORAGE_ROOT = "/var/lib/di-framework/storage";
17
17
  export declare const STORAGE_HOSTGROUP = "storage";
18
18
  /** Guest mount path for application SQLite storage. */
19
19
  export declare const DEFAULT_STORAGE_MOUNT = "/data";
20
+ /**
21
+ * Tenant workloads ask the platform for storage instead of naming a host path. The
22
+ * controller creates a tenant-scoped directory per workload and injects the volume and
23
+ * the preopen; tenant credentials cannot set either.
24
+ */
25
+ export declare const PERSISTENT_STORAGE_ANNOTATION = "di-framework.dev/persistent-storage";
26
+ /**
27
+ * "false" when the project opts out of guest logs: the platform publishes no wasi:logging
28
+ * lines for the deployment, only host failure lines.
29
+ */
30
+ export declare const LOGS_ANNOTATION = "di-framework.dev/logs";
31
+ /** Guest mount when it is not the default `/data`; the controller accepts only these two. */
32
+ export declare const STORAGE_MOUNT_ANNOTATION = "di-framework.dev/storage-mount";
33
+ /** A tenant target names its host group; its storage belongs to the platform. */
34
+ export declare function usesPlatformStorage(connection: Pick<ClusterConnection, 'hostgroup'>): boolean;
20
35
  /** Pinned CronJob invoker image that POSTs to the Wasm HTTP control API. */
21
36
  export declare const CRON_INVOKER_IMAGE = "curlimages/curl:8.11.1";
22
37
  export declare function deploymentResourceName(project: WasmcloudProject): string;
23
38
  export declare function generatedManifestPath(project: WasmcloudProject): string;
24
39
  export declare function hostStoragePath(applicationName: string): string;
40
+ /** Members of one persistent workload share a directory. Other apps keep their own. */
41
+ export declare function storageDirectoryName(project: {
42
+ applicationName: string;
43
+ workload?: string;
44
+ persistentStorage?: boolean;
45
+ }): string;
46
+ export type StorageClaim = {
47
+ metadata?: {
48
+ name?: string;
49
+ labels?: Record<string, string>;
50
+ };
51
+ spec?: {
52
+ template?: {
53
+ spec?: {
54
+ volumes?: Array<{
55
+ hostPath?: {
56
+ path?: string;
57
+ };
58
+ }>;
59
+ };
60
+ };
61
+ };
62
+ };
63
+ /** Another deployment may use the path only when it belongs to the same workload. */
64
+ export declare function storageOwnershipConflict(project: {
65
+ applicationName: string;
66
+ workload?: string;
67
+ }, hostPath: string, items: readonly StorageClaim[]): {
68
+ owner: string;
69
+ } | undefined;
25
70
  /** Kubernetes Secret that holds DI_CONTROL_TOKEN for a workload. */
26
71
  export declare function controlSecretResourceName(workloadName: string): string;
27
72
  export interface WorkloadManifestOptions {
package/dist/workload.js CHANGED
@@ -5,12 +5,13 @@ import { CommandFailure } from '@di-framework/cli-extension';
5
5
  import { discoverActors } from './actors.js';
6
6
  import { discoverBindings, requirementsFromBindings } from './bindings.js';
7
7
  import { discoverScheduledJobs } from './cron.js';
8
+ import { applyWorkloadEgress, removeWorkloadEgress, reportEgressStatus, usesPlatformEgress, warnIfTenantHostLacksTls, } from './egress.js';
8
9
  import { hostInterfacesFromRequirements, renderHostInterfacesYaml } from './host-interface.js';
9
10
  import { captureKubectl, runKubectl } from './kubernetes.js';
10
11
  import { applyManagedBindings, cleanupManagedBindings } from './managed-bindings.js';
11
12
  import { asWitIdentifier } from './project.js';
12
13
  import { discoverQueueHandlers, isQueueWorkerProject } from './queues.js';
13
- import { defaultProjectRequirements, queueProjectRequirements } from './wit.js';
14
+ import { defaultProjectRequirements, guestLoggingRequirement, queueProjectRequirements, } from './wit.js';
14
15
  export const MANAGED_BY_LABEL = 'di-framework';
15
16
  export const WAIT_ATTEMPTS = 30;
16
17
  export const WAIT_INTERVAL_MS = 2_000;
@@ -22,6 +23,24 @@ export const HOST_STORAGE_ROOT = '/var/lib/di-framework/storage';
22
23
  export const STORAGE_HOSTGROUP = 'storage';
23
24
  /** Guest mount path for application SQLite storage. */
24
25
  export const DEFAULT_STORAGE_MOUNT = '/data';
26
+ /**
27
+ * Tenant workloads ask the platform for storage instead of naming a host path. The
28
+ * controller creates a tenant-scoped directory per workload and injects the volume and
29
+ * the preopen; tenant credentials cannot set either.
30
+ */
31
+ export const PERSISTENT_STORAGE_ANNOTATION = 'di-framework.dev/persistent-storage';
32
+ /**
33
+ * "false" when the project opts out of guest logs: the platform publishes no wasi:logging
34
+ * lines for the deployment, only host failure lines.
35
+ */
36
+ export const LOGS_ANNOTATION = 'di-framework.dev/logs';
37
+ /** Guest mount when it is not the default `/data`; the controller accepts only these two. */
38
+ export const STORAGE_MOUNT_ANNOTATION = 'di-framework.dev/storage-mount';
39
+ const PLATFORM_STORAGE_MOUNTS = [DEFAULT_STORAGE_MOUNT, `${DEFAULT_STORAGE_MOUNT}/actors`];
40
+ /** A tenant target names its host group; its storage belongs to the platform. */
41
+ export function usesPlatformStorage(connection) {
42
+ return connection.hostgroup !== undefined;
43
+ }
25
44
  /** Pinned CronJob invoker image that POSTs to the Wasm HTTP control API. */
26
45
  export const CRON_INVOKER_IMAGE = 'curlimages/curl:8.11.1';
27
46
  export function deploymentResourceName(project) {
@@ -33,6 +52,27 @@ export function generatedManifestPath(project) {
33
52
  export function hostStoragePath(applicationName) {
34
53
  return `${HOST_STORAGE_ROOT}/${asWitIdentifier(applicationName)}`;
35
54
  }
55
+ /** Members of one persistent workload share a directory. Other apps keep their own. */
56
+ export function storageDirectoryName(project) {
57
+ return project.persistentStorage === true && project.workload
58
+ ? project.workload
59
+ : project.applicationName;
60
+ }
61
+ /** Another deployment may use the path only when it belongs to the same workload. */
62
+ export function storageOwnershipConflict(project, hostPath, items) {
63
+ for (const item of items) {
64
+ const labels = item.metadata?.labels;
65
+ if (project.workload !== undefined &&
66
+ labels?.['di-framework.dev/workload'] === project.workload) {
67
+ continue;
68
+ }
69
+ const volumes = item.spec?.template?.spec?.volumes ?? [];
70
+ if (volumes.some((volume) => volume.hostPath?.path === hostPath)) {
71
+ return { owner: item.metadata?.name ?? 'unknown' };
72
+ }
73
+ }
74
+ return undefined;
75
+ }
36
76
  /** Kubernetes Secret that holds DI_CONTROL_TOKEN for a workload. */
37
77
  export function controlSecretResourceName(workloadName) {
38
78
  return `${workloadName}-control`;
@@ -65,7 +105,19 @@ export function renderWorkloadManifest(project, connection, image, requirements
65
105
  const volumeName = opts.storageVolume?.volumeName ?? 'app-storage';
66
106
  const mountPath = opts.storageVolume?.mountPath ??
67
107
  (hasActors ? `${DEFAULT_STORAGE_MOUNT}/actors` : DEFAULT_STORAGE_MOUNT);
68
- const hostPath = opts.storageVolume?.hostPath ?? hostStoragePath(project.applicationName);
108
+ const hostPath = opts.storageVolume?.hostPath ?? hostStoragePath(storageDirectoryName(project));
109
+ const platformStorage = needsPersistentStorage && usesPlatformStorage(connection);
110
+ if (platformStorage && !PLATFORM_STORAGE_MOUNTS.includes(mountPath)) {
111
+ throw new CommandFailure('WASMCLOUD_STORAGE_MOUNT_UNSUPPORTED', `Tenant storage mounts at ${PLATFORM_STORAGE_MOUNTS.join(' or ')}, not ${mountPath}`, 2, { mountPath });
112
+ }
113
+ const annotationLines = [
114
+ ...(platformStorage ? [` ${PERSISTENT_STORAGE_ANNOTATION}: "true"`] : []),
115
+ ...(platformStorage && mountPath !== DEFAULT_STORAGE_MOUNT
116
+ ? [` ${STORAGE_MOUNT_ANNOTATION}: ${yamlQuote(mountPath)}`]
117
+ : []),
118
+ ...(project.logs === false ? [` ${LOGS_ANNOTATION}: "false"`] : []),
119
+ ];
120
+ const annotations = annotationLines.length > 0 ? [' annotations:', ...annotationLines] : [];
69
121
  const environment = { ...(opts.environment ?? {}) };
70
122
  if (needsPersistentStorage) {
71
123
  environment.DI_SQLITE_BACKEND = 'wasm';
@@ -122,6 +174,8 @@ spec:
122
174
  protocol: TCP`);
123
175
  }
124
176
  const localResourcesLines = [];
177
+ // Tenant admission rejects these fields; the platform's egress binding writes them.
178
+ const ipNameLookups = usesPlatformEgress(connection) ? undefined : project.allowedIpNameLookups;
125
179
  const envKeys = Object.keys(environment).sort();
126
180
  if (envKeys.length > 0 || controlSecretName !== undefined) {
127
181
  localResourcesLines.push(' localResources:');
@@ -137,20 +191,30 @@ spec:
137
191
  localResourcesLines.push(` - name: ${controlSecretName}`);
138
192
  }
139
193
  }
140
- else if (project.allowedIpNameLookups !== undefined) {
194
+ else if (ipNameLookups !== undefined) {
141
195
  localResourcesLines.push(' localResources:');
142
196
  }
143
- if (needsPersistentStorage) {
197
+ if (needsPersistentStorage && !platformStorage) {
144
198
  localResourcesLines.push(' volumeMounts:');
145
199
  localResourcesLines.push(` - name: ${volumeName}`);
146
200
  localResourcesLines.push(` mountPath: ${mountPath}`);
147
201
  }
148
- if (project.allowedIpNameLookups !== undefined) {
149
- localResourcesLines.push(` allowedIpNameLookups: ${JSON.stringify(project.allowedIpNameLookups)}`);
202
+ if (ipNameLookups !== undefined) {
203
+ localResourcesLines.push(` allowedIpNameLookups: ${JSON.stringify(ipNameLookups)}`);
150
204
  }
151
- const hostInterfaces = renderHostInterfacesYaml(hostInterfacesFromRequirements(hasHttp && !requirements.some((r) => r.package === 'wasi:http' && r.direction === 'export')
205
+ // A long-lived wasi:cli/run program is a WorkloadService: wash runs it only from
206
+ // spec.template.spec.service, never as a component export.
207
+ const runsAsService = !hasHttp &&
208
+ !isWorker &&
209
+ project.workloadEntry?.kind === 'service' &&
210
+ project.workloadEntry.subscriptions === undefined;
211
+ // Deploy builds link the wasi:logging console unless the project opts out of logs
212
+ // (see buildComponent).
213
+ const interfaceRequirements = project.logs === false ? requirements : [...requirements, guestLoggingRequirement()];
214
+ const hostInterfaces = renderHostInterfacesYaml(hostInterfacesFromRequirements(hasHttp &&
215
+ !interfaceRequirements.some((r) => r.package === 'wasi:http' && r.direction === 'export')
152
216
  ? [
153
- ...requirements,
217
+ ...interfaceRequirements,
154
218
  {
155
219
  package: 'wasi:http',
156
220
  version: '0.3.0',
@@ -159,7 +223,7 @@ spec:
159
223
  source: 'control-http',
160
224
  },
161
225
  ]
162
- : requirements, {
226
+ : interfaceRequirements, {
163
227
  ...(hasHttp ? { httpHost: advertisedHttpHost } : {}),
164
228
  subscriptions: project.workloadEntry?.subscriptions,
165
229
  }, bindings.map((binding) => ({
@@ -176,14 +240,14 @@ metadata:
176
240
  namespace: ${connection.namespace}
177
241
  labels:
178
242
  ${labels}
179
- spec:
243
+ ${annotations.length > 0 ? `${annotations.join('\n')}\n` : ''}spec:
180
244
  replicas: 1
181
245
  ${needsPersistentStorage ? ' deployPolicy: Recreate\n' : ''} template:
182
246
  spec:
183
247
  environment: ${yamlQuote(connection.namespace)}
184
248
  hostSelector:
185
- hostgroup: ${needsPersistentStorage ? (connection.storageHostgroup ?? STORAGE_HOSTGROUP) : (connection.hostgroup ?? 'default')}
186
- ${needsPersistentStorage
249
+ hostgroup: ${needsPersistentStorage && !platformStorage ? (connection.storageHostgroup ?? STORAGE_HOSTGROUP) : (connection.hostgroup ?? 'default')}
250
+ ${needsPersistentStorage && !platformStorage
187
251
  ? ` volumes:
188
252
  - name: ${volumeName}
189
253
  hostPath:
@@ -194,10 +258,14 @@ ${needsPersistentStorage
194
258
  service:
195
259
  name: ${name}
196
260
  `
197
- : ''} components:
261
+ : ''}${runsAsService
262
+ ? ` service:
263
+ image: ${yamlQuote(image)}
264
+ ${localResourcesLines.length > 0 ? `${localResourcesLines.map((line) => line.slice(2)).join('\n')}\n` : ''}`
265
+ : ` components:
198
266
  - name: ${name}
199
267
  image: ${yamlQuote(image)}
200
- ${localResourcesLines.length > 0 ? `${localResourcesLines.join('\n')}\n` : ''}${hostInterfaces}`;
268
+ ${localResourcesLines.length > 0 ? `${localResourcesLines.join('\n')}\n` : ''}`}${hostInterfaces}`;
201
269
  sections.push(workloadDeployment);
202
270
  for (const job of cronJobs) {
203
271
  const jobKebab = job.kebabId || asWitIdentifier(job.name || `${job.className}-${job.methodName}`);
@@ -311,7 +379,11 @@ export async function applyWorkload(project, connection, image, io, deps) {
311
379
  direction: 'export',
312
380
  source: 'workload-service',
313
381
  });
382
+ await warnIfTenantHostLacksTls(project, connection, io, deps);
314
383
  const associations = await applyManagedBindings(project, connection, bindings, deps);
384
+ const egress = await applyWorkloadEgress(project, connection, deps);
385
+ if (egress !== undefined)
386
+ associations.add(egress);
315
387
  await assertStorageOwnership(project, connection, deps, {
316
388
  hasActors,
317
389
  hasQueues: queueHandlers.length > 0,
@@ -329,13 +401,19 @@ export async function applyWorkload(project, connection, image, io, deps) {
329
401
  await runKubectl(deps, connection, ['apply', '-f', path], project.projectRoot);
330
402
  await waitForReady(project, connection, deps, io);
331
403
  await cleanupManagedBindings(project, connection, associations, deps);
404
+ if (egress === undefined)
405
+ await removeWorkloadEgress(project, connection, deps);
406
+ else
407
+ await reportEgressStatus(project, connection, io, deps);
332
408
  return path;
333
409
  }
334
410
  async function assertStorageOwnership(project, connection, deps, flags) {
335
411
  if (!flags.hasActors && !flags.hasQueues && !flags.hasPersistentStorage)
336
412
  return;
337
- const name = deploymentResourceName(project);
338
- const hostPath = hostStoragePath(project.applicationName);
413
+ // The platform keys tenant storage by workload, so another app cannot reach this path.
414
+ if (usesPlatformStorage(connection))
415
+ return;
416
+ const hostPath = hostStoragePath(storageDirectoryName(project));
339
417
  const result = await captureKubectl(deps, connection, [
340
418
  'get',
341
419
  WORKLOAD_DEPLOYMENT_RESOURCE,
@@ -348,22 +426,15 @@ async function assertStorageOwnership(project, connection, deps, flags) {
348
426
  return;
349
427
  try {
350
428
  const list = JSON.parse(result.stdout);
351
- let conflict;
352
- for (const item of list.items ?? []) {
353
- for (const volume of item.spec?.template?.spec?.volumes ?? []) {
354
- if (volume.hostPath?.path === hostPath) {
355
- conflict = new CommandFailure('WASMCLOUD_STORAGE_OWNERSHIP_CONFLICT', `Storage path ${hostPath} is already claimed by WorkloadDeployment ${item.metadata?.name ?? 'unknown'}`, 2, { application: project.applicationName, path: hostPath, owner: item.metadata?.name });
356
- }
357
- }
429
+ const conflict = storageOwnershipConflict(project, hostPath, list.items ?? []);
430
+ if (conflict) {
431
+ throw new CommandFailure('WASMCLOUD_STORAGE_OWNERSHIP_CONFLICT', `Storage path ${hostPath} is already claimed by WorkloadDeployment ${conflict.owner}`, 2, { application: project.applicationName, path: hostPath, owner: conflict.owner });
358
432
  }
359
- if (conflict)
360
- throw conflict;
361
433
  }
362
434
  catch (error) {
363
435
  if (error instanceof CommandFailure)
364
436
  throw error;
365
437
  }
366
- void name;
367
438
  }
368
439
  export async function deleteWorkload(project, connection, io, deps) {
369
440
  const name = deploymentResourceName(project);
@@ -378,6 +449,7 @@ export async function deleteWorkload(project, connection, io, deps) {
378
449
  '--timeout=180s',
379
450
  ], project.projectRoot);
380
451
  await cleanupManagedBindings(project, connection, new Set(), deps);
452
+ await removeWorkloadEgress(project, connection, deps);
381
453
  }
382
454
  export async function waitForReady(project, connection, deps, io) {
383
455
  const name = deploymentResourceName(project);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@di-framework/cli-plugin-platform",
3
- "version": "6.0.3",
3
+ "version": "6.0.6",
4
4
  "description": "di-framework CLI extension that builds, serves, and deploys DI Framework apps as platform WebAssembly components.",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -28,7 +28,7 @@
28
28
  ],
29
29
  "scripts": {
30
30
  "test": "bun test",
31
- "build": "rm -rf dist && bun x tsc -p tsconfig.dist.json && bun build assets/http-adapter.ts --outfile dist/assets/http-adapter.js --packages bundle --external 'wasi:*' --external 'wasmcloud:*' --external 'di-framework:*' --external '@di-framework/actors' --external '@di-framework/actors/portable' --external '@di-framework/repo' --external '@di-framework/repo/portable' --external '@di-framework/queues' --external '@di-framework/queues/portable' --external 'virtual:di-framework-application' --external 'virtual:di-framework-wasmcloud-guests' --external 'virtual:di-framework-wasmcloud-actors' --external 'virtual:di-framework-wasmcloud-cron' --external 'virtual:di-framework-wasmcloud-queues' --external 'virtual:di-framework-wasmcloud-runtime' && bun build assets/queue-adapter.ts --outfile dist/assets/queue-adapter.js --packages bundle --external 'wasi:*' --external 'wasmcloud:*' --external 'di-framework:*' --external '@di-framework/actors' --external '@di-framework/actors/portable' --external 'virtual:di-framework-application' --external 'virtual:di-framework-wasmcloud-guests' --external 'virtual:di-framework-wasmcloud-actors' && cp -R assets/wit dist/assets/wit && cp -R assets/platform dist/assets/platform && bun ../../scripts/copy-sqlite-asset.ts && bun ../../scripts/fix-esm-imports.ts dist"
31
+ "build": "rm -rf dist && bun x tsc -p tsconfig.dist.json && bun build assets/http-adapter.ts --outfile dist/assets/http-adapter.js --packages bundle --external 'wasi:*' --external 'wasmcloud:*' --external 'di-framework:*' --external '@di-framework/actors' --external '@di-framework/actors/portable' --external '@di-framework/repo' --external '@di-framework/repo/portable' --external '@di-framework/queues' --external '@di-framework/queues/portable' --external 'virtual:di-framework-application' --external 'virtual:di-framework-wasmcloud-guests' --external 'virtual:di-framework-wasmcloud-actors' --external 'virtual:di-framework-wasmcloud-cron' --external 'virtual:di-framework-wasmcloud-queues' --external 'virtual:di-framework-wasmcloud-runtime' && bun build assets/queue-adapter.ts --outfile dist/assets/queue-adapter.js --packages bundle --external 'wasi:*' --external 'wasmcloud:*' --external 'di-framework:*' --external '@di-framework/actors' --external '@di-framework/actors/portable' --external 'virtual:di-framework-application' --external 'virtual:di-framework-wasmcloud-guests' --external 'virtual:di-framework-wasmcloud-actors' && cp -R assets/wit dist/assets/wit && cp -R assets/platform dist/assets/platform && bun ../../scripts/copy-sqlite-asset.ts && bun ../../scripts/fix-esm-imports.ts dist && bun build console-ui/src/main.tsx --outdir dist/console-ui --target browser --minify --entry-naming 'app.[ext]' --asset-naming '[name].[ext]' --public-path /assets/ && cp console-ui/index.html dist/console-ui/index.html"
32
32
  },
33
33
  "exports": {
34
34
  ".": {
@@ -61,9 +61,19 @@
61
61
  "README.md"
62
62
  ],
63
63
  "devDependencies": {
64
+ "@di-framework/bindings": "^6",
64
65
  "@di-framework/config": "^5",
65
66
  "@di-framework/core": "^5",
66
- "@di-framework/bindings": "^6",
67
- "@types/babel__core": "^7.20.5"
67
+ "@patternfly/react-core": "^6.6.1",
68
+ "@patternfly/react-icons": "^6.6.1",
69
+ "@patternfly/react-table": "^6.6.1",
70
+ "@types/babel__core": "^7.20.5",
71
+ "@types/react": "^19.3.0",
72
+ "@types/react-dom": "^19.3.0",
73
+ "mobx": "^7.0.5",
74
+ "mobx-react-lite": "^5.1.0",
75
+ "mobx-state-tree": "^8.0.0",
76
+ "react": "19",
77
+ "react-dom": "19"
68
78
  }
69
79
  }