Skip to content

Commit

Permalink
feat: point apps to the proper redis cluster (#169)
Browse files Browse the repository at this point in the history
We deployed a new cluster with the proper redis configuration
  • Loading branch information
geclos authored Sep 13, 2024
1 parent 2790fc7 commit e7919d6
Show file tree
Hide file tree
Showing 11 changed files with 31 additions and 50 deletions.
5 changes: 0 additions & 5 deletions apps/gateway/docker/run-production.sh
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
#!/bin/bash
export DATABASE_URL="postgres://latitude:secret@db:5432/latitude_development"

# Redis
export REDIS_PORT=6379
export REDIS_HOST=redis

# Gateway hostname and port
export HOST="0.0.0.0"
export PORT

docker compose run -it \
-p $PORT:$PORT \
-e DATABASE_URL="$DATABASE_URL" \
-e REDIS_HOST="$REDIS_HOST" \
-e HOST="$HOST" \
-e PORT="$PORT" \
gateway dist/server.js -p $PORT
3 changes: 0 additions & 3 deletions apps/gateway/src/common/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ export default createEnv({
process.env.BUILDING_CONTAINER == 'true' || process.env.NODE_ENV === 'test',
server: {
DATABASE_URL: z.string(),
REDIS_HOST: z.string(),
REDIS_PORT: z.coerce.number().optional(),
REDIS_PASSWORD: z.string().optional(),
HOSTNAME: z.string().default('localhost'),
PORT: z.coerce.number(),
},
Expand Down
18 changes: 9 additions & 9 deletions apps/infra/src/core/elasticCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ const SecurityGroup = new aws.ec2.SecurityGroup('LatitudeLLMCacheSg', {
})

// Create an ElastiCache cluster
const cacheCluster = new aws.elasticache.Cluster('LatitudeLLMCacheCluster', {
engine: 'redis',
nodeType: 'cache.t3.micro',
numCacheNodes: 1,
port: 6379,
subnetGroupName: subnetGroup.name,
securityGroupIds: [SecurityGroup.id],
})
// const cacheCluster = new aws.elasticache.Cluster('LatitudeLLMCacheCluster', {
// engine: 'redis',
// nodeType: 'cache.t3.micro',
// numCacheNodes: 1,
// port: 6379,
// subnetGroupName: subnetGroup.name,
// securityGroupIds: [SecurityGroup.id],
// })

const queueParameterGroup = new aws.elasticache.ParameterGroup(
'LatitudeLLMQueueParameterGroup',
Expand Down Expand Up @@ -60,5 +60,5 @@ const queueCluster = new aws.elasticache.Cluster('LatitudeLLMQueueCluster', {
})

// Export the cluster endpoint and port
export const cacheEndpoint = cacheCluster.cacheNodes[0].address
// export const cacheEndpoint = cacheCluster.cacheNodes[0].address
export const queueEndpoint = queueCluster.cacheNodes[0].address
6 changes: 3 additions & 3 deletions apps/infra/src/deployments/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const dbPasswordSecretId = coreStack.requireOutput('dbPasswordSecretId')
const dbEndpoint = coreStack.requireOutput('dbEndpoint')
const dbName = coreStack.requireOutput('dbName')
const mailerApiKeyArn = coreStack.requireOutput('mailerApiKeyArn')
const cacheEndpoint = coreStack.requireOutput('cacheEndpoint')
const queueEndpoint = coreStack.requireOutput('queueEndpoint')
const awsAccessKeyArn = coreStack.requireOutput('awsAccessKeyArn')
const awsAccessSecretArn = coreStack.requireOutput('awsAccessSecretArn')
const sentryDsnArn = coreStack.requireOutput('sentryDsnArn')
Expand Down Expand Up @@ -38,7 +38,7 @@ export const environment = pulumi
.all([
awsAccessKey,
awsAccessSecret,
cacheEndpoint,
queueEndpoint,
dbUrl,
mailerApiKey,
sentryDsn,
Expand All @@ -50,7 +50,7 @@ export const environment = pulumi
{ name: 'HOSTNAME', value: '0.0.0.0' },
{ name: 'PORT', value: '8080' },
{ name: 'DATABASE_URL', value: dbUrl },
{ name: 'REDIS_HOST', value: cacheEndpoint },
{ name: 'QUEUE_HOST', value: queueEndpoint },
{ name: 'GATEWAY_HOSTNAME', value: 'gateway.latitude.so' },
{ name: 'GATEWAY_SSL', value: 'true' },
{ name: 'LATITUDE_DOMAIN', value: 'latitude.so' },
Expand Down
4 changes: 0 additions & 4 deletions apps/web/docker/run-production.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
#!/bin/bash
export DATABASE_URL="postgres://latitude:secret@db:5432/latitude_development"

# Redis
export REDIS_PORT=6379
export REDIS_HOST=redis

docker compose up web
6 changes: 0 additions & 6 deletions apps/web/src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ export default createEnv({
server: {
NODE_ENV: z.string(),
DATABASE_URL: z.string(),
REDIS_HOST: z.string(),
REDIS_PORT: z.coerce.number().optional(),
REDIS_PASSWORD: z.string().optional(),
GATEWAY_HOSTNAME: z.string(),
GATEWAY_PORT: z.coerce.number().optional(),
GATEWAY_SSL: z
Expand All @@ -23,9 +20,6 @@ export default createEnv({
runtimeEnv: {
NODE_ENV: process.env.NODE_ENV,
DATABASE_URL: process.env.DATABASE_URL,
REDIS_HOST: process.env.REDIS_HOST,
REDIS_PORT: process.env.REDIS_PORT,
REDIS_PASSWORD: process.env.REDIS_PASSWORD,
GATEWAY_HOSTNAME: process.env.GATEWAY_HOSTNAME,
GATEWAY_PORT: process.env.GATEWAY_PORT,
GATEWAY_SSL: process.env.GATEWAY_SSL,
Expand Down
5 changes: 2 additions & 3 deletions apps/workers/docker/run-production.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
export DATABASE_URL="postgres://latitude:secret@db:5432/latitude_development"

# Redis
export REDIS_PORT=6379
export REDIS_HOST=redis
export QUEUE_HOST=redis

docker compose run -it \
-e DATABASE_URL="$DATABASE_URL" \
-e REDIS_HOST="$REDIS_HOST" \
-e QUEUE_HOST="$QUEUE_HOST" \
workers dist/server.js
12 changes: 6 additions & 6 deletions apps/workers/src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ export default createEnv({
process.env.BUILDING_CONTAINER == 'true' || process.env.NODE_ENV === 'test',
server: {
DATABASE_URL: z.string(),
REDIS_HOST: z.string(),
REDIS_PORT: z.coerce.number().optional(),
REDIS_PASSWORD: z.string().optional(),
QUEUE_HOST: z.string(),
QUEUE_PORT: z.coerce.number().optional(),
QUEUE_PASSWORD: z.string().optional(),
},
runtimeEnv: {
DATABASE_URL: process.env.DATABASE_URL,
REDIS_HOST: process.env.REDIS_HOST,
REDIS_PORT: process.env.REDIS_PORT,
REDIS_PASSWORD: process.env.REDIS_PASSWORD,
QUEUE_HOST: process.env.QUEUE_HOST,
QUEUE_PORT: process.env.QUEUE_PORT,
QUEUE_PASSWORD: process.env.QUEUE_PASSWORD,
},
})
10 changes: 5 additions & 5 deletions packages/env/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ if (environment !== 'production') {
{
NODE_ENV: environment,
DATABASE_URL: `postgres://latitude:secret@localhost:5432/latitude_${environment}`,
REDIS_PORT: '6379',
REDIS_HOST: '0.0.0.0',
QUEUE_PORT: '6379',
QUEUE_HOST: '0.0.0.0',
GATEWAY_HOSTNAME: 'localhost',
GATEWAY_PORT: '8787',
GATEWAY_SSL: 'false',
Expand All @@ -46,9 +46,9 @@ export const env = createEnv({
server: {
NODE_ENV: z.string(),
DATABASE_URL: z.string().url(),
REDIS_PORT: z.coerce.number().optional().default(6379),
REDIS_HOST: z.string(),
REDIS_PASSWORD: z.string().optional(),
QUEUE_PORT: z.coerce.number().optional().default(6379),
QUEUE_HOST: z.string(),
QUEUE_PASSWORD: z.string().optional(),
LATITUDE_URL: z.string().url(),
MAILER_API_KEY: z.string().optional(),
FROM_MAILER_EMAIL: z.string(),
Expand Down
6 changes: 3 additions & 3 deletions packages/jobs/src/utils/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { env } from '@latitude-data/env'
import { buildConnection } from '../connection'

export const connection = buildConnection({
host: env.REDIS_HOST,
port: env.REDIS_PORT,
password: env.REDIS_PASSWORD,
host: env.QUEUE_HOST,
port: env.QUEUE_PORT,
password: env.QUEUE_PASSWORD,
})
6 changes: 3 additions & 3 deletions turbo.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
"BUILDING_CONTAINER",
"LATITUDE_API_KEY",
"DATABASE_URL",
"REDIS_HOST",
"REDIS_PORT",
"REDIS_PASSWORD",
"QUEUE_HOST",
"QUEUE_PORT",
"QUEUE_PASSWORD",
"USE_LOCALHOST",
"GATEWAY_HOSTNAME",
"GATEWAY_PORT",
Expand Down

0 comments on commit e7919d6

Please sign in to comment.