sst 2.25.2 → 2.25.4
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/App.js +3 -4
- package/constructs/AppSyncApi.js +2 -2
- package/constructs/Function.js +5 -8
- package/constructs/RemixSite.js +0 -1
- package/constructs/SsrSite.js +1 -0
- package/node/event-bus/index.d.ts +8 -1
- package/node/future/auth/handler.d.ts +3 -1
- package/node/future/auth/handler.js +19 -3
- package/package.json +1 -1
- package/runtime/handlers/container.d.ts +2 -1
- package/runtime/handlers/container.js +103 -104
- package/runtime/handlers/dotnet.d.ts +2 -1
- package/runtime/handlers/dotnet.js +6 -9
- package/runtime/handlers/go.d.ts +2 -1
- package/runtime/handlers/go.js +6 -9
- package/runtime/handlers/java.d.ts +2 -1
- package/runtime/handlers/java.js +6 -9
- package/runtime/handlers/node.d.ts +2 -1
- package/runtime/handlers/node.js +5 -8
- package/runtime/handlers/python.d.ts +2 -1
- package/runtime/handlers/python.js +6 -9
- package/runtime/handlers/rust.d.ts +2 -1
- package/runtime/handlers/rust.js +6 -9
- package/runtime/handlers.js +16 -1
- package/stacks/synth.js +0 -8
package/constructs/App.js
CHANGED
|
@@ -190,13 +190,13 @@ export class App extends CDKApp {
|
|
|
190
190
|
this.createBindingSsmParameters();
|
|
191
191
|
this.removeGovCloudUnsupportedResourceProperties();
|
|
192
192
|
useWarning().print();
|
|
193
|
-
const bootstrap = await useBootstrap();
|
|
194
193
|
for (const child of this.node.children) {
|
|
195
194
|
if (isStackConstruct(child)) {
|
|
196
195
|
// Tag stacks
|
|
197
196
|
Tags.of(child).add("sst:app", this.name);
|
|
198
197
|
Tags.of(child).add("sst:stage", this.stage);
|
|
199
|
-
if (child instanceof Stack) {
|
|
198
|
+
if (child instanceof Stack && !this.isRunningSSTTest()) {
|
|
199
|
+
const bootstrap = await useBootstrap();
|
|
200
200
|
const functions = useFunctions();
|
|
201
201
|
const sourcemaps = functions.sourcemaps.forStack(child.stackName);
|
|
202
202
|
if (sourcemaps.length) {
|
|
@@ -240,8 +240,7 @@ export class App extends CDKApp {
|
|
|
240
240
|
}
|
|
241
241
|
}
|
|
242
242
|
isRunningSSTTest() {
|
|
243
|
-
|
|
244
|
-
return process.env.SST_RESOURCES_TESTS === "enabled";
|
|
243
|
+
return process.env.NODE_ENV === "test";
|
|
245
244
|
}
|
|
246
245
|
getInputFilesFromEsbuildMetafile(file) {
|
|
247
246
|
let metaJson;
|
package/constructs/AppSyncApi.js
CHANGED
|
@@ -15,7 +15,7 @@ import * as appSyncApiDomain from "./util/appSyncApiDomain.js";
|
|
|
15
15
|
import { getFunctionRef, isCDKConstruct } from "./Construct.js";
|
|
16
16
|
import { Function as Fn, } from "./Function.js";
|
|
17
17
|
import { useProject } from "../project.js";
|
|
18
|
-
import { GraphqlApi, MappingTemplate as CDKMappingTemplate, SchemaFile, } from "aws-cdk-lib/aws-appsync";
|
|
18
|
+
import { GraphqlApi, MappingTemplate as CDKMappingTemplate, SchemaFile, Definition, } from "aws-cdk-lib/aws-appsync";
|
|
19
19
|
/////////////////////
|
|
20
20
|
// Construct
|
|
21
21
|
/////////////////////
|
|
@@ -306,7 +306,7 @@ export class AppSyncApi extends Construct {
|
|
|
306
306
|
this.cdk.graphqlApi = new GraphqlApi(this, "Api", {
|
|
307
307
|
name: app.logicalPrefixedName(id),
|
|
308
308
|
xrayEnabled: true,
|
|
309
|
-
|
|
309
|
+
definition: Definition.fromSchema(mainSchema),
|
|
310
310
|
domainName: domainData && {
|
|
311
311
|
certificate: domainData.certificate,
|
|
312
312
|
domainName: domainData.domainName,
|
package/constructs/Function.js
CHANGED
|
@@ -176,6 +176,8 @@ export class Function extends CDKFunction {
|
|
|
176
176
|
});
|
|
177
177
|
this.addEnvironment("SST_FUNCTION_ID", this.node.addr);
|
|
178
178
|
useDeferredTasks().add(async () => {
|
|
179
|
+
if (app.isRunningSSTTest())
|
|
180
|
+
return;
|
|
179
181
|
const bootstrap = await useBootstrap();
|
|
180
182
|
const bootstrapBucketArn = `arn:${Stack.of(this).partition}:s3:::${bootstrap.bucket}`;
|
|
181
183
|
this.attachPermissions([
|
|
@@ -276,15 +278,10 @@ export class Function extends CDKFunction {
|
|
|
276
278
|
this.runtime =
|
|
277
279
|
supportedRuntimes[props.runtime];
|
|
278
280
|
cfnFunction.runtime = this.runtime.toString();
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
.experimentalUseProvidedRuntime;
|
|
283
|
-
if (providedRuntime) {
|
|
284
|
-
cfnFunction.runtime = providedRuntime;
|
|
285
|
-
}
|
|
281
|
+
if (props.runtime?.startsWith("java") &&
|
|
282
|
+
props.java?.experimentalUseProvidedRuntime) {
|
|
283
|
+
cfnFunction.runtime = props.java?.experimentalUseProvidedRuntime;
|
|
286
284
|
}
|
|
287
|
-
*/
|
|
288
285
|
});
|
|
289
286
|
}
|
|
290
287
|
this.id = id;
|
package/constructs/RemixSite.js
CHANGED
package/constructs/SsrSite.js
CHANGED
|
@@ -4,6 +4,14 @@ export declare const EventBus: EventBusResources;
|
|
|
4
4
|
import { PutEventsCommandOutput } from "@aws-sdk/client-eventbridge";
|
|
5
5
|
import { EventBridgeEvent } from "aws-lambda";
|
|
6
6
|
import { ZodAny, ZodObject, ZodRawShape, z } from "zod";
|
|
7
|
+
/**
|
|
8
|
+
* PutEventsCommandOutput is used in return type of createEvent, in case the consumer of SST builds
|
|
9
|
+
* their project with declaration files, this is not portable. In order to allow TS to generate a
|
|
10
|
+
* declaration file without reference to @aws-sdk/client-eventbridge, we must re-export the type.
|
|
11
|
+
*
|
|
12
|
+
* More information here: https://github.com/microsoft/TypeScript/issues/47663#issuecomment-1519138189
|
|
13
|
+
*/
|
|
14
|
+
export { PutEventsCommandOutput };
|
|
7
15
|
export declare function createEventBuilder<Bus extends keyof typeof EventBus, MetadataShape extends ZodRawShape | undefined, MetadataFunction extends () => any>(props: {
|
|
8
16
|
bus: Bus;
|
|
9
17
|
metadata?: MetadataShape;
|
|
@@ -41,4 +49,3 @@ export declare function EventHandler<Events extends Event>(_events: Events | Eve
|
|
|
41
49
|
}[Events["type"]]) => Promise<void>): (event: EventBridgeEvent<string, any> & {
|
|
42
50
|
attempts?: number;
|
|
43
51
|
}) => Promise<void>;
|
|
44
|
-
export {};
|
|
@@ -25,7 +25,9 @@ export declare function AuthHandler<Providers extends Record<string, Adapter<any
|
|
|
25
25
|
}[keyof Providers]>(input: {
|
|
26
26
|
providers: Providers;
|
|
27
27
|
sessions?: Sessions;
|
|
28
|
-
|
|
28
|
+
/** @deprecated use allowClient callback instead */
|
|
29
|
+
clients?: () => Promise<Record<string, string>>;
|
|
30
|
+
allowClient?: (clientID: string, redirect: string) => Promise<boolean>;
|
|
29
31
|
onAuthorize?: (event: APIGatewayProxyEventV2) => Promise<void | keyof Providers>;
|
|
30
32
|
onSuccess: (input: Result, response: OnSuccessResponder<SessionValue | {
|
|
31
33
|
[key in keyof Sessions["$type"]]: {
|
|
@@ -14,7 +14,7 @@ export function AuthHandler(input) {
|
|
|
14
14
|
if (input.onIndex) {
|
|
15
15
|
return input.onIndex(evt);
|
|
16
16
|
}
|
|
17
|
-
const clients = await input.clients();
|
|
17
|
+
const clients = (await input.clients?.()) || {};
|
|
18
18
|
return {
|
|
19
19
|
statusCode: 200,
|
|
20
20
|
headers: {
|
|
@@ -107,6 +107,12 @@ export function AuthHandler(input) {
|
|
|
107
107
|
...useCookies(),
|
|
108
108
|
...useQueryParams(),
|
|
109
109
|
};
|
|
110
|
+
if (!redirect_uri) {
|
|
111
|
+
return {
|
|
112
|
+
statusCode: 400,
|
|
113
|
+
body: "Missing redirect_uri",
|
|
114
|
+
};
|
|
115
|
+
}
|
|
110
116
|
if (!provider) {
|
|
111
117
|
return {
|
|
112
118
|
statusCode: 400,
|
|
@@ -125,10 +131,20 @@ export function AuthHandler(input) {
|
|
|
125
131
|
body: "Missing client_id",
|
|
126
132
|
};
|
|
127
133
|
}
|
|
128
|
-
if (
|
|
134
|
+
if (input.clients) {
|
|
135
|
+
const clients = await input.clients();
|
|
136
|
+
if (clients[client_id] !== redirect_uri) {
|
|
137
|
+
return {
|
|
138
|
+
statusCode: 400,
|
|
139
|
+
body: "Invalid redirect_uri",
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
if (input.allowClient &&
|
|
144
|
+
!(await input.allowClient(client_id, redirect_uri))) {
|
|
129
145
|
return {
|
|
130
146
|
statusCode: 400,
|
|
131
|
-
body: "
|
|
147
|
+
body: "Invalid redirect_uri",
|
|
132
148
|
};
|
|
133
149
|
}
|
|
134
150
|
useResponse().cookies({
|
package/package.json
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import { RuntimeHandler } from "../handlers.js";
|
|
2
|
+
export declare const useContainerHandler: () => RuntimeHandler;
|
|
@@ -1,114 +1,16 @@
|
|
|
1
1
|
import http from "http";
|
|
2
2
|
import { spawn } from "child_process";
|
|
3
|
-
import { useRuntimeHandlers } from "../handlers.js";
|
|
4
3
|
import { useRuntimeWorkers } from "../workers.js";
|
|
5
4
|
import { useRuntimeServerConfig } from "../server.js";
|
|
6
|
-
import { Context } from "../../context/context.js";
|
|
7
5
|
import { VisibleError } from "../../error.js";
|
|
8
6
|
import { isChild } from "../../util/fs.js";
|
|
9
7
|
import { execAsync } from "../../util/process.js";
|
|
10
8
|
import { useFunctions } from "../../constructs/Function.js";
|
|
11
|
-
export const useContainerHandler =
|
|
12
|
-
const workers = await useRuntimeWorkers();
|
|
13
|
-
const server = await useRuntimeServerConfig();
|
|
14
|
-
const handlers = useRuntimeHandlers();
|
|
9
|
+
export const useContainerHandler = () => {
|
|
15
10
|
const containers = new Map();
|
|
16
11
|
const sources = new Map();
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
const parent = sources.get(input.functionID);
|
|
20
|
-
if (!parent)
|
|
21
|
-
return false;
|
|
22
|
-
return isChild(parent, input.file);
|
|
23
|
-
},
|
|
24
|
-
canHandle: (input) => input.startsWith("container"),
|
|
25
|
-
startWorker: async (input) => {
|
|
26
|
-
input.environment.SST_DEBUG_JOB
|
|
27
|
-
? startJobWorker(input)
|
|
28
|
-
: startLambdaWorker(input);
|
|
29
|
-
},
|
|
30
|
-
stopWorker: async (workerID) => {
|
|
31
|
-
const name = containers.get(workerID);
|
|
32
|
-
if (name) {
|
|
33
|
-
try {
|
|
34
|
-
// note:
|
|
35
|
-
// - calling `docker kill` kills the docker process much faster than `docker stop`
|
|
36
|
-
// - process.kill() does not work on docker processes
|
|
37
|
-
await execAsync(`docker kill ${name}`, {
|
|
38
|
-
env: {
|
|
39
|
-
...process.env,
|
|
40
|
-
},
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
catch (ex) {
|
|
44
|
-
console.error(ex);
|
|
45
|
-
throw new VisibleError(`Could not stop docker container ${name}`);
|
|
46
|
-
}
|
|
47
|
-
containers.delete(workerID);
|
|
48
|
-
}
|
|
49
|
-
},
|
|
50
|
-
build: async (input) => {
|
|
51
|
-
const project = input.props.handler;
|
|
52
|
-
sources.set(input.functionID, project);
|
|
53
|
-
if (input.mode === "start") {
|
|
54
|
-
try {
|
|
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
|
-
...Object.entries(input.props.container?.buildArgs || {}).map(([k, v]) => `--build-arg ${k}=${v}`),
|
|
62
|
-
`.`,
|
|
63
|
-
].join(" "), {
|
|
64
|
-
cwd: project,
|
|
65
|
-
env: {
|
|
66
|
-
...process.env,
|
|
67
|
-
},
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
catch (ex) {
|
|
71
|
-
return {
|
|
72
|
-
type: "error",
|
|
73
|
-
errors: [String(ex)],
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
if (input.mode === "deploy") {
|
|
78
|
-
try {
|
|
79
|
-
const platform = input.props.architecture === "arm_64"
|
|
80
|
-
? "linux/arm64"
|
|
81
|
-
: "linux/amd64";
|
|
82
|
-
await execAsync([
|
|
83
|
-
`docker build`,
|
|
84
|
-
`-t sst-build:${input.functionID}`,
|
|
85
|
-
...(input.props.container?.file
|
|
86
|
-
? [`-f ${input.props.container.file}`]
|
|
87
|
-
: []),
|
|
88
|
-
...Object.entries(input.props.container?.buildArgs || {}).map(([k, v]) => `--build-arg ${k}=${v}`),
|
|
89
|
-
`--platform ${platform}`,
|
|
90
|
-
`.`,
|
|
91
|
-
].join(" "), {
|
|
92
|
-
cwd: project,
|
|
93
|
-
env: {
|
|
94
|
-
...process.env,
|
|
95
|
-
},
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
catch (ex) {
|
|
99
|
-
return {
|
|
100
|
-
type: "error",
|
|
101
|
-
errors: [String(ex)],
|
|
102
|
-
};
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
return {
|
|
106
|
-
type: "success",
|
|
107
|
-
handler: "not required for container",
|
|
108
|
-
};
|
|
109
|
-
},
|
|
110
|
-
});
|
|
111
|
-
function dockerRun(input, opts, onExit) {
|
|
12
|
+
async function dockerRun(input, opts, onExit) {
|
|
13
|
+
const workers = await useRuntimeWorkers();
|
|
112
14
|
const name = `sst-workerID-${input.workerID}-${Date.now()}`;
|
|
113
15
|
const proc = spawn("docker", [
|
|
114
16
|
"run",
|
|
@@ -144,7 +46,9 @@ export const useContainerHandler = Context.memo(async () => {
|
|
|
144
46
|
});
|
|
145
47
|
containers.set(input.workerID, name);
|
|
146
48
|
}
|
|
147
|
-
function startLambdaWorker(input) {
|
|
49
|
+
async function startLambdaWorker(input) {
|
|
50
|
+
const server = await useRuntimeServerConfig();
|
|
51
|
+
const workers = await useRuntimeWorkers();
|
|
148
52
|
const fn = useFunctions().fromID(input.functionID);
|
|
149
53
|
dockerRun(input, {
|
|
150
54
|
cmd: fn?.container?.cmd,
|
|
@@ -156,6 +60,7 @@ export const useContainerHandler = Context.memo(async () => {
|
|
|
156
60
|
});
|
|
157
61
|
}
|
|
158
62
|
async function startJobWorker(input) {
|
|
63
|
+
const workers = await useRuntimeWorkers();
|
|
159
64
|
// Job container is special:
|
|
160
65
|
// 1. Not capable of receiving the `event` payload
|
|
161
66
|
// - on `sst deploy`, the CodeBuild job is started with `SST_PAYLOAD` env var
|
|
@@ -166,7 +71,7 @@ export const useContainerHandler = Context.memo(async () => {
|
|
|
166
71
|
const awsRequestId = result.headers["lambda-runtime-aws-request-id"];
|
|
167
72
|
const fn = useFunctions().fromID(input.functionID);
|
|
168
73
|
try {
|
|
169
|
-
dockerRun(input, {
|
|
74
|
+
await dockerRun(input, {
|
|
170
75
|
entrypoint: "",
|
|
171
76
|
cmd: fn?.container?.cmd,
|
|
172
77
|
envs: {
|
|
@@ -261,4 +166,98 @@ export const useContainerHandler = Context.memo(async () => {
|
|
|
261
166
|
});
|
|
262
167
|
}
|
|
263
168
|
}
|
|
264
|
-
|
|
169
|
+
return {
|
|
170
|
+
shouldBuild: (input) => {
|
|
171
|
+
const parent = sources.get(input.functionID);
|
|
172
|
+
if (!parent)
|
|
173
|
+
return false;
|
|
174
|
+
return isChild(parent, input.file);
|
|
175
|
+
},
|
|
176
|
+
canHandle: (input) => input.startsWith("container"),
|
|
177
|
+
startWorker: async (input) => {
|
|
178
|
+
input.environment.SST_DEBUG_JOB
|
|
179
|
+
? await startJobWorker(input)
|
|
180
|
+
: await startLambdaWorker(input);
|
|
181
|
+
},
|
|
182
|
+
stopWorker: async (workerID) => {
|
|
183
|
+
const name = containers.get(workerID);
|
|
184
|
+
if (name) {
|
|
185
|
+
try {
|
|
186
|
+
// note:
|
|
187
|
+
// - calling `docker kill` kills the docker process much faster than `docker stop`
|
|
188
|
+
// - process.kill() does not work on docker processes
|
|
189
|
+
await execAsync(`docker kill ${name}`, {
|
|
190
|
+
env: {
|
|
191
|
+
...process.env,
|
|
192
|
+
},
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
catch (ex) {
|
|
196
|
+
console.error(ex);
|
|
197
|
+
throw new VisibleError(`Could not stop docker container ${name}`);
|
|
198
|
+
}
|
|
199
|
+
containers.delete(workerID);
|
|
200
|
+
}
|
|
201
|
+
},
|
|
202
|
+
build: async (input) => {
|
|
203
|
+
const project = input.props.handler;
|
|
204
|
+
sources.set(input.functionID, project);
|
|
205
|
+
if (input.mode === "start") {
|
|
206
|
+
try {
|
|
207
|
+
const result = await execAsync([
|
|
208
|
+
`docker build`,
|
|
209
|
+
`-t sst-dev:${input.functionID}`,
|
|
210
|
+
...(input.props.container?.file
|
|
211
|
+
? [`-f ${input.props.container.file}`]
|
|
212
|
+
: []),
|
|
213
|
+
...Object.entries(input.props.container?.buildArgs || {}).map(([k, v]) => `--build-arg ${k}=${v}`),
|
|
214
|
+
`.`,
|
|
215
|
+
].join(" "), {
|
|
216
|
+
cwd: project,
|
|
217
|
+
env: {
|
|
218
|
+
...process.env,
|
|
219
|
+
},
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
catch (ex) {
|
|
223
|
+
return {
|
|
224
|
+
type: "error",
|
|
225
|
+
errors: [String(ex)],
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
if (input.mode === "deploy") {
|
|
230
|
+
try {
|
|
231
|
+
const platform = input.props.architecture === "arm_64"
|
|
232
|
+
? "linux/arm64"
|
|
233
|
+
: "linux/amd64";
|
|
234
|
+
await execAsync([
|
|
235
|
+
`docker build`,
|
|
236
|
+
`-t sst-build:${input.functionID}`,
|
|
237
|
+
...(input.props.container?.file
|
|
238
|
+
? [`-f ${input.props.container.file}`]
|
|
239
|
+
: []),
|
|
240
|
+
...Object.entries(input.props.container?.buildArgs || {}).map(([k, v]) => `--build-arg ${k}=${v}`),
|
|
241
|
+
`--platform ${platform}`,
|
|
242
|
+
`.`,
|
|
243
|
+
].join(" "), {
|
|
244
|
+
cwd: project,
|
|
245
|
+
env: {
|
|
246
|
+
...process.env,
|
|
247
|
+
},
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
catch (ex) {
|
|
251
|
+
return {
|
|
252
|
+
type: "error",
|
|
253
|
+
errors: [String(ex)],
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
return {
|
|
258
|
+
type: "success",
|
|
259
|
+
handler: "not required for container",
|
|
260
|
+
};
|
|
261
|
+
},
|
|
262
|
+
};
|
|
263
|
+
};
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import { RuntimeHandler } from "../handlers.js";
|
|
2
|
+
export declare const useDotnetHandler: () => RuntimeHandler;
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import { useRuntimeHandlers } from "../handlers.js";
|
|
2
1
|
import { useRuntimeWorkers } from "../workers.js";
|
|
3
|
-
import { Context } from "../../context/context.js";
|
|
4
2
|
import { spawn } from "child_process";
|
|
5
3
|
import { useRuntimeServerConfig } from "../server.js";
|
|
6
4
|
import { findBelow, isChild } from "../../util/fs.js";
|
|
@@ -21,14 +19,11 @@ const BOOTSTRAP_MAP = {
|
|
|
21
19
|
"dotnetcore3.1": "dotnet31-bootstrap",
|
|
22
20
|
dotnet6: "dotnet6-bootstrap",
|
|
23
21
|
};
|
|
24
|
-
export const useDotnetHandler =
|
|
25
|
-
const workers = await useRuntimeWorkers();
|
|
26
|
-
const server = await useRuntimeServerConfig();
|
|
27
|
-
const handlers = useRuntimeHandlers();
|
|
22
|
+
export const useDotnetHandler = () => {
|
|
28
23
|
const processes = new Map();
|
|
29
24
|
const sources = new Map();
|
|
30
25
|
const handlerName = process.platform === "win32" ? `handler.exe` : `handler`;
|
|
31
|
-
|
|
26
|
+
return {
|
|
32
27
|
shouldBuild: (input) => {
|
|
33
28
|
if (!input.file.endsWith(".cs") && !input.file.endsWith(".fs"))
|
|
34
29
|
return false;
|
|
@@ -39,6 +34,8 @@ export const useDotnetHandler = Context.memo(async () => {
|
|
|
39
34
|
},
|
|
40
35
|
canHandle: (input) => input.startsWith("dotnet"),
|
|
41
36
|
startWorker: async (input) => {
|
|
37
|
+
const workers = await useRuntimeWorkers();
|
|
38
|
+
const server = await useRuntimeServerConfig();
|
|
42
39
|
const name = input.handler.split(":")[0];
|
|
43
40
|
const proc = spawn(`dotnet`, [
|
|
44
41
|
`exec`,
|
|
@@ -114,5 +111,5 @@ export const useDotnetHandler = Context.memo(async () => {
|
|
|
114
111
|
};
|
|
115
112
|
}
|
|
116
113
|
},
|
|
117
|
-
}
|
|
118
|
-
}
|
|
114
|
+
};
|
|
115
|
+
};
|
package/runtime/handlers/go.d.ts
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import { RuntimeHandler } from "../handlers.js";
|
|
2
|
+
export declare const useGoHandler: () => RuntimeHandler;
|
package/runtime/handlers/go.js
CHANGED
|
@@ -1,22 +1,17 @@
|
|
|
1
1
|
import path from "path";
|
|
2
2
|
import fs from "fs/promises";
|
|
3
3
|
import os from "os";
|
|
4
|
-
import { useRuntimeHandlers } from "../handlers.js";
|
|
5
4
|
import { useRuntimeWorkers } from "../workers.js";
|
|
6
|
-
import { Context } from "../../context/context.js";
|
|
7
5
|
import { VisibleError } from "../../error.js";
|
|
8
6
|
import { spawn } from "child_process";
|
|
9
7
|
import { useRuntimeServerConfig } from "../server.js";
|
|
10
8
|
import { isChild } from "../../util/fs.js";
|
|
11
9
|
import { execAsync } from "../../util/process.js";
|
|
12
|
-
export const useGoHandler =
|
|
13
|
-
const workers = await useRuntimeWorkers();
|
|
14
|
-
const server = await useRuntimeServerConfig();
|
|
15
|
-
const handlers = useRuntimeHandlers();
|
|
10
|
+
export const useGoHandler = () => {
|
|
16
11
|
const processes = new Map();
|
|
17
12
|
const sources = new Map();
|
|
18
13
|
const handlerName = process.platform === "win32" ? `bootstrap.exe` : `bootstrap`;
|
|
19
|
-
|
|
14
|
+
return {
|
|
20
15
|
shouldBuild: (input) => {
|
|
21
16
|
const parent = sources.get(input.functionID);
|
|
22
17
|
if (!parent)
|
|
@@ -25,6 +20,8 @@ export const useGoHandler = Context.memo(async () => {
|
|
|
25
20
|
},
|
|
26
21
|
canHandle: (input) => input.startsWith("go"),
|
|
27
22
|
startWorker: async (input) => {
|
|
23
|
+
const workers = await useRuntimeWorkers();
|
|
24
|
+
const server = await useRuntimeServerConfig();
|
|
28
25
|
const proc = spawn(path.join(input.out, handlerName), {
|
|
29
26
|
env: {
|
|
30
27
|
...process.env,
|
|
@@ -115,8 +112,8 @@ export const useGoHandler = Context.memo(async () => {
|
|
|
115
112
|
handler: "bootstrap",
|
|
116
113
|
};
|
|
117
114
|
},
|
|
118
|
-
}
|
|
119
|
-
}
|
|
115
|
+
};
|
|
116
|
+
};
|
|
120
117
|
async function find(dir, target) {
|
|
121
118
|
if (dir === "/")
|
|
122
119
|
throw new VisibleError(`Could not find a ${target} file`);
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import { RuntimeHandler } from "../handlers.js";
|
|
2
|
+
export declare const useJavaHandler: () => RuntimeHandler;
|
package/runtime/handlers/java.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import path from "path";
|
|
2
2
|
import fs from "fs/promises";
|
|
3
3
|
import os from "os";
|
|
4
|
-
import { useRuntimeHandlers } from "../handlers.js";
|
|
5
4
|
import { useRuntimeWorkers } from "../workers.js";
|
|
6
|
-
import { Context } from "../../context/context.js";
|
|
7
5
|
import { spawn } from "child_process";
|
|
8
6
|
import { useRuntimeServerConfig } from "../server.js";
|
|
9
7
|
import { existsAsync, findBelow, isChild } from "../../util/fs.js";
|
|
@@ -11,14 +9,11 @@ import { useProject } from "../../project.js";
|
|
|
11
9
|
import { execAsync } from "../../util/process.js";
|
|
12
10
|
import url from "url";
|
|
13
11
|
import AdmZip from "adm-zip";
|
|
14
|
-
export const useJavaHandler =
|
|
15
|
-
const workers = await useRuntimeWorkers();
|
|
16
|
-
const server = await useRuntimeServerConfig();
|
|
17
|
-
const handlers = useRuntimeHandlers();
|
|
12
|
+
export const useJavaHandler = () => {
|
|
18
13
|
const processes = new Map();
|
|
19
14
|
const sources = new Map();
|
|
20
15
|
const runningBuilds = new Map();
|
|
21
|
-
|
|
16
|
+
return {
|
|
22
17
|
shouldBuild: (input) => {
|
|
23
18
|
if (!input.file.endsWith(".java"))
|
|
24
19
|
return false;
|
|
@@ -29,6 +24,8 @@ export const useJavaHandler = Context.memo(async () => {
|
|
|
29
24
|
},
|
|
30
25
|
canHandle: (input) => input.startsWith("java"),
|
|
31
26
|
startWorker: async (input) => {
|
|
27
|
+
const workers = await useRuntimeWorkers();
|
|
28
|
+
const server = await useRuntimeServerConfig();
|
|
32
29
|
const proc = spawn(`java`, [
|
|
33
30
|
`-cp`,
|
|
34
31
|
[
|
|
@@ -96,8 +93,8 @@ export const useJavaHandler = Context.memo(async () => {
|
|
|
96
93
|
};
|
|
97
94
|
}
|
|
98
95
|
},
|
|
99
|
-
}
|
|
100
|
-
}
|
|
96
|
+
};
|
|
97
|
+
};
|
|
101
98
|
async function getGradleBinary(srcPath) {
|
|
102
99
|
// Use a gradle wrapper if provided in the folder, otherwise fall back
|
|
103
100
|
// to system "gradle"
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import { RuntimeHandler } from "../handlers.js";
|
|
2
|
+
export declare const useNodeHandler: () => RuntimeHandler;
|
package/runtime/handlers/node.js
CHANGED
|
@@ -7,15 +7,11 @@ import { useProject } from "../../project.js";
|
|
|
7
7
|
import esbuild from "esbuild";
|
|
8
8
|
import url from "url";
|
|
9
9
|
import { Worker } from "worker_threads";
|
|
10
|
-
import { useRuntimeHandlers } from "../handlers.js";
|
|
11
10
|
import { useRuntimeWorkers } from "../workers.js";
|
|
12
|
-
import { Context } from "../../context/context.js";
|
|
13
11
|
import { Colors } from "../../cli/colors.js";
|
|
14
12
|
import { Logger } from "../../logger.js";
|
|
15
13
|
import { findAbove } from "../../util/fs.js";
|
|
16
|
-
export const useNodeHandler =
|
|
17
|
-
const workers = await useRuntimeWorkers();
|
|
18
|
-
const handlers = useRuntimeHandlers();
|
|
14
|
+
export const useNodeHandler = () => {
|
|
19
15
|
const rebuildCache = {};
|
|
20
16
|
process.on("exit", () => {
|
|
21
17
|
for (const { ctx } of Object.values(rebuildCache)) {
|
|
@@ -24,7 +20,7 @@ export const useNodeHandler = Context.memo(async () => {
|
|
|
24
20
|
});
|
|
25
21
|
const project = useProject();
|
|
26
22
|
const threads = new Map();
|
|
27
|
-
|
|
23
|
+
return {
|
|
28
24
|
shouldBuild: (input) => {
|
|
29
25
|
const cache = rebuildCache[input.functionID];
|
|
30
26
|
if (!cache)
|
|
@@ -37,6 +33,7 @@ export const useNodeHandler = Context.memo(async () => {
|
|
|
37
33
|
},
|
|
38
34
|
canHandle: (input) => input.startsWith("nodejs"),
|
|
39
35
|
startWorker: async (input) => {
|
|
36
|
+
const workers = await useRuntimeWorkers();
|
|
40
37
|
new Promise(async () => {
|
|
41
38
|
const worker = new Worker(url.fileURLToPath(new URL("../../support/nodejs-runtime/index.mjs", import.meta.url)), {
|
|
42
39
|
env: {
|
|
@@ -253,8 +250,8 @@ export const useNodeHandler = Context.memo(async () => {
|
|
|
253
250
|
};
|
|
254
251
|
}
|
|
255
252
|
},
|
|
256
|
-
}
|
|
257
|
-
}
|
|
253
|
+
};
|
|
254
|
+
};
|
|
258
255
|
function logMemoryUsage(functionID, handler) {
|
|
259
256
|
const printInMB = (bytes) => `${Math.round(bytes / 1024 / 1024)} MB`;
|
|
260
257
|
const used = process.memoryUsage();
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import { RuntimeHandler } from "../handlers.js";
|
|
2
|
+
export declare const usePythonHandler: () => RuntimeHandler;
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import path from "path";
|
|
2
|
-
import { useRuntimeHandlers } from "../handlers.js";
|
|
3
2
|
import { useRuntimeWorkers } from "../workers.js";
|
|
4
|
-
import { Context } from "../../context/context.js";
|
|
5
3
|
import { exec, spawn } from "child_process";
|
|
6
4
|
import { promisify } from "util";
|
|
7
5
|
import { useRuntimeServerConfig } from "../server.js";
|
|
@@ -20,10 +18,7 @@ const RUNTIME_MAP = {
|
|
|
20
18
|
"python3.10": Runtime.PYTHON_3_10,
|
|
21
19
|
"python3.11": Runtime.PYTHON_3_11,
|
|
22
20
|
};
|
|
23
|
-
export const usePythonHandler =
|
|
24
|
-
const workers = await useRuntimeWorkers();
|
|
25
|
-
const server = await useRuntimeServerConfig();
|
|
26
|
-
const handlers = useRuntimeHandlers();
|
|
21
|
+
export const usePythonHandler = () => {
|
|
27
22
|
const processes = new Map();
|
|
28
23
|
const sources = new Map();
|
|
29
24
|
async function findSrc(input) {
|
|
@@ -34,7 +29,7 @@ export const usePythonHandler = Context.memo(async () => {
|
|
|
34
29
|
return result;
|
|
35
30
|
}
|
|
36
31
|
}
|
|
37
|
-
|
|
32
|
+
return {
|
|
38
33
|
shouldBuild: (input) => {
|
|
39
34
|
const parent = sources.get(input.functionID);
|
|
40
35
|
if (!parent)
|
|
@@ -43,6 +38,8 @@ export const usePythonHandler = Context.memo(async () => {
|
|
|
43
38
|
},
|
|
44
39
|
canHandle: (input) => input.startsWith("python"),
|
|
45
40
|
startWorker: async (input) => {
|
|
41
|
+
const workers = await useRuntimeWorkers();
|
|
42
|
+
const server = await useRuntimeServerConfig();
|
|
46
43
|
const src = await findSrc(input.handler);
|
|
47
44
|
if (!src)
|
|
48
45
|
throw new Error(`Could not find src for ${input.handler}`);
|
|
@@ -142,5 +139,5 @@ export const usePythonHandler = Context.memo(async () => {
|
|
|
142
139
|
.join(path.posix.sep),
|
|
143
140
|
};
|
|
144
141
|
},
|
|
145
|
-
}
|
|
146
|
-
}
|
|
142
|
+
};
|
|
143
|
+
};
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import { RuntimeHandler } from "../handlers.js";
|
|
2
|
+
export declare const useRustHandler: () => RuntimeHandler;
|
package/runtime/handlers/rust.js
CHANGED
|
@@ -1,21 +1,16 @@
|
|
|
1
1
|
import path from "path";
|
|
2
2
|
import fs from "fs/promises";
|
|
3
|
-
import { useRuntimeHandlers } from "../handlers.js";
|
|
4
3
|
import { useRuntimeWorkers } from "../workers.js";
|
|
5
|
-
import { Context } from "../../context/context.js";
|
|
6
4
|
import { exec, spawn } from "child_process";
|
|
7
5
|
import { promisify } from "util";
|
|
8
6
|
import { useRuntimeServerConfig } from "../server.js";
|
|
9
7
|
import { findAbove, isChild } from "../../util/fs.js";
|
|
10
8
|
const execAsync = promisify(exec);
|
|
11
|
-
export const useRustHandler =
|
|
12
|
-
const workers = await useRuntimeWorkers();
|
|
13
|
-
const server = await useRuntimeServerConfig();
|
|
14
|
-
const handlers = useRuntimeHandlers();
|
|
9
|
+
export const useRustHandler = () => {
|
|
15
10
|
const processes = new Map();
|
|
16
11
|
const sources = new Map();
|
|
17
12
|
const handlerName = process.platform === "win32" ? `handler.exe` : `handler`;
|
|
18
|
-
|
|
13
|
+
return {
|
|
19
14
|
shouldBuild: (input) => {
|
|
20
15
|
if (!input.file.endsWith(".rs"))
|
|
21
16
|
return false;
|
|
@@ -27,6 +22,8 @@ export const useRustHandler = Context.memo(async () => {
|
|
|
27
22
|
},
|
|
28
23
|
canHandle: (input) => input.startsWith("rust"),
|
|
29
24
|
startWorker: async (input) => {
|
|
25
|
+
const workers = await useRuntimeWorkers();
|
|
26
|
+
const server = await useRuntimeServerConfig();
|
|
30
27
|
const proc = spawn(path.join(input.out, handlerName), {
|
|
31
28
|
env: {
|
|
32
29
|
...process.env,
|
|
@@ -109,5 +106,5 @@ export const useRustHandler = Context.memo(async () => {
|
|
|
109
106
|
handler: "handler",
|
|
110
107
|
};
|
|
111
108
|
},
|
|
112
|
-
}
|
|
113
|
-
}
|
|
109
|
+
};
|
|
110
|
+
};
|
package/runtime/handlers.js
CHANGED
|
@@ -6,8 +6,23 @@ import { useWatcher } from "../watcher.js";
|
|
|
6
6
|
import { useBus } from "../bus.js";
|
|
7
7
|
import { useProject } from "../project.js";
|
|
8
8
|
import { useFunctions } from "../constructs/Function.js";
|
|
9
|
+
import { useNodeHandler } from "./handlers/node.js";
|
|
10
|
+
import { useContainerHandler } from "./handlers/container.js";
|
|
11
|
+
import { useDotnetHandler } from "./handlers/dotnet.js";
|
|
12
|
+
import { useGoHandler } from "./handlers/go.js";
|
|
13
|
+
import { useJavaHandler } from "./handlers/java.js";
|
|
14
|
+
import { usePythonHandler } from "./handlers/python.js";
|
|
15
|
+
import { useRustHandler } from "./handlers/rust.js";
|
|
9
16
|
export const useRuntimeHandlers = Context.memo(() => {
|
|
10
|
-
const handlers = [
|
|
17
|
+
const handlers = [
|
|
18
|
+
useNodeHandler(),
|
|
19
|
+
useGoHandler(),
|
|
20
|
+
useContainerHandler(),
|
|
21
|
+
usePythonHandler(),
|
|
22
|
+
useJavaHandler(),
|
|
23
|
+
useDotnetHandler(),
|
|
24
|
+
useRustHandler(),
|
|
25
|
+
];
|
|
11
26
|
const project = useProject();
|
|
12
27
|
const bus = useBus();
|
|
13
28
|
const pendingBuilds = new Map();
|
package/stacks/synth.js
CHANGED
|
@@ -4,7 +4,6 @@ import { useAWSProvider, useSTSIdentity } from "../credentials.js";
|
|
|
4
4
|
import * as contextproviders from "sst-aws-cdk/lib/context-providers/index.js";
|
|
5
5
|
import path from "path";
|
|
6
6
|
import { VisibleError } from "../error.js";
|
|
7
|
-
import { useDotnetHandler } from "../runtime/handlers/dotnet.js";
|
|
8
7
|
export async function synth(opts) {
|
|
9
8
|
Logger.debug("Synthesizing stacks...");
|
|
10
9
|
const { App } = await import("../constructs/App.js");
|
|
@@ -15,13 +14,6 @@ export async function synth(opts) {
|
|
|
15
14
|
const { usePythonHandler } = await import("../runtime/handlers/python.js");
|
|
16
15
|
const { useJavaHandler } = await import("../runtime/handlers/java.js");
|
|
17
16
|
if (opts.mode !== "remove") {
|
|
18
|
-
useNodeHandler();
|
|
19
|
-
useGoHandler();
|
|
20
|
-
useContainerHandler();
|
|
21
|
-
usePythonHandler();
|
|
22
|
-
useJavaHandler();
|
|
23
|
-
useDotnetHandler();
|
|
24
|
-
useRustHandler();
|
|
25
17
|
}
|
|
26
18
|
const cxapi = await import("@aws-cdk/cx-api");
|
|
27
19
|
const { Configuration } = await import("sst-aws-cdk/lib/settings.js");
|