pmcf 1.61.11 → 1.63.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pmcf",
3
- "version": "1.61.11",
3
+ "version": "1.63.0",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -38,7 +38,7 @@
38
38
  "lint:typescript": "tsc --allowJs --checkJs --noEmit --resolveJsonModule --target es2024 --lib esnext -m esnext --module nodenext --moduleResolution nodenext ./src**/*.mjs"
39
39
  },
40
40
  "dependencies": {
41
- "npm-pkgbuild": "^17.2.5",
41
+ "npm-pkgbuild": "^17.3.0",
42
42
  "pacc": "^3.3.0",
43
43
  "pkg-dir": "^8.0.0"
44
44
  },
package/src/base.mjs CHANGED
@@ -1,5 +1,6 @@
1
1
  import { join } from "node:path";
2
- import { allOutputs } from "npm-pkgbuild";
2
+ import { createReadStream } from "node:fs";
3
+ import { allOutputs, extractFunctions } from "npm-pkgbuild";
3
4
  import { getAttribute } from "pacc";
4
5
  import { addType, primitives } from "./types.mjs";
5
6
 
@@ -203,20 +204,18 @@ export class Base {
203
204
  }
204
205
  }
205
206
 
206
- named(name)
207
- {
208
- }
207
+ named(name) {}
209
208
 
