sst 2.22.7 → 2.22.9
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/constructs/EdgeFunction.d.ts +3 -2
- package/constructs/EdgeFunction.js +7 -2
- package/constructs/Function.d.ts +10 -0
- package/constructs/Function.js +3 -0
- package/constructs/Job.d.ts +10 -0
- package/constructs/Job.js +1 -0
- package/constructs/SsrSite.d.ts +1 -2
- package/constructs/SsrSite.js +6 -10
- package/package.json +1 -1
- package/runtime/handlers/container.js +11 -1
- package/sst.mjs +7 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Construct, IConstruct } from "constructs";
|
|
2
2
|
import { Role } from "aws-cdk-lib/aws-iam";
|
|
3
|
-
import { IVersion } from "aws-cdk-lib/aws-lambda";
|
|
3
|
+
import { IVersion, IFunction as CdkIFunction } from "aws-cdk-lib/aws-lambda";
|
|
4
4
|
import { SSTConstruct } from "./Construct.js";
|
|
5
5
|
import { NodeJSProps } from "./Function.js";
|
|
6
6
|
import { Size } from "./util/size.js";
|
|
@@ -21,7 +21,8 @@ export interface EdgeFunctionProps {
|
|
|
21
21
|
export declare class EdgeFunction extends Construct {
|
|
22
22
|
role: Role;
|
|
23
23
|
functionArn: string;
|
|
24
|
-
|
|
24
|
+
function: CdkIFunction;
|
|
25
|
+
private functionCR;
|
|
25
26
|
private assetReplacer;
|
|
26
27
|
private assetReplacerPolicy;
|
|
27
28
|
private scope;
|
|
@@ -24,6 +24,7 @@ export class EdgeFunction extends Construct {
|
|
|
24
24
|
role;
|
|
25
25
|
functionArn;
|
|
26
26
|
function;
|
|
27
|
+
functionCR;
|
|
27
28
|
assetReplacer;
|
|
28
29
|
assetReplacerPolicy;
|
|
29
30
|
scope;
|
|
@@ -57,7 +58,11 @@ export class EdgeFunction extends Construct {
|
|
|
57
58
|
const { fn, fnArn } = this.createFunctionInUsEast1(assetBucket, assetKey, lambdaBucket);
|
|
58
59
|
const { versionId } = this.createVersionInUsEast1(fn, fnArn);
|
|
59
60
|
fn.node.addDependency(assetReplacer);
|
|
60
|
-
this.function =
|
|
61
|
+
this.function = CdkFunction.fromFunctionAttributes(this.scope, "ICdkFunction", {
|
|
62
|
+
functionArn: fnArn,
|
|
63
|
+
role: this.role,
|
|
64
|
+
});
|
|
65
|
+
this.functionCR = fn;
|
|
61
66
|
this.functionArn = fnArn;
|
|
62
67
|
this.versionId = versionId;
|
|
63
68
|
this.assetReplacer = assetReplacer;
|
|
@@ -343,7 +348,7 @@ export class EdgeFunction extends Construct {
|
|
|
343
348
|
return { fn, fnArn: fn.getAttString("FunctionArn") };
|
|
344
349
|
}
|
|
345
350
|
updateFunctionInUsEast1(assetBucket, assetKey) {
|
|
346
|
-
const cfnLambda = this.
|
|
351
|
+
const cfnLambda = this.functionCR.node.defaultChild;
|
|
347
352
|
cfnLambda.addPropertyOverride("FunctionParams.Code", {
|
|
348
353
|
S3Bucket: assetBucket,
|
|
349
354
|
S3Key: assetKey,
|
package/constructs/Function.d.ts
CHANGED
|
@@ -554,6 +554,16 @@ export interface ContainerProps {
|
|
|
554
554
|
* ```
|
|
555
555
|
*/
|
|
556
556
|
cmd?: string[];
|
|
557
|
+
/**
|
|
558
|
+
* Name of the Dockerfile.
|
|
559
|
+
* @example
|
|
560
|
+
* ```js
|
|
561
|
+
* container: {
|
|
562
|
+
* file: "path/to/Dockerfile.prod"
|
|
563
|
+
* }
|
|
564
|
+
* ```
|
|
565
|
+
*/
|
|
566
|
+
file?: string;
|
|
557
567
|
}
|
|
558
568
|
/**
|
|
559
569
|
* Used to configure additional files to copy into the function bundle
|
package/constructs/Function.js
CHANGED
|
@@ -198,6 +198,9 @@ export class Function extends CDKFunction {
|
|
|
198
198
|
? { platform: Platform.custom(architecture.dockerPlatform) }
|
|
199
199
|
: {}),
|
|
200
200
|
...(props.container?.cmd ? { cmd: props.container.cmd } : {}),
|
|
201
|
+
...(props.container?.file
|
|
202
|
+
? { file: props.container.file }
|
|
203
|
+
: {}),
|
|
201
204
|
}),
|
|
202
205
|
handler: CDKHandler.FROM_IMAGE,
|
|
203
206
|
runtime: CDKRuntime.FROM_IMAGE,
|
package/constructs/Job.d.ts
CHANGED
|
@@ -21,6 +21,16 @@ export interface JobContainerProps {
|
|
|
21
21
|
* ```
|
|
22
22
|
*/
|
|
23
23
|
cmd: string[];
|
|
24
|
+
/**
|
|
25
|
+
* Name of the Dockerfile.
|
|
26
|
+
* @example
|
|
27
|
+
* ```js
|
|
28
|
+
* container: {
|
|
29
|
+
* file: "path/to/Dockerfile.prod"
|
|
30
|
+
* }
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
file?: string;
|
|
24
34
|
}
|
|
25
35
|
export interface JobProps {
|
|
26
36
|
/**
|
package/constructs/Job.js
CHANGED
|
@@ -209,6 +209,7 @@ export class Job extends Construct {
|
|
|
209
209
|
platform: architecture === "arm_64"
|
|
210
210
|
? Platform.custom("linux/arm64")
|
|
211
211
|
: Platform.custom("linux/amd64"),
|
|
212
|
+
file: container?.file,
|
|
212
213
|
});
|
|
213
214
|
image.repository?.grantPull(this.job.role);
|
|
214
215
|
const project = this.job.node.defaultChild;
|
package/constructs/SsrSite.d.ts
CHANGED
|
@@ -273,7 +273,6 @@ export declare abstract class SsrSite extends Construct implements SSTConstruct
|
|
|
273
273
|
protected doNotDeploy: boolean;
|
|
274
274
|
protected buildConfig: SsrBuildConfig;
|
|
275
275
|
protected deferredTaskCallbacks: (() => void)[];
|
|
276
|
-
private serverLambdaCdkFunctionForEdge?;
|
|
277
276
|
protected serverLambdaForEdge?: EdgeFunction;
|
|
278
277
|
protected serverLambdaForRegional?: SsrFunction;
|
|
279
278
|
private serverLambdaForDev?;
|
|
@@ -297,7 +296,7 @@ export declare abstract class SsrSite extends Construct implements SSTConstruct
|
|
|
297
296
|
* The internally created CDK resources.
|
|
298
297
|
*/
|
|
299
298
|
get cdk(): {
|
|
300
|
-
function: ICdkFunction |
|
|
299
|
+
function: ICdkFunction | undefined;
|
|
301
300
|
bucket: Bucket;
|
|
302
301
|
distribution: Distribution;
|
|
303
302
|
hostedZone: IHostedZone | undefined;
|
package/constructs/SsrSite.js
CHANGED
|
@@ -48,7 +48,6 @@ export class SsrSite extends Construct {
|
|
|
48
48
|
doNotDeploy;
|
|
49
49
|
buildConfig;
|
|
50
50
|
deferredTaskCallbacks = [];
|
|
51
|
-
serverLambdaCdkFunctionForEdge;
|
|
52
51
|
serverLambdaForEdge;
|
|
53
52
|
serverLambdaForRegional;
|
|
54
53
|
serverLambdaForDev;
|
|
@@ -89,10 +88,6 @@ export class SsrSite extends Construct {
|
|
|
89
88
|
// Create Server functions
|
|
90
89
|
if (this.props.edge) {
|
|
91
90
|
this.serverLambdaForEdge = this.createFunctionForEdge();
|
|
92
|
-
this.serverLambdaCdkFunctionForEdge = CdkFunction.fromFunctionAttributes(this, "IEdgeFunction", {
|
|
93
|
-
functionArn: this.serverLambdaForEdge.functionArn,
|
|
94
|
-
role: this.serverLambdaForEdge.role,
|
|
95
|
-
});
|
|
96
91
|
}
|
|
97
92
|
else {
|
|
98
93
|
this.serverLambdaForRegional = this.createFunctionForRegional();
|
|
@@ -168,7 +163,8 @@ export class SsrSite extends Construct {
|
|
|
168
163
|
if (this.doNotDeploy)
|
|
169
164
|
return;
|
|
170
165
|
return {
|
|
171
|
-
function: this.
|
|
166
|
+
function: this.serverLambdaForEdge?.function ||
|
|
167
|
+
this.serverLambdaForRegional?.function,
|
|
172
168
|
bucket: this.bucket,
|
|
173
169
|
distribution: this.distribution,
|
|
174
170
|
hostedZone: this.hostedZone,
|
|
@@ -188,7 +184,7 @@ export class SsrSite extends Construct {
|
|
|
188
184
|
* ```
|
|
189
185
|
*/
|
|
190
186
|
attachPermissions(permissions) {
|
|
191
|
-
const server = this.
|
|
187
|
+
const server = this.serverLambdaForEdge ||
|
|
192
188
|
this.serverLambdaForRegional ||
|
|
193
189
|
this.serverLambdaForDev;
|
|
194
190
|
attachPermissionsToRole(server?.role, permissions);
|
|
@@ -206,7 +202,7 @@ export class SsrSite extends Construct {
|
|
|
206
202
|
edge: this.props.edge,
|
|
207
203
|
server: (this.serverLambdaForDev ||
|
|
208
204
|
this.serverLambdaForRegional ||
|
|
209
|
-
this.
|
|
205
|
+
this.serverLambdaForEdge)?.functionArn,
|
|
210
206
|
secrets: (this.props.bind || [])
|
|
211
207
|
.filter((c) => c instanceof Secret)
|
|
212
208
|
.map((c) => c.name),
|
|
@@ -480,12 +476,12 @@ export class SsrSite extends Construct {
|
|
|
480
476
|
return ssrFn;
|
|
481
477
|
}
|
|
482
478
|
grantServerS3Permissions() {
|
|
483
|
-
const server = this.
|
|
479
|
+
const server = this.serverLambdaForEdge || this.serverLambdaForRegional;
|
|
484
480
|
this.bucket.grantReadWrite(server.role);
|
|
485
481
|
}
|
|
486
482
|
grantServerCloudFrontPermissions() {
|
|
487
483
|
const stack = Stack.of(this);
|
|
488
|
-
const server = this.
|
|
484
|
+
const server = this.serverLambdaForEdge || this.serverLambdaForRegional;
|
|
489
485
|
const policy = new Policy(this, "ServerFunctionInvalidatorPolicy", {
|
|
490
486
|
statements: [
|
|
491
487
|
new PolicyStatement({
|
package/package.json
CHANGED
|
@@ -52,7 +52,14 @@ export const useContainerHandler = Context.memo(async () => {
|
|
|
52
52
|
sources.set(input.functionID, project);
|
|
53
53
|
if (input.mode === "start") {
|
|
54
54
|
try {
|
|
55
|
-
const result = await execAsync(
|
|
55
|
+
const result = await execAsync([
|
|
56
|
+
`docker build`,
|
|
57
|
+
`-t sst-dev:${input.functionID}`,
|
|
58
|
+
...(input.props.container?.file
|
|
59
|
+
? [`-f ${input.props.container.file}`]
|
|
60
|
+
: []),
|
|
61
|
+
`.`,
|
|
62
|
+
].join(" "), {
|
|
56
63
|
cwd: project,
|
|
57
64
|
env: {
|
|
58
65
|
...process.env,
|
|
@@ -74,6 +81,9 @@ export const useContainerHandler = Context.memo(async () => {
|
|
|
74
81
|
await execAsync([
|
|
75
82
|
`docker build`,
|
|
76
83
|
`-t sst-build:${input.functionID}`,
|
|
84
|
+
...(input.props.container?.file
|
|
85
|
+
? [`-f ${input.props.container.file}`]
|
|
86
|
+
: []),
|
|
77
87
|
`--platform ${platform}`,
|
|
78
88
|
`.`,
|
|
79
89
|
].join(" "), {
|
package/sst.mjs
CHANGED
|
@@ -4929,7 +4929,12 @@ var init_container = __esm({
|
|
|
4929
4929
|
if (input.mode === "start") {
|
|
4930
4930
|
try {
|
|
4931
4931
|
const result = await execAsync(
|
|
4932
|
-
|
|
4932
|
+
[
|
|
4933
|
+
`docker build`,
|
|
4934
|
+
`-t sst-dev:${input.functionID}`,
|
|
4935
|
+
...input.props.container?.file ? [`-f ${input.props.container.file}`] : [],
|
|
4936
|
+
`.`
|
|
4937
|
+
].join(" "),
|
|
4933
4938
|
{
|
|
4934
4939
|
cwd: project,
|
|
4935
4940
|
env: {
|
|
@@ -4951,6 +4956,7 @@ var init_container = __esm({
|
|
|
4951
4956
|
[
|
|
4952
4957
|
`docker build`,
|
|
4953
4958
|
`-t sst-build:${input.functionID}`,
|
|
4959
|
+
...input.props.container?.file ? [`-f ${input.props.container.file}`] : [],
|
|
4954
4960
|
`--platform ${platform}`,
|
|
4955
4961
|
`.`
|
|
4956
4962
|
].join(" "),
|