@platformatic/runtime 1.53.3 → 2.0.0-alpha.10
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/config.d.ts +284 -0
- package/eslint.config.js +8 -0
- package/fixtures/botched-start/platformatic.runtime.json +1 -1
- package/fixtures/botched-start/services/a/platformatic.service.json +1 -1
- package/fixtures/composerApp/platformatic.composer.json +1 -1
- package/fixtures/configs/{monorepo-hotreload.json → invalid-autoload-with-services.json} +8 -8
- package/fixtures/configs/invalid-entrypoint.json +1 -1
- package/fixtures/configs/invalid-schema-type.config.json +1 -1
- package/fixtures/configs/missing-property.config.json +1 -1
- package/fixtures/configs/missing-service-config.json +1 -1
- package/fixtures/configs/monorepo-composer-no-autoload.json +32 -0
- package/fixtures/configs/monorepo-composer.json +2 -2
- package/fixtures/configs/monorepo-create-cycle.json +2 -3
- package/fixtures/configs/monorepo-missing-dependencies.json +9 -0
- package/fixtures/configs/monorepo-no-cycles.json +2 -3
- package/fixtures/configs/monorepo-openapi.json +2 -2
- package/fixtures/configs/{hotreload.json → monorepo-watch-env.json} +2 -3
- package/fixtures/configs/monorepo-watch-single.json +12 -0
- package/fixtures/configs/monorepo-watch.json +26 -9
- package/fixtures/configs/monorepo-with-dependencies.json +2 -2
- package/fixtures/configs/{monorepo-client-without-id.json → monorepo-with-management-api-without-metrics.json} +5 -8
- package/fixtures/configs/monorepo-with-management-api.json +2 -3
- package/fixtures/configs/monorepo-with-metrics.json +1 -2
- package/fixtures/configs/monorepo.json +2 -3
- package/fixtures/configs/no-services.config.json +1 -1
- package/fixtures/configs/no-sources.config.json +1 -1
- package/fixtures/configs/service-throws-on-start.json +1 -1
- package/fixtures/configs/service-with-env-port.json +2 -3
- package/fixtures/configs/service-with-stdio.json +12 -0
- package/fixtures/configs/{monorepo-hotreload-env.json → watch.json} +2 -3
- package/fixtures/crash-on-bootstrap/platformatic.runtime.json +15 -0
- package/fixtures/crash-on-bootstrap/services/service-1/platformatic.service.json +14 -0
- package/fixtures/crash-on-bootstrap/services/service-1/plugin.js +5 -0
- package/fixtures/crash-on-bootstrap/services/service-2/platformatic.service.json +14 -0
- package/fixtures/crash-on-bootstrap/services/service-2/plugin.js +5 -0
- package/fixtures/dbApp/platformatic.db.json +1 -1
- package/fixtures/dbAppNoName/platformatic.db.json +1 -1
- package/fixtures/dbAppNoPackageJson/platformatic.db.json +1 -1
- package/fixtures/dbAppWithMigrationError/platformatic.db.json +1 -1
- package/fixtures/do-not-reload-dependencies/platformatic.service.json +1 -1
- package/fixtures/do-not-restart-on-crash/platformatic.runtime.json +3 -2
- package/fixtures/do-not-restart-on-crash/services/a/platformatic.service.json +1 -1
- package/fixtures/express/platformatic.runtime.json +1 -1
- package/fixtures/express/services/a/platformatic.service.json +1 -1
- package/fixtures/express/services/b/platformatic.service.json +1 -1
- package/fixtures/external-client/platformatic.service.json +1 -1
- package/fixtures/interceptors/idp.js +2 -2
- package/fixtures/interceptors/platformatic.runtime.json +1 -1
- package/fixtures/interceptors/services/a/platformatic.service.json +1 -1
- package/fixtures/interceptors-2/platformatic.runtime.json +1 -1
- package/fixtures/interceptors-2/services/a/platformatic.service.json +1 -1
- package/fixtures/leven/platformatic.runtime.json +2 -3
- package/fixtures/leven/services/deeply-spittle/platformatic.service.json +1 -1
- package/fixtures/leven/services/rainy-empire/platformatic.composer.json +1 -1
- package/fixtures/management-api/platformatic.json +8 -4
- package/fixtures/management-api/services/service-1/platformatic.json +1 -1
- package/fixtures/management-api/services/service-1/plugin.js +4 -3
- package/fixtures/management-api/services/service-2/platformatic.json +1 -1
- package/fixtures/management-api/services/service-db/platformatic.db.json +1 -1
- package/fixtures/management-api-custom-labels/platformatic.json +2 -3
- package/fixtures/management-api-custom-labels/services/service-1/platformatic.json +1 -1
- package/fixtures/management-api-custom-labels/services/service-1/plugin.js +4 -3
- package/fixtures/management-api-custom-labels/services/service-2/platformatic.json +1 -1
- package/fixtures/management-api-custom-labels/services/service-db/platformatic.db.json +1 -1
- package/fixtures/management-api-without-metrics/platformatic.json +3 -3
- package/fixtures/management-api-without-metrics/services/service-1/platformatic.json +1 -1
- package/fixtures/monorepo/composerApp/platformatic.composer.json +1 -2
- package/fixtures/monorepo/dbApp/platformatic.db.json +1 -1
- package/fixtures/monorepo/serviceApp/platformatic.service.json +3 -2
- package/fixtures/monorepo/serviceApp/with-logger/with-logger.cjs +2 -2
- package/fixtures/monorepo/serviceApp/with-logger/with-logger.d.ts +7 -7
- package/fixtures/monorepo/serviceAppWithLogger/platformatic.service.json +1 -1
- package/fixtures/monorepo/serviceAppWithLogger/plugin.js +12 -0
- package/fixtures/monorepo/serviceAppWithMultiplePlugins/platformatic.service.json +3 -2
- package/fixtures/monorepo-missing-dependencies/composer/platformatic.json +24 -0
- package/fixtures/monorepo-openapi/serviceAppWithoutOpenapi/platformatic.service.json +1 -1
- package/fixtures/monorepo-watch/service1/platformatic.service.json +1 -1
- package/fixtures/monorepo-with-dependencies/main/platformatic.json +1 -1
- package/fixtures/monorepo-with-dependencies/service-1/platformatic.json +1 -1
- package/fixtures/monorepo-with-dependencies/service-2/platformatic.json +1 -1
- package/fixtures/no-env.service.json +1 -1
- package/fixtures/preload/platformatic.runtime.json +1 -1
- package/fixtures/preload/services/a/platformatic.service.json +1 -1
- package/fixtures/prom-server/platformatic.json +2 -3
- package/fixtures/prom-server/services/service-1/platformatic.json +1 -1
- package/fixtures/prom-server/services/service-2/platformatic.json +1 -1
- package/fixtures/restart-on-crash/platformatic.runtime.json +1 -1
- package/fixtures/restart-on-crash/services/a/platformatic.service.json +1 -1
- package/fixtures/sample-runtime/package.json +1 -1
- package/fixtures/sample-runtime/platformatic.json +2 -3
- package/fixtures/sample-runtime/services/rival/package.json +1 -1
- package/fixtures/sample-runtime/services/rival/platformatic.json +1 -1
- package/fixtures/sample-runtime-with-2-services/package.json +1 -1
- package/fixtures/sample-runtime-with-2-services/platformatic.json +2 -3
- package/fixtures/sample-runtime-with-2-services/services/foobar/package.json +1 -1
- package/fixtures/sample-runtime-with-2-services/services/foobar/platformatic.json +1 -1
- package/fixtures/sample-runtime-with-2-services/services/rival/package.json +1 -1
- package/fixtures/sample-runtime-with-2-services/services/rival/platformatic.json +1 -1
- package/fixtures/server/logger-transport/platformatic.runtime.json +2 -3
- package/fixtures/server/logger-transport/services/echo/platformatic.service.json +1 -1
- package/fixtures/server/overrides-service/platformatic.runtime.json +2 -3
- package/fixtures/server/overrides-service/services/echo/platformatic.service.json +1 -1
- package/fixtures/server/runtime-server/platformatic.runtime.json +2 -3
- package/fixtures/server/runtime-server/services/echo/platformatic.service.json +1 -1
- package/fixtures/serviceAppThrowsOnStart/platformatic.service.json +1 -1
- package/fixtures/stackables/node_modules/foo/foo.js +2 -1
- package/fixtures/start-command-in-runtime.js +1 -1
- package/fixtures/stdio/platformatic.service.json +6 -0
- package/fixtures/stdio/plugin.js +24 -0
- package/fixtures/telemetry/platformatic.runtime.json +2 -3
- package/fixtures/telemetry/services/echo/platformatic.service.json +1 -1
- package/fixtures/telemetry/services/echo/routes/span.js +16 -2
- package/fixtures/telemetry/services/service-1/platformatic.service.json +19 -0
- package/fixtures/telemetry/services/service-1/routes/echo.js +7 -0
- package/fixtures/typescript/platformatic.runtime.json +2 -3
- package/fixtures/typescript/services/composer/platformatic.composer.json +1 -1
- package/fixtures/typescript/services/movies/global.d.ts +2 -3
- package/fixtures/typescript/services/movies/platformatic.db.json +1 -1
- package/fixtures/typescript/services/movies/types/Movie.d.ts +3 -3
- package/fixtures/typescript/services/movies/types/index.d.ts +6 -6
- package/fixtures/typescript/services/titles/client/client.d.ts +35 -35
- package/fixtures/typescript/services/titles/platformatic.service.json +1 -1
- package/fixtures/typescript-custom-flags/platformatic.runtime.json +2 -3
- package/fixtures/typescript-custom-flags/services/composer/platformatic.composer.json +1 -1
- package/fixtures/typescript-custom-flags/services/movies/global.d.ts +2 -3
- package/fixtures/typescript-custom-flags/services/movies/platformatic.db.json +1 -1
- package/fixtures/typescript-custom-flags/services/movies/types/Movie.d.ts +3 -3
- package/fixtures/typescript-custom-flags/services/movies/types/index.d.ts +6 -6
- package/fixtures/typescript-custom-flags/services/titles/client/client.d.ts +35 -35
- package/fixtures/typescript-custom-flags/services/titles/platformatic.service.json +1 -1
- package/fixtures/typescript-no-env/platformatic.runtime.json +2 -3
- package/fixtures/typescript-no-env/services/composer/platformatic.composer.json +1 -1
- package/fixtures/typescript-no-env/services/movies/global.d.ts +2 -3
- package/fixtures/typescript-no-env/services/movies/platformatic.db.json +1 -1
- package/fixtures/typescript-no-env/services/movies/types/Movie.d.ts +3 -3
- package/fixtures/typescript-no-env/services/movies/types/index.d.ts +6 -6
- package/fixtures/typescript-no-env/services/titles/client/client.d.ts +35 -35
- package/fixtures/typescript-no-env/services/titles/platformatic.service.json +1 -1
- package/index.d.ts +7 -8
- package/index.js +15 -10
- package/index.test-d.ts +10 -12
- package/lib/build-server.js +23 -15
- package/lib/compile.js +56 -13
- package/lib/config.js +27 -139
- package/lib/dependencies.js +59 -0
- package/lib/errors.js +6 -2
- package/lib/generator/errors.js +1 -1
- package/lib/generator/runtime-generator.d.ts +15 -15
- package/lib/generator/runtime-generator.js +81 -66
- package/lib/logger.js +55 -0
- package/lib/management-api.js +29 -44
- package/lib/prom-server.js +5 -9
- package/lib/runtime.js +1005 -0
- package/lib/schema.js +46 -44
- package/lib/start.js +49 -117
- package/lib/upgrade.js +4 -3
- package/lib/utils.js +49 -1
- package/lib/versions/v1.36.0.js +1 -1
- package/lib/versions/v1.5.0.js +1 -1
- package/lib/versions/v2.0.0.js +17 -0
- package/lib/worker/app.js +266 -0
- package/lib/worker/default-stackable.js +32 -0
- package/lib/worker/itc.js +149 -0
- package/lib/worker/main.js +129 -0
- package/lib/worker/metrics.js +106 -0
- package/lib/worker/symbols.js +7 -0
- package/package.json +44 -44
- package/runtime.mjs +11 -6
- package/schema.json +25 -13
- package/fixtures/monorepo/serviceApp/platformatic.service-client-without-id.json +0 -21
- package/lib/api-client.js +0 -497
- package/lib/api.js +0 -397
- package/lib/app.js +0 -365
- package/lib/load-config.js +0 -20
- package/lib/loader.mjs +0 -103
- package/lib/message-port-writable.js +0 -50
- package/lib/worker.js +0 -182
- /package/lib/{interceptors.js → worker/interceptors.js} +0 -0
package/lib/schema.js
CHANGED
|
@@ -2,11 +2,13 @@
|
|
|
2
2
|
'use strict'
|
|
3
3
|
|
|
4
4
|
const telemetry = require('@platformatic/telemetry').schema
|
|
5
|
-
const {
|
|
5
|
+
const {
|
|
6
|
+
schemaComponents: { server }
|
|
7
|
+
} = require('@platformatic/utils')
|
|
8
|
+
|
|
6
9
|
const pkg = require('../package.json')
|
|
7
|
-
const version = 'v' + pkg.version
|
|
8
10
|
const platformaticRuntimeSchema = {
|
|
9
|
-
$id: `https://platformatic.dev/
|
|
11
|
+
$id: `https://schemas.platformatic.dev/@platformatic/runtime/${pkg.version}.json`,
|
|
10
12
|
$schema: 'http://json-schema.org/draft-07/schema#',
|
|
11
13
|
type: 'object',
|
|
12
14
|
properties: {
|
|
@@ -38,7 +40,7 @@ const platformaticRuntimeSchema = {
|
|
|
38
40
|
additionalProperties: {
|
|
39
41
|
type: 'object',
|
|
40
42
|
additionalProperties: false,
|
|
41
|
-
required: ['id'
|
|
43
|
+
required: ['id'],
|
|
42
44
|
properties: {
|
|
43
45
|
id: {
|
|
44
46
|
type: 'string'
|
|
@@ -59,7 +61,7 @@ const platformaticRuntimeSchema = {
|
|
|
59
61
|
entrypoint: {
|
|
60
62
|
type: 'string'
|
|
61
63
|
},
|
|
62
|
-
|
|
64
|
+
watch: {
|
|
63
65
|
anyOf: [
|
|
64
66
|
{
|
|
65
67
|
type: 'boolean'
|
|
@@ -69,9 +71,6 @@ const platformaticRuntimeSchema = {
|
|
|
69
71
|
}
|
|
70
72
|
]
|
|
71
73
|
},
|
|
72
|
-
allowCycles: {
|
|
73
|
-
type: 'boolean'
|
|
74
|
-
},
|
|
75
74
|
inspectorOptions: {
|
|
76
75
|
type: 'object',
|
|
77
76
|
properties: {
|
|
@@ -84,7 +83,7 @@ const platformaticRuntimeSchema = {
|
|
|
84
83
|
breakFirstLine: {
|
|
85
84
|
type: 'boolean'
|
|
86
85
|
},
|
|
87
|
-
|
|
86
|
+
watchDisabled: {
|
|
88
87
|
type: 'boolean'
|
|
89
88
|
}
|
|
90
89
|
}
|
|
@@ -97,34 +96,37 @@ const platformaticRuntimeSchema = {
|
|
|
97
96
|
additionalProperties: true
|
|
98
97
|
},
|
|
99
98
|
interceptors: {
|
|
100
|
-
anyOf: [
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
99
|
+
anyOf: [
|
|
100
|
+
{
|
|
101
|
+
type: 'array',
|
|
102
|
+
items: {
|
|
103
|
+
$ref: '#/$defs/undiciInterceptor'
|
|
104
|
+
}
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
type: 'object',
|
|
108
|
+
properties: {
|
|
109
|
+
Client: {
|
|
110
|
+
type: 'array',
|
|
111
|
+
items: {
|
|
112
|
+
$ref: '#/$defs/undiciInterceptor'
|
|
113
|
+
}
|
|
114
|
+
},
|
|
115
|
+
Pool: {
|
|
116
|
+
type: 'array',
|
|
117
|
+
items: {
|
|
118
|
+
$ref: '#/$defs/undiciInterceptor'
|
|
119
|
+
}
|
|
120
|
+
},
|
|
121
|
+
Agent: {
|
|
122
|
+
type: 'array',
|
|
123
|
+
items: {
|
|
124
|
+
$ref: '#/$defs/undiciInterceptor'
|
|
125
|
+
}
|
|
124
126
|
}
|
|
125
127
|
}
|
|
126
128
|
}
|
|
127
|
-
|
|
129
|
+
]
|
|
128
130
|
}
|
|
129
131
|
}
|
|
130
132
|
},
|
|
@@ -155,10 +157,7 @@ const platformaticRuntimeSchema = {
|
|
|
155
157
|
type: 'object',
|
|
156
158
|
properties: {
|
|
157
159
|
port: {
|
|
158
|
-
anyOf: [
|
|
159
|
-
{ type: 'integer' },
|
|
160
|
-
{ type: 'string' }
|
|
161
|
-
]
|
|
160
|
+
anyOf: [{ type: 'integer' }, { type: 'string' }]
|
|
162
161
|
},
|
|
163
162
|
hostname: { type: 'string' },
|
|
164
163
|
endpoint: { type: 'string' },
|
|
@@ -184,14 +183,17 @@ const platformaticRuntimeSchema = {
|
|
|
184
183
|
default: true,
|
|
185
184
|
anyOf: [
|
|
186
185
|
{ type: 'boolean' },
|
|
187
|
-
{
|
|
186
|
+
{
|
|
187
|
+
type: 'number',
|
|
188
|
+
minimum: 100
|
|
189
|
+
}
|
|
188
190
|
]
|
|
189
191
|
},
|
|
190
192
|
services: {
|
|
191
193
|
type: 'array',
|
|
192
194
|
items: {
|
|
193
195
|
type: 'object',
|
|
194
|
-
required: ['id', 'path', '
|
|
196
|
+
anyOf: [{ required: ['id', 'path'] }, { required: ['id', 'url'] }],
|
|
195
197
|
properties: {
|
|
196
198
|
id: {
|
|
197
199
|
type: 'string'
|
|
@@ -203,6 +205,9 @@ const platformaticRuntimeSchema = {
|
|
|
203
205
|
config: {
|
|
204
206
|
type: 'string'
|
|
205
207
|
},
|
|
208
|
+
url: {
|
|
209
|
+
type: 'string'
|
|
210
|
+
},
|
|
206
211
|
useHttp: {
|
|
207
212
|
type: 'boolean'
|
|
208
213
|
}
|
|
@@ -210,10 +215,7 @@ const platformaticRuntimeSchema = {
|
|
|
210
215
|
}
|
|
211
216
|
}
|
|
212
217
|
},
|
|
213
|
-
anyOf: [
|
|
214
|
-
{ required: ['autoload', 'entrypoint'] },
|
|
215
|
-
{ required: ['services', 'entrypoint'] }
|
|
216
|
-
],
|
|
218
|
+
anyOf: [{ required: ['autoload', 'entrypoint'] }, { required: ['services', 'entrypoint'] }],
|
|
217
219
|
additionalProperties: false,
|
|
218
220
|
$defs: {
|
|
219
221
|
undiciInterceptor: {
|
package/lib/start.js
CHANGED
|
@@ -1,47 +1,25 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
const { once } = require('node:events')
|
|
4
3
|
const inspector = require('node:inspector')
|
|
5
|
-
const { join, resolve, dirname } = require('node:path')
|
|
6
4
|
const { writeFile } = require('node:fs/promises')
|
|
7
|
-
const {
|
|
8
|
-
|
|
9
|
-
const { start: serviceStart } = require('@platformatic/service')
|
|
5
|
+
const { join, resolve, dirname } = require('node:path')
|
|
6
|
+
|
|
10
7
|
const { printConfigValidationErrors } = require('@platformatic/config')
|
|
8
|
+
const {
|
|
9
|
+
errors: { ensureLoggableError }
|
|
10
|
+
} = require('@platformatic/utils')
|
|
11
11
|
const closeWithGrace = require('close-with-grace')
|
|
12
|
-
const { loadConfig } = require('./load-config')
|
|
13
|
-
const { startManagementApi } = require('./management-api')
|
|
14
|
-
const { startPrometheusServer } = require('./prom-server.js')
|
|
15
|
-
const { parseInspectorOptions, wrapConfigInRuntimeConfig } = require('./config')
|
|
16
|
-
const { RuntimeApiClient, getRuntimeLogsDir } = require('./api-client.js')
|
|
17
|
-
const errors = require('./errors')
|
|
18
|
-
const pkg = require('../package.json')
|
|
19
12
|
const pino = require('pino')
|
|
20
13
|
const pretty = require('pino-pretty')
|
|
21
14
|
|
|
22
|
-
const
|
|
23
|
-
const
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
kLoaderFile
|
|
28
|
-
]
|
|
29
|
-
|
|
30
|
-
function startWorker ({ config, dirname, runtimeLogsDir }, env) {
|
|
31
|
-
const worker = new Worker(kWorkerFile, {
|
|
32
|
-
/* c8 ignore next */
|
|
33
|
-
execArgv: config.hotReload ? kWorkerExecArgv : [],
|
|
34
|
-
transferList: config.loggingPort ? [config.loggingPort] : [],
|
|
35
|
-
workerData: { config, dirname, runtimeLogsDir },
|
|
36
|
-
env
|
|
37
|
-
})
|
|
38
|
-
|
|
39
|
-
return worker
|
|
40
|
-
}
|
|
15
|
+
const pkg = require('../package.json')
|
|
16
|
+
const { parseInspectorOptions, wrapConfigInRuntimeConfig } = require('./config')
|
|
17
|
+
const { Runtime } = require('./runtime')
|
|
18
|
+
const errors = require('./errors')
|
|
19
|
+
const { getRuntimeLogsDir, loadConfig } = require('./utils')
|
|
41
20
|
|
|
42
21
|
async function buildRuntime (configManager, env) {
|
|
43
22
|
env = env || process.env
|
|
44
|
-
const config = configManager.current
|
|
45
23
|
|
|
46
24
|
if (inspector.url()) {
|
|
47
25
|
throw new errors.NodeInspectorFlagsNotSupportedError()
|
|
@@ -51,93 +29,37 @@ async function buildRuntime (configManager, env) {
|
|
|
51
29
|
parseInspectorOptions(configManager)
|
|
52
30
|
}
|
|
53
31
|
|
|
54
|
-
if (config.hotReload) {
|
|
55
|
-
config.loaderFile = kLoaderFile
|
|
56
|
-
}
|
|
57
|
-
|
|
58
32
|
const dirname = configManager.dirname
|
|
59
33
|
const runtimeLogsDir = getRuntimeLogsDir(dirname, process.pid)
|
|
60
34
|
|
|
61
|
-
|
|
62
|
-
delete config.configManager
|
|
35
|
+
const runtime = new Runtime(configManager, runtimeLogsDir, env)
|
|
63
36
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
if (config.hotReload) {
|
|
69
|
-
/* c8 ignore next 3 */
|
|
70
|
-
process.on('SIGUSR2', () => {
|
|
71
|
-
worker.postMessage({ signal: 'SIGUSR2' })
|
|
72
|
-
})
|
|
73
|
-
|
|
74
|
-
/* c8 ignore next 3 */
|
|
75
|
-
configManager.on('update', () => {
|
|
76
|
-
// TODO(cjihrig): Need to clean up and restart the worker.
|
|
77
|
-
})
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
function setupExit () {
|
|
81
|
-
worker.on('exit', (code) => {
|
|
82
|
-
// runtimeApiClient.started can be false if a stop command was issued
|
|
83
|
-
// via the management API.
|
|
84
|
-
if (config.restartOnError === false || !runtimeApiClient.started) {
|
|
85
|
-
// We must stop those here in case the `closeWithGrace` callback
|
|
86
|
-
// was not called.
|
|
87
|
-
configManager.fileWatcher?.stopWatching()
|
|
88
|
-
managementApi?.close()
|
|
89
|
-
return
|
|
90
|
-
}
|
|
37
|
+
/* c8 ignore next 3 */
|
|
38
|
+
process.on('SIGUSR2', async () => {
|
|
39
|
+
runtime.logger.info('Received SIGUSR2, restarting all services ...')
|
|
91
40
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
// should we limit this to a number of retries?
|
|
99
|
-
})
|
|
100
|
-
})
|
|
101
|
-
})
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
setupExit()
|
|
105
|
-
|
|
106
|
-
await once(worker, 'message') // plt:init
|
|
107
|
-
|
|
108
|
-
const runtimeApiClient = new RuntimeApiClient(
|
|
109
|
-
worker,
|
|
110
|
-
configManager,
|
|
111
|
-
runtimeLogsDir
|
|
112
|
-
)
|
|
113
|
-
|
|
114
|
-
if (config.managementApi) {
|
|
115
|
-
managementApi = await startManagementApi(runtimeApiClient, configManager)
|
|
116
|
-
runtimeApiClient.managementApi = managementApi
|
|
117
|
-
runtimeApiClient.on('start', () => {
|
|
118
|
-
runtimeApiClient.startCollectingMetrics()
|
|
119
|
-
})
|
|
120
|
-
}
|
|
121
|
-
if (config.metrics) {
|
|
122
|
-
runtimeApiClient.on('start', async () => {
|
|
123
|
-
await startPrometheusServer(runtimeApiClient, config.metrics)
|
|
124
|
-
})
|
|
125
|
-
}
|
|
41
|
+
try {
|
|
42
|
+
await runtime.restart()
|
|
43
|
+
} catch (err) {
|
|
44
|
+
runtime.logger.error({ err: ensureLoggableError(err) }, 'Failed to restart services.')
|
|
45
|
+
}
|
|
46
|
+
})
|
|
126
47
|
|
|
127
|
-
|
|
48
|
+
await runtime.init()
|
|
49
|
+
return runtime
|
|
128
50
|
}
|
|
129
51
|
|
|
130
52
|
async function start (args) {
|
|
131
53
|
const config = await loadConfig({}, args)
|
|
132
54
|
|
|
133
|
-
if (config.configType
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
await app.start()
|
|
137
|
-
return app
|
|
55
|
+
if (config.configType !== 'runtime') {
|
|
56
|
+
const configManager = await wrapConfigInRuntimeConfig(config)
|
|
57
|
+
config.configManager = configManager
|
|
138
58
|
}
|
|
139
59
|
|
|
140
|
-
|
|
60
|
+
const app = await buildRuntime(config.configManager)
|
|
61
|
+
await app.start()
|
|
62
|
+
return app
|
|
141
63
|
}
|
|
142
64
|
|
|
143
65
|
async function setupAndStartRuntime (config) {
|
|
@@ -156,16 +78,16 @@ async function setupAndStartRuntime (config) {
|
|
|
156
78
|
let runtime = await buildRuntime(runtimeConfig)
|
|
157
79
|
|
|
158
80
|
let address = null
|
|
159
|
-
|
|
81
|
+
const startErr = null
|
|
160
82
|
const originalPort = runtimeConfig.current.server?.port || 0
|
|
161
83
|
while (address === null) {
|
|
162
84
|
try {
|
|
163
85
|
address = await runtime.start()
|
|
164
86
|
} catch (err) {
|
|
165
|
-
startErr = err
|
|
166
87
|
if (err.code === 'EADDRINUSE') {
|
|
167
88
|
await runtime.close()
|
|
168
|
-
|
|
89
|
+
|
|
90
|
+
if (runtimeConfig.current?.server?.port > MAX_PORT) throw err
|
|
169
91
|
runtimeConfig.current.server.port++
|
|
170
92
|
runtime = await buildRuntime(runtimeConfig)
|
|
171
93
|
} else {
|
|
@@ -174,10 +96,12 @@ async function setupAndStartRuntime (config) {
|
|
|
174
96
|
}
|
|
175
97
|
}
|
|
176
98
|
if (startErr?.code === 'PLT_RUNTIME_EADDR_IN_USE') {
|
|
177
|
-
const logger = pino(
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
99
|
+
const logger = pino(
|
|
100
|
+
pretty({
|
|
101
|
+
translateTime: 'SYS:HH:MM:ss',
|
|
102
|
+
ignore: 'hostname,pid'
|
|
103
|
+
})
|
|
104
|
+
)
|
|
181
105
|
logger.warn(`Port: ${originalPort} is already in use!`)
|
|
182
106
|
logger.warn(`Starting service on port: ${runtimeConfig.current.server.port}`)
|
|
183
107
|
}
|
|
@@ -186,14 +110,22 @@ async function setupAndStartRuntime (config) {
|
|
|
186
110
|
|
|
187
111
|
async function startCommand (args) {
|
|
188
112
|
try {
|
|
189
|
-
const config = await loadConfig(
|
|
113
|
+
const config = await loadConfig(
|
|
114
|
+
{
|
|
115
|
+
alias: {
|
|
116
|
+
p: 'production'
|
|
117
|
+
},
|
|
118
|
+
boolean: ['p', 'production']
|
|
119
|
+
},
|
|
120
|
+
args
|
|
121
|
+
)
|
|
190
122
|
|
|
191
123
|
const startResult = await setupAndStartRuntime(config)
|
|
192
124
|
|
|
193
125
|
const runtime = startResult.runtime
|
|
194
126
|
const res = startResult.address
|
|
195
127
|
|
|
196
|
-
closeWithGrace(async
|
|
128
|
+
closeWithGrace(async event => {
|
|
197
129
|
if (event.err instanceof Error) {
|
|
198
130
|
console.error(event.err)
|
|
199
131
|
}
|
|
@@ -204,7 +136,7 @@ async function startCommand (args) {
|
|
|
204
136
|
} catch (err) {
|
|
205
137
|
if (err.code === 'PLT_CONFIG_NO_CONFIG_FILE_FOUND' && args.length === 1) {
|
|
206
138
|
const config = {
|
|
207
|
-
$schema: `https://platformatic.dev/
|
|
139
|
+
$schema: `https://schemas.platformatic.dev/@platformatic/service/${pkg.version}.json`,
|
|
208
140
|
server: {
|
|
209
141
|
hostname: '127.0.0.1',
|
|
210
142
|
port: 3042,
|
|
@@ -230,7 +162,7 @@ async function startCommand (args) {
|
|
|
230
162
|
console.error(`Missing config file!
|
|
231
163
|
Be sure to have a config file with one of the following names:
|
|
232
164
|
|
|
233
|
-
${err.filenames.map(
|
|
165
|
+
${err.filenames.map(s => ' * ' + s).join('\n')}
|
|
234
166
|
|
|
235
167
|
In alternative run "npm create platformatic@latest" to generate a basic plt service config.`)
|
|
236
168
|
process.exit(1)
|
package/lib/upgrade.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
const { join } = require('path')
|
|
3
|
+
const { join } = require('node:path')
|
|
4
|
+
|
|
4
5
|
const pkg = require('../package.json')
|
|
5
6
|
|
|
6
7
|
module.exports = async function upgrade (config, version) {
|
|
@@ -10,7 +11,7 @@ module.exports = async function upgrade (config, version) {
|
|
|
10
11
|
version,
|
|
11
12
|
path: join(__dirname, 'versions'),
|
|
12
13
|
input: config,
|
|
13
|
-
logger: this.logger.child({ name: '@platformatic/runtime' })
|
|
14
|
+
logger: this.logger.child({ name: '@platformatic/runtime' }),
|
|
14
15
|
})
|
|
15
16
|
|
|
16
17
|
let result
|
|
@@ -19,7 +20,7 @@ module.exports = async function upgrade (config, version) {
|
|
|
19
20
|
result = updated.result
|
|
20
21
|
}
|
|
21
22
|
|
|
22
|
-
result.$schema = `https://platformatic.dev/
|
|
23
|
+
result.$schema = `https://schemas.platformatic.dev/@platformatic/runtime/${pkg.version}.json`
|
|
23
24
|
|
|
24
25
|
return result
|
|
25
26
|
}
|
package/lib/utils.js
CHANGED
|
@@ -1,10 +1,58 @@
|
|
|
1
1
|
'use strict'
|
|
2
|
+
|
|
3
|
+
const { createHash } = require('node:crypto')
|
|
4
|
+
const { tmpdir } = require('node:os')
|
|
5
|
+
const { join } = require('node:path')
|
|
6
|
+
|
|
7
|
+
const {
|
|
8
|
+
Store,
|
|
9
|
+
loadConfig: pltConfigLoadConfig,
|
|
10
|
+
loadEmptyConfig: pltConfigLoadEmptyConfig,
|
|
11
|
+
} = require('@platformatic/config')
|
|
12
|
+
|
|
13
|
+
const { platformaticRuntime } = require('./config')
|
|
14
|
+
|
|
2
15
|
function getArrayDifference (a, b) {
|
|
3
16
|
return a.filter(element => {
|
|
4
17
|
return !b.includes(element)
|
|
5
18
|
})
|
|
6
19
|
}
|
|
7
20
|
|
|
21
|
+
function getServiceUrl (id) {
|
|
22
|
+
return `http://${id}.plt.local`
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function getRuntimeTmpDir (runtimeDir) {
|
|
26
|
+
const platformaticTmpDir = join(tmpdir(), 'platformatic', 'applications')
|
|
27
|
+
const runtimeDirHash = createHash('md5').update(runtimeDir).digest('hex')
|
|
28
|
+
return join(platformaticTmpDir, runtimeDirHash)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function getRuntimeLogsDir (runtimeDir, runtimePID) {
|
|
32
|
+
const runtimeTmpDir = getRuntimeTmpDir(runtimeDir)
|
|
33
|
+
return join(runtimeTmpDir, runtimePID.toString(), 'logs')
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
async function loadConfig (minimistConfig, args, overrides, replaceEnv = true) {
|
|
37
|
+
const { default: platformaticBasic } = await import('@platformatic/basic')
|
|
38
|
+
const store = new Store()
|
|
39
|
+
store.add(platformaticRuntime)
|
|
40
|
+
store.add(platformaticBasic)
|
|
41
|
+
|
|
42
|
+
return pltConfigLoadConfig(minimistConfig, args, store, overrides, replaceEnv)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
async function loadEmptyConfig (path, overrides, replaceEnv = true) {
|
|
46
|
+
const { default: platformaticBasic } = await import('@platformatic/basic')
|
|
47
|
+
|
|
48
|
+
return pltConfigLoadEmptyConfig(path, platformaticBasic, overrides, replaceEnv)
|
|
49
|
+
}
|
|
50
|
+
|
|
8
51
|
module.exports = {
|
|
9
|
-
getArrayDifference
|
|
52
|
+
getArrayDifference,
|
|
53
|
+
getRuntimeLogsDir,
|
|
54
|
+
getRuntimeTmpDir,
|
|
55
|
+
getServiceUrl,
|
|
56
|
+
loadConfig,
|
|
57
|
+
loadEmptyConfig,
|
|
10
58
|
}
|
package/lib/versions/v1.36.0.js
CHANGED
package/lib/versions/v1.5.0.js
CHANGED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
module.exports = {
|
|
4
|
+
version: '1.99.0', // This is to account alpha versions as well
|
|
5
|
+
up: function (config) {
|
|
6
|
+
if (config.restartOnError === undefined) {
|
|
7
|
+
config.restartOnError = true
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
if (config.hotReload) {
|
|
11
|
+
config.watch = config.hotReload
|
|
12
|
+
delete config.hotReload
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
return config
|
|
16
|
+
},
|
|
17
|
+
}
|