@friggframework/devtools 2.0.0--canary.705.9cfd819.0 → 2.0.0--canary.704.6a606c3.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/README.md +14 -0
- package/frigg-cli/README.md +83 -30
- package/frigg-cli/__tests__/unit/commands/generate-iam.test.js +18 -0
- package/frigg-cli/__tests__/unit/commands/init.test.js +688 -0
- package/frigg-cli/__tests__/unit/commands/install.test.js +594 -341
- package/frigg-cli/__tests__/unit/dependencies.test.js +3 -5
- package/frigg-cli/__tests__/unit/utils/node-version.test.js +66 -0
- package/frigg-cli/generate-command/index.js +1 -0
- package/frigg-cli/generate-iam-command.js +1 -0
- package/frigg-cli/index.js +12 -4
- package/frigg-cli/init-command/backend-first-handler.js +397 -554
- package/frigg-cli/init-command/deployment-modes.js +7 -0
- package/frigg-cli/init-command/index.js +82 -35
- package/frigg-cli/init-command/safe-path.js +58 -0
- package/frigg-cli/init-command/scaffold-dependencies.js +202 -0
- package/frigg-cli/install-command/app-definition.js +174 -0
- package/frigg-cli/install-command/commit-changes.js +40 -8
- package/frigg-cli/install-command/environment-variables.js +15 -0
- package/frigg-cli/install-command/index.js +96 -21
- package/frigg-cli/install-command/install-package.js +77 -4
- package/frigg-cli/install-command/integration-file.js +20 -11
- package/frigg-cli/install-command/resolve-module.js +69 -0
- package/frigg-cli/install-command/template.js +102 -75
- package/frigg-cli/install-command/validate-package.js +36 -4
- package/frigg-cli/package.json +3 -3
- package/frigg-cli/templates/backend/README.md +267 -0
- package/frigg-cli/templates/backend/env.example +20 -0
- package/frigg-cli/templates/backend/gitignore +10 -0
- package/frigg-cli/templates/backend/index.js +114 -0
- package/frigg-cli/templates/backend/infrastructure.js +20 -0
- package/frigg-cli/test/init-command.test.js +9 -2
- package/frigg-cli/utils/node-version.js +51 -0
- package/infrastructure/README.md +20 -0
- package/infrastructure/__tests__/package-patterns-composition.test.js +153 -0
- package/infrastructure/__tests__/scaffold-default-infrastructure.test.js +148 -0
- package/infrastructure/docs/POSTGRES-CONFIGURATION.md +21 -1
- package/infrastructure/domains/admin-scripts/admin-script-builder.js +50 -46
- package/infrastructure/domains/admin-scripts/admin-script-builder.test.js +46 -7
- package/infrastructure/domains/database/aurora-builder.js +13 -2
- package/infrastructure/domains/database/aurora-builder.test.js +22 -0
- package/infrastructure/domains/database/migration-builder.js +182 -175
- package/infrastructure/domains/database/migration-builder.test.js +36 -5
- package/infrastructure/domains/integration/integration-builder.js +65 -61
- package/infrastructure/domains/integration/integration-builder.test.js +73 -8
- package/infrastructure/domains/security/iam-generator.js +112 -5
- package/infrastructure/domains/security/iam-generator.test.js +94 -0
- package/infrastructure/domains/shared/utilities/base-definition-factory.js +83 -124
- package/infrastructure/domains/shared/utilities/base-definition-factory.test.js +116 -26
- package/infrastructure/domains/shared/utilities/framework-version.js +14 -0
- package/infrastructure/domains/shared/utilities/framework-version.test.js +27 -0
- package/infrastructure/domains/shared/utilities/logging-config.js +3 -4
- package/infrastructure/domains/shared/utilities/logging-config.test.js +1 -2
- package/infrastructure/domains/shared/utilities/package-patterns.js +35 -0
- package/infrastructure/domains/shared/utilities/package-patterns.test.js +112 -0
- package/infrastructure/infrastructure-composer.test.js +3 -3
- package/package.json +13 -8
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Composer-level guard for ADR-050 (osls 4).
|
|
3
|
+
*
|
|
4
|
+
* osls 4 rejects package.include / package.exclude at every level and only
|
|
5
|
+
* accepts `useDotenv: true` (or no key). Walk every function of a fully
|
|
6
|
+
* featured composed definition and assert Frigg emits neither.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
const { composeServerlessDefinition } = require('../infrastructure-composer');
|
|
10
|
+
|
|
11
|
+
jest.mock('../domains/shared/resource-discovery', () => {
|
|
12
|
+
const originalModule = jest.requireActual('../domains/shared/resource-discovery');
|
|
13
|
+
return {
|
|
14
|
+
...originalModule,
|
|
15
|
+
gatherDiscoveredResources: jest.fn().mockResolvedValue({
|
|
16
|
+
defaultVpcId: 'vpc-123456',
|
|
17
|
+
defaultSecurityGroupId: 'sg-123456',
|
|
18
|
+
privateSubnetId1: 'subnet-123456',
|
|
19
|
+
privateSubnetId2: 'subnet-789012',
|
|
20
|
+
defaultKmsKeyId:
|
|
21
|
+
'arn:aws:kms:us-east-1:123456789012:key/12345678-1234-1234-1234-123456789012',
|
|
22
|
+
auroraClusterEndpoint: 'test-cluster.cluster-abc123.us-east-1.rds.amazonaws.com',
|
|
23
|
+
auroraPort: 5432,
|
|
24
|
+
}),
|
|
25
|
+
};
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
const featuredApp = () => ({
|
|
29
|
+
name: 'featured-app',
|
|
30
|
+
provider: 'aws',
|
|
31
|
+
vpc: { enable: true },
|
|
32
|
+
encryption: { useDefaultKMSForFieldLevelEncryption: true },
|
|
33
|
+
database: {
|
|
34
|
+
postgres: { enable: true },
|
|
35
|
+
documentDB: { tlsCAFile: './global-bundle.pem' },
|
|
36
|
+
},
|
|
37
|
+
adminScripts: [{ Definition: { name: 'fixThings' } }],
|
|
38
|
+
reports: [{ Definition: { name: 'usageReport' } }],
|
|
39
|
+
integrations: [
|
|
40
|
+
{
|
|
41
|
+
Definition: {
|
|
42
|
+
name: 'hubspot',
|
|
43
|
+
webhooks: true,
|
|
44
|
+
extensions: {
|
|
45
|
+
hubspotWebhooks: {
|
|
46
|
+
extension: {
|
|
47
|
+
name: 'hubspot-webhooks',
|
|
48
|
+
routes: [
|
|
49
|
+
{
|
|
50
|
+
path: '/webhooks',
|
|
51
|
+
method: 'POST',
|
|
52
|
+
event: 'HUBSPOT_WEBHOOK_RECEIVED',
|
|
53
|
+
},
|
|
54
|
+
],
|
|
55
|
+
events: {
|
|
56
|
+
HUBSPOT_WEBHOOK_RECEIVED: {
|
|
57
|
+
type: 'LIFE_CYCLE_EVENT',
|
|
58
|
+
handler: () => {},
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
handlers: {},
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
{ Definition: { name: 'slack' } },
|
|
68
|
+
],
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
describe('composed definition is valid for osls 4 packaging (ADR-050)', () => {
|
|
72
|
+
const originalArgv = process.argv;
|
|
73
|
+
|
|
74
|
+
beforeEach(() => {
|
|
75
|
+
delete process.env.FRIGG_SKIP_AWS_DISCOVERY;
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
afterEach(() => {
|
|
79
|
+
process.argv = originalArgv;
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it('no function, the service or a layer carries package.include or package.exclude', async () => {
|
|
83
|
+
process.argv = ['node', 'osls', 'package', '--stage', 'prod'];
|
|
84
|
+
const definition = await composeServerlessDefinition(featuredApp());
|
|
85
|
+
|
|
86
|
+
expect(definition.package).not.toHaveProperty('include');
|
|
87
|
+
expect(definition.package).not.toHaveProperty('exclude');
|
|
88
|
+
for (const layer of Object.values(definition.layers || {})) {
|
|
89
|
+
expect(layer.package?.include).toBeUndefined();
|
|
90
|
+
expect(layer.package?.exclude).toBeUndefined();
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const functionNames = Object.keys(definition.functions);
|
|
94
|
+
expect(functionNames).toEqual(
|
|
95
|
+
expect.arrayContaining([
|
|
96
|
+
'auth',
|
|
97
|
+
'user',
|
|
98
|
+
'health',
|
|
99
|
+
'hubspot',
|
|
100
|
+
'hubspotWebhook',
|
|
101
|
+
'hubspot__hubspotWebhooks',
|
|
102
|
+
'hubspotQueueWorker',
|
|
103
|
+
'slack',
|
|
104
|
+
'slackQueueWorker',
|
|
105
|
+
'dlqProcessor',
|
|
106
|
+
'dbMigrationWorker',
|
|
107
|
+
'dbMigrationRouter',
|
|
108
|
+
'adminScriptExecutor',
|
|
109
|
+
'adminScriptRouter',
|
|
110
|
+
])
|
|
111
|
+
);
|
|
112
|
+
|
|
113
|
+
for (const [name, fn] of Object.entries(definition.functions)) {
|
|
114
|
+
if (!fn.package) continue;
|
|
115
|
+
expect({ name, include: fn.package.include }).toEqual({ name, include: undefined });
|
|
116
|
+
expect({ name, exclude: fn.package.exclude }).toEqual({ name, exclude: undefined });
|
|
117
|
+
expect(Array.isArray(fn.package.patterns)).toBe(true);
|
|
118
|
+
|
|
119
|
+
// Excludes first, then includes: once a positive pattern appears,
|
|
120
|
+
// no negated pattern may follow it.
|
|
121
|
+
const firstInclude = fn.package.patterns.findIndex((p) => !p.startsWith('!'));
|
|
122
|
+
if (firstInclude !== -1) {
|
|
123
|
+
expect(
|
|
124
|
+
fn.package.patterns.slice(firstInclude).every((p) => !p.startsWith('!'))
|
|
125
|
+
).toBe(true);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// The skipEsbuild core and admin functions re-add the DocumentDB CA file.
|
|
130
|
+
for (const name of ['auth', 'user', 'health', 'adminScriptExecutor', 'adminScriptRouter']) {
|
|
131
|
+
const { patterns } = definition.functions[name].package;
|
|
132
|
+
expect(patterns[patterns.length - 1]).toBe('global-bundle.pem');
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
it.each([['package'], ['deploy']])('never emits useDotenv for `osls %s`', async (command) => {
|
|
137
|
+
process.argv = ['node', 'osls', command, '--stage', 'prod'];
|
|
138
|
+
const definition = await composeServerlessDefinition(featuredApp());
|
|
139
|
+
|
|
140
|
+
expect(definition).not.toHaveProperty('useDotenv');
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
it('emits useDotenv: true for `osls offline`', async () => {
|
|
144
|
+
process.argv = ['node', 'osls', 'offline', '--stage', 'dev'];
|
|
145
|
+
process.env.FRIGG_SKIP_AWS_DISCOVERY = 'true';
|
|
146
|
+
try {
|
|
147
|
+
const definition = await composeServerlessDefinition(featuredApp());
|
|
148
|
+
expect(definition.useDotenv).toBe(true);
|
|
149
|
+
} finally {
|
|
150
|
+
delete process.env.FRIGG_SKIP_AWS_DISCOVERY;
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
});
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The app scaffolded by `frigg init` must deploy with no always-on AWS cost.
|
|
3
|
+
*
|
|
4
|
+
* Scaffolds the backend template, loads its Definition and composes it the way
|
|
5
|
+
* `frigg deploy` does (AWS discovery stubbed), then asserts the template has
|
|
6
|
+
* no VPC, NAT gateway, Elastic IP, VPC endpoint or RDS/Aurora resource, that
|
|
7
|
+
* no Lambda is attached to a VPC, and that field-level encryption still gets
|
|
8
|
+
* its KMS key.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
const os = require('os');
|
|
12
|
+
const path = require('path');
|
|
13
|
+
const fs = require('fs-extra');
|
|
14
|
+
|
|
15
|
+
jest.mock('../domains/shared/resource-discovery', () => ({
|
|
16
|
+
...jest.requireActual('../domains/shared/resource-discovery'),
|
|
17
|
+
gatherDiscoveredResources: jest.fn(),
|
|
18
|
+
}));
|
|
19
|
+
jest.mock('../domains/shared/utilities/prisma-layer-manager', () => ({
|
|
20
|
+
ensurePrismaLayerExists: jest.fn().mockResolvedValue(undefined),
|
|
21
|
+
}));
|
|
22
|
+
|
|
23
|
+
const {
|
|
24
|
+
gatherDiscoveredResources,
|
|
25
|
+
} = require('../domains/shared/resource-discovery');
|
|
26
|
+
const { composeServerlessDefinition } = require('../infrastructure-composer');
|
|
27
|
+
const BackendFirstHandler = require('../../frigg-cli/init-command/backend-first-handler');
|
|
28
|
+
|
|
29
|
+
const FORBIDDEN_RESOURCE_TYPES = [
|
|
30
|
+
'AWS::EC2::VPC',
|
|
31
|
+
'AWS::EC2::NatGateway',
|
|
32
|
+
'AWS::EC2::EIP',
|
|
33
|
+
'AWS::EC2::VPCEndpoint',
|
|
34
|
+
'AWS::RDS::DBCluster',
|
|
35
|
+
'AWS::RDS::DBInstance',
|
|
36
|
+
'AWS::RDS::DBSubnetGroup',
|
|
37
|
+
];
|
|
38
|
+
|
|
39
|
+
// An account that already holds a default VPC, subnets, a NAT gateway and an
|
|
40
|
+
// Aurora cluster: none of it may leak into the scaffolded app's template.
|
|
41
|
+
const BUSY_ACCOUNT_DISCOVERY = {
|
|
42
|
+
defaultVpcId: 'vpc-123456',
|
|
43
|
+
vpcCidr: '172.31.0.0/16',
|
|
44
|
+
defaultSecurityGroupId: 'sg-123456',
|
|
45
|
+
privateSubnetId1: 'subnet-123456',
|
|
46
|
+
privateSubnetId2: 'subnet-789012',
|
|
47
|
+
publicSubnetId1: 'subnet-public-1',
|
|
48
|
+
publicSubnetId2: 'subnet-public-2',
|
|
49
|
+
defaultRouteTableId: 'rtb-123456',
|
|
50
|
+
existingNatGatewayId: 'nat-default123',
|
|
51
|
+
auroraClusterEndpoint: 'c.cluster-abc123.us-east-1.rds.amazonaws.com',
|
|
52
|
+
auroraPort: 5432,
|
|
53
|
+
auroraEngine: 'aurora-postgresql',
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
describe('frigg init default infrastructure', () => {
|
|
57
|
+
let tmpDir;
|
|
58
|
+
let Definition;
|
|
59
|
+
let logSpy;
|
|
60
|
+
|
|
61
|
+
beforeAll(async () => {
|
|
62
|
+
logSpy = jest.spyOn(console, 'log').mockImplementation();
|
|
63
|
+
tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'frigg-default-infra-'));
|
|
64
|
+
const target = path.join(tmpDir, 'demo-app');
|
|
65
|
+
await new BackendFirstHandler(target, {
|
|
66
|
+
yes: true,
|
|
67
|
+
install: false,
|
|
68
|
+
git: false,
|
|
69
|
+
}).initialize();
|
|
70
|
+
({ Definition } = require(path.join(target, 'index.js')));
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
afterAll(() => {
|
|
74
|
+
fs.removeSync(tmpDir);
|
|
75
|
+
logSpy.mockRestore();
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
beforeEach(() => {
|
|
79
|
+
delete process.env.FRIGG_SKIP_AWS_DISCOVERY;
|
|
80
|
+
process.argv = ['node', 'test'];
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
const compose = async (discovery) => {
|
|
84
|
+
gatherDiscoveredResources.mockResolvedValue(discovery);
|
|
85
|
+
// The composer mutates nested parts of the definition.
|
|
86
|
+
return composeServerlessDefinition(
|
|
87
|
+
JSON.parse(JSON.stringify(Definition))
|
|
88
|
+
);
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
const resourceTypes = (definition) =>
|
|
92
|
+
Object.values(definition.resources.Resources).map((r) => r.Type);
|
|
93
|
+
|
|
94
|
+
it('passes the app-definition schema', () => {
|
|
95
|
+
const { validateAppDefinition } = require('@friggframework/schemas');
|
|
96
|
+
expect(validateAppDefinition(Definition).valid).toBe(true);
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it.each([
|
|
100
|
+
['an empty account', {}],
|
|
101
|
+
['an account with existing VPC/NAT/Aurora', BUSY_ACCOUNT_DISCOVERY],
|
|
102
|
+
])('composes no always-on resources in %s', async (_label, discovery) => {
|
|
103
|
+
const definition = await compose(discovery);
|
|
104
|
+
const types = resourceTypes(definition);
|
|
105
|
+
|
|
106
|
+
for (const forbidden of FORBIDDEN_RESOURCE_TYPES) {
|
|
107
|
+
expect(types).not.toContain(forbidden);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// No Lambda is attached to a VPC.
|
|
111
|
+
expect(definition.provider.vpc).toBeUndefined();
|
|
112
|
+
for (const fn of Object.values(definition.functions)) {
|
|
113
|
+
expect(fn.vpc).toBeUndefined();
|
|
114
|
+
}
|
|
115
|
+
for (const resource of Object.values(definition.resources.Resources)) {
|
|
116
|
+
expect(resource.Properties?.VpcConfig).toBeUndefined();
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it('keeps field-level encryption on with a per-stage KMS key', async () => {
|
|
121
|
+
const definition = await compose({});
|
|
122
|
+
|
|
123
|
+
expect(definition.resources.Resources.FriggKMSKey.Type).toBe(
|
|
124
|
+
'AWS::KMS::Key'
|
|
125
|
+
);
|
|
126
|
+
expect(definition.provider.environment.KMS_KEY_ARN).toEqual({
|
|
127
|
+
'Fn::GetAtt': ['FriggKMSKey', 'Arn'],
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
it('connects to the external database through DATABASE_URL', async () => {
|
|
132
|
+
const definition = await compose({});
|
|
133
|
+
|
|
134
|
+
expect(definition.provider.environment.DATABASE_URL).toBe(
|
|
135
|
+
"${env:DATABASE_URL, ''}"
|
|
136
|
+
);
|
|
137
|
+
expect(definition.provider.environment.DB_TYPE).toBe('postgresql');
|
|
138
|
+
expect(definition.resources.Resources.FriggDBSecret).toBeUndefined();
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
it('expires Lambda logs after 14 days', async () => {
|
|
142
|
+
// Without provider.logRetentionInDays, osls creates log groups that
|
|
143
|
+
// never expire, so CloudWatch storage grows forever.
|
|
144
|
+
const definition = await compose({});
|
|
145
|
+
|
|
146
|
+
expect(definition.provider.logRetentionInDays).toBe(14);
|
|
147
|
+
});
|
|
148
|
+
});
|
|
@@ -11,10 +11,30 @@ Frigg Framework supports automatic provisioning of Amazon Aurora Serverless v2 P
|
|
|
11
11
|
- **Aurora Serverless v2**: Cost-efficient auto-scaling database (0.5-1.0 ACU default)
|
|
12
12
|
- **VPC Integration**: Deployed in same private subnets as Lambda functions
|
|
13
13
|
- **Secrets Manager**: Automatic credential management and rotation
|
|
14
|
-
- **
|
|
14
|
+
- **Management Modes**: discover, create-new, use-existing, external (bring your own `DATABASE_URL`)
|
|
15
15
|
- **Security**: Private subnet deployment with security group isolation
|
|
16
16
|
- **High Availability**: Multi-AZ deployment with automatic failover
|
|
17
17
|
|
|
18
|
+
### Bring your own PostgreSQL (`management: 'external'`)
|
|
19
|
+
|
|
20
|
+
To connect to a PostgreSQL that Frigg does not manage (any hosted provider, or
|
|
21
|
+
a database you run yourself), set `management: 'external'`. Frigg then creates
|
|
22
|
+
and discovers no database resources (no RDS/Aurora, no Secrets Manager secret)
|
|
23
|
+
and needs no VPC for the database; the app connects through `DATABASE_URL`.
|
|
24
|
+
This check takes precedence over a top-level `managementMode`. The migration
|
|
25
|
+
infrastructure is still composed, so migrations run against `DATABASE_URL`.
|
|
26
|
+
|
|
27
|
+
```javascript
|
|
28
|
+
const appDefinition = {
|
|
29
|
+
vpc: { enable: false },
|
|
30
|
+
database: { postgres: { enable: true, management: 'external' } },
|
|
31
|
+
environment: { DATABASE_URL: true }, // read from the shell that runs `frigg deploy` (not .env)
|
|
32
|
+
};
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
Use `sslmode=require` in the URL. This is the default for apps scaffolded by
|
|
36
|
+
`frigg init`.
|
|
37
|
+
|
|
18
38
|
---
|
|
19
39
|
|
|
20
40
|
## Configuration Schema
|
|
@@ -16,6 +16,7 @@
|
|
|
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 { toPackagePatterns } = require('../shared/utilities/package-patterns');
|
|
19
20
|
|
|
20
21
|
class AdminScriptBuilder extends InfrastructureBuilder {
|
|
21
22
|
constructor() {
|
|
@@ -397,52 +398,55 @@ class AdminScriptBuilder extends InfrastructureBuilder {
|
|
|
397
398
|
skipEsbuildPackageConfig(appDefinition, usePrismaLayer) {
|
|
398
399
|
const tlsCAFile = appDefinition?.database?.documentDB?.tlsCAFile;
|
|
399
400
|
return {
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
401
|
+
// osls 4 only reads package.patterns (ADR-050): excludes first, then includes.
|
|
402
|
+
patterns: toPackagePatterns({
|
|
403
|
+
include: [
|
|
404
|
+
// Handlers connect to the DB, so ship the DocumentDB CA cert.
|
|
405
|
+
...(tlsCAFile ? [tlsCAFile.replace(/^\.\//, '')] : []),
|
|
406
|
+
],
|
|
407
|
+
exclude: [
|
|
408
|
+
'node_modules/aws-sdk/**',
|
|
409
|
+
'node_modules/@aws-sdk/**',
|
|
410
|
+
...(usePrismaLayer
|
|
411
|
+
? [
|
|
412
|
+
'node_modules/@prisma/**',
|
|
413
|
+
'node_modules/.prisma/**',
|
|
414
|
+
'node_modules/prisma/**',
|
|
415
|
+
'node_modules/@friggframework/core/generated/**',
|
|
416
|
+
]
|
|
417
|
+
: []),
|
|
418
|
+
...nestedNodeModulesExcludes(appDefinition, usePrismaLayer),
|
|
419
|
+
'node_modules/@friggframework/test/**',
|
|
420
|
+
'node_modules/@friggframework/eslint-config/**',
|
|
421
|
+
'node_modules/@friggframework/prettier-config/**',
|
|
422
|
+
'node_modules/jest/**',
|
|
423
|
+
'node_modules/prettier/**',
|
|
424
|
+
'node_modules/eslint/**',
|
|
425
|
+
'node_modules/esbuild/**',
|
|
426
|
+
'node_modules/@esbuild/**',
|
|
427
|
+
'node_modules/typescript/**',
|
|
428
|
+
'node_modules/webpack/**',
|
|
429
|
+
'node_modules/osls/**',
|
|
430
|
+
'node_modules/serverless-esbuild/**',
|
|
431
|
+
'node_modules/serverless-jetpack/**',
|
|
432
|
+
'node_modules/serverless-offline/**',
|
|
433
|
+
'node_modules/serverless-offline-sqs/**',
|
|
434
|
+
'node_modules/serverless-dotenv-plugin/**',
|
|
435
|
+
'node_modules/serverless-kms-grants/**',
|
|
436
|
+
// Never deploy secrets or the lockfile.
|
|
437
|
+
'.env',
|
|
438
|
+
'.env.*',
|
|
439
|
+
'**/.env',
|
|
440
|
+
'**/.env.*',
|
|
441
|
+
'.frigg-credentials.json',
|
|
442
|
+
'package-lock.json',
|
|
443
|
+
'test/**',
|
|
444
|
+
'layers/**',
|
|
445
|
+
'coverage/**',
|
|
446
|
+
'**/*.test.js',
|
|
447
|
+
'**/*.spec.js',
|
|
448
|
+
],
|
|
449
|
+
}),
|
|
446
450
|
};
|
|
447
451
|
}
|
|
448
452
|
|
|
@@ -285,11 +285,11 @@ describe('AdminScriptBuilder', () => {
|
|
|
285
285
|
result.functions.adminScriptExecutor,
|
|
286
286
|
result.functions.adminScriptRouter,
|
|
287
287
|
]) {
|
|
288
|
-
expect(fn.package.
|
|
288
|
+
expect(fn.package.patterns).toEqual(
|
|
289
289
|
expect.arrayContaining([
|
|
290
|
-
'node_modules/aws-sdk/**',
|
|
291
|
-
'node_modules/@aws-sdk/**',
|
|
292
|
-
'node_modules/@prisma/**',
|
|
290
|
+
'!node_modules/aws-sdk/**',
|
|
291
|
+
'!node_modules/@aws-sdk/**',
|
|
292
|
+
'!node_modules/@prisma/**',
|
|
293
293
|
])
|
|
294
294
|
);
|
|
295
295
|
}
|
|
@@ -1029,7 +1029,7 @@ describe('AdminScriptBuilder nested node_modules (lambda.keepNestedNodeModules)'
|
|
|
1029
1029
|
const result = await new AdminScriptBuilder().build(appDefinition(), {});
|
|
1030
1030
|
|
|
1031
1031
|
for (const fn of executorAndRouter(result)) {
|
|
1032
|
-
expect(fn.package.
|
|
1032
|
+
expect(fn.package.patterns).toContain('!node_modules/**/node_modules/**');
|
|
1033
1033
|
}
|
|
1034
1034
|
});
|
|
1035
1035
|
|
|
@@ -1040,8 +1040,47 @@ describe('AdminScriptBuilder nested node_modules (lambda.keepNestedNodeModules)'
|
|
|
1040
1040
|
);
|
|
1041
1041
|
|
|
1042
1042
|
for (const fn of executorAndRouter(result)) {
|
|
1043
|
-
expect(fn.package.
|
|
1044
|
-
expect(fn.package.
|
|
1043
|
+
expect(fn.package.patterns).not.toContain('!node_modules/**/node_modules/**');
|
|
1044
|
+
expect(fn.package.patterns).toContain('!node_modules/**/node_modules/@friggframework/**');
|
|
1045
1045
|
}
|
|
1046
1046
|
});
|
|
1047
1047
|
});
|
|
1048
|
+
|
|
1049
|
+
describe('AdminScriptBuilder function package patterns (ADR-050)', () => {
|
|
1050
|
+
it('emits package.patterns, never include/exclude, on every skipEsbuild function', async () => {
|
|
1051
|
+
const result = await new AdminScriptBuilder().build(
|
|
1052
|
+
{
|
|
1053
|
+
adminScripts: [{ Definition: { name: 'test-script' } }],
|
|
1054
|
+
reports: [{ Definition: { name: 'test-report' } }],
|
|
1055
|
+
},
|
|
1056
|
+
{}
|
|
1057
|
+
);
|
|
1058
|
+
|
|
1059
|
+
const packaged = Object.entries(result.functions).filter(([, fn]) => fn.package);
|
|
1060
|
+
expect(packaged.map(([name]) => name)).toEqual(
|
|
1061
|
+
expect.arrayContaining(['adminScriptExecutor', 'adminScriptRouter'])
|
|
1062
|
+
);
|
|
1063
|
+
for (const [, fn] of packaged) {
|
|
1064
|
+
expect(fn.package).not.toHaveProperty('include');
|
|
1065
|
+
expect(fn.package).not.toHaveProperty('exclude');
|
|
1066
|
+
expect(fn.package.patterns.every((p) => p.startsWith('!'))).toBe(true);
|
|
1067
|
+
expect(fn.package.patterns).toEqual(
|
|
1068
|
+
expect.arrayContaining(['!node_modules/aws-sdk/**', '!.env', '!test/**'])
|
|
1069
|
+
);
|
|
1070
|
+
}
|
|
1071
|
+
});
|
|
1072
|
+
|
|
1073
|
+
it('re-adds the DocumentDB CA file after every exclude', async () => {
|
|
1074
|
+
const result = await new AdminScriptBuilder().build(
|
|
1075
|
+
{
|
|
1076
|
+
adminScripts: [{ Definition: { name: 'test-script' } }],
|
|
1077
|
+
database: { documentDB: { tlsCAFile: './global-bundle.pem' } },
|
|
1078
|
+
},
|
|
1079
|
+
{}
|
|
1080
|
+
);
|
|
1081
|
+
|
|
1082
|
+
const { patterns } = result.functions.adminScriptExecutor.package;
|
|
1083
|
+
expect(patterns[patterns.length - 1]).toBe('global-bundle.pem');
|
|
1084
|
+
expect(patterns.slice(0, -1).every((p) => p.startsWith('!'))).toBe(true);
|
|
1085
|
+
});
|
|
1086
|
+
});
|
|
@@ -64,7 +64,18 @@ class AuroraBuilder extends InfrastructureBuilder {
|
|
|
64
64
|
return false;
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
-
|
|
67
|
+
const postgres = appDefinition.database?.postgres;
|
|
68
|
+
|
|
69
|
+
// management='external': the app brings its own PostgreSQL (any
|
|
70
|
+
// provider) and connects through DATABASE_URL. Frigg creates and
|
|
71
|
+
// discovers no database resources and needs no VPC for it. This
|
|
72
|
+
// check precedes managementMode, which otherwise always manages
|
|
73
|
+
// Aurora. Migrations still run (MigrationBuilder) against DATABASE_URL.
|
|
74
|
+
if (postgres?.management === 'external') {
|
|
75
|
+
return false;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return postgres?.enable === true;
|
|
68
79
|
}
|
|
69
80
|
|
|
70
81
|
getDependencies() {
|
|
@@ -82,7 +93,7 @@ class AuroraBuilder extends InfrastructureBuilder {
|
|
|
82
93
|
const dbConfig = appDefinition.database.postgres;
|
|
83
94
|
|
|
84
95
|
// Validate management mode
|
|
85
|
-
const validModes = ['discover', 'managed', 'use-existing'];
|
|
96
|
+
const validModes = ['discover', 'managed', 'use-existing', 'external'];
|
|
86
97
|
const management = dbConfig.management || 'discover';
|
|
87
98
|
if (!validModes.includes(management)) {
|
|
88
99
|
result.addError(`Invalid database.postgres.management: "${management}"`);
|
|
@@ -42,6 +42,28 @@ describe('AuroraBuilder', () => {
|
|
|
42
42
|
expect(auroraBuilder.shouldExecute(appDefinition)).toBe(false);
|
|
43
43
|
});
|
|
44
44
|
|
|
45
|
+
it('should return false when Postgres is external (bring your own DATABASE_URL)', () => {
|
|
46
|
+
const appDefinition = {
|
|
47
|
+
database: {
|
|
48
|
+
postgres: { enable: true, management: 'external' },
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
expect(auroraBuilder.shouldExecute(appDefinition)).toBe(false);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it('should return false for external Postgres even with managementMode=managed', () => {
|
|
56
|
+
const appDefinition = {
|
|
57
|
+
managementMode: 'managed',
|
|
58
|
+
vpcIsolation: 'isolated',
|
|
59
|
+
database: {
|
|
60
|
+
postgres: { enable: true, management: 'external' },
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
expect(auroraBuilder.shouldExecute(appDefinition)).toBe(false);
|
|
65
|
+
});
|
|
66
|
+
|
|
45
67
|
it('should return false when database is not defined', () => {
|
|
46
68
|
const appDefinition = {};
|
|
47
69
|
|