@platformatic/runtime 1.30.0 → 1.31.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/fixtures/management-api/services/service-1/platformatic.json +1 -4
- package/fixtures/management-api/services/service-2/platformatic.json +1 -2
- package/fixtures/sample-runtime-with-2-services/.env +10 -0
- package/fixtures/sample-runtime-with-2-services/package.json +16 -0
- package/fixtures/sample-runtime-with-2-services/platformatic.json +19 -0
- package/fixtures/sample-runtime-with-2-services/services/foobar/package.json +16 -0
- package/fixtures/sample-runtime-with-2-services/services/foobar/platformatic.json +18 -0
- package/fixtures/sample-runtime-with-2-services/services/foobar/routes/root.js +7 -0
- package/fixtures/sample-runtime-with-2-services/services/rival/package.json +16 -0
- package/fixtures/sample-runtime-with-2-services/services/rival/platformatic.json +33 -0
- package/fixtures/sample-runtime-with-2-services/services/rival/routes/root.js +7 -0
- package/lib/app.js +44 -37
- package/lib/errors.js +2 -0
- package/lib/generator/runtime-generator.js +36 -6
- package/lib/management-api.js +4 -4
- package/package.json +10 -10
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
PLT_SERVER_HOSTNAME=0.0.0.0
|
|
2
|
+
PORT=3042
|
|
3
|
+
PLT_SERVER_LOGGER_LEVEL=info
|
|
4
|
+
PLT_RIVAL_TYPESCRIPT=true
|
|
5
|
+
PLT_RIVAL_FST_PLUGIN_OAUTH2_NAME=googleOAuth2
|
|
6
|
+
PLT_RIVAL_FST_PLUGIN_OAUTH2_CREDENTIALS_CLIENT_ID=sample_client_id
|
|
7
|
+
PLT_RIVAL_FST_PLUGIN_OAUTH2_CREDENTIALS_CLIENT_SECRET=sample_client_secret
|
|
8
|
+
PLT_RIVAL_FST_PLUGIN_OAUTH2_REDIRECT_PATH=/login/google
|
|
9
|
+
PLT_RIVAL_FST_PLUGIN_OAUTH2_CALLBACK_URI=http://localhost:3000/login/google/callback
|
|
10
|
+
PLT_FOOBAR_TYPESCRIPT=true
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"scripts": {
|
|
3
|
+
"start": "platformatic start",
|
|
4
|
+
"test": "node --test test/*/*.test.js"
|
|
5
|
+
},
|
|
6
|
+
"devDependencies": {
|
|
7
|
+
"fastify": "^4.26.0"
|
|
8
|
+
},
|
|
9
|
+
"dependencies": {
|
|
10
|
+
"platformatic": "^1.25.0",
|
|
11
|
+
"@fastify/oauth2": "7.8.0"
|
|
12
|
+
},
|
|
13
|
+
"engines": {
|
|
14
|
+
"node": "^18.8.0 || >=20.6.0"
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://platformatic.dev/schemas/v1.25.0/runtime",
|
|
3
|
+
"entrypoint": "rival",
|
|
4
|
+
"allowCycles": false,
|
|
5
|
+
"hotReload": true,
|
|
6
|
+
"autoload": {
|
|
7
|
+
"path": "services",
|
|
8
|
+
"exclude": [
|
|
9
|
+
"docs"
|
|
10
|
+
]
|
|
11
|
+
},
|
|
12
|
+
"server": {
|
|
13
|
+
"hostname": "{PLT_SERVER_HOSTNAME}",
|
|
14
|
+
"port": "{PORT}",
|
|
15
|
+
"logger": {
|
|
16
|
+
"level": "{PLT_SERVER_LOGGER_LEVEL}"
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"scripts": {
|
|
3
|
+
"start": "platformatic start",
|
|
4
|
+
"test": "node --test test/**"
|
|
5
|
+
},
|
|
6
|
+
"devDependencies": {
|
|
7
|
+
"fastify": "^4.26.0"
|
|
8
|
+
},
|
|
9
|
+
"dependencies": {
|
|
10
|
+
"platformatic": "^1.25.0",
|
|
11
|
+
"@platformatic/service": "^1.25.0"
|
|
12
|
+
},
|
|
13
|
+
"engines": {
|
|
14
|
+
"node": "^18.8.0 || >=20.6.0"
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://platformatic.dev/schemas/v1.25.0/service",
|
|
3
|
+
"service": {
|
|
4
|
+
"openapi": true
|
|
5
|
+
},
|
|
6
|
+
"watch": true,
|
|
7
|
+
"plugins": {
|
|
8
|
+
"paths": [
|
|
9
|
+
{
|
|
10
|
+
"path": "./plugins",
|
|
11
|
+
"encapsulate": false
|
|
12
|
+
},
|
|
13
|
+
"./routes"
|
|
14
|
+
],
|
|
15
|
+
"typescript": "{PLT_FOOBAR_TYPESCRIPT}",
|
|
16
|
+
"packages": []
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"scripts": {
|
|
3
|
+
"start": "platformatic start",
|
|
4
|
+
"test": "node --test test/**"
|
|
5
|
+
},
|
|
6
|
+
"devDependencies": {
|
|
7
|
+
"fastify": "^4.26.0"
|
|
8
|
+
},
|
|
9
|
+
"dependencies": {
|
|
10
|
+
"platformatic": "^1.25.0",
|
|
11
|
+
"@platformatic/service": "^1.25.0"
|
|
12
|
+
},
|
|
13
|
+
"engines": {
|
|
14
|
+
"node": "^18.8.0 || >=20.6.0"
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://platformatic.dev/schemas/v1.25.0/service",
|
|
3
|
+
"service": {
|
|
4
|
+
"openapi": true
|
|
5
|
+
},
|
|
6
|
+
"watch": true,
|
|
7
|
+
"plugins": {
|
|
8
|
+
"paths": [
|
|
9
|
+
{
|
|
10
|
+
"path": "./plugins",
|
|
11
|
+
"encapsulate": false
|
|
12
|
+
},
|
|
13
|
+
"./routes"
|
|
14
|
+
],
|
|
15
|
+
"typescript": "{PLT_RIVAL_TYPESCRIPT}",
|
|
16
|
+
"packages": [
|
|
17
|
+
{
|
|
18
|
+
"name": "@fastify/oauth2",
|
|
19
|
+
"options": {
|
|
20
|
+
"name": "{PLT_RIVAL_FST_PLUGIN_OAUTH2_NAME}",
|
|
21
|
+
"credentials": {
|
|
22
|
+
"client": {
|
|
23
|
+
"id": "{PLT_RIVAL_FST_PLUGIN_OAUTH2_CREDENTIALS_CLIENT_ID}",
|
|
24
|
+
"secret": "{PLT_RIVAL_FST_PLUGIN_OAUTH2_CREDENTIALS_CLIENT_SECRET}"
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
"startRedirectPath": "{PLT_RIVAL_FST_PLUGIN_OAUTH2_REDIRECT_PATH}",
|
|
28
|
+
"callbackUri": "{PLT_RIVAL_FST_PLUGIN_OAUTH2_CALLBACK_URI}"
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
]
|
|
32
|
+
}
|
|
33
|
+
}
|
package/lib/app.js
CHANGED
|
@@ -73,6 +73,8 @@ class PlatformaticApp {
|
|
|
73
73
|
|
|
74
74
|
try {
|
|
75
75
|
await this.config.configManager.parseAndValidate()
|
|
76
|
+
await this.#updateConfig()
|
|
77
|
+
|
|
76
78
|
this.#setuplogger(this.config.configManager)
|
|
77
79
|
await this.server.restart()
|
|
78
80
|
} catch (err) {
|
|
@@ -93,44 +95,9 @@ class PlatformaticApp {
|
|
|
93
95
|
this.#started = true
|
|
94
96
|
|
|
95
97
|
await this.#initializeConfig()
|
|
96
|
-
this.#
|
|
97
|
-
this.config.configManager.current.watch = { enabled: false }
|
|
98
|
-
|
|
99
|
-
const { configManager } = this.config
|
|
100
|
-
configManager.update({
|
|
101
|
-
...configManager.current,
|
|
102
|
-
telemetry: this.#telemetryConfig
|
|
103
|
-
})
|
|
104
|
-
|
|
105
|
-
if (this.#serverConfig) {
|
|
106
|
-
configManager.update({
|
|
107
|
-
...configManager.current,
|
|
108
|
-
server: this.#serverConfig
|
|
109
|
-
})
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
if (this.#hasManagementApi || configManager.current.metrics) {
|
|
113
|
-
configManager.update({
|
|
114
|
-
...configManager.current,
|
|
115
|
-
metrics: {
|
|
116
|
-
server: 'parent',
|
|
117
|
-
defaultMetrics: { enabled: this.appConfig.entrypoint },
|
|
118
|
-
prefix: snakeCase(this.appConfig.id) + '_',
|
|
119
|
-
...configManager.current.metrics
|
|
120
|
-
}
|
|
121
|
-
})
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
if (!this.appConfig.entrypoint) {
|
|
125
|
-
configManager.update({
|
|
126
|
-
...configManager.current,
|
|
127
|
-
server: {
|
|
128
|
-
...(configManager.current.server || {}),
|
|
129
|
-
trustProxy: true
|
|
130
|
-
}
|
|
131
|
-
})
|
|
132
|
-
}
|
|
98
|
+
await this.#updateConfig()
|
|
133
99
|
|
|
100
|
+
const configManager = this.config.configManager
|
|
134
101
|
const config = configManager.current
|
|
135
102
|
|
|
136
103
|
this.#setuplogger(configManager)
|
|
@@ -262,6 +229,46 @@ class PlatformaticApp {
|
|
|
262
229
|
})
|
|
263
230
|
}
|
|
264
231
|
|
|
232
|
+
async #updateConfig () {
|
|
233
|
+
this.#originalWatch = this.config.configManager.current.watch
|
|
234
|
+
this.config.configManager.current.watch = { enabled: false }
|
|
235
|
+
|
|
236
|
+
const { configManager } = this.config
|
|
237
|
+
configManager.update({
|
|
238
|
+
...configManager.current,
|
|
239
|
+
telemetry: this.#telemetryConfig
|
|
240
|
+
})
|
|
241
|
+
|
|
242
|
+
if (this.#serverConfig) {
|
|
243
|
+
configManager.update({
|
|
244
|
+
...configManager.current,
|
|
245
|
+
server: this.#serverConfig
|
|
246
|
+
})
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
if (this.#hasManagementApi || configManager.current.metrics) {
|
|
250
|
+
configManager.update({
|
|
251
|
+
...configManager.current,
|
|
252
|
+
metrics: {
|
|
253
|
+
server: 'hide',
|
|
254
|
+
defaultMetrics: { enabled: this.appConfig.entrypoint },
|
|
255
|
+
prefix: snakeCase(this.appConfig.id) + '_',
|
|
256
|
+
...configManager.current.metrics
|
|
257
|
+
}
|
|
258
|
+
})
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
if (!this.appConfig.entrypoint) {
|
|
262
|
+
configManager.update({
|
|
263
|
+
...configManager.current,
|
|
264
|
+
server: {
|
|
265
|
+
...(configManager.current.server || {}),
|
|
266
|
+
trustProxy: true
|
|
267
|
+
}
|
|
268
|
+
})
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
|
|
265
272
|
#setuplogger (configManager) {
|
|
266
273
|
configManager.current.server = configManager.current.server || {}
|
|
267
274
|
const level = configManager.current.server.logger?.level
|
package/lib/errors.js
CHANGED
|
@@ -25,5 +25,7 @@ module.exports = {
|
|
|
25
25
|
FailedToUnlinkManagementApiSocket: createError(`${ERROR_PREFIX}_FAILED_TO_UNLINK_MANAGEMENT_API_SOCKET`, 'Failed to unlink management API socket "%s"'),
|
|
26
26
|
LogFileNotFound: createError(`${ERROR_PREFIX}_LOG_FILE_NOT_FOUND`, 'Log file with index %s not found', 404),
|
|
27
27
|
CannotFindGeneratorForTemplateError: createError(`${ERROR_PREFIX}_CANNOT_FIND_GENERATOR_FOR_TEMPLATE`, 'Cannot find a generator for template "%s"'),
|
|
28
|
+
|
|
29
|
+
// TODO: should remove next one as it's not used anymore
|
|
28
30
|
CannotRemoveServiceOnUpdateError: createError(`${ERROR_PREFIX}_CANNOT_REMOVE_SERVICE_ON_UPDATE`, 'Cannot remove service "%s" when updating a Runtime')
|
|
29
31
|
}
|
|
@@ -5,13 +5,13 @@ const { NoEntryPointError, NoServiceNamedError } = require('./errors')
|
|
|
5
5
|
const generateName = require('boring-name-generator')
|
|
6
6
|
const { join } = require('node:path')
|
|
7
7
|
const { envObjectToString } = require('@platformatic/generators/lib/utils')
|
|
8
|
-
const { readFile, readdir, stat } = require('node:fs/promises')
|
|
8
|
+
const { readFile, readdir, stat, rm } = require('node:fs/promises')
|
|
9
9
|
const { ConfigManager } = require('@platformatic/config')
|
|
10
10
|
const { platformaticRuntime } = require('../config')
|
|
11
11
|
const ServiceGenerator = require('@platformatic/service/lib/generator/service-generator')
|
|
12
12
|
const DBGenerator = require('@platformatic/db/lib/generator/db-generator')
|
|
13
13
|
const ComposerGenerator = require('@platformatic/composer/lib/generator/composer-generator')
|
|
14
|
-
const { CannotFindGeneratorForTemplateError
|
|
14
|
+
const { CannotFindGeneratorForTemplateError } = require('../errors')
|
|
15
15
|
const { getServiceTemplateFromSchemaUrl } = require('@platformatic/generators/lib/utils')
|
|
16
16
|
const { DotEnvTool } = require('dotenv-tool')
|
|
17
17
|
const { getArrayDifference } = require('../utils')
|
|
@@ -357,7 +357,30 @@ class RuntimeGenerator extends BaseGenerator {
|
|
|
357
357
|
|
|
358
358
|
const removedServices = getArrayDifference(allCurrentServicesNames, allNewServicesNames)
|
|
359
359
|
if (removedServices.length > 0) {
|
|
360
|
-
|
|
360
|
+
for (const removedService of removedServices) {
|
|
361
|
+
// handle service delete
|
|
362
|
+
|
|
363
|
+
// delete env variables
|
|
364
|
+
const s = this.services.find((f) => f.name === removedService)
|
|
365
|
+
const allKeys = envTool.getKeys()
|
|
366
|
+
allKeys.forEach((k) => {
|
|
367
|
+
if (k.startsWith(`PLT_${s.service.config.envPrefix}`)) {
|
|
368
|
+
envTool.deleteKey(k)
|
|
369
|
+
}
|
|
370
|
+
})
|
|
371
|
+
|
|
372
|
+
// delete dependencies
|
|
373
|
+
const servicePackageJson = JSON.parse(await readFile(join(this.targetDirectory, 'services', s.name, 'platformatic.json')))
|
|
374
|
+
if (servicePackageJson.plugins && servicePackageJson.plugins.packages) {
|
|
375
|
+
servicePackageJson.plugins.packages
|
|
376
|
+
.forEach((p) => {
|
|
377
|
+
delete (currrentPackageJson.dependencies[p.name])
|
|
378
|
+
})
|
|
379
|
+
}
|
|
380
|
+
// delete directory
|
|
381
|
+
await rm(join(this.targetDirectory, 'services', s.name), { recursive: true })
|
|
382
|
+
}
|
|
383
|
+
// throw new CannotRemoveServiceOnUpdateError(removedServices.join(', '))
|
|
361
384
|
}
|
|
362
385
|
|
|
363
386
|
// handle new services
|
|
@@ -368,7 +391,8 @@ class RuntimeGenerator extends BaseGenerator {
|
|
|
368
391
|
const baseConfig = {
|
|
369
392
|
isRuntimeContext: true,
|
|
370
393
|
targetDirectory: join(this.targetDirectory, 'services', newService.name),
|
|
371
|
-
serviceName: newService.name
|
|
394
|
+
serviceName: newService.name,
|
|
395
|
+
plugin: true
|
|
372
396
|
}
|
|
373
397
|
if (allCurrentServicesNames.includes(newService.name)) {
|
|
374
398
|
// update existing services env values
|
|
@@ -383,6 +407,7 @@ class RuntimeGenerator extends BaseGenerator {
|
|
|
383
407
|
pluginsToRemove.forEach((p) => delete currentRuntimeDependencies[p])
|
|
384
408
|
}
|
|
385
409
|
serviceInstance.setConfig(baseConfig)
|
|
410
|
+
serviceInstance.setConfigFields(newService.fields)
|
|
386
411
|
|
|
387
412
|
const serviceEnvPrefix = `PLT_${serviceInstance.config.envPrefix}`
|
|
388
413
|
for (const plug of newService.plugins) {
|
|
@@ -399,15 +424,20 @@ class RuntimeGenerator extends BaseGenerator {
|
|
|
399
424
|
}
|
|
400
425
|
}
|
|
401
426
|
allServicesDependencies = { ...allServicesDependencies, ...serviceInstance.config.dependencies }
|
|
402
|
-
await serviceInstance.prepare()
|
|
427
|
+
const afterPrepareMetadata = await serviceInstance.prepare()
|
|
403
428
|
await serviceInstance.writeFiles()
|
|
404
429
|
// cleanup runtime env removing keys not present anymore in service plugins
|
|
405
430
|
const allKeys = envTool.getKeys()
|
|
406
431
|
allKeys.forEach((k) => {
|
|
407
|
-
if (k.startsWith(
|
|
432
|
+
if (k.startsWith(`${serviceEnvPrefix}_FST_PLUGIN`) && !runtimeAddedEnvKeys.includes(k)) {
|
|
408
433
|
envTool.deleteKey(k)
|
|
409
434
|
}
|
|
410
435
|
})
|
|
436
|
+
|
|
437
|
+
// add service env variables to runtime env
|
|
438
|
+
Object.entries(afterPrepareMetadata.env).forEach(([key, value]) => {
|
|
439
|
+
envTool.addKey(key, value)
|
|
440
|
+
})
|
|
411
441
|
}
|
|
412
442
|
|
|
413
443
|
// update runtime package.json dependencies
|
package/lib/management-api.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
const { tmpdir, platform } = require('node:os')
|
|
4
4
|
const { join } = require('node:path')
|
|
5
|
-
const { readFile, mkdir,
|
|
5
|
+
const { readFile, mkdir, rm } = require('node:fs/promises')
|
|
6
6
|
const fastify = require('fastify')
|
|
7
7
|
const ws = require('ws')
|
|
8
8
|
const errors = require('./errors')
|
|
@@ -197,12 +197,12 @@ async function startManagementApi (configManager, runtimeApiClient) {
|
|
|
197
197
|
}
|
|
198
198
|
|
|
199
199
|
try {
|
|
200
|
-
await
|
|
201
|
-
await unlink(socketPath).catch((err) => {
|
|
200
|
+
await rm(runtimeTmpDir, { recursive: true, force: true }).catch((err) => {
|
|
202
201
|
if (err.code !== 'ENOENT') {
|
|
203
202
|
throw new errors.FailedToUnlinkManagementApiSocket(err.message)
|
|
204
203
|
}
|
|
205
204
|
})
|
|
205
|
+
await mkdir(runtimeTmpDir, { recursive: true })
|
|
206
206
|
|
|
207
207
|
const managementApi = await createManagementApi(
|
|
208
208
|
configManager,
|
|
@@ -211,7 +211,7 @@ async function startManagementApi (configManager, runtimeApiClient) {
|
|
|
211
211
|
|
|
212
212
|
if (platform() !== 'win32') {
|
|
213
213
|
managementApi.addHook('onClose', async () => {
|
|
214
|
-
await
|
|
214
|
+
await rm(runtimeTmpDir, { recursive: true, force: true }).catch()
|
|
215
215
|
})
|
|
216
216
|
}
|
|
217
217
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@platformatic/runtime",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.31.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"bin": {
|
|
@@ -33,8 +33,8 @@
|
|
|
33
33
|
"typescript": "^5.4.2",
|
|
34
34
|
"undici-oidc-interceptor": "^0.5.0",
|
|
35
35
|
"why-is-node-running": "^2.2.2",
|
|
36
|
-
"@platformatic/sql-
|
|
37
|
-
"@platformatic/sql-
|
|
36
|
+
"@platformatic/sql-graphql": "1.31.1",
|
|
37
|
+
"@platformatic/sql-mapper": "1.31.1"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
40
|
"ws": "^8.16.0",
|
|
@@ -62,13 +62,13 @@
|
|
|
62
62
|
"tail-file-stream": "^0.1.0",
|
|
63
63
|
"undici": "^6.9.0",
|
|
64
64
|
"why-is-node-running": "^2.2.2",
|
|
65
|
-
"@platformatic/composer": "1.
|
|
66
|
-
"@platformatic/
|
|
67
|
-
"@platformatic/
|
|
68
|
-
"@platformatic/generators": "1.
|
|
69
|
-
"@platformatic/service": "1.
|
|
70
|
-
"@platformatic/telemetry": "1.
|
|
71
|
-
"@platformatic/utils": "1.
|
|
65
|
+
"@platformatic/composer": "1.31.1",
|
|
66
|
+
"@platformatic/config": "1.31.1",
|
|
67
|
+
"@platformatic/db": "1.31.1",
|
|
68
|
+
"@platformatic/generators": "1.31.1",
|
|
69
|
+
"@platformatic/service": "1.31.1",
|
|
70
|
+
"@platformatic/telemetry": "1.31.1",
|
|
71
|
+
"@platformatic/utils": "1.31.1"
|
|
72
72
|
},
|
|
73
73
|
"standard": {
|
|
74
74
|
"ignore": [
|