@friggframework/devtools 2.0.0--canary.728.ee615d5.0 → 2.0.0--canary.731.fbc1a37.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 +27 -0
- package/infrastructure/__tests__/management-api-gateway-routes.test.js +3 -0
- package/infrastructure/__tests__/postgres-config.test.js +3 -0
- package/infrastructure/__tests__/scaffold-default-infrastructure.test.js +3 -0
- package/infrastructure/__tests__/scoped-environment.test.js +3 -0
- package/infrastructure/__tests__/ssm-preload-node-options.test.js +3 -0
- package/infrastructure/__tests__/template-generation.test.js +3 -0
- package/infrastructure/app-definition-schema-contract.test.js +5 -0
- package/infrastructure/domains/admin-scripts/admin-script-builder.js +7 -1
- package/infrastructure/domains/admin-scripts/admin-script-builder.test.js +43 -0
- package/infrastructure/domains/database/migration-builder.js +21 -2
- package/infrastructure/domains/database/migration-builder.test.js +55 -0
- package/infrastructure/domains/database/migration-engines.js +88 -0
- package/infrastructure/domains/database/migration-engines.test.js +106 -0
- package/infrastructure/domains/integration/integration-builder.js +7 -1
- package/infrastructure/domains/integration/integration-builder.test.js +43 -0
- package/infrastructure/domains/shared/lambda-architectures.js +99 -0
- package/infrastructure/domains/shared/lambda-architectures.test.js +147 -0
- package/infrastructure/domains/shared/utilities/base-definition-factory.js +16 -1
- package/infrastructure/domains/shared/utilities/base-definition-factory.test.js +74 -0
- package/infrastructure/domains/shared/utilities/prisma-layer-manager.js +91 -12
- package/infrastructure/domains/shared/utilities/prisma-layer-manager.test.js +158 -6
- package/infrastructure/infrastructure-composer.js +12 -1
- package/infrastructure/infrastructure-composer.test.js +71 -0
- package/infrastructure/scripts/build-prisma-layer.js +136 -50
- package/infrastructure/scripts/build-prisma-layer.test.js +100 -0
- package/package.json +7 -7
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lambda architectures and the Prisma engine each one runs.
|
|
3
|
+
*
|
|
4
|
+
* The registry keys are the AWS architecture names, so they go into
|
|
5
|
+
* `provider.architecture` and the layer `compatibleArchitectures` as they
|
|
6
|
+
* are. Every architecture-dependent value (layer build, layer cache key,
|
|
7
|
+
* migration worker engines, package excludes) reads from here.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
const LAMBDA_ARCHITECTURES = {
|
|
11
|
+
x86_64: { prismaBinaryTarget: 'rhel-openssl-3.0.x' },
|
|
12
|
+
arm64: { prismaBinaryTarget: 'linux-arm64-openssl-3.0.x' },
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
const DEFAULT_LAMBDA_ARCHITECTURE = 'x86_64';
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @param {Object} appDefinition
|
|
19
|
+
* @returns {{ name: string, prismaBinaryTarget: string, explicit: boolean }}
|
|
20
|
+
* `explicit` is false when the app definition does not set `architecture`,
|
|
21
|
+
* so callers can leave the template unchanged for existing apps.
|
|
22
|
+
* @throws {Error} on an architecture the registry does not know
|
|
23
|
+
*/
|
|
24
|
+
function resolveLambdaArchitecture(appDefinition = {}) {
|
|
25
|
+
const explicit = appDefinition.architecture !== undefined;
|
|
26
|
+
const name = explicit
|
|
27
|
+
? appDefinition.architecture
|
|
28
|
+
: DEFAULT_LAMBDA_ARCHITECTURE;
|
|
29
|
+
const entry = LAMBDA_ARCHITECTURES[name];
|
|
30
|
+
if (!entry) {
|
|
31
|
+
throw new Error(
|
|
32
|
+
`Unknown Lambda architecture '${name}'. ` +
|
|
33
|
+
`Set architecture to one of: ${Object.keys(
|
|
34
|
+
LAMBDA_ARCHITECTURES
|
|
35
|
+
).join(', ')}`
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
return { name, prismaBinaryTarget: entry.prismaBinaryTarget, explicit };
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** Where the migration worker's engines live, relative to the app root and to /var/task. */
|
|
42
|
+
const PRISMA_ENGINES_PACKAGE_DIR = 'node_modules/@prisma/engines';
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* The two engine files `prisma migrate` needs for a target, as
|
|
46
|
+
* @prisma/engines names them.
|
|
47
|
+
* @param {string} prismaBinaryTarget
|
|
48
|
+
* @returns {{ schemaEngine: string, queryEngineLibrary: string }}
|
|
49
|
+
*/
|
|
50
|
+
function prismaEngineFileNames(prismaBinaryTarget) {
|
|
51
|
+
return {
|
|
52
|
+
schemaEngine: `schema-engine-${prismaBinaryTarget}`,
|
|
53
|
+
queryEngineLibrary: `libquery_engine-${prismaBinaryTarget}.so.node`,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const PRISMA_ENGINE_FILE_PREFIXES = [
|
|
58
|
+
'libquery_engine-',
|
|
59
|
+
'query-engine-',
|
|
60
|
+
'query_engine-',
|
|
61
|
+
'schema-engine-',
|
|
62
|
+
];
|
|
63
|
+
|
|
64
|
+
const HOST_PLATFORM_ENGINE_TOKENS = [
|
|
65
|
+
'darwin',
|
|
66
|
+
'debian',
|
|
67
|
+
'linux-musl',
|
|
68
|
+
'windows',
|
|
69
|
+
];
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Package exclude patterns for every Prisma engine file the named
|
|
73
|
+
* architecture does not load: the deploy host's own platforms and the other
|
|
74
|
+
* Lambda architectures. Each pattern starts with an engine file prefix, so a
|
|
75
|
+
* runtime dependency that only has a platform word in its name is kept.
|
|
76
|
+
* @param {string} name - A registry key
|
|
77
|
+
* @returns {string[]}
|
|
78
|
+
*/
|
|
79
|
+
function foreignPrismaEngineExcludes(name) {
|
|
80
|
+
const foreignTokens = [
|
|
81
|
+
...HOST_PLATFORM_ENGINE_TOKENS,
|
|
82
|
+
...Object.entries(LAMBDA_ARCHITECTURES)
|
|
83
|
+
.filter(([other]) => other !== name)
|
|
84
|
+
.map(([, { prismaBinaryTarget }]) => prismaBinaryTarget),
|
|
85
|
+
];
|
|
86
|
+
return PRISMA_ENGINE_FILE_PREFIXES.flatMap((prefix) =>
|
|
87
|
+
foreignTokens.map((token) => `**/${prefix}${token}*`)
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
module.exports = {
|
|
92
|
+
LAMBDA_ARCHITECTURES,
|
|
93
|
+
DEFAULT_LAMBDA_ARCHITECTURE,
|
|
94
|
+
resolveLambdaArchitecture,
|
|
95
|
+
PRISMA_ENGINE_FILE_PREFIXES,
|
|
96
|
+
PRISMA_ENGINES_PACKAGE_DIR,
|
|
97
|
+
prismaEngineFileNames,
|
|
98
|
+
foreignPrismaEngineExcludes,
|
|
99
|
+
};
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
const micromatch = require('micromatch');
|
|
2
|
+
const {
|
|
3
|
+
LAMBDA_ARCHITECTURES,
|
|
4
|
+
resolveLambdaArchitecture,
|
|
5
|
+
prismaEngineFileNames,
|
|
6
|
+
foreignPrismaEngineExcludes,
|
|
7
|
+
} = require('./lambda-architectures');
|
|
8
|
+
|
|
9
|
+
describe('resolveLambdaArchitecture()', () => {
|
|
10
|
+
it('resolves to x86_64 with the rhel engine when the key is unset', () => {
|
|
11
|
+
expect(resolveLambdaArchitecture({})).toEqual({
|
|
12
|
+
name: 'x86_64',
|
|
13
|
+
prismaBinaryTarget: 'rhel-openssl-3.0.x',
|
|
14
|
+
explicit: false,
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it('resolves an explicit x86_64', () => {
|
|
19
|
+
expect(resolveLambdaArchitecture({ architecture: 'x86_64' })).toEqual({
|
|
20
|
+
name: 'x86_64',
|
|
21
|
+
prismaBinaryTarget: 'rhel-openssl-3.0.x',
|
|
22
|
+
explicit: true,
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it('resolves arm64 to the linux-arm64 engine', () => {
|
|
27
|
+
expect(resolveLambdaArchitecture({ architecture: 'arm64' })).toEqual({
|
|
28
|
+
name: 'arm64',
|
|
29
|
+
prismaBinaryTarget: 'linux-arm64-openssl-3.0.x',
|
|
30
|
+
explicit: true,
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it('throws on an unknown architecture, naming the accepted ones', () => {
|
|
35
|
+
expect(() =>
|
|
36
|
+
resolveLambdaArchitecture({ architecture: 'aarch64' })
|
|
37
|
+
).toThrow(/aarch64.*x86_64.*arm64/);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it('uses the AWS architecture names as registry keys', () => {
|
|
41
|
+
expect(Object.keys(LAMBDA_ARCHITECTURES)).toEqual(['x86_64', 'arm64']);
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
describe('prismaEngineFileNames()', () => {
|
|
46
|
+
it('names the schema engine and the query engine library the migrate CLI needs for a target', () => {
|
|
47
|
+
expect(prismaEngineFileNames('linux-arm64-openssl-3.0.x')).toEqual({
|
|
48
|
+
schemaEngine: 'schema-engine-linux-arm64-openssl-3.0.x',
|
|
49
|
+
queryEngineLibrary: 'libquery_engine-linux-arm64-openssl-3.0.x.so.node',
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
describe('foreignPrismaEngineExcludes()', () => {
|
|
55
|
+
const matches = (name, filePath) =>
|
|
56
|
+
micromatch([filePath], foreignPrismaEngineExcludes(name), {
|
|
57
|
+
dot: true,
|
|
58
|
+
}).length > 0;
|
|
59
|
+
|
|
60
|
+
const foreignEngineFiles = {
|
|
61
|
+
x86_64: [
|
|
62
|
+
'node_modules/@prisma/engines/libquery_engine-darwin-arm64.dylib.node',
|
|
63
|
+
'node_modules/@prisma/engines/schema-engine-darwin-arm64',
|
|
64
|
+
'node_modules/.prisma/client/query_engine-windows.dll.node',
|
|
65
|
+
'node_modules/@prisma/engines/query-engine-debian-openssl-3.0.x',
|
|
66
|
+
'node_modules/.prisma/client/libquery_engine-debian-openssl-3.0.x.so.node',
|
|
67
|
+
'node_modules/@prisma/engines/libquery_engine-linux-musl-openssl-3.0.x.so.node',
|
|
68
|
+
'node_modules/@prisma/engines/schema-engine-linux-arm64-openssl-3.0.x',
|
|
69
|
+
'node_modules/@prisma/engines/libquery_engine-linux-arm64-openssl-3.0.x.so.node',
|
|
70
|
+
],
|
|
71
|
+
arm64: [
|
|
72
|
+
'node_modules/@prisma/engines/libquery_engine-darwin-arm64.dylib.node',
|
|
73
|
+
'node_modules/.prisma/client/query_engine-windows.dll.node',
|
|
74
|
+
'node_modules/@prisma/engines/libquery_engine-linux-musl-openssl-3.0.x.so.node',
|
|
75
|
+
'node_modules/@prisma/engines/schema-engine-rhel-openssl-3.0.x',
|
|
76
|
+
'node_modules/@prisma/engines/libquery_engine-rhel-openssl-3.0.x.so.node',
|
|
77
|
+
],
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
const targetEngineFiles = {
|
|
81
|
+
x86_64: [
|
|
82
|
+
'node_modules/@prisma/engines/schema-engine-rhel-openssl-3.0.x',
|
|
83
|
+
'node_modules/@prisma/engines/libquery_engine-rhel-openssl-3.0.x.so.node',
|
|
84
|
+
],
|
|
85
|
+
arm64: [
|
|
86
|
+
'node_modules/@prisma/engines/schema-engine-linux-arm64-openssl-3.0.x',
|
|
87
|
+
'node_modules/@prisma/engines/libquery_engine-linux-arm64-openssl-3.0.x.so.node',
|
|
88
|
+
],
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
const nonEngineFiles = [
|
|
92
|
+
'node_modules/is-windows/index.js',
|
|
93
|
+
'node_modules/is-windows/package.json',
|
|
94
|
+
'node_modules/darwin-utils/lib/index.js',
|
|
95
|
+
'node_modules/some-pkg/lib/debian-release.js',
|
|
96
|
+
'node_modules/some-pkg/linux-musl-detect.js',
|
|
97
|
+
'node_modules/@prisma/engines/query_engine_bg.wasm',
|
|
98
|
+
'node_modules/.prisma/client/query_engine_bg.js',
|
|
99
|
+
'node_modules/some-pkg/dist/linux-arm64-notes.js',
|
|
100
|
+
'src/handlers/windows-handler.js',
|
|
101
|
+
];
|
|
102
|
+
|
|
103
|
+
it.each(['x86_64', 'arm64'])(
|
|
104
|
+
'matches every foreign engine file for %s',
|
|
105
|
+
(name) => {
|
|
106
|
+
foreignEngineFiles[name].forEach((file) =>
|
|
107
|
+
expect({ name, file, hit: matches(name, file) }).toEqual({
|
|
108
|
+
name,
|
|
109
|
+
file,
|
|
110
|
+
hit: true,
|
|
111
|
+
})
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
);
|
|
115
|
+
|
|
116
|
+
it.each(['x86_64', 'arm64'])(
|
|
117
|
+
'keeps the engine files of the %s target',
|
|
118
|
+
(name) => {
|
|
119
|
+
targetEngineFiles[name].forEach((file) =>
|
|
120
|
+
expect({ file, hit: matches(name, file) }).toEqual({
|
|
121
|
+
file,
|
|
122
|
+
hit: false,
|
|
123
|
+
})
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
);
|
|
127
|
+
|
|
128
|
+
it.each(['x86_64', 'arm64'])(
|
|
129
|
+
'keeps runtime files that only share a platform word with an engine for %s',
|
|
130
|
+
(name) => {
|
|
131
|
+
nonEngineFiles.forEach((file) =>
|
|
132
|
+
expect({ file, hit: matches(name, file) }).toEqual({
|
|
133
|
+
file,
|
|
134
|
+
hit: false,
|
|
135
|
+
})
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
);
|
|
139
|
+
|
|
140
|
+
it('never uses negation', () => {
|
|
141
|
+
['x86_64', 'arm64'].forEach((name) =>
|
|
142
|
+
foreignPrismaEngineExcludes(name).forEach((pattern) =>
|
|
143
|
+
expect(pattern.startsWith('!')).toBe(false)
|
|
144
|
+
)
|
|
145
|
+
);
|
|
146
|
+
});
|
|
147
|
+
});
|
|
@@ -10,6 +10,10 @@
|
|
|
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
|
+
foreignPrismaEngineExcludes,
|
|
16
|
+
} = require('../lambda-architectures');
|
|
13
17
|
|
|
14
18
|
/**
|
|
15
19
|
* Create base serverless definition with core functions and resources
|
|
@@ -35,6 +39,11 @@ function createBaseDefinition(
|
|
|
35
39
|
) {
|
|
36
40
|
const region = process.env.AWS_REGION || 'us-east-1';
|
|
37
41
|
const loggingConfig = buildLoggingProviderConfig(AppDefinition.logging);
|
|
42
|
+
const architecture = resolveLambdaArchitecture(AppDefinition);
|
|
43
|
+
// Bundled Prisma carries every generated engine; keep the target's only
|
|
44
|
+
const bundledEngineExcludes = usePrismaLayer
|
|
45
|
+
? []
|
|
46
|
+
: foreignPrismaEngineExcludes(architecture.name);
|
|
38
47
|
|
|
39
48
|
// Package config for handlers that skip esbuild (need node_modules dependencies)
|
|
40
49
|
// Include backend src/ and index.js since handlers load the app definition
|
|
@@ -54,6 +63,7 @@ function createBaseDefinition(
|
|
|
54
63
|
'node_modules/prisma/**',
|
|
55
64
|
'node_modules/@friggframework/core/generated/**',
|
|
56
65
|
] : []),
|
|
66
|
+
...bundledEngineExcludes,
|
|
57
67
|
|
|
58
68
|
// Exclude AWS SDK (provided by Lambda runtime)
|
|
59
69
|
'node_modules/aws-sdk/**',
|
|
@@ -127,6 +137,7 @@ function createBaseDefinition(
|
|
|
127
137
|
'node_modules/prisma/**',
|
|
128
138
|
'node_modules/@friggframework/core/generated/**',
|
|
129
139
|
] : []),
|
|
140
|
+
...bundledEngineExcludes,
|
|
130
141
|
|
|
131
142
|
// Exclude nested node_modules from symlinked frigg packages (for npm link development)
|
|
132
143
|
'node_modules/@friggframework/core/node_modules/**',
|
|
@@ -178,6 +189,7 @@ function createBaseDefinition(
|
|
|
178
189
|
name: AppDefinition.provider || 'aws',
|
|
179
190
|
...(process.env.AWS_PROFILE && { profile: process.env.AWS_PROFILE }),
|
|
180
191
|
runtime: 'nodejs22.x', // Node.js 22.x (latest Lambda runtime with AWS SDK v3)
|
|
192
|
+
...(architecture.explicit && { architecture: architecture.name }),
|
|
181
193
|
timeout: 29, // Set to 29s to give buffer before API Gateway's 30s timeout
|
|
182
194
|
region,
|
|
183
195
|
stage: '${opt:stage}',
|
|
@@ -341,8 +353,11 @@ function createBaseDefinition(
|
|
|
341
353
|
prisma: {
|
|
342
354
|
path: 'layers/prisma',
|
|
343
355
|
name: '${self:service}-prisma-${sls:stage}',
|
|
344
|
-
description: 'Prisma runtime client only (NO CLI) with
|
|
356
|
+
description: 'Prisma runtime client only (NO CLI) with the query engine for the deployed Lambda architecture (~10-15MB). CLI packaged separately in dbMigrate function.',
|
|
345
357
|
compatibleRuntimes: ['nodejs20.x', 'nodejs22.x'],
|
|
358
|
+
...(architecture.explicit && {
|
|
359
|
+
compatibleArchitectures: [architecture.name],
|
|
360
|
+
}),
|
|
346
361
|
retain: false,
|
|
347
362
|
},
|
|
348
363
|
} : {},
|
|
@@ -323,6 +323,80 @@ describe('Base Definition Factory', () => {
|
|
|
323
323
|
});
|
|
324
324
|
|
|
325
325
|
|
|
326
|
+
describe('Lambda architecture (architecture)', () => {
|
|
327
|
+
const build = (appDefinition) => createBaseDefinition(appDefinition, {}, {}, true);
|
|
328
|
+
|
|
329
|
+
it('adds no architecture fields when the key is unset, so existing templates do not change', () => {
|
|
330
|
+
const result = build({ name: 'test-app' });
|
|
331
|
+
|
|
332
|
+
expect(result.provider.architecture).toBeUndefined();
|
|
333
|
+
expect(result.layers.prisma.compatibleArchitectures).toBeUndefined();
|
|
334
|
+
});
|
|
335
|
+
|
|
336
|
+
it.each(['x86_64', 'arm64'])(
|
|
337
|
+
'sets provider.architecture and the layer compatibleArchitectures to %s when set',
|
|
338
|
+
(architecture) => {
|
|
339
|
+
const result = build({ name: 'test-app', architecture });
|
|
340
|
+
|
|
341
|
+
expect(result.provider.architecture).toBe(architecture);
|
|
342
|
+
expect(result.layers.prisma.compatibleArchitectures).toEqual([architecture]);
|
|
343
|
+
}
|
|
344
|
+
);
|
|
345
|
+
|
|
346
|
+
it('describes the layer without naming an engine, since the engine follows the architecture', () => {
|
|
347
|
+
const result = build({ name: 'test-app' });
|
|
348
|
+
|
|
349
|
+
expect(result.layers.prisma.description).not.toContain('rhel');
|
|
350
|
+
});
|
|
351
|
+
|
|
352
|
+
it('rejects an architecture the registry does not know', () => {
|
|
353
|
+
expect(() => build({ name: 'test-app', architecture: 'aarch64' })).toThrow(
|
|
354
|
+
/aarch64/
|
|
355
|
+
);
|
|
356
|
+
});
|
|
357
|
+
});
|
|
358
|
+
|
|
359
|
+
describe('Lambda architecture with usePrismaLambdaLayer=false', () => {
|
|
360
|
+
const functionsOf = (usePrismaLayer, architecture) => {
|
|
361
|
+
const result = createBaseDefinition(
|
|
362
|
+
{ name: 'test-app', ...(architecture && { architecture }) },
|
|
363
|
+
{},
|
|
364
|
+
{},
|
|
365
|
+
usePrismaLayer
|
|
366
|
+
);
|
|
367
|
+
return Object.values(result.functions);
|
|
368
|
+
};
|
|
369
|
+
const layerOff = (architecture) => functionsOf(false, architecture);
|
|
370
|
+
const layerOn = (architecture) => functionsOf(true, architecture);
|
|
371
|
+
|
|
372
|
+
it.each([
|
|
373
|
+
[undefined, 'rhel-openssl-3.0.x', 'linux-arm64-openssl-3.0.x'],
|
|
374
|
+
['x86_64', 'rhel-openssl-3.0.x', 'linux-arm64-openssl-3.0.x'],
|
|
375
|
+
['arm64', 'linux-arm64-openssl-3.0.x', 'rhel-openssl-3.0.x'],
|
|
376
|
+
])(
|
|
377
|
+
'with the layer off and architecture %s, the bundled Prisma keeps only the %s engine',
|
|
378
|
+
async (architecture, target, otherTarget) => {
|
|
379
|
+
for (const fn of await layerOff(architecture)) {
|
|
380
|
+
expect(fn.package.exclude).toEqual(
|
|
381
|
+
expect.arrayContaining(['**/libquery_engine-debian*', `**/libquery_engine-${otherTarget}*`])
|
|
382
|
+
);
|
|
383
|
+
expect(fn.package.exclude).not.toContain(`**/libquery_engine-${target}*`);
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
);
|
|
387
|
+
|
|
388
|
+
it('with the layer on, adds no engine patterns, since the layer carries the engines', async () => {
|
|
389
|
+
for (const fn of await layerOn('arm64')) {
|
|
390
|
+
expect(fn.package.exclude).not.toEqual(
|
|
391
|
+
expect.arrayContaining(['**/libquery_engine-rhel-openssl-3.0.x*'])
|
|
392
|
+
);
|
|
393
|
+
expect(fn.package.exclude).not.toEqual(
|
|
394
|
+
expect.arrayContaining(['**/libquery_engine-debian*'])
|
|
395
|
+
);
|
|
396
|
+
}
|
|
397
|
+
});
|
|
398
|
+
});
|
|
399
|
+
|
|
326
400
|
describe('nested node_modules (lambda.keepNestedNodeModules)', () => {
|
|
327
401
|
const build = (appDefinition) => createBaseDefinition(appDefinition, {}, {}, true);
|
|
328
402
|
|
|
@@ -9,7 +9,11 @@
|
|
|
9
9
|
|
|
10
10
|
const path = require('path');
|
|
11
11
|
const fs = require('fs');
|
|
12
|
-
const {
|
|
12
|
+
const {
|
|
13
|
+
buildPrismaLayer,
|
|
14
|
+
layerBuildInputs,
|
|
15
|
+
} = require('../../../scripts/build-prisma-layer');
|
|
16
|
+
const { resolveLambdaArchitecture } = require('../lambda-architectures');
|
|
13
17
|
|
|
14
18
|
/**
|
|
15
19
|
* Check if a process is still running
|
|
@@ -26,6 +30,47 @@ function isProcessRunning(pid) {
|
|
|
26
30
|
}
|
|
27
31
|
}
|
|
28
32
|
|
|
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 (error) {
|
|
53
|
+
return {
|
|
54
|
+
prismaBinaryTarget: LEGACY_MARKER_TARGET,
|
|
55
|
+
clientPackages: null,
|
|
56
|
+
coreVersion: null,
|
|
57
|
+
prismaClientVersion: null,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function sameLayerInputs(a, b) {
|
|
63
|
+
return (
|
|
64
|
+
a.prismaBinaryTarget === b.prismaBinaryTarget &&
|
|
65
|
+
a.coreVersion === b.coreVersion &&
|
|
66
|
+
a.prismaClientVersion === b.prismaClientVersion &&
|
|
67
|
+
Array.isArray(a.clientPackages) &&
|
|
68
|
+
Array.isArray(b.clientPackages) &&
|
|
69
|
+
a.clientPackages.length === b.clientPackages.length &&
|
|
70
|
+
a.clientPackages.every((pkg, i) => pkg === b.clientPackages[i])
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
|
|
29
74
|
/**
|
|
30
75
|
* Ensure Prisma Lambda Layer exists
|
|
31
76
|
*
|
|
@@ -34,23 +79,38 @@ function isProcessRunning(pid) {
|
|
|
34
79
|
* Prisma CLI is bundled separately in the dbMigrate function.
|
|
35
80
|
*
|
|
36
81
|
* Domain Concept: Build Completion State & Process Locking
|
|
37
|
-
* - Uses .build-complete marker file to track successful builds
|
|
82
|
+
* - Uses .build-complete marker file to track successful builds; it records
|
|
83
|
+
* the inputs the layer was built from, and a built layer is reused only
|
|
84
|
+
* when they match the requested ones
|
|
38
85
|
* - Uses .build-lock PID file to prevent concurrent builds
|
|
39
86
|
* - Waits for active builds to complete before starting new one
|
|
40
87
|
* - Cleans stale locks and incomplete builds before retry
|
|
41
88
|
*
|
|
42
|
-
* @param {Object}
|
|
89
|
+
* @param {Object} options
|
|
90
|
+
* @param {Object} options.databaseConfig - Database configuration from app definition
|
|
91
|
+
* @param {string} options.prismaBinaryTarget - The engine the deployed architecture loads
|
|
43
92
|
* @returns {Promise<void>}
|
|
44
93
|
* @throws {Error} If layer build fails
|
|
45
94
|
*/
|
|
46
|
-
async function ensurePrismaLayerExists(
|
|
95
|
+
async function ensurePrismaLayerExists({
|
|
96
|
+
databaseConfig = {},
|
|
97
|
+
prismaBinaryTarget = resolveLambdaArchitecture().prismaBinaryTarget,
|
|
98
|
+
} = {}) {
|
|
47
99
|
const projectRoot = process.cwd();
|
|
48
100
|
const layerPath = path.join(projectRoot, 'layers/prisma');
|
|
49
101
|
const completionMarkerPath = path.join(layerPath, '.build-complete');
|
|
50
102
|
const lockFilePath = path.join(layerPath, '.build-lock');
|
|
103
|
+
const inputs = layerBuildInputs({ databaseConfig, prismaBinaryTarget });
|
|
104
|
+
|
|
105
|
+
const builtLayerMatches = () =>
|
|
106
|
+
fs.existsSync(completionMarkerPath) &&
|
|
107
|
+
sameLayerInputs(
|
|
108
|
+
parseLayerMarker(fs.readFileSync(completionMarkerPath, 'utf-8')),
|
|
109
|
+
inputs
|
|
110
|
+
);
|
|
51
111
|
|
|
52
112
|
// Check if build is complete (marker exists)
|
|
53
|
-
if (
|
|
113
|
+
if (builtLayerMatches()) {
|
|
54
114
|
console.log('✓ Prisma Lambda Layer already exists at', layerPath);
|
|
55
115
|
return;
|
|
56
116
|
}
|
|
@@ -68,8 +128,13 @@ async function ensurePrismaLayerExists(databaseConfig = {}) {
|
|
|
68
128
|
|
|
69
129
|
// Check if build completed
|
|
70
130
|
if (fs.existsSync(completionMarkerPath)) {
|
|
71
|
-
|
|
72
|
-
|
|
131
|
+
if (builtLayerMatches()) {
|
|
132
|
+
console.log('✓ Concurrent build completed successfully');
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
console.log('⚠ Concurrent build completed for other inputs - rebuilding');
|
|
136
|
+
fs.rmSync(lockFilePath, { force: true });
|
|
137
|
+
break;
|
|
73
138
|
}
|
|
74
139
|
|
|
75
140
|
// Check if process died
|
|
@@ -81,14 +146,16 @@ async function ensurePrismaLayerExists(databaseConfig = {}) {
|
|
|
81
146
|
}
|
|
82
147
|
|
|
83
148
|
// Timeout - check one final time
|
|
84
|
-
if (
|
|
149
|
+
if (builtLayerMatches()) {
|
|
85
150
|
console.log('✓ Concurrent build completed');
|
|
86
151
|
return;
|
|
87
152
|
}
|
|
88
153
|
|
|
89
154
|
// Still locked after 60s - remove stale lock
|
|
90
|
-
|
|
91
|
-
|
|
155
|
+
if (fs.existsSync(lockFilePath)) {
|
|
156
|
+
console.log('⚠ Build timeout - removing stale lock and rebuilding');
|
|
157
|
+
fs.rmSync(lockFilePath, { force: true });
|
|
158
|
+
}
|
|
92
159
|
} else {
|
|
93
160
|
// Stale lock file (process not running)
|
|
94
161
|
console.log(`⚠ Stale lock file detected (PID ${lockPid} not running) - cleaning up`);
|
|
@@ -99,6 +166,8 @@ async function ensurePrismaLayerExists(databaseConfig = {}) {
|
|
|
99
166
|
// Check if incomplete build exists (directory without marker)
|
|
100
167
|
if (fs.existsSync(layerPath) && !fs.existsSync(completionMarkerPath)) {
|
|
101
168
|
console.log('⚠ Incomplete Prisma layer detected - will be cleaned by buildPrismaLayer()');
|
|
169
|
+
} else if (fs.existsSync(completionMarkerPath)) {
|
|
170
|
+
console.log(`⚠ Built Prisma layer does not match ${JSON.stringify(inputs)} - rebuilding`);
|
|
102
171
|
}
|
|
103
172
|
|
|
104
173
|
// Build layer
|
|
@@ -119,12 +188,21 @@ async function ensurePrismaLayerExists(databaseConfig = {}) {
|
|
|
119
188
|
|
|
120
189
|
try {
|
|
121
190
|
// Build layer WITHOUT CLI (runtime only for minimal size)
|
|
122
|
-
await buildPrismaLayer(databaseConfig);
|
|
191
|
+
await buildPrismaLayer({ databaseConfig, prismaBinaryTarget });
|
|
123
192
|
|
|
124
193
|
// Create completion marker
|
|
125
194
|
fs.writeFileSync(
|
|
126
195
|
completionMarkerPath,
|
|
127
|
-
|
|
196
|
+
JSON.stringify(
|
|
197
|
+
{
|
|
198
|
+
...inputs,
|
|
199
|
+
builtAt: new Date().toISOString(),
|
|
200
|
+
node: process.version,
|
|
201
|
+
platform: process.platform,
|
|
202
|
+
},
|
|
203
|
+
null,
|
|
204
|
+
2
|
|
205
|
+
)
|
|
128
206
|
);
|
|
129
207
|
|
|
130
208
|
console.log('✓ Prisma Lambda Layer built successfully (~10-15MB)\n');
|
|
@@ -155,5 +233,6 @@ async function ensurePrismaLayerExists(databaseConfig = {}) {
|
|
|
155
233
|
|
|
156
234
|
module.exports = {
|
|
157
235
|
ensurePrismaLayerExists,
|
|
236
|
+
parseLayerMarker,
|
|
158
237
|
};
|
|
159
238
|
|