Skip to content

Commit

Permalink
infra: added health checks to worker container, finally fixed sentry …
Browse files Browse the repository at this point in the history
…in production
  • Loading branch information
geclos committed Sep 15, 2024
1 parent 3c168d7 commit cc238fb
Show file tree
Hide file tree
Showing 11 changed files with 235 additions and 182 deletions.
43 changes: 25 additions & 18 deletions apps/infra/src/deployments/web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,31 @@ const coreRepo = new aws.ecr.Repository('latitude-llm-core-repo')

// Build and push the Docker image
const token = await aws.ecr.getAuthorizationToken()
const image = new docker.Image('LatitudeLLMAppImage', {
build: {
platform: 'linux/amd64',
context: resolve('../../../'),
dockerfile: resolve('../../../apps/web/docker/Dockerfile'),
args: {
SENTRY_DSN: sentryDsn,
SENTRY_ORG: sentryOrg,
SENTRY_PROJECT: sentryProject,
},
},
imageName: pulumi.interpolate`${repo.repositoryUrl}:latest`,
registry: {
server: repo.repositoryUrl,
username: token.userName,
password: pulumi.secret(token.password),
},
})

const image = pulumi.all([sentryDsn, sentryOrg, sentryProject]).apply(
([sentryDsn, sentryOrg, sentryProject]) =>
new docker.Image('LatitudeLLMAppImage', {
build: {
platform: 'linux/amd64',
context: resolve('../../../'),
dockerfile: resolve('../../../apps/web/docker/Dockerfile'),
cacheFrom: {
images: [pulumi.interpolate`${repo.repositoryUrl}:latest`],
},
args: {
SENTRY_DSN: sentryDsn,
SENTRY_ORG: sentryOrg,
SENTRY_PROJECT: sentryProject,
},
},
imageName: pulumi.interpolate`${repo.repositoryUrl}:latest`,
registry: {
server: repo.repositoryUrl,
username: token.userName,
password: pulumi.secret(token.password),
},
}),
)
const coreImage = new docker.Image('LatitudeLLMCoreImage', {
build: {
platform: 'linux/amd64',
Expand Down
29 changes: 11 additions & 18 deletions apps/infra/src/deployments/workers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,11 @@ import { Cluster } from '@pulumi/aws/ecs'
import * as docker from '@pulumi/docker'
import * as pulumi from '@pulumi/pulumi'

import {
ecsSecurityGroup,
ecsTaskExecutionRole,
privateSubnets,
resolve,
} from '../shared'
import { ecsTaskExecutionRole, resolve } from '../shared'
import { coreStack, environment } from './shared'

// Create an ECR repository
const repo = new aws.ecr.Repository('latitude-llm-workers-repo')

// Build and push the Docker image
const token = await aws.ecr.getAuthorizationToken()
const image = new docker.Image('LatitudeLLMWorkersImage', {
build: {
Expand All @@ -30,9 +23,7 @@ const image = new docker.Image('LatitudeLLMWorkersImage', {
},
})

// Create a Fargate task definition
const containerName = 'LatitudeLLMWorkersContainer'
// Create the log group
const logGroup = new aws.cloudwatch.LogGroup('LatitudeLLMWorkersLogGroup', {
name: '/ecs/LatitudeLLMWorkers',
retentionInDays: 7,
Expand All @@ -54,10 +45,17 @@ const taskDefinition = pulumi
name: containerName,
image: imageName,
essential: true,
portMappings: [
{ containerPort: 8080, hostPort: 8080, protocol: 'tcp' },
],
environment,
healthCheck: {
command: [
'CMD-SHELL',
'curl -f http://localhost:3000/health || exit 1',
],
interval: 30,
timeout: 5,
retries: 3,
startPeriod: 60,
},
logConfiguration: {
logDriver: 'awslogs',
options: {
Expand All @@ -78,11 +76,6 @@ export const service = new aws.ecs.Service('LatitudeLLMWorkers', {
desiredCount: 1,
launchType: 'FARGATE',
forceNewDeployment: true,
networkConfiguration: {
subnets: privateSubnets.ids,
assignPublicIp: false,
securityGroups: [ecsSecurityGroup],
},
tags: {
diggest: image.repoDigest,
},
Expand Down
7 changes: 7 additions & 0 deletions apps/web/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
ARG PROJECT="@latitude-data/web"
ARG PROJECT_PATH="apps/web"
ARG SENTRY_DSN
ARG SENTRY_ORG
ARG SENTRY_PROJECT

FROM node:20-alpine AS alpine

Expand Down Expand Up @@ -55,6 +58,10 @@ COPY --from=pruner /app/out/full/ .

RUN --mount=type=cache,id=pnpm,target=/pnpm/store \
BUILDING_CONTAINER=true \
NEXT_TELEMETRY_DISABLED=1 \
SENTRY_ORG=$SENTRY_ORG \
SENTRY_PROJECT=$SENTRY_PROJECT \
SENTRY_DSN=$SENTRY_DSN \
pnpm turbo build --filter="${PROJECT}..."

RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm prune --prod --no-optional
Expand Down
10 changes: 8 additions & 2 deletions apps/web/src/app/global-error.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { useEffect } from 'react'
import { Button } from '@latitude-data/web-ui'
import { ErrorComponent } from '@latitude-data/web-ui/browser'
import * as Sentry from '@sentry/nextjs'
import { fontMono, fontSans } from '$/helpers/fonts'
import { ROUTES } from '$/services/routes'
import Link from 'next/link'

Expand All @@ -18,8 +19,13 @@ export default function GlobalError({
}, [error])

return (
<html>
<body>
<html lang='en' suppressHydrationWarning>
<head>
<meta charSet='utf-8' />
<meta name='viewport' content='width=device-width, initial-scale=1' />
<link rel='icon' href='/favicon.svg' />
</head>
<body className={`${fontSans.variable} ${fontMono.variable} font-sans`}>
<ErrorComponent
message={error.message}
type='red'
Expand Down
134 changes: 1 addition & 133 deletions apps/web/src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,139 +7,7 @@ import '@latitude-data/web-ui/styles.css'

import { ToastProvider, TooltipProvider } from '@latitude-data/web-ui'
import { ThemeProvider } from '$/components/Providers/ThemeProvider'
import localFont from 'next/font/local'

const fontSans = localFont({
src: [
{
path: '../assets/fonts/JetBrainsMono-ExtraLight.ttf',
weight: '200',
style: 'normal',
},
{
path: '../assets/fonts/JetBrainsMono-ExtraLightItalic.ttf',
weight: '200',
style: 'italic',
},
{
path: '../assets/fonts/JetBrainsMono-Light.ttf',
weight: '300',
style: 'normal',
},
{
path: '../assets/fonts/JetBrainsMono-LightItalic.ttf',
weight: '300',
style: 'italic',
},
{
path: '../assets/fonts/JetBrainsMono-Regular.ttf',
weight: '400',
style: 'normal',
},
{
path: '../assets/fonts/JetBrainsMono-Italic.ttf',
weight: '400',
style: 'italic',
},
{
path: '../assets/fonts/JetBrainsMono-Medium.ttf',
weight: '500',
style: 'normal',
},
{
path: '../assets/fonts/JetBrainsMono-MediumItalic.ttf',
weight: '500',
style: 'italic',
},
{
path: '../assets/fonts/JetBrainsMono-SemiBold.ttf',
weight: '600',
style: 'normal',
},
{
path: '../assets/fonts/JetBrainsMono-SemiBoldItalic.ttf',
weight: '600',
style: 'italic',
},
{
path: '../assets/fonts/JetBrainsMono-Bold.ttf',
weight: '700',
style: 'normal',
},
{
path: '../assets/fonts/JetBrainsMono-BoldItalic.ttf',
weight: '700',
style: 'italic',
},
],
variable: '--font-sans',
})

const fontMono = localFont({
src: [
{
path: '../assets/fonts/JetBrainsMono-ExtraLight.ttf',
weight: '200',
style: 'normal',
},
{
path: '../assets/fonts/JetBrainsMono-ExtraLightItalic.ttf',
weight: '200',
style: 'italic',
},
{
path: '../assets/fonts/JetBrainsMono-Light.ttf',
weight: '300',
style: 'normal',
},
{
path: '../assets/fonts/JetBrainsMono-LightItalic.ttf',
weight: '300',
style: 'italic',
},
{
path: '../assets/fonts/JetBrainsMono-Regular.ttf',
weight: '400',
style: 'normal',
},
{
path: '../assets/fonts/JetBrainsMono-Italic.ttf',
weight: '400',
style: 'italic',
},
{
path: '../assets/fonts/JetBrainsMono-Medium.ttf',
weight: '500',
style: 'normal',
},
{
path: '../assets/fonts/JetBrainsMono-MediumItalic.ttf',
weight: '500',
style: 'italic',
},
{
path: '../assets/fonts/JetBrainsMono-SemiBold.ttf',
weight: '600',
style: 'normal',
},
{
path: '../assets/fonts/JetBrainsMono-SemiBoldItalic.ttf',
weight: '600',
style: 'italic',
},
{
path: '../assets/fonts/JetBrainsMono-Bold.ttf',
weight: '700',
style: 'normal',
},
{
path: '../assets/fonts/JetBrainsMono-BoldItalic.ttf',
weight: '700',
style: 'italic',
},
],
variable: '--font-mono',
})
import { fontMono, fontSans } from '$/helpers/fonts'

export const metadata: Metadata = {
title: 'Latitude App',
Expand Down
Loading

0 comments on commit cc238fb

Please sign in to comment.