210
209
  typeNamed(typeName, name) {
211
210
  if (this.owner) {
212
211
  const object = this.owner.typeNamed(typeName, name); // TODO split
213
- if(object) {
212
+ if (object) {
214
213
  return object;
215
214
  }
216
215
  }
217
216
 
218
217
  const object = this.named(name);
219
- if(object?.typeName === typeName) {
218
+ if (object?.typeName === typeName) {
220
219
  return object;
221
220
  }
222
221
  }
@@ -337,18 +336,25 @@ export class Base {
337
336
  return this.#packaging;
338
337
  }
339
338
 
339
+ #packageHooks = {};
340
340
 
341
- #packageHooks = new Map();
341
+ get packageHooks() {
342
+ return this.#packageHooks;
343
+ }
342
344
 
343
- addPackageHook(name,content)
344
- {
345
- let hook = this.#packageHooks.get(name);
346
- if(hook) {
347
- content = hook + content;
345
+ async loadPackageHooks(file) {
346
+ for await (const f of extractFunctions(createReadStream(file, "utf8"))) {
347
+ this.addPackageHook(f.name, f.body);
348
348
  }
349
+ }
349
350
 
350
- this.#packageHooks.set(name, content);
351
+ addPackageHook(name, content) {
352
+ const hook = this.#packageHooks[name];
353
+ if (hook) {
354
+ content = hook + "\n" + content;
355
+ }
351
356
 
357
+ this.#packageHooks[name] = content;
352
358
  }
353
359
 
354
360
  get outputs() {
package/src/cluster.mjs CHANGED
@@ -51,6 +51,10 @@ export class Cluster extends Host {
51
51
  return this.#backups;
52
52
  }
53
53
 
54
+ get members() {
55
+ return this.masters.union(this.backups);
56
+ }
57
+
54
58
  async *preparePackages(stagingDir) {
55
59
  const result = {
56
60
  sources: [],
@@ -93,6 +97,31 @@ export class Cluster extends Host {
93
97
  cfg.push(" }");
94
98
  cfg.push("}");
95
99
  cfg.push("");
100
+
101
+ for (const service of cluster.findServices({ type: "http" })) {
102
+ console.log("S",service.host.name,service.name);
103
+ cfg.push(`virtual_server ${cluster.rawAddress} ${service.port} {`);
104
+ cfg.push(" delay_loop 6");
105
+ cfg.push(" lb_algo wlc");
106
+ cfg.push(" persistence_timeout 600");
107
+ cfg.push(` protocol ${service.protocol.toUpperCase()}`);
108
+
109
+ for (const member of this.members) {
110
+ cfg.push(` real_server ${member.rawAddress} ${service.port} {`);
111
+ cfg.push(" weight 100");
112
+
113
+ if (service.protocol === "tcp") {
114
+ cfg.push(` TCP_CHECK {`);
115
+ cfg.push(" connect_timeout 3");
116
+ cfg.push(" }");
117
+ }
118
+
119
+ cfg.push(" }");
120
+ }
121
+
122
+ cfg.push("}");
123
+ cfg.push("");
124
+ }
96
125
  }
97
126
 
98
127
  await writeLines(
package/src/host.mjs CHANGED
@@ -254,8 +254,12 @@ export class Host extends Base {
254
254
  return this.#services;
255
255
  }
256
256
 
257
- set services(services) {
258
- this.#services.push(services);
257
+ set services(service) {
258
+ const present = this.#services.find(s => s.name === service.name);
259
+
260
+ if (!present) {
261
+ this.#services.push(service);
262
+ }
259
263
  }
260
264
 
261
265
  *findServices(filter) {
@@ -346,6 +350,10 @@ export class Host extends Base {
346
350
  }
347
351
 
348
352
  async *preparePackages(stagingDir) {
353
+ await this.loadPackageHooks(
354
+ new URL("host.install", import.meta.url).pathname
355
+ );
356
+
349
357
  for await (const result of super.preparePackages(stagingDir)) {
350
358
  await generateNetworkDefs(this, stagingDir);
351
359
  await generateMachineInfo(this, stagingDir);
@@ -363,10 +371,7 @@ export class Host extends Base {
363
371
  result.properties.provides = [...this.provides];
364
372
  result.properties.replaces = [`mf-${this.hostName}`, ...this.replaces];
365
373
  result.properties.backup = "root/.ssh/known_hosts";
366
- result.properties.hooks = new URL(
367
- "host.install",
368
- import.meta.url
369
- ).pathname;
374
+ result.properties.hooks = this.packageHooks;
370
375
 
371
376
  result.sources.push(
372
377
  new FileContentProvider(stagingDir + "/")[Symbol.asyncIterator]()
package/src/location.mjs CHANGED
@@ -47,6 +47,11 @@ export class Location extends Owner {
47
47
  }
48
48
 
49
49
  async *preparePackages(stagingDir) {
50
+
51
+ await this.loadPackageHooks(
52
+ new URL("location.install", import.meta.url).pathname
53
+ );
54
+
50
55
  for await (const result of super.preparePackages(stagingDir)) {
51
56
  await writeLines(
52
57
  join(stagingDir, "etc/systemd/resolved.conf.d"),
@@ -97,10 +102,7 @@ export class Location extends Owner {
97
102
  new FileContentProvider(stagingDir + "/")[Symbol.asyncIterator]()
98
103
  );
99
104
 
100
- result.properties.hooks = new URL(
101
- "location.install",
102
- import.meta.url
103
- ).pathname;
105
+ result.properties.hooks = this.packageHooks;
104
106
 
105
107
  yield result;
106
108
  }
package/types/base.d.mts CHANGED
@@ -70,6 +70,8 @@ export class Base {
70
70
  set packaging(value: Set<any>);
71
71
  get packaging(): Set<any>;
72
72
  get derivedPackaging(): any;
73
+ get packageHooks(): {};
74
+ loadPackageHooks(file: any): Promise<void>;
73
75
  addPackageHook(name: any, content: any): void;
74
76
  get outputs(): Set<typeof import("npm-pkgbuild").ARCH | typeof import("npm-pkgbuild").DOCKER>;
75
77
  preparePackages(stagingDir: any): AsyncGenerator<{
@@ -381,6 +381,7 @@ export class Cluster extends Host {
381
381
  get masters(): Set<any>;
382
382
  set backups(value: Set<any>);
383
383
  get backups(): Set<any>;
384
+ get members(): Set<any>;
384
385
  preparePackages(stagingDir: any): AsyncGenerator<{
385
386
  sources: any[];
386
387
  properties: {
package/types/host.d.mts CHANGED
@@ -151,7 +151,7 @@ export class Host extends Base {
151
151
  get provides(): Set<any>;
152
152
  set replaces(value: Set<any>);
153
153
  get replaces(): Set<any>;
154
- set services(services: any[]);
154
+ set services(service: any[]);
155
155
  get services(): any[];
156
156
  _traverse(...args: any[]): boolean;
157
157
  set deployment(value: any);