@platformatic/watt-extra 1.11.2 → 1.12.0-alpha.1

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/lib/watt.js CHANGED
@@ -524,6 +524,10 @@ class Watt {
524
524
  ) {
525
525
  await this.#configurePlatformaticServices(runtime, app)
526
526
  }
527
+ // else if (app.type === '@platformatic/regina') {
528
+ // this.#configureReginaService(runtime, app)
529
+ // }
530
+ this.#configureReginaService(runtime, app)
527
531
  }
528
532
  }
529
533
 
@@ -599,6 +603,62 @@ class Watt {
599
603
  }
600
604
  }
601
605
 
606
+ #configureReginaService (runtime, app) {
607
+ process._rawDebug('--------INS CONFIG--------', this.#instanceConfig)
608
+
609
+ const privateIp = this.#instanceConfig?.privateIp
610
+ const port = this.#getContainerHttpPort()
611
+
612
+ if (!privateIp) {
613
+ this.#logger.warn('Missing private IP address, not setting up Regina member address')
614
+ return
615
+ }
616
+
617
+ const address = `http://${privateIp}:${port}`
618
+ process._rawDebug('--------ADDRESS--------', address)
619
+
620
+ // const patches = [
621
+ // { op: 'add', path: '/regina/memberAddress', value: address },
622
+ // ]
623
+ }
624
+
625
+ #getContainerHttpPort () {
626
+ const defaultPort = this.#env.PLT_DEFAULT_CONTAINER_PORT
627
+
628
+ let ports = this.#instanceConfig?.ports
629
+ if (!Array.isArray(ports) || ports.length === 0) {
630
+ return defaultPort
631
+ }
632
+
633
+ ports = ports.filter((port) => port.protocol === 'TCP')
634
+ if (ports.length === 0) {
635
+ return defaultPort
636
+ }
637
+
638
+ if (ports.length === 1) {
639
+ return ports[0].containerPort
640
+ }
641
+
642
+ const httpPort = ports.find((port) => port.name === 'http')
643
+ if (httpPort) {
644
+ return httpPort.containerPort
645
+ }
646
+
647
+ const metricPorts = [9090]
648
+ ports = ports.filter((port) => !metricPorts.includes(port.containerPort))
649
+
650
+ if (ports.length === 1) {
651
+ return ports[0].containerPort
652
+ }
653
+
654
+ this.#logger.warn(
655
+ { ports: this.#instanceConfig.ports, defaultPort },
656
+ 'Multiple ports found, cannot determine the HTTP port, using default'
657
+ )
658
+
659
+ return defaultPort
660
+ }
661
+
602
662
  async #patchService (runtime, id, patches) {
603
663
  this.#logger.info({ patches }, `Applying patches to service ${id} ...`)
604
664
  runtime.setApplicationConfigPatch(id, patches)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@platformatic/watt-extra",
3
- "version": "1.11.2",
3
+ "version": "1.12.0-alpha.1",
4
4
  "description": "The Platformatic runtime manager",
5
5
  "type": "module",
6
6
  "scripts": {
package/plugins/env.js CHANGED
@@ -32,6 +32,7 @@ const schema = {
32
32
  PLT_HEALTH_SIGNALS_LONG_BATCH_TIMEOUT: { type: 'number', default: 30000 },
33
33
  PLT_HEALTH_SIGNALS_ELU_BATCH_THRESHOLD: { type: 'number', default: 0.5 },
34
34
  PLT_HEALTH_SIGNALS_HEAP_BATCH_THRESHOLD: { type: ['number', 'string'], default: '300MB' },
35
+ PLT_DEFAULT_CONTAINER_PORT: { type: 'number', default: 8080 }
35
36
  }
36
37
  }
37
38