Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SST #361

Closed
wants to merge 8 commits into from
Closed

SST #361

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.sst

# keep types in repo to track them
# **/types/**/*.d.ts
# but map can be ignored and just published on npm
Expand Down
2 changes: 2 additions & 0 deletions apps/chat/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
"files": [],
"type": "module",
"scripts": {
"sso": "aws sso login --sso-session=tamagui",
"sst:deploy:production": "sst deploy --stage production",
"backend": "yarn docker up",
"backend:clean": "docker compose down --volumes; rm /tmp/onechat_replica.db || true",
"backend:run-clean": "yarn backend:clean; yarn backend",
Expand Down
83 changes: 83 additions & 0 deletions sst.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/// <reference path="./.sst/platform/config.d.ts" />

export default $config({
app(input) {
return {
name: 'chat',
home: 'aws',
removal: input?.stage === 'production' ? 'retain' : 'remove',
providers: {
aws: {
profile: input.stage === 'production' ? 'tamagui-production' : 'tamagui-dev',
},
},
}
},
async run() {
const vpc = new sst.aws.Vpc('Vpc', { bastion: true })

const db = new sst.aws.Postgres('Database', {
vpc,
transform: {
parameterGroup: {
parameters: [
{
name: 'rds.logical_replication',
value: '1',
applyMethod: 'pending-reboot',
},
{
name: 'rds.force_ssl',
value: '0',
applyMethod: 'pending-reboot',
},
{
name: 'max_connections',
value: '1000',
applyMethod: 'pending-reboot',
},
],
},
},
})

const cluster = new sst.aws.Cluster('Cluster', { vpc })

const connection = $interpolate`postgres://${db.username}:${db.password}@${db.host}:${db.port}`

const service = cluster.addService('Zero', {
image: 'rocicorp/zero',
dev: {
command: 'npx zero-cache',
},
loadBalancer: {
ports: [{ listen: '80/http', forward: '4848/http' }],
},
environment: {
ZERO_UPSTREAM_DB: $interpolate`${connection}/${db.database}`,
ZERO_CVR_DB: $interpolate`${connection}/zero_cvr`,
ZERO_CHANGE_DB: $interpolate`${connection}/zero_change`,
ZERO_REPLICA_FILE: 'zero.db',
ZERO_NUM_SYNC_WORKERS: '1',
ZERO_SCHEMA_FILE: 'packages/web/zero-schema.json',
ZERO_AUTH_SECRET: 'secretkey',
},
})

new sst.aws.StaticSite('Web', {
path: 'apps/chat',
build: {
command: 'yarn build:web',
output: 'dist',
},
environment: {
ZERO_AUTH_SECRET: 'secretkey',
VITE_ZERO_CACHE_URL: $app.stage !== 'production' ? 'http://localhost:4848' : service.url,
},
})

return {
connection: $interpolate`${connection}`,
}
},
})
Loading