@friggframework/devtools 2.0.0--canary.730.f2ba24a.0 → 2.0.0--canary.731.ffe61d3.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__/helpers/bundled-prisma-engine-excludes.js +39 -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 +2 -0
- package/infrastructure/domains/admin-scripts/admin-script-builder.test.js +16 -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 +93 -0
- package/infrastructure/domains/database/migration-engines.test.js +142 -0
- package/infrastructure/domains/integration/integration-builder.js +2 -0
- package/infrastructure/domains/integration/integration-builder.test.js +16 -0
- package/infrastructure/domains/shared/environment-builder.js +31 -5
- package/infrastructure/domains/shared/environment-builder.test.js +93 -7
- package/infrastructure/domains/shared/lambda-architectures.js +113 -0
- package/infrastructure/domains/shared/lambda-architectures.test.js +164 -0
- package/infrastructure/domains/shared/utilities/base-definition-factory.js +13 -1
- package/infrastructure/domains/shared/utilities/base-definition-factory.test.js +47 -0
- package/infrastructure/domains/shared/utilities/prisma-layer-manager.js +92 -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
|
@@ -16,9 +16,12 @@ const {
|
|
|
16
16
|
const { normalizeLogLevel } = require('./utilities/logging-config');
|
|
17
17
|
|
|
18
18
|
// OTLP-family exporters read their endpoint/headers from these standard env
|
|
19
|
-
// vars (ADR-011). When such an exporter is configured
|
|
20
|
-
//
|
|
21
|
-
//
|
|
19
|
+
// vars (ADR-011). When such an exporter is configured — or when the adopter
|
|
20
|
+
// opts into zero-code OTLP by setting OTEL_EXPORTER_OTLP_ENDPOINT (or marking
|
|
21
|
+
// it for SSM offload) with no Definition.telemetry.exporter — we auto-register
|
|
22
|
+
// them as Serverless passthroughs so the deployed Lambda inherits them from
|
|
23
|
+
// the deploy environment. An explicit exporter.type always wins: 'none' /
|
|
24
|
+
// 'console' do NOT register passthroughs even if the deploy shell has the env.
|
|
22
25
|
//
|
|
23
26
|
// NOTE (VPC egress): a Lambda in a private subnet needs a NAT gateway or a VPC
|
|
24
27
|
// endpoint to reach an external OTLP backend (Honeycomb/Datadog). Without egress
|
|
@@ -29,9 +32,31 @@ const OTEL_PASSTHROUGH_VARS = [
|
|
|
29
32
|
'OTEL_EXPORTER_OTLP_HEADERS',
|
|
30
33
|
];
|
|
31
34
|
|
|
35
|
+
function hasOtlpEndpointEnv() {
|
|
36
|
+
const endpoint = process.env.OTEL_EXPORTER_OTLP_ENDPOINT;
|
|
37
|
+
return typeof endpoint === 'string' && endpoint.trim().length > 0;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Zero-code OTLP is active when Definition.telemetry.exporter is omitted and
|
|
42
|
+
* either the deploy shell has a non-empty OTEL_EXPORTER_OTLP_ENDPOINT or that
|
|
43
|
+
* key is declared for SSM offload (`environment: 'ssm'` / `ssm.parameters`).
|
|
44
|
+
*/
|
|
45
|
+
function isZeroCodeOtlpActive(appDefinition) {
|
|
46
|
+
if (hasOtlpEndpointEnv()) return true;
|
|
47
|
+
return getOffloadedKeys(appDefinition).includes(
|
|
48
|
+
'OTEL_EXPORTER_OTLP_ENDPOINT'
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
|
|
32
52
|
function addTelemetryEnvPassthrough(appDefinition, envVars) {
|
|
33
53
|
const exporterType = appDefinition?.telemetry?.exporter?.type;
|
|
34
|
-
if (
|
|
54
|
+
if (exporterType !== undefined) {
|
|
55
|
+
// Explicit Definition.telemetry.exporter.type wins over the env var.
|
|
56
|
+
if (!OTLP_EXPORTER_TYPES.has(exporterType)) return;
|
|
57
|
+
} else if (!isZeroCodeOtlpActive(appDefinition)) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
35
60
|
|
|
36
61
|
// Skip offloaded keys here: baking '${env:KEY, ''}' resolves to '' at
|
|
37
62
|
// deploy (the value lives only in SSM), and '' !== undefined then blocks
|
|
@@ -49,7 +74,8 @@ function addTelemetryEnvPassthrough(appDefinition, envVars) {
|
|
|
49
74
|
// the core default, so it emits no env var.
|
|
50
75
|
function addLoggingEnv(appDefinition, envVars) {
|
|
51
76
|
const level = appDefinition?.logging?.level;
|
|
52
|
-
const normalized =
|
|
77
|
+
const normalized =
|
|
78
|
+
level === undefined ? undefined : normalizeLogLevel(level);
|
|
53
79
|
|
|
54
80
|
// serverless-offline copies only AWS_* shell vars into handlers, so under
|
|
55
81
|
// frigg start the shell level must travel through provider.environment.
|
|
@@ -10,6 +10,22 @@ const {
|
|
|
10
10
|
} = require('./environment-builder');
|
|
11
11
|
|
|
12
12
|
describe('Environment Builder', () => {
|
|
13
|
+
// Keep stage-default / empty-definition assertions deterministic even when
|
|
14
|
+
// a developer shell has OTEL_EXPORTER_OTLP_ENDPOINT set (zero-code path).
|
|
15
|
+
const originalOtelEndpoint = process.env.OTEL_EXPORTER_OTLP_ENDPOINT;
|
|
16
|
+
|
|
17
|
+
beforeEach(() => {
|
|
18
|
+
delete process.env.OTEL_EXPORTER_OTLP_ENDPOINT;
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
afterEach(() => {
|
|
22
|
+
if (originalOtelEndpoint === undefined) {
|
|
23
|
+
delete process.env.OTEL_EXPORTER_OTLP_ENDPOINT;
|
|
24
|
+
} else {
|
|
25
|
+
process.env.OTEL_EXPORTER_OTLP_ENDPOINT = originalOtelEndpoint;
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
|
|
13
29
|
describe('getAppEnvironmentVars()', () => {
|
|
14
30
|
it('should extract environment variables with value true', () => {
|
|
15
31
|
const appDefinition = {
|
|
@@ -145,6 +161,44 @@ describe('Environment Builder', () => {
|
|
|
145
161
|
getAppEnvironmentVars({}).OTEL_EXPORTER_OTLP_ENDPOINT
|
|
146
162
|
).toBeUndefined();
|
|
147
163
|
});
|
|
164
|
+
|
|
165
|
+
it('zero-code: emits OTLP passthroughs when Definition omits exporter and the deploy env has the endpoint', () => {
|
|
166
|
+
process.env.OTEL_EXPORTER_OTLP_ENDPOINT =
|
|
167
|
+
'https://watchtower.example/api/v1/watchtower/otel';
|
|
168
|
+
|
|
169
|
+
const result = getAppEnvironmentVars({});
|
|
170
|
+
|
|
171
|
+
expect(result.OTEL_EXPORTER_OTLP_ENDPOINT).toBe(
|
|
172
|
+
"${env:OTEL_EXPORTER_OTLP_ENDPOINT, ''}"
|
|
173
|
+
);
|
|
174
|
+
expect(result.OTEL_EXPORTER_OTLP_HEADERS).toBe(
|
|
175
|
+
"${env:OTEL_EXPORTER_OTLP_HEADERS, ''}"
|
|
176
|
+
);
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
it('zero-code: whitespace-only OTEL_EXPORTER_OTLP_ENDPOINT does not emit passthroughs', () => {
|
|
180
|
+
process.env.OTEL_EXPORTER_OTLP_ENDPOINT = ' ';
|
|
181
|
+
|
|
182
|
+
const result = getAppEnvironmentVars({});
|
|
183
|
+
|
|
184
|
+
expect(result.OTEL_EXPORTER_OTLP_ENDPOINT).toBeUndefined();
|
|
185
|
+
expect(result.OTEL_EXPORTER_OTLP_HEADERS).toBeUndefined();
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
it.each(['none', 'console'])(
|
|
189
|
+
'explicit exporter type "%s" wins over a set deploy-shell endpoint',
|
|
190
|
+
(type) => {
|
|
191
|
+
process.env.OTEL_EXPORTER_OTLP_ENDPOINT =
|
|
192
|
+
'https://watchtower.example/api/v1/watchtower/otel';
|
|
193
|
+
|
|
194
|
+
const result = getAppEnvironmentVars({
|
|
195
|
+
telemetry: { exporter: { type } },
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
expect(result.OTEL_EXPORTER_OTLP_ENDPOINT).toBeUndefined();
|
|
199
|
+
expect(result.OTEL_EXPORTER_OTLP_HEADERS).toBeUndefined();
|
|
200
|
+
}
|
|
201
|
+
);
|
|
148
202
|
});
|
|
149
203
|
|
|
150
204
|
describe('logging env (ADR-048)', () => {
|
|
@@ -217,7 +271,12 @@ describe('Environment Builder', () => {
|
|
|
217
271
|
}
|
|
218
272
|
};
|
|
219
273
|
|
|
220
|
-
beforeEach(() =>
|
|
274
|
+
beforeEach(() =>
|
|
275
|
+
setEnv({
|
|
276
|
+
FRIGG_SKIP_AWS_DISCOVERY: 'true',
|
|
277
|
+
FRIGG_LOG_LEVEL: undefined,
|
|
278
|
+
})
|
|
279
|
+
);
|
|
221
280
|
|
|
222
281
|
afterEach(() => {
|
|
223
282
|
for (const [key, value] of Object.entries(saved)) {
|
|
@@ -236,29 +295,39 @@ describe('Environment Builder', () => {
|
|
|
236
295
|
setEnv({ FRIGG_LOG_LEVEL: 'error' });
|
|
237
296
|
|
|
238
297
|
expect(
|
|
239
|
-
getAppEnvironmentVars({ logging: { level: 'debug' } })
|
|
298
|
+
getAppEnvironmentVars({ logging: { level: 'debug' } })
|
|
299
|
+
.FRIGG_LOG_LEVEL
|
|
240
300
|
).toBe('error');
|
|
241
301
|
});
|
|
242
302
|
|
|
243
303
|
it('emits logging.level INFO, so the local DEBUG default does not replace it', () => {
|
|
244
304
|
expect(
|
|
245
|
-
getAppEnvironmentVars({ logging: { level: 'info' } })
|
|
305
|
+
getAppEnvironmentVars({ logging: { level: 'info' } })
|
|
306
|
+
.FRIGG_LOG_LEVEL
|
|
246
307
|
).toBe('INFO');
|
|
247
308
|
});
|
|
248
309
|
|
|
249
310
|
it('ignores an empty shell value', () => {
|
|
250
311
|
setEnv({ FRIGG_LOG_LEVEL: ' ' });
|
|
251
312
|
|
|
252
|
-
expect(getAppEnvironmentVars({})).not.toHaveProperty(
|
|
313
|
+
expect(getAppEnvironmentVars({})).not.toHaveProperty(
|
|
314
|
+
'FRIGG_LOG_LEVEL'
|
|
315
|
+
);
|
|
253
316
|
expect(
|
|
254
|
-
getAppEnvironmentVars({ logging: { level: 'warn' } })
|
|
317
|
+
getAppEnvironmentVars({ logging: { level: 'warn' } })
|
|
318
|
+
.FRIGG_LOG_LEVEL
|
|
255
319
|
).toBe('WARN');
|
|
256
320
|
});
|
|
257
321
|
|
|
258
322
|
it('does not read the shell value outside frigg start', () => {
|
|
259
|
-
setEnv({
|
|
323
|
+
setEnv({
|
|
324
|
+
FRIGG_SKIP_AWS_DISCOVERY: undefined,
|
|
325
|
+
FRIGG_LOG_LEVEL: 'error',
|
|
326
|
+
});
|
|
260
327
|
|
|
261
|
-
expect(getAppEnvironmentVars({})).not.toHaveProperty(
|
|
328
|
+
expect(getAppEnvironmentVars({})).not.toHaveProperty(
|
|
329
|
+
'FRIGG_LOG_LEVEL'
|
|
330
|
+
);
|
|
262
331
|
expect(
|
|
263
332
|
getAppEnvironmentVars({ logging: { level: 'info' } })
|
|
264
333
|
).not.toHaveProperty('FRIGG_LOG_LEVEL');
|
|
@@ -466,6 +535,23 @@ describe('Environment Builder', () => {
|
|
|
466
535
|
|
|
467
536
|
expect(result.OTEL_EXPORTER_OTLP_ENDPOINT).toBeUndefined();
|
|
468
537
|
});
|
|
538
|
+
|
|
539
|
+
it('zero-code: omitted exporter + SSM-offloaded endpoint still passes through headers', () => {
|
|
540
|
+
delete process.env.FRIGG_SKIP_AWS_DISCOVERY;
|
|
541
|
+
const appDefinition = {
|
|
542
|
+
ssm: { enable: true },
|
|
543
|
+
environment: {
|
|
544
|
+
OTEL_EXPORTER_OTLP_ENDPOINT: 'ssm',
|
|
545
|
+
},
|
|
546
|
+
};
|
|
547
|
+
|
|
548
|
+
const result = getAppEnvironmentVars(appDefinition);
|
|
549
|
+
|
|
550
|
+
expect(result.OTEL_EXPORTER_OTLP_ENDPOINT).toBeUndefined();
|
|
551
|
+
expect(result.OTEL_EXPORTER_OTLP_HEADERS).toBe(
|
|
552
|
+
"${env:OTEL_EXPORTER_OTLP_HEADERS, ''}"
|
|
553
|
+
);
|
|
554
|
+
});
|
|
469
555
|
});
|
|
470
556
|
|
|
471
557
|
describe('buildEnvironment()', () => {
|
|
@@ -0,0 +1,113 @@
|
|
|
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
|
+
/**
|
|
92
|
+
* Package exclude patterns for a function that bundles Prisma itself. With
|
|
93
|
+
* the Prisma layer on, the layer carries the engines and nothing is added.
|
|
94
|
+
* @param {Object} appDefinition
|
|
95
|
+
* @param {boolean} usePrismaLayer
|
|
96
|
+
* @returns {string[]}
|
|
97
|
+
*/
|
|
98
|
+
function bundledPrismaEngineExcludes(appDefinition, usePrismaLayer) {
|
|
99
|
+
return usePrismaLayer
|
|
100
|
+
? []
|
|
101
|
+
: foreignPrismaEngineExcludes(resolveLambdaArchitecture(appDefinition).name);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
module.exports = {
|
|
105
|
+
LAMBDA_ARCHITECTURES,
|
|
106
|
+
DEFAULT_LAMBDA_ARCHITECTURE,
|
|
107
|
+
resolveLambdaArchitecture,
|
|
108
|
+
PRISMA_ENGINE_FILE_PREFIXES,
|
|
109
|
+
PRISMA_ENGINES_PACKAGE_DIR,
|
|
110
|
+
prismaEngineFileNames,
|
|
111
|
+
foreignPrismaEngineExcludes,
|
|
112
|
+
bundledPrismaEngineExcludes,
|
|
113
|
+
};
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
const micromatch = require('micromatch');
|
|
2
|
+
const {
|
|
3
|
+
LAMBDA_ARCHITECTURES,
|
|
4
|
+
resolveLambdaArchitecture,
|
|
5
|
+
prismaEngineFileNames,
|
|
6
|
+
foreignPrismaEngineExcludes,
|
|
7
|
+
bundledPrismaEngineExcludes,
|
|
8
|
+
} = require('./lambda-architectures');
|
|
9
|
+
|
|
10
|
+
describe('resolveLambdaArchitecture()', () => {
|
|
11
|
+
it('resolves to x86_64 with the rhel engine when the key is unset', () => {
|
|
12
|
+
expect(resolveLambdaArchitecture({})).toEqual({
|
|
13
|
+
name: 'x86_64',
|
|
14
|
+
prismaBinaryTarget: 'rhel-openssl-3.0.x',
|
|
15
|
+
explicit: false,
|
|
16
|
+
});
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it('resolves an explicit x86_64', () => {
|
|
20
|
+
expect(resolveLambdaArchitecture({ architecture: 'x86_64' })).toEqual({
|
|
21
|
+
name: 'x86_64',
|
|
22
|
+
prismaBinaryTarget: 'rhel-openssl-3.0.x',
|
|
23
|
+
explicit: true,
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it('resolves arm64 to the linux-arm64 engine', () => {
|
|
28
|
+
expect(resolveLambdaArchitecture({ architecture: 'arm64' })).toEqual({
|
|
29
|
+
name: 'arm64',
|
|
30
|
+
prismaBinaryTarget: 'linux-arm64-openssl-3.0.x',
|
|
31
|
+
explicit: true,
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it('throws on an unknown architecture, naming the accepted ones', () => {
|
|
36
|
+
expect(() =>
|
|
37
|
+
resolveLambdaArchitecture({ architecture: 'aarch64' })
|
|
38
|
+
).toThrow(/aarch64.*x86_64.*arm64/);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it('uses the AWS architecture names as registry keys', () => {
|
|
42
|
+
expect(Object.keys(LAMBDA_ARCHITECTURES)).toEqual(['x86_64', 'arm64']);
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
describe('prismaEngineFileNames()', () => {
|
|
47
|
+
it('names the schema engine and the query engine library the migrate CLI needs for a target', () => {
|
|
48
|
+
expect(prismaEngineFileNames('linux-arm64-openssl-3.0.x')).toEqual({
|
|
49
|
+
schemaEngine: 'schema-engine-linux-arm64-openssl-3.0.x',
|
|
50
|
+
queryEngineLibrary: 'libquery_engine-linux-arm64-openssl-3.0.x.so.node',
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
describe('foreignPrismaEngineExcludes()', () => {
|
|
56
|
+
const matches = (name, filePath) =>
|
|
57
|
+
micromatch([filePath], foreignPrismaEngineExcludes(name), {
|
|
58
|
+
dot: true,
|
|
59
|
+
}).length > 0;
|
|
60
|
+
|
|
61
|
+
const foreignEngineFiles = {
|
|
62
|
+
x86_64: [
|
|
63
|
+
'node_modules/@prisma/engines/libquery_engine-darwin-arm64.dylib.node',
|
|
64
|
+
'node_modules/@prisma/engines/schema-engine-darwin-arm64',
|
|
65
|
+
'node_modules/.prisma/client/query_engine-windows.dll.node',
|
|
66
|
+
'node_modules/@prisma/engines/query-engine-debian-openssl-3.0.x',
|
|
67
|
+
'node_modules/.prisma/client/libquery_engine-debian-openssl-3.0.x.so.node',
|
|
68
|
+
'node_modules/@prisma/engines/libquery_engine-linux-musl-openssl-3.0.x.so.node',
|
|
69
|
+
'node_modules/@prisma/engines/schema-engine-linux-arm64-openssl-3.0.x',
|
|
70
|
+
'node_modules/@prisma/engines/libquery_engine-linux-arm64-openssl-3.0.x.so.node',
|
|
71
|
+
],
|
|
72
|
+
arm64: [
|
|
73
|
+
'node_modules/@prisma/engines/libquery_engine-darwin-arm64.dylib.node',
|
|
74
|
+
'node_modules/.prisma/client/query_engine-windows.dll.node',
|
|
75
|
+
'node_modules/@prisma/engines/libquery_engine-linux-musl-openssl-3.0.x.so.node',
|
|
76
|
+
'node_modules/@prisma/engines/schema-engine-rhel-openssl-3.0.x',
|
|
77
|
+
'node_modules/@prisma/engines/libquery_engine-rhel-openssl-3.0.x.so.node',
|
|
78
|
+
],
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
const targetEngineFiles = {
|
|
82
|
+
x86_64: [
|
|
83
|
+
'node_modules/@prisma/engines/schema-engine-rhel-openssl-3.0.x',
|
|
84
|
+
'node_modules/@prisma/engines/libquery_engine-rhel-openssl-3.0.x.so.node',
|
|
85
|
+
],
|
|
86
|
+
arm64: [
|
|
87
|
+
'node_modules/@prisma/engines/schema-engine-linux-arm64-openssl-3.0.x',
|
|
88
|
+
'node_modules/@prisma/engines/libquery_engine-linux-arm64-openssl-3.0.x.so.node',
|
|
89
|
+
],
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
const nonEngineFiles = [
|
|
93
|
+
'node_modules/is-windows/index.js',
|
|
94
|
+
'node_modules/is-windows/package.json',
|
|
95
|
+
'node_modules/darwin-utils/lib/index.js',
|
|
96
|
+
'node_modules/some-pkg/lib/debian-release.js',
|
|
97
|
+
'node_modules/some-pkg/linux-musl-detect.js',
|
|
98
|
+
'node_modules/@prisma/engines/query_engine_bg.wasm',
|
|
99
|
+
'node_modules/.prisma/client/query_engine_bg.js',
|
|
100
|
+
'node_modules/some-pkg/dist/linux-arm64-notes.js',
|
|
101
|
+
'src/handlers/windows-handler.js',
|
|
102
|
+
];
|
|
103
|
+
|
|
104
|
+
it.each(['x86_64', 'arm64'])(
|
|
105
|
+
'matches every foreign engine file for %s',
|
|
106
|
+
(name) => {
|
|
107
|
+
foreignEngineFiles[name].forEach((file) =>
|
|
108
|
+
expect({ name, file, hit: matches(name, file) }).toEqual({
|
|
109
|
+
name,
|
|
110
|
+
file,
|
|
111
|
+
hit: true,
|
|
112
|
+
})
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
);
|
|
116
|
+
|
|
117
|
+
it.each(['x86_64', 'arm64'])(
|
|
118
|
+
'keeps the engine files of the %s target',
|
|
119
|
+
(name) => {
|
|
120
|
+
targetEngineFiles[name].forEach((file) =>
|
|
121
|
+
expect({ file, hit: matches(name, file) }).toEqual({
|
|
122
|
+
file,
|
|
123
|
+
hit: false,
|
|
124
|
+
})
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
);
|
|
128
|
+
|
|
129
|
+
it.each(['x86_64', 'arm64'])(
|
|
130
|
+
'keeps runtime files that only share a platform word with an engine for %s',
|
|
131
|
+
(name) => {
|
|
132
|
+
nonEngineFiles.forEach((file) =>
|
|
133
|
+
expect({ file, hit: matches(name, file) }).toEqual({
|
|
134
|
+
file,
|
|
135
|
+
hit: false,
|
|
136
|
+
})
|
|
137
|
+
);
|
|
138
|
+
}
|
|
139
|
+
);
|
|
140
|
+
|
|
141
|
+
it('never uses negation', () => {
|
|
142
|
+
['x86_64', 'arm64'].forEach((name) =>
|
|
143
|
+
foreignPrismaEngineExcludes(name).forEach((pattern) =>
|
|
144
|
+
expect(pattern.startsWith('!')).toBe(false)
|
|
145
|
+
)
|
|
146
|
+
);
|
|
147
|
+
});
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
describe('bundledPrismaEngineExcludes()', () => {
|
|
151
|
+
it('adds nothing when the Prisma layer carries the engines', () => {
|
|
152
|
+
expect(bundledPrismaEngineExcludes({ architecture: 'arm64' }, true)).toEqual([]);
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
it.each([
|
|
156
|
+
[{}, 'x86_64'],
|
|
157
|
+
[{ architecture: 'x86_64' }, 'x86_64'],
|
|
158
|
+
[{ architecture: 'arm64' }, 'arm64'],
|
|
159
|
+
])('with the layer off, excludes the engines %j does not load', (appDefinition, name) => {
|
|
160
|
+
expect(bundledPrismaEngineExcludes(appDefinition, false)).toEqual(
|
|
161
|
+
foreignPrismaEngineExcludes(name)
|
|
162
|
+
);
|
|
163
|
+
});
|
|
164
|
+
});
|
|
@@ -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
|
+
bundledPrismaEngineExcludes,
|
|
16
|
+
} = require('../lambda-architectures');
|
|
13
17
|
|
|
14
18
|
/**
|
|
15
19
|
* Create base serverless definition with core functions and resources
|
|
@@ -35,6 +39,8 @@ 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
|
+
const bundledEngineExcludes = bundledPrismaEngineExcludes(AppDefinition, usePrismaLayer);
|
|
38
44
|
|
|
39
45
|
// Package config for handlers that skip esbuild (need node_modules dependencies)
|
|
40
46
|
// Include backend src/ and index.js since handlers load the app definition
|
|
@@ -54,6 +60,7 @@ function createBaseDefinition(
|
|
|
54
60
|
'node_modules/prisma/**',
|
|
55
61
|
'node_modules/@friggframework/core/generated/**',
|
|
56
62
|
] : []),
|
|
63
|
+
...bundledEngineExcludes,
|
|
57
64
|
|
|
58
65
|
// Exclude AWS SDK (provided by Lambda runtime)
|
|
59
66
|
'node_modules/aws-sdk/**',
|
|
@@ -127,6 +134,7 @@ function createBaseDefinition(
|
|
|
127
134
|
'node_modules/prisma/**',
|
|
128
135
|
'node_modules/@friggframework/core/generated/**',
|
|
129
136
|
] : []),
|
|
137
|
+
...bundledEngineExcludes,
|
|
130
138
|
|
|
131
139
|
// Exclude nested node_modules from symlinked frigg packages (for npm link development)
|
|
132
140
|
'node_modules/@friggframework/core/node_modules/**',
|
|
@@ -178,6 +186,7 @@ function createBaseDefinition(
|
|
|
178
186
|
name: AppDefinition.provider || 'aws',
|
|
179
187
|
...(process.env.AWS_PROFILE && { profile: process.env.AWS_PROFILE }),
|
|
180
188
|
runtime: 'nodejs22.x', // Node.js 22.x (latest Lambda runtime with AWS SDK v3)
|
|
189
|
+
...(architecture.explicit && { architecture: architecture.name }),
|
|
181
190
|
timeout: 29, // Set to 29s to give buffer before API Gateway's 30s timeout
|
|
182
191
|
region,
|
|
183
192
|
stage: '${opt:stage}',
|
|
@@ -341,8 +350,11 @@ function createBaseDefinition(
|
|
|
341
350
|
prisma: {
|
|
342
351
|
path: 'layers/prisma',
|
|
343
352
|
name: '${self:service}-prisma-${sls:stage}',
|
|
344
|
-
description: 'Prisma runtime client only (NO CLI) with
|
|
353
|
+
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
354
|
compatibleRuntimes: ['nodejs20.x', 'nodejs22.x'],
|
|
355
|
+
...(architecture.explicit && {
|
|
356
|
+
compatibleArchitectures: [architecture.name],
|
|
357
|
+
}),
|
|
346
358
|
retain: false,
|
|
347
359
|
},
|
|
348
360
|
} : {},
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
const { createBaseDefinition } = require('./base-definition-factory');
|
|
8
|
+
const { itBundlesOnlyTheTargetPrismaEngine } = require('../../../__tests__/helpers/bundled-prisma-engine-excludes');
|
|
8
9
|
|
|
9
10
|
describe('Base Definition Factory', () => {
|
|
10
11
|
beforeEach(() => {
|
|
@@ -323,6 +324,52 @@ describe('Base Definition Factory', () => {
|
|
|
323
324
|
});
|
|
324
325
|
|
|
325
326
|
|
|
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
|
+
|
|
326
373
|
describe('nested node_modules (lambda.keepNestedNodeModules)', () => {
|
|
327
374
|
const build = (appDefinition) => createBaseDefinition(appDefinition, {}, {}, true);
|
|
328
375
|
|