-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsst.config.ts
116 lines (105 loc) · 2.86 KB
/
sst.config.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/// <reference path="./.sst/platform/config.d.ts" />
import { execSync } from "node:child_process";
export default $config({
app(input) {
return {
name: "a2025BlogBackendSyncBenchmarks",
removal: input?.stage === "production" ? "retain" : "remove",
home: "aws",
providers: {
aws: {
profile: `marketing`,
},
neon: "0.6.3",
command: `1.0.1`,
},
};
},
async run() {
const { getNeonConnectionString, createNeonDb } = await import("./neon");
// Create a db in Neon
const project = neon.getProjectOutput({ id: `square-flower-52864146` });
const dbName = `user_benchmark_${$app.stage.replace(/-/g, `_`)}`;
const branchId = `br-blue-morning-a4ywuv4l`;
type NeonConnOptions = Parameters<typeof getNeonConnectionString>[0];
let dbOpts: NeonConnOptions = {
project,
branchId,
roleName: "",
databaseName: "",
pooled: false,
};
const { dbName: resultingDbName, ownerName } = createNeonDb({
projectId: project.id,
branchId,
dbName,
});
dbOpts.roleName = ownerName;
dbOpts.databaseName = resultingDbName;
const dbUrl = getNeonConnectionString(dbOpts);
const postgres = new sst.Linkable(`postgres`, {
properties: {
url: dbUrl,
},
});
dbUrl.apply((url) => {
applyMigrations(url);
});
const vpc = sst.aws.Vpc.get(
"examples-infra-shared-examplesInfraVpcShared",
"vpc-044836d73fc26a218",
);
const cluster = sst.aws.Cluster.get(
"examples-infra-shared-examplesInfraClusterSharedCluster",
{
vpc,
id: `arn:aws:ecs:us-east-1:904233135193:cluster/examples-infra-shared-examplesInfraClusterSharedCluster`,
},
);
const redisBenchmark = cluster.addService("redis-benchmark", {
link: [postgres],
dev: {
command: `npx tsx ./node/index.ts`,
url: `http://localhost:4005`,
},
memory: `8 GB`,
cpu: `4 vCPU`,
containers: [
{
name: `benchmark-script`,
image: {
dockerfile: `./node/Dockerfile.redis`,
},
environment: {
SOURCE_ID: process.env.SOURCE_ID,
SOURCE_SECRET: process.env.SOURCE_SECRET,
NO_COLOR: "1",
FORCE_COLOR: "0",
},
cpu: `2 vCPU`,
memory: `4 GB`,
},
{
name: `redis`,
image: {
dockerfile: `./node/Dockerfile.redis-server`,
},
cpu: `2 vCPU`,
memory: `4 GB`,
},
],
});
return {
dbUrl: postgres.properties.url,
};
},
});
function applyMigrations(uri: string) {
console.log(`apply migrations to `, uri);
execSync(`npx pg-migrations apply --directory ./db/migrations`, {
env: {
...process.env,
DATABASE_URL: uri,
},
});
}