@friggframework/devtools 2.0.0--canary.731.44132f0.0 → 2.0.0--canary.730.541f199.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/infrastructure/README.md +0 -27
- package/infrastructure/__tests__/management-api-gateway-routes.test.js +0 -3
- package/infrastructure/__tests__/postgres-config.test.js +0 -3
- package/infrastructure/__tests__/scaffold-default-infrastructure.test.js +0 -3
- package/infrastructure/__tests__/scoped-environment.test.js +0 -3
- package/infrastructure/__tests__/ssm-preload-node-options.test.js +0 -3
- package/infrastructure/__tests__/template-generation.test.js +0 -3
- package/infrastructure/app-definition-schema-contract.test.js +0 -5
- package/infrastructure/domains/admin-scripts/admin-script-builder.js +0 -2
- package/infrastructure/domains/admin-scripts/admin-script-builder.test.js +0 -16
- package/infrastructure/domains/database/migration-builder.js +2 -21
- package/infrastructure/domains/database/migration-builder.test.js +0 -55
- package/infrastructure/domains/integration/integration-builder.js +0 -2
- package/infrastructure/domains/integration/integration-builder.test.js +0 -16
- package/infrastructure/domains/shared/utilities/base-definition-factory.js +1 -13
- package/infrastructure/domains/shared/utilities/base-definition-factory.test.js +0 -47
- package/infrastructure/domains/shared/utilities/prisma-layer-manager.js +12 -92
- package/infrastructure/domains/shared/utilities/prisma-layer-manager.test.js +6 -158
- package/infrastructure/infrastructure-composer.js +1 -12
- package/infrastructure/infrastructure-composer.test.js +0 -71
- package/infrastructure/scripts/build-prisma-layer.js +50 -136
- package/infrastructure/scripts/build-prisma-layer.test.js +0 -100
- package/package.json +7 -7
- package/infrastructure/__tests__/helpers/bundled-prisma-engine-excludes.js +0 -39
- package/infrastructure/domains/database/migration-engines.js +0 -88
- package/infrastructure/domains/database/migration-engines.test.js +0 -106
- package/infrastructure/domains/shared/lambda-architectures.js +0 -113
- package/infrastructure/domains/shared/lambda-architectures.test.js +0 -164
package/infrastructure/README.md
CHANGED
|
@@ -303,33 +303,6 @@ const appDefinition = {
|
|
|
303
303
|
|
|
304
304
|
Nested copies of `@friggframework/*`, `aws-sdk`, `@aws-sdk/*` and, when the Prisma layer is enabled, `@prisma/*` and `.prisma` stay excluded: the app's single core, the Lambda runtime and the layer provide them. Expect each function package to grow by the size of the nested directories that remain (a few MB compressed in a typical app). The default stays unchanged for apps that do not set the flag.
|
|
305
305
|
|
|
306
|
-
**Lambda architecture (arm64 / Graviton):**
|
|
307
|
-
|
|
308
|
-
Every function, the Prisma layer and the migration worker deploy as x86_64 unless the app definition sets `architecture`:
|
|
309
|
-
|
|
310
|
-
```javascript
|
|
311
|
-
const appDefinition = {
|
|
312
|
-
name: 'my-app',
|
|
313
|
-
architecture: 'arm64', // or 'x86_64'; unset keeps today's template
|
|
314
|
-
integrations: [{ Definition: { name: 'hubspot' } }],
|
|
315
|
-
};
|
|
316
|
-
```
|
|
317
|
-
|
|
318
|
-
An explicit value sets `provider.architecture` and the layer's `compatibleArchitectures`, builds the layer with that architecture's Prisma query engine, ships the migration worker with its schema engine and query engine library, and pins the migrate CLI to them through `PRISMA_SCHEMA_ENGINE_BINARY` and `PRISMA_QUERY_ENGINE_LIBRARY`. With `usePrismaLambdaLayer: false`, each function bundles only that engine. An unset key adds no field to the template.
|
|
319
|
-
|
|
320
|
-
Before you flip an app to `arm64`:
|
|
321
|
-
|
|
322
|
-
- It needs a `@friggframework/core` release whose generated Prisma clients include the `linux-arm64-openssl-3.0.x` engine (both schemas list it in `binaryTargets`). With an older core the layer build fails naming the core version.
|
|
323
|
-
- The deploy host must reach Prisma's engine CDN (`binaries.prisma.sh`) at package time: the migration worker's engines for the target are fetched there, and packaging fails if either is missing.
|
|
324
|
-
- This runs on every compose where the migration worker is enabled, and downloads only when the target's engines are missing from the app's `node_modules/@prisma/engines`.
|
|
325
|
-
- Air-gapped or offline deploy hosts set `PRISMA_ENGINES_MIRROR` to an internal mirror of the CDN. Prisma's download honours it (`@prisma/fetch-engine` 6.19.3, `dist/chunk-LONQL55G.js`, where the download URL is built from `PRISMA_BINARIES_MIRROR || PRISMA_ENGINES_MIRROR || "https://binaries.prisma.sh"`).
|
|
326
|
-
- The app must have `prisma` installed in its own `node_modules`, not only in a hoisted parent: the worker ships its engines from there, and packaging fails otherwise. The worker pins `PRISMA_SCHEMA_ENGINE_BINARY` and `PRISMA_QUERY_ENGINE_LIBRARY` to that `@prisma/engines`, so its version must match the Prisma version of `@friggframework/core`.
|
|
327
|
-
- Published core carries one more query engine per generated client (about 15 MB unpacked each).
|
|
328
|
-
- Native addons of the app itself (`sharp`, `bcrypt`, and the like) are built for the deploy host's architecture by `npm ci`, not for the target. Build them for arm64 or replace them.
|
|
329
|
-
- During the stack update, functions run mixed for a short time, so flip in a low-traffic window.
|
|
330
|
-
- The cached layer under `layers/prisma` rebuilds on the flip: its marker records the Prisma binary target, the client set and the core and `@prisma/client` versions, and a mismatch rebuilds.
|
|
331
|
-
- The first compose after upgrading to a Frigg release with this support rebuilds the Prisma layer once, because cache markers written by older releases never match.
|
|
332
|
-
|
|
333
306
|
## Usage Examples
|
|
334
307
|
|
|
335
308
|
### Basic Deployment
|
|
@@ -37,9 +37,6 @@ jest.mock('../domains/shared/resource-discovery', () => {
|
|
|
37
37
|
}),
|
|
38
38
|
};
|
|
39
39
|
});
|
|
40
|
-
jest.mock('../domains/database/migration-engines', () => ({
|
|
41
|
-
ensureMigrationEngines: jest.fn().mockResolvedValue(undefined),
|
|
42
|
-
}));
|
|
43
40
|
|
|
44
41
|
// createIntegrationRouter loads the app definition from the consuming
|
|
45
42
|
// backend; give it an empty one so the router can be built in isolation.
|
|
@@ -36,9 +36,6 @@ const accountWithDefaultVpc = (overrides = {}) => ({
|
|
|
36
36
|
defaultRouteTableId: 'rtb-12345',
|
|
37
37
|
...overrides,
|
|
38
38
|
});
|
|
39
|
-
jest.mock('../domains/database/migration-engines', () => ({
|
|
40
|
-
ensureMigrationEngines: jest.fn().mockResolvedValue(undefined),
|
|
41
|
-
}));
|
|
42
39
|
|
|
43
40
|
const postgresApp = (postgres, extra = {}) => ({
|
|
44
41
|
name: 'test-app',
|
|
@@ -146,6 +146,3 @@ describe('frigg init default infrastructure', () => {
|
|
|
146
146
|
expect(definition.provider.logRetentionInDays).toBe(14);
|
|
147
147
|
});
|
|
148
148
|
});
|
|
149
|
-
jest.mock('../domains/database/migration-engines', () => ({
|
|
150
|
-
ensureMigrationEngines: jest.fn().mockResolvedValue(undefined),
|
|
151
|
-
}));
|
|
@@ -24,9 +24,6 @@ jest.mock('../domains/shared/resource-discovery', () => {
|
|
|
24
24
|
}),
|
|
25
25
|
};
|
|
26
26
|
});
|
|
27
|
-
jest.mock('../domains/database/migration-engines', () => ({
|
|
28
|
-
ensureMigrationEngines: jest.fn().mockResolvedValue(undefined),
|
|
29
|
-
}));
|
|
30
27
|
|
|
31
28
|
const buildApp = (overrides = {}) => ({
|
|
32
29
|
name: 'scoped-test-app',
|
|
@@ -23,9 +23,6 @@ jest.mock('../domains/shared/resource-discovery', () => {
|
|
|
23
23
|
}),
|
|
24
24
|
};
|
|
25
25
|
});
|
|
26
|
-
jest.mock('../domains/database/migration-engines', () => ({
|
|
27
|
-
ensureMigrationEngines: jest.fn().mockResolvedValue(undefined),
|
|
28
|
-
}));
|
|
29
26
|
|
|
30
27
|
const buildApp = (overrides = {}) => ({
|
|
31
28
|
name: 'preload-test',
|
|
@@ -631,9 +631,6 @@ describe('CloudFormation Template Generation', () => {
|
|
|
631
631
|
});
|
|
632
632
|
});
|
|
633
633
|
});
|
|
634
|
-
jest.mock('../domains/database/migration-engines', () => ({
|
|
635
|
-
ensureMigrationEngines: jest.fn().mockResolvedValue(undefined),
|
|
636
|
-
}));
|
|
637
634
|
|
|
638
635
|
// Helper functions
|
|
639
636
|
function findAllRefs(obj, refs = []) {
|
|
@@ -40,9 +40,6 @@ jest.mock('./domains/shared/resource-discovery', () => {
|
|
|
40
40
|
const actual = jest.requireActual('./domains/shared/resource-discovery');
|
|
41
41
|
return { ...actual, gatherDiscoveredResources: jest.fn() };
|
|
42
42
|
});
|
|
43
|
-
jest.mock('./domains/database/migration-engines', () => ({
|
|
44
|
-
ensureMigrationEngines: jest.fn().mockResolvedValue(undefined),
|
|
45
|
-
}));
|
|
46
43
|
jest.mock('./domains/shared/utilities/prisma-layer-manager', () => ({
|
|
47
44
|
ensurePrismaLayerExists: jest.fn().mockResolvedValue(undefined),
|
|
48
45
|
}));
|
|
@@ -281,7 +278,6 @@ const MATRIX = {
|
|
|
281
278
|
},
|
|
282
279
|
lambda: { scopedEnvironment: true, keepNestedNodeModules: false },
|
|
283
280
|
usePrismaLambdaLayer: true,
|
|
284
|
-
architecture: 'x86_64',
|
|
285
281
|
}),
|
|
286
282
|
'frigg init scaffold (external db, no vpc)': () => ({
|
|
287
283
|
...base(),
|
|
@@ -298,7 +294,6 @@ const MATRIX = {
|
|
|
298
294
|
database: { postgres: { enable: true, management: 'external' } },
|
|
299
295
|
logging: { retentionInDays: 14 },
|
|
300
296
|
ssm: { enable: false },
|
|
301
|
-
architecture: 'arm64',
|
|
302
297
|
}),
|
|
303
298
|
'external db, encryption none': () => ({
|
|
304
299
|
...base(),
|
|
@@ -16,7 +16,6 @@
|
|
|
16
16
|
const { InfrastructureBuilder, ValidationResult } = require('../shared/base-builder');
|
|
17
17
|
const { isScopedEnvironmentActive } = require('../shared/function-environments');
|
|
18
18
|
const { nestedNodeModulesExcludes } = require('../shared/utilities/nested-node-modules');
|
|
19
|
-
const { bundledPrismaEngineExcludes } = require('../shared/lambda-architectures');
|
|
20
19
|
|
|
21
20
|
class AdminScriptBuilder extends InfrastructureBuilder {
|
|
22
21
|
constructor() {
|
|
@@ -413,7 +412,6 @@ class AdminScriptBuilder extends InfrastructureBuilder {
|
|
|
413
412
|
'node_modules/@friggframework/core/generated/**',
|
|
414
413
|
]
|
|
415
414
|
: []),
|
|
416
|
-
...bundledPrismaEngineExcludes(appDefinition, usePrismaLayer),
|
|
417
415
|
...nestedNodeModulesExcludes(appDefinition, usePrismaLayer),
|
|
418
416
|
'node_modules/@friggframework/test/**',
|
|
419
417
|
'node_modules/@friggframework/eslint-config/**',
|
|
@@ -10,7 +10,6 @@
|
|
|
10
10
|
|
|
11
11
|
const { AdminScriptBuilder } = require('./admin-script-builder');
|
|
12
12
|
const { ValidationResult } = require('../shared/base-builder');
|
|
13
|
-
const { itBundlesOnlyTheTargetPrismaEngine } = require('../../__tests__/helpers/bundled-prisma-engine-excludes');
|
|
14
13
|
|
|
15
14
|
describe('AdminScriptBuilder', () => {
|
|
16
15
|
let adminScriptBuilder;
|
|
@@ -964,21 +963,6 @@ describe('AdminScriptBuilder', () => {
|
|
|
964
963
|
});
|
|
965
964
|
});
|
|
966
965
|
|
|
967
|
-
describe('Lambda architecture with usePrismaLambdaLayer=false', () => {
|
|
968
|
-
const functionsOf = async (usePrismaLambdaLayer, architecture) => {
|
|
969
|
-
const result = await adminScriptBuilder.build(
|
|
970
|
-
{
|
|
971
|
-
adminScripts: [{ Definition: { name: 'cleanup' } }],
|
|
972
|
-
usePrismaLambdaLayer,
|
|
973
|
-
...(architecture && { architecture }),
|
|
974
|
-
},
|
|
975
|
-
{}
|
|
976
|
-
);
|
|
977
|
-
return Object.values(result.functions);
|
|
978
|
-
};
|
|
979
|
-
itBundlesOnlyTheTargetPrismaEngine(functionsOf);
|
|
980
|
-
});
|
|
981
|
-
|
|
982
966
|
describe('getName()', () => {
|
|
983
967
|
it('should return AdminScriptBuilder', () => {
|
|
984
968
|
expect(adminScriptBuilder.getName()).toBe('AdminScriptBuilder');
|
|
@@ -16,12 +16,6 @@
|
|
|
16
16
|
const { InfrastructureBuilder, ValidationResult } = require('../shared/base-builder');
|
|
17
17
|
const { isScopedEnvironmentActive } = require('../shared/function-environments');
|
|
18
18
|
const { nestedNodeModulesExcludes } = require('../shared/utilities/nested-node-modules');
|
|
19
|
-
const {
|
|
20
|
-
resolveLambdaArchitecture,
|
|
21
|
-
PRISMA_ENGINES_PACKAGE_DIR,
|
|
22
|
-
prismaEngineFileNames,
|
|
23
|
-
foreignPrismaEngineExcludes,
|
|
24
|
-
} = require('../shared/lambda-architectures');
|
|
25
19
|
const { MigrationResourceResolver } = require('./migration-resolver');
|
|
26
20
|
const { createEmptyDiscoveryResult, ResourceOwnership } = require('../shared/types');
|
|
27
21
|
|
|
@@ -245,9 +239,6 @@ class MigrationBuilder extends InfrastructureBuilder {
|
|
|
245
239
|
async createFunctionDefinitions(result, usePrismaLayer = true, appDefinition = {}) {
|
|
246
240
|
console.log(' 🔍 DEBUG: createFunctionDefinitions called');
|
|
247
241
|
console.log(' 🔍 DEBUG: result.functions is:', typeof result.functions, result.functions);
|
|
248
|
-
const architecture = resolveLambdaArchitecture(appDefinition);
|
|
249
|
-
const engineExcludes = foreignPrismaEngineExcludes(architecture.name);
|
|
250
|
-
const engines = prismaEngineFileNames(architecture.prismaBinaryTarget);
|
|
251
242
|
// Migration WORKER package config (needs Prisma CLI WASM files)
|
|
252
243
|
const migrationWorkerPackageConfig = {
|
|
253
244
|
individually: true,
|
|
@@ -302,14 +293,12 @@ class MigrationBuilder extends InfrastructureBuilder {
|
|
|
302
293
|
'node_modules/@friggframework/core/handlers/routers/integration-*.js',
|
|
303
294
|
'node_modules/@friggframework/core/handlers/workers/integration-*.js',
|
|
304
295
|
|
|
305
|
-
// Exclude
|
|
306
|
-
// stack does not run on
|
|
296
|
+
// Exclude wrong OS binaries
|
|
307
297
|
'**/query-engine-darwin*',
|
|
308
298
|
'**/schema-engine-darwin*',
|
|
309
299
|
'**/libquery_engine-darwin*',
|
|
310
300
|
'**/*-darwin-arm64*',
|
|
311
301
|
'**/*-darwin*',
|
|
312
|
-
...engineExcludes,
|
|
313
302
|
|
|
314
303
|
// Migration worker DOES need Prisma CLI WASM files (for migrate deploy)
|
|
315
304
|
// Only exclude runtime engine WASM (query engine internals)
|
|
@@ -396,14 +385,12 @@ class MigrationBuilder extends InfrastructureBuilder {
|
|
|
396
385
|
'node_modules/@friggframework/core/handlers/routers/integration-*.js',
|
|
397
386
|
'node_modules/@friggframework/core/handlers/workers/**',
|
|
398
387
|
|
|
399
|
-
// Exclude
|
|
400
|
-
// stack does not run on
|
|
388
|
+
// Exclude wrong OS binaries
|
|
401
389
|
'**/query-engine-darwin*',
|
|
402
390
|
'**/schema-engine-darwin*',
|
|
403
391
|
'**/libquery_engine-darwin*',
|
|
404
392
|
'**/*-darwin-arm64*',
|
|
405
393
|
'**/*-darwin*',
|
|
406
|
-
...engineExcludes,
|
|
407
394
|
|
|
408
395
|
// Router doesn't run migrations - exclude ALL WASM files
|
|
409
396
|
'**/runtime/*.wasm',
|
|
@@ -451,12 +438,6 @@ class MigrationBuilder extends InfrastructureBuilder {
|
|
|
451
438
|
environment: {
|
|
452
439
|
// Ensure migration functions get DATABASE_URL from provider.environment
|
|
453
440
|
// Note: Serverless will merge this with provider.environment
|
|
454
|
-
|
|
455
|
-
// Pin the migrate CLI to the shipped engines. With these set,
|
|
456
|
-
// Prisma neither downloads an engine at cold start (into the
|
|
457
|
-
// read-only /var/task) nor picks another file.
|
|
458
|
-
PRISMA_SCHEMA_ENGINE_BINARY: `/var/task/${PRISMA_ENGINES_PACKAGE_DIR}/${engines.schemaEngine}`,
|
|
459
|
-
PRISMA_QUERY_ENGINE_LIBRARY: `/var/task/${PRISMA_ENGINES_PACKAGE_DIR}/${engines.queryEngineLibrary}`,
|
|
460
441
|
},
|
|
461
442
|
events: [
|
|
462
443
|
{
|
|
@@ -322,61 +322,6 @@ describe('MigrationBuilder', () => {
|
|
|
322
322
|
});
|
|
323
323
|
});
|
|
324
324
|
|
|
325
|
-
describe('Lambda architecture (architecture)', () => {
|
|
326
|
-
const baseAppDefinition = { database: { postgres: { enable: true } } };
|
|
327
|
-
const workerAndRouter = (result) => [
|
|
328
|
-
result.functions.dbMigrationWorker,
|
|
329
|
-
result.functions.dbMigrationRouter,
|
|
330
|
-
];
|
|
331
|
-
|
|
332
|
-
it.each([
|
|
333
|
-
[undefined, 'rhel-openssl-3.0.x', 'linux-arm64-openssl-3.0.x'],
|
|
334
|
-
['x86_64', 'rhel-openssl-3.0.x', 'linux-arm64-openssl-3.0.x'],
|
|
335
|
-
['arm64', 'linux-arm64-openssl-3.0.x', 'rhel-openssl-3.0.x'],
|
|
336
|
-
])(
|
|
337
|
-
'with architecture %s the worker and router ship only the %s engines',
|
|
338
|
-
async (architecture, target, otherTarget) => {
|
|
339
|
-
const result = await builder.build(
|
|
340
|
-
{ ...baseAppDefinition, ...(architecture && { architecture }) },
|
|
341
|
-
{}
|
|
342
|
-
);
|
|
343
|
-
|
|
344
|
-
for (const fn of workerAndRouter(result)) {
|
|
345
|
-
expect(fn.package.exclude).toEqual(
|
|
346
|
-
expect.arrayContaining([
|
|
347
|
-
'**/libquery_engine-debian*',
|
|
348
|
-
'**/libquery_engine-linux-musl*',
|
|
349
|
-
`**/libquery_engine-${otherTarget}*`,
|
|
350
|
-
])
|
|
351
|
-
);
|
|
352
|
-
expect(fn.package.exclude).not.toContain(`**/libquery_engine-${target}*`);
|
|
353
|
-
}
|
|
354
|
-
}
|
|
355
|
-
);
|
|
356
|
-
|
|
357
|
-
it.each([
|
|
358
|
-
[undefined, 'rhel-openssl-3.0.x'],
|
|
359
|
-
['x86_64', 'rhel-openssl-3.0.x'],
|
|
360
|
-
['arm64', 'linux-arm64-openssl-3.0.x'],
|
|
361
|
-
])(
|
|
362
|
-
'with architecture %s the worker pins the migrate CLI to the shipped %s engines',
|
|
363
|
-
async (architecture, target) => {
|
|
364
|
-
const result = await builder.build(
|
|
365
|
-
{ ...baseAppDefinition, ...(architecture && { architecture }) },
|
|
366
|
-
{}
|
|
367
|
-
);
|
|
368
|
-
|
|
369
|
-
expect(result.functions.dbMigrationWorker.environment).toEqual(
|
|
370
|
-
expect.objectContaining({
|
|
371
|
-
PRISMA_SCHEMA_ENGINE_BINARY: `/var/task/node_modules/@prisma/engines/schema-engine-${target}`,
|
|
372
|
-
PRISMA_QUERY_ENGINE_LIBRARY: `/var/task/node_modules/@prisma/engines/libquery_engine-${target}.so.node`,
|
|
373
|
-
})
|
|
374
|
-
);
|
|
375
|
-
expect(result.functions.dbMigrationRouter.environment.PRISMA_SCHEMA_ENGINE_BINARY).toBeUndefined();
|
|
376
|
-
}
|
|
377
|
-
);
|
|
378
|
-
});
|
|
379
|
-
|
|
380
325
|
describe('scoped environment (lambda.scopedEnvironment)', () => {
|
|
381
326
|
beforeEach(() => {
|
|
382
327
|
delete process.env.FRIGG_SKIP_AWS_DISCOVERY;
|
|
@@ -32,7 +32,6 @@ const {
|
|
|
32
32
|
const {
|
|
33
33
|
nestedNodeModulesExcludes,
|
|
34
34
|
} = require('../shared/utilities/nested-node-modules');
|
|
35
|
-
const { bundledPrismaEngineExcludes } = require('../shared/lambda-architectures');
|
|
36
35
|
const {
|
|
37
36
|
INTEGRATION_QUEUE_MAX_RECEIVE_COUNT,
|
|
38
37
|
QUEUE_MAX_RECEIVE_COUNT_ENV,
|
|
@@ -269,7 +268,6 @@ class IntegrationBuilder extends InfrastructureBuilder {
|
|
|
269
268
|
'node_modules/@friggframework/core/generated/**',
|
|
270
269
|
]
|
|
271
270
|
: []),
|
|
272
|
-
...bundledPrismaEngineExcludes(appDefinition, usePrismaLayer),
|
|
273
271
|
|
|
274
272
|
...nestedNodeModulesExcludes(appDefinition, usePrismaLayer),
|
|
275
273
|
|
|
@@ -10,7 +10,6 @@ const {
|
|
|
10
10
|
} = require('@friggframework/core/queues/queue-delivery');
|
|
11
11
|
const { IntegrationBuilder } = require('./integration-builder');
|
|
12
12
|
const { ValidationResult } = require('../shared/base-builder');
|
|
13
|
-
const { itBundlesOnlyTheTargetPrismaEngine } = require('../../__tests__/helpers/bundled-prisma-engine-excludes');
|
|
14
13
|
|
|
15
14
|
describe('IntegrationBuilder', () => {
|
|
16
15
|
let integrationBuilder;
|
|
@@ -1086,21 +1085,6 @@ describe('IntegrationBuilder', () => {
|
|
|
1086
1085
|
});
|
|
1087
1086
|
|
|
1088
1087
|
|
|
1089
|
-
describe('IntegrationBuilder Lambda architecture with usePrismaLambdaLayer=false', () => {
|
|
1090
|
-
const functionsOf = async (usePrismaLambdaLayer, architecture) => {
|
|
1091
|
-
const result = await new IntegrationBuilder().build(
|
|
1092
|
-
{
|
|
1093
|
-
integrations: [{ Definition: { name: 'crm' } }],
|
|
1094
|
-
usePrismaLambdaLayer,
|
|
1095
|
-
...(architecture && { architecture }),
|
|
1096
|
-
},
|
|
1097
|
-
{}
|
|
1098
|
-
);
|
|
1099
|
-
return Object.values(result.functions);
|
|
1100
|
-
};
|
|
1101
|
-
itBundlesOnlyTheTargetPrismaEngine(functionsOf);
|
|
1102
|
-
});
|
|
1103
|
-
|
|
1104
1088
|
describe('IntegrationBuilder nested node_modules (lambda.keepNestedNodeModules)', () => {
|
|
1105
1089
|
const appDefinition = (lambda) => ({
|
|
1106
1090
|
integrations: [{ Definition: { name: 'test', webhooks: true } }],
|
|
@@ -10,10 +10,6 @@
|
|
|
10
10
|
const { buildEnvironment } = require('../environment-builder');
|
|
11
11
|
const { nestedNodeModulesExcludes } = require('./nested-node-modules');
|
|
12
12
|
const { buildLoggingProviderConfig } = require('./logging-config');
|
|
13
|
-
const {
|
|
14
|
-
resolveLambdaArchitecture,
|
|
15
|
-
bundledPrismaEngineExcludes,
|
|
16
|
-
} = require('../lambda-architectures');
|
|
17
13
|
|
|
18
14
|
/**
|
|
19
15
|
* Create base serverless definition with core functions and resources
|
|
@@ -39,8 +35,6 @@ function createBaseDefinition(
|
|
|
39
35
|
) {
|
|
40
36
|
const region = process.env.AWS_REGION || 'us-east-1';
|
|
41
37
|
const loggingConfig = buildLoggingProviderConfig(AppDefinition.logging);
|
|
42
|
-
const architecture = resolveLambdaArchitecture(AppDefinition);
|
|
43
|
-
const bundledEngineExcludes = bundledPrismaEngineExcludes(AppDefinition, usePrismaLayer);
|
|
44
38
|
|
|
45
39
|
// Package config for handlers that skip esbuild (need node_modules dependencies)
|
|
46
40
|
// Include backend src/ and index.js since handlers load the app definition
|
|
@@ -60,7 +54,6 @@ function createBaseDefinition(
|
|
|
60
54
|
'node_modules/prisma/**',
|
|
61
55
|
'node_modules/@friggframework/core/generated/**',
|
|
62
56
|
] : []),
|
|
63
|
-
...bundledEngineExcludes,
|
|
64
57
|
|
|
65
58
|
// Exclude AWS SDK (provided by Lambda runtime)
|
|
66
59
|
'node_modules/aws-sdk/**',
|
|
@@ -134,7 +127,6 @@ function createBaseDefinition(
|
|
|
134
127
|
'node_modules/prisma/**',
|
|
135
128
|
'node_modules/@friggframework/core/generated/**',
|
|
136
129
|
] : []),
|
|
137
|
-
...bundledEngineExcludes,
|
|
138
130
|
|
|
139
131
|
// Exclude nested node_modules from symlinked frigg packages (for npm link development)
|
|
140
132
|
'node_modules/@friggframework/core/node_modules/**',
|
|
@@ -186,7 +178,6 @@ function createBaseDefinition(
|
|
|
186
178
|
name: AppDefinition.provider || 'aws',
|
|
187
179
|
...(process.env.AWS_PROFILE && { profile: process.env.AWS_PROFILE }),
|
|
188
180
|
runtime: 'nodejs22.x', // Node.js 22.x (latest Lambda runtime with AWS SDK v3)
|
|
189
|
-
...(architecture.explicit && { architecture: architecture.name }),
|
|
190
181
|
timeout: 29, // Set to 29s to give buffer before API Gateway's 30s timeout
|
|
191
182
|
region,
|
|
192
183
|
stage: '${opt:stage}',
|
|
@@ -350,11 +341,8 @@ function createBaseDefinition(
|
|
|
350
341
|
prisma: {
|
|
351
342
|
path: 'layers/prisma',
|
|
352
343
|
name: '${self:service}-prisma-${sls:stage}',
|
|
353
|
-
description: 'Prisma runtime client only (NO CLI) with
|
|
344
|
+
description: 'Prisma runtime client only (NO CLI) with rhel-openssl-3.0.x binaries (~10-15MB). CLI packaged separately in dbMigrate function.',
|
|
354
345
|
compatibleRuntimes: ['nodejs20.x', 'nodejs22.x'],
|
|
355
|
-
...(architecture.explicit && {
|
|
356
|
-
compatibleArchitectures: [architecture.name],
|
|
357
|
-
}),
|
|
358
346
|
retain: false,
|
|
359
347
|
},
|
|
360
348
|
} : {},
|
|
@@ -5,7 +5,6 @@
|
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
const { createBaseDefinition } = require('./base-definition-factory');
|
|
8
|
-
const { itBundlesOnlyTheTargetPrismaEngine } = require('../../../__tests__/helpers/bundled-prisma-engine-excludes');
|
|
9
8
|
|
|
10
9
|
describe('Base Definition Factory', () => {
|
|
11
10
|
beforeEach(() => {
|
|
@@ -324,52 +323,6 @@ describe('Base Definition Factory', () => {
|
|
|
324
323
|
});
|
|
325
324
|
|
|
326
325
|
|
|
327
|
-
describe('Lambda architecture (architecture)', () => {
|
|
328
|
-
const build = (appDefinition) => createBaseDefinition(appDefinition, {}, {}, true);
|
|
329
|
-
|
|
330
|
-
it('adds no architecture fields when the key is unset, so existing templates do not change', () => {
|
|
331
|
-
const result = build({ name: 'test-app' });
|
|
332
|
-
|
|
333
|
-
expect(result.provider.architecture).toBeUndefined();
|
|
334
|
-
expect(result.layers.prisma.compatibleArchitectures).toBeUndefined();
|
|
335
|
-
});
|
|
336
|
-
|
|
337
|
-
it.each(['x86_64', 'arm64'])(
|
|
338
|
-
'sets provider.architecture and the layer compatibleArchitectures to %s when set',
|
|
339
|
-
(architecture) => {
|
|
340
|
-
const result = build({ name: 'test-app', architecture });
|
|
341
|
-
|
|
342
|
-
expect(result.provider.architecture).toBe(architecture);
|
|
343
|
-
expect(result.layers.prisma.compatibleArchitectures).toEqual([architecture]);
|
|
344
|
-
}
|
|
345
|
-
);
|
|
346
|
-
|
|
347
|
-
it('describes the layer without naming an engine, since the engine follows the architecture', () => {
|
|
348
|
-
const result = build({ name: 'test-app' });
|
|
349
|
-
|
|
350
|
-
expect(result.layers.prisma.description).not.toContain('rhel');
|
|
351
|
-
});
|
|
352
|
-
|
|
353
|
-
it('rejects an architecture the registry does not know', () => {
|
|
354
|
-
expect(() => build({ name: 'test-app', architecture: 'aarch64' })).toThrow(
|
|
355
|
-
/aarch64/
|
|
356
|
-
);
|
|
357
|
-
});
|
|
358
|
-
});
|
|
359
|
-
|
|
360
|
-
describe('Lambda architecture with usePrismaLambdaLayer=false', () => {
|
|
361
|
-
const functionsOf = (usePrismaLayer, architecture) => {
|
|
362
|
-
const result = createBaseDefinition(
|
|
363
|
-
{ name: 'test-app', ...(architecture && { architecture }) },
|
|
364
|
-
{},
|
|
365
|
-
{},
|
|
366
|
-
usePrismaLayer
|
|
367
|
-
);
|
|
368
|
-
return Object.values(result.functions);
|
|
369
|
-
};
|
|
370
|
-
itBundlesOnlyTheTargetPrismaEngine(functionsOf);
|
|
371
|
-
});
|
|
372
|
-
|
|
373
326
|
describe('nested node_modules (lambda.keepNestedNodeModules)', () => {
|
|
374
327
|
const build = (appDefinition) => createBaseDefinition(appDefinition, {}, {}, true);
|
|
375
328
|
|
|
@@ -9,11 +9,7 @@
|
|
|
9
9
|
|
|
10
10
|
const path = require('path');
|
|
11
11
|
const fs = require('fs');
|
|
12
|
-
const {
|
|
13
|
-
buildPrismaLayer,
|
|
14
|
-
layerBuildInputs,
|
|
15
|
-
} = require('../../../scripts/build-prisma-layer');
|
|
16
|
-
const { resolveLambdaArchitecture } = require('../lambda-architectures');
|
|
12
|
+
const { buildPrismaLayer } = require('../../../scripts/build-prisma-layer');
|
|
17
13
|
|
|
18
14
|
/**
|
|
19
15
|
* Check if a process is still running
|
|
@@ -30,48 +26,6 @@ function isProcessRunning(pid) {
|
|
|
30
26
|
}
|
|
31
27
|
}
|
|
32
28
|
|
|
33
|
-
const LEGACY_MARKER_TARGET = 'rhel-openssl-3.0.x';
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* The inputs a completion marker records. A marker written before the
|
|
37
|
-
* marker became JSON recorded nothing, and every layer then held the rhel
|
|
38
|
-
* engine; its versions are unknown, so it never matches and the layer is
|
|
39
|
-
* rebuilt once.
|
|
40
|
-
* @param {string} markerText
|
|
41
|
-
* @returns {{ prismaBinaryTarget: string, clientPackages: string[]|null, coreVersion: string|null, prismaClientVersion: string|null }}
|
|
42
|
-
*/
|
|
43
|
-
function parseLayerMarker(markerText) {
|
|
44
|
-
try {
|
|
45
|
-
const marker = JSON.parse(markerText);
|
|
46
|
-
return {
|
|
47
|
-
prismaBinaryTarget: marker.prismaBinaryTarget,
|
|
48
|
-
clientPackages: marker.clientPackages,
|
|
49
|
-
coreVersion: marker.coreVersion,
|
|
50
|
-
prismaClientVersion: marker.prismaClientVersion,
|
|
51
|
-
};
|
|
52
|
-
} catch {
|
|
53
|
-
// A marker written before the JSON format is plain text: treat it as a legacy build
|
|
54
|
-
return {
|
|
55
|
-
prismaBinaryTarget: LEGACY_MARKER_TARGET,
|
|
56
|
-
clientPackages: null,
|
|
57
|
-
coreVersion: null,
|
|
58
|
-
prismaClientVersion: null,
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
function sameLayerInputs(a, b) {
|
|
64
|
-
return (
|
|
65
|
-
a.prismaBinaryTarget === b.prismaBinaryTarget &&
|
|
66
|
-
a.coreVersion === b.coreVersion &&
|
|
67
|
-
a.prismaClientVersion === b.prismaClientVersion &&
|
|
68
|
-
Array.isArray(a.clientPackages) &&
|
|
69
|
-
Array.isArray(b.clientPackages) &&
|
|
70
|
-
a.clientPackages.length === b.clientPackages.length &&
|
|
71
|
-
a.clientPackages.every((pkg, i) => pkg === b.clientPackages[i])
|
|
72
|
-
);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
29
|
/**
|
|
76
30
|
* Ensure Prisma Lambda Layer exists
|
|
77
31
|
*
|
|
@@ -80,38 +34,23 @@ function sameLayerInputs(a, b) {
|
|
|
80
34
|
* Prisma CLI is bundled separately in the dbMigrate function.
|
|
81
35
|
*
|
|
82
36
|
* Domain Concept: Build Completion State & Process Locking
|
|
83
|
-
* - Uses .build-complete marker file to track successful builds
|
|
84
|
-
* the inputs the layer was built from, and a built layer is reused only
|
|
85
|
-
* when they match the requested ones
|
|
37
|
+
* - Uses .build-complete marker file to track successful builds
|
|
86
38
|
* - Uses .build-lock PID file to prevent concurrent builds
|
|
87
39
|
* - Waits for active builds to complete before starting new one
|
|
88
40
|
* - Cleans stale locks and incomplete builds before retry
|
|
89
41
|
*
|
|
90
|
-
* @param {Object}
|
|
91
|
-
* @param {Object} options.databaseConfig - Database configuration from app definition
|
|
92
|
-
* @param {string} options.prismaBinaryTarget - The engine the deployed architecture loads
|
|
42
|
+
* @param {Object} databaseConfig - Database configuration from app definition
|
|
93
43
|
* @returns {Promise<void>}
|
|
94
44
|
* @throws {Error} If layer build fails
|
|
95
45
|
*/
|
|
96
|
-
async function ensurePrismaLayerExists({
|
|
97
|
-
databaseConfig = {},
|
|
98
|
-
prismaBinaryTarget = resolveLambdaArchitecture().prismaBinaryTarget,
|
|
99
|
-
} = {}) {
|
|
46
|
+
async function ensurePrismaLayerExists(databaseConfig = {}) {
|
|
100
47
|
const projectRoot = process.cwd();
|
|
101
48
|
const layerPath = path.join(projectRoot, 'layers/prisma');
|
|
102
49
|
const completionMarkerPath = path.join(layerPath, '.build-complete');
|
|
103
50
|
const lockFilePath = path.join(layerPath, '.build-lock');
|
|
104
|
-
const inputs = layerBuildInputs({ databaseConfig, prismaBinaryTarget });
|
|
105
|
-
|
|
106
|
-
const builtLayerMatches = () =>
|
|
107
|
-
fs.existsSync(completionMarkerPath) &&
|
|
108
|
-
sameLayerInputs(
|
|
109
|
-
parseLayerMarker(fs.readFileSync(completionMarkerPath, 'utf-8')),
|
|
110
|
-
inputs
|
|
111
|
-
);
|
|
112
51
|
|
|
113
52
|
// Check if build is complete (marker exists)
|
|
114
|
-
if (
|
|
53
|
+
if (fs.existsSync(completionMarkerPath)) {
|
|
115
54
|
console.log('✓ Prisma Lambda Layer already exists at', layerPath);
|
|
116
55
|
return;
|
|
117
56
|
}
|
|
@@ -129,13 +68,8 @@ async function ensurePrismaLayerExists({
|
|
|
129
68
|
|
|
130
69
|
// Check if build completed
|
|
131
70
|
if (fs.existsSync(completionMarkerPath)) {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
return;
|
|
135
|
-
}
|
|
136
|
-
console.log('⚠ Concurrent build completed for other inputs - rebuilding');
|
|
137
|
-
fs.rmSync(lockFilePath, { force: true });
|
|
138
|
-
break;
|
|
71
|
+
console.log('✓ Concurrent build completed successfully');
|
|
72
|
+
return;
|
|
139
73
|
}
|
|
140
74
|
|
|
141
75
|
// Check if process died
|
|
@@ -147,16 +81,14 @@ async function ensurePrismaLayerExists({
|
|
|
147
81
|
}
|
|
148
82
|
|
|
149
83
|
// Timeout - check one final time
|
|
150
|
-
if (
|
|
84
|
+
if (fs.existsSync(completionMarkerPath)) {
|
|
151
85
|
console.log('✓ Concurrent build completed');
|
|
152
86
|
return;
|
|
153
87
|
}
|
|
154
88
|
|
|
155
89
|
// Still locked after 60s - remove stale lock
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
fs.rmSync(lockFilePath, { force: true });
|
|
159
|
-
}
|
|
90
|
+
console.log('⚠ Build timeout - removing stale lock and rebuilding');
|
|
91
|
+
fs.rmSync(lockFilePath, { force: true });
|
|
160
92
|
} else {
|
|
161
93
|
// Stale lock file (process not running)
|
|
162
94
|
console.log(`⚠ Stale lock file detected (PID ${lockPid} not running) - cleaning up`);
|
|
@@ -167,8 +99,6 @@ async function ensurePrismaLayerExists({
|
|
|
167
99
|
// Check if incomplete build exists (directory without marker)
|
|
168
100
|
if (fs.existsSync(layerPath) && !fs.existsSync(completionMarkerPath)) {
|
|
169
101
|
console.log('⚠ Incomplete Prisma layer detected - will be cleaned by buildPrismaLayer()');
|
|
170
|
-
} else if (fs.existsSync(completionMarkerPath)) {
|
|
171
|
-
console.log(`⚠ Built Prisma layer does not match ${JSON.stringify(inputs)} - rebuilding`);
|
|
172
102
|
}
|
|
173
103
|
|
|
174
104
|
// Build layer
|
|
@@ -189,21 +119,12 @@ async function ensurePrismaLayerExists({
|
|
|
189
119
|
|
|
190
120
|
try {
|
|
191
121
|
// Build layer WITHOUT CLI (runtime only for minimal size)
|
|
192
|
-
await buildPrismaLayer(
|
|
122
|
+
await buildPrismaLayer(databaseConfig);
|
|
193
123
|
|
|
194
124
|
// Create completion marker
|
|
195
125
|
fs.writeFileSync(
|
|
196
126
|
completionMarkerPath,
|
|
197
|
-
|
|
198
|
-
{
|
|
199
|
-
...inputs,
|
|
200
|
-
builtAt: new Date().toISOString(),
|
|
201
|
-
node: process.version,
|
|
202
|
-
platform: process.platform,
|
|
203
|
-
},
|
|
204
|
-
null,
|
|
205
|
-
2
|
|
206
|
-
)
|
|
127
|
+
`Build completed: ${new Date().toISOString()}\nNode: ${process.version}\nPlatform: ${process.platform}\n`
|
|
207
128
|
);
|
|
208
129
|
|
|
209
130
|
console.log('✓ Prisma Lambda Layer built successfully (~10-15MB)\n');
|
|
@@ -234,6 +155,5 @@ async function ensurePrismaLayerExists({
|
|
|
234
155
|
|
|
235
156
|
module.exports = {
|
|
236
157
|
ensurePrismaLayerExists,
|
|
237
|
-
parseLayerMarker,
|
|
238
158
|
};
|
|
239
159
|
|