Skip to content

Commit a852496

Browse files
committed
Update for Bref v3
1 parent be3e04a commit a852496

24 files changed

+65
-1319
lines changed

.github/workflows/ci.yml

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,11 @@ jobs:
1515
strategy:
1616
matrix:
1717
node:
18-
- 14
19-
- 16
20-
- 18
2118
- 20
19+
- 22
2220
steps:
23-
- uses: actions/checkout@v3
24-
- uses: actions/setup-node@v3
21+
- uses: actions/checkout@v6
22+
- uses: actions/setup-node@v6
2523
with:
2624
node-version: ${{ matrix.node }}
2725
- uses: actions/cache@v3
@@ -35,10 +33,10 @@ jobs:
3533
name: Lint
3634
runs-on: ubuntu-latest
3735
steps:
38-
- uses: actions/checkout@v3
39-
- uses: actions/setup-node@v3
36+
- uses: actions/checkout@v6
37+
- uses: actions/setup-node@v6
4038
with:
41-
node-version: 18
39+
node-version: 22
4240
- uses: actions/cache@v3
4341
with:
4442
path: ~/.npm
@@ -50,10 +48,10 @@ jobs:
5048
name: Check types
5149
runs-on: ubuntu-latest
5250
steps:
53-
- uses: actions/checkout@v3
54-
- uses: actions/setup-node@v3
51+
- uses: actions/checkout@v6
52+
- uses: actions/setup-node@v6
5553
with:
56-
node-version: 18
54+
node-version: 22
5755
- uses: actions/cache@v3
5856
with:
5957
path: ~/.npm

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ new PhpFpmFunction(this, 'MyFunction', {
5656
It inherits from the AWS CDK [`Function` construct](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_lambda.Function.html) with these options set by default:
5757

5858
- `handler`: `index.php` by default
59-
- `runtime`: `provided.al2`
59+
- `runtime`: `provided.al2023`
6060
- `code`: the code is automatically zipped from the current directory.
6161
- `layers`: the Bref layer is automatically added.
6262
- `memorySize`: `1024`
@@ -78,7 +78,7 @@ The following paths are always excluded: `.git`, `.idea`, `cdk.out`, `node_modul
7878

7979
The construct also adds the following options:
8080

81-
- `phpVersion` (default: `8.1`): the PHP version to use.
81+
- `phpVersion` (default: `8.4`): the PHP version to use.
8282

8383
#### `PhpFunction`
8484

@@ -92,7 +92,7 @@ new PhpFunction(this, 'MyFunction', {
9292

9393
It inherits from the AWS CDK [`Function` construct](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_lambda.Function.html) with these options set by default:
9494

95-
- `runtime`: `provided.al2`
95+
- `runtime`: `provided.al2023`
9696
- `code`: the code is automatically zipped from the current directory.
9797
- `layers`: the Bref layer is automatically added.
9898
- `memorySize`: `1024`
@@ -115,7 +115,7 @@ The following paths are always excluded: `.git`, `.idea`, `cdk.out`, `node_modul
115115

116116
The construct also adds the following options:
117117

118-
- `phpVersion` (default: `8.1`): the PHP version to use.
118+
- `phpVersion` (default: `8.4`): the PHP version to use.
119119

120120
#### `ConsoleFunction`
121121

@@ -129,9 +129,9 @@ new ConsoleFunction(this, 'Artisan', {
129129

130130
It inherits from the AWS CDK [`Function` construct](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_lambda.Function.html) with these options set by default:
131131

132-
- `runtime`: `provided.al2`
132+
- `runtime`: `provided.al2023`
133133
- `code`: the code is automatically zipped from the current directory.
134-
- `layers`: the Bref layers are automatically added.
134+
- `layers`: the Bref layer is automatically added.
135135
- `memorySize`: `1024`
136136
- `timeout`: `6` (seconds)
137137

@@ -152,4 +152,4 @@ The following paths are always excluded: `.git`, `.idea`, `cdk.out`, `node_modul
152152

153153
The construct also adds the following options:
154154

155-
- `phpVersion` (default: `8.1`): the PHP version to use.
155+
- `phpVersion` (default: `8.4`): the PHP version to use.

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,18 @@
99
"test": "vitest"
1010
},
1111
"peerDependencies": {
12-
"aws-cdk-lib": "^2.55.0",
12+
"aws-cdk-lib": "^2.100.0",
1313
"constructs": "^10.0.0"
1414
},
1515
"dependencies": {
16-
"@bref.sh/layers": "^2.0.95"
16+
"@bref.sh/layers": "^3.0.0"
1717
},
1818
"devDependencies": {
1919
"@types/lodash": "^4.14.195",
2020
"@types/node": "^18.11.3",
2121
"@typescript-eslint/eslint-plugin": "^5.40.1",
2222
"@typescript-eslint/parser": "^5.40.1",
23-
"aws-cdk-lib": "^2.55.0",
23+
"aws-cdk-lib": "^2.240.0",
2424
"constructs": "^10.0.0",
2525
"esbuild-node-tsc": "^1.8.5",
2626
"eslint": "8.22.0",

src/cache/Redis.ts

Lines changed: 0 additions & 47 deletions
This file was deleted.

src/function/ConsoleFunction.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
import { Stack } from 'aws-cdk-lib';
21
import { Construct } from 'constructs';
3-
import { consoleLayer } from '../layers';
42
import { PhpFunction, PhpFunctionProps } from './PhpFunction';
53

64
export class ConsoleFunction extends PhpFunction {
75
constructor(scope: Construct, id: string, props: PhpFunctionProps) {
86
super(scope, id, props);
97

10-
this.addLayers(consoleLayer(this, Stack.of(scope).region));
8+
this.addEnvironment('BREF_RUNTIME', 'console');
119
}
1210
}

src/function/PhpFpmFunction.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@ import { Function, FunctionProps, Runtime } from 'aws-cdk-lib/aws-lambda';
22
import { Duration, Stack } from 'aws-cdk-lib';
33
import { Construct } from 'constructs';
44
import { functionDefaults, vpcDefaults } from './defaults';
5-
import { fpmLayer } from '../layers';
5+
import { phpLayer } from '../layers';
66
import { packagePhpCode } from '../package';
77

88
export type PhpFpmFunctionProps = Partial<FunctionProps> & {
9-
phpVersion?: '8.0' | '8.1' | '8.2' | '8.3' | '8.4';
9+
phpVersion?: '8.2' | '8.3' | '8.4' | '8.5';
1010
};
1111

1212
export class PhpFpmFunction extends Function {
1313
constructor(scope: Construct, id: string, props: PhpFpmFunctionProps = {}) {
1414
const defaults = {
1515
description: 'HTTP application',
16-
runtime: Runtime.PROVIDED_AL2,
16+
runtime: Runtime.PROVIDED_AL2023,
1717
handler: props.handler ?? 'index.php',
1818
code: props.code ?? packagePhpCode(),
1919
// API Gateway has a 29s timeout
@@ -42,9 +42,10 @@ export class PhpFpmFunction extends Function {
4242
}
4343
const phpVersion = props.phpVersion ?? functionDefaults.phpVersion;
4444
this.addLayers(
45-
// Add the FPM layer first so that other layers can override it
46-
fpmLayer(this, region, phpVersion, props.architecture ?? functionDefaults.architecture),
45+
// Add the PHP layer first so that other layers can override it
46+
phpLayer(this, 'BrefPhpLayer', region, phpVersion, props.architecture ?? functionDefaults.architecture),
4747
...layers
4848
);
49+
this.addEnvironment('BREF_RUNTIME', 'fpm');
4950
}
5051
}

src/function/PhpFunction.ts

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,21 @@ import { Function, FunctionProps, Runtime } from 'aws-cdk-lib/aws-lambda';
22
import { Duration, Stack } from 'aws-cdk-lib';
33
import { Construct } from 'constructs';
44
import { functionDefaults, vpcDefaults } from './defaults';
5-
import { functionLayer } from '../layers';
5+
import { phpLayer } from '../layers';
66
import { packagePhpCode } from '../package';
77
import { IVpc } from 'aws-cdk-lib/aws-ec2';
88
import { VpcForServerlessApp } from '../vpc/VpcForServerlessApp';
99

1010
export type PhpFunctionProps = Partial<FunctionProps> & {
11-
phpVersion?: '8.0' | '8.1' | '8.2' | '8.3' | '8.4';
11+
phpVersion?: '8.2' | '8.3' | '8.4' | '8.5';
1212
handler: string;
1313
vpc?: IVpc | VpcForServerlessApp;
1414
};
1515

1616
export class PhpFunction extends Function {
1717
constructor(scope: Construct, id: string, props: PhpFunctionProps) {
1818
const defaults = {
19-
runtime: Runtime.PROVIDED_AL2,
19+
runtime: Runtime.PROVIDED_AL2023,
2020
code: props.code ?? packagePhpCode(),
2121
timeout: Duration.seconds(6),
2222
memorySize: functionDefaults.memorySize,
@@ -42,15 +42,12 @@ export class PhpFunction extends Function {
4242
);
4343
}
4444
const phpVersion = props.phpVersion ?? functionDefaults.phpVersion;
45+
const arch = props.architecture ?? functionDefaults.architecture;
4546
this.addLayers(
46-
// Add the function layer first so that other layers can override it
47-
functionLayer(
48-
this,
49-
region,
50-
phpVersion,
51-
props.architecture ?? functionDefaults.architecture
52-
),
47+
// Add the PHP layer first so that other layers can override it
48+
phpLayer(this, 'BrefPhpLayer', region, phpVersion, arch),
5349
...layers
5450
);
51+
this.addEnvironment('BREF_RUNTIME', 'function');
5552
}
5653
}

src/function/defaults.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { Architecture } from 'aws-cdk-lib/aws-lambda';
44

55
export const functionDefaults = {
66
path: process.cwd(),
7-
phpVersion: '8.1',
7+
phpVersion: '8.4',
88
memorySize: 1024,
99
architecture: Architecture.X86_64,
1010
excludedPhpPaths: ['.git', '.idea', 'cdk.out', 'node_modules', '.bref', '.serverless', 'tests'],

src/index.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
import { Redis } from './cache/Redis';
21
import { ConsoleFunction } from './function/ConsoleFunction';
32
import { PhpFpmFunction, PhpFpmFunctionProps } from './function/PhpFpmFunction';
43
import { PhpFunction, PhpFunctionProps } from './function/PhpFunction';
54
import { packagePhpCode } from './package';
6-
import { VpcForServerlessApp } from './vpc/VpcForServerlessApp';
75

86
export {
97
PhpFunction,
@@ -12,6 +10,4 @@ export {
1210
PhpFpmFunctionProps,
1311
ConsoleFunction,
1412
packagePhpCode,
15-
VpcForServerlessApp,
16-
Redis,
1713
};

src/layers.ts

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import { Architecture, ILayerVersion, LayerVersion } from 'aws-cdk-lib/aws-lambda';
22
import { Construct } from 'constructs';
3-
import { functionLayerArn, fpmLayerArn, consoleLayerArn } from '@bref.sh/layers';
3+
import { layerArn } from '@bref.sh/layers';
44

5-
export function functionLayer(
5+
export function phpLayer(
66
scope: Construct,
7+
id: string,
78
region: string,
89
phpVersion: string,
910
architecture: Architecture
@@ -12,26 +13,7 @@ export function functionLayer(
1213

1314
return LayerVersion.fromLayerVersionArn(
1415
scope,
15-
'Bref001FunctionLayer',
16-
functionLayerArn(region, phpVersion, platform)
16+
id,
17+
layerArn(region, phpVersion, platform)
1718
);
1819
}
19-
20-
export function fpmLayer(
21-
scope: Construct,
22-
region: string,
23-
phpVersion: string,
24-
architecture: Architecture
25-
): ILayerVersion {
26-
const platform = architecture === Architecture.X86_64 ? 'x86' : 'arm';
27-
28-
return LayerVersion.fromLayerVersionArn(
29-
scope,
30-
'Bref101FpmLayer',
31-
fpmLayerArn(region, phpVersion, platform)
32-
);
33-
}
34-
35-
export function consoleLayer(scope: Construct, region: string): ILayerVersion {
36-
return LayerVersion.fromLayerVersionArn(scope, 'Bref201ConsoleLayer', consoleLayerArn(region));
37-
}

0 commit comments

Comments
 (0)