From 37a8a4ff42c33c727aa927eb4eaaf13f0bb2d9e5 Mon Sep 17 00:00:00 2001 From: Aditya Tripathi Date: Fri, 16 May 2025 00:03:13 +0000 Subject: [PATCH] feat: agnostic image with runtime variables + typed config --- README.md | 2 +- apps/mail/app/(auth)/login/login-client.tsx | 4 +- apps/mail/app/(auth)/login/page.tsx | 22 +++--- .../(routes)/settings/connections/page.tsx | 3 +- apps/mail/app/layout.tsx | 2 + apps/mail/app/og-api/home/route.tsx | 11 ++- apps/mail/components/connection/add.tsx | 3 +- apps/mail/components/create/ai-chat.tsx | 3 +- apps/mail/components/create/voice.tsx | 5 +- apps/mail/components/party.tsx | 3 +- apps/mail/instrumentation.ts | 5 +- apps/mail/lib/auth-client.ts | 3 +- apps/mail/lib/constants.ts | 4 +- apps/mail/lib/email-utils.client.tsx | 16 +++-- apps/mail/lib/env.ts | 42 +++++++++++ apps/mail/lib/groq.ts | 7 +- apps/mail/lib/posthog-provider.tsx | 7 +- apps/mail/lib/services.ts | 7 +- apps/mail/lib/site-config.ts | 7 +- apps/mail/lib/utils.ts | 5 +- apps/mail/middleware.ts | 3 +- apps/mail/next.config.ts | 9 +-- apps/mail/package.json | 2 + apps/mail/providers/query-provider.tsx | 3 +- bun.lock | 46 ++++++++++++ docker-compose.prod.yaml | 32 ++++----- docker/app/Dockerfile | 72 +++---------------- scripts/docker/entrypoint.sh | 10 +++ scripts/docker/replace-placeholder.sh | 36 ++++++++++ 29 files changed, 244 insertions(+), 130 deletions(-) create mode 100644 apps/mail/lib/env.ts create mode 100644 scripts/docker/entrypoint.sh create mode 100644 scripts/docker/replace-placeholder.sh diff --git a/README.md b/README.md index 29610f2f1..2d802f91c 100644 --- a/README.md +++ b/README.md @@ -81,7 +81,7 @@ You can set up Zero in two ways: ``` - Configure your environment variables (see below) - Setup cloudflare with `bun run cf-install`, you will need to run this everytime there is a `.env` change - - Start the database with the provided docker compose setup: `bun docker:up` + - Start the database with the provided docker compose setup: `bun docker:db:up` - Initialize the database: `bun db:push` 3. **Start the App** diff --git a/apps/mail/app/(auth)/login/login-client.tsx b/apps/mail/app/(auth)/login/login-client.tsx index 9af92b1d5..7ea98b155 100644 --- a/apps/mail/app/(auth)/login/login-client.tsx +++ b/apps/mail/app/(auth)/login/login-client.tsx @@ -10,7 +10,7 @@ import { TriangleAlert } from 'lucide-react'; import { useRouter } from 'next/navigation'; import Image from 'next/image'; import { toast } from 'sonner'; -import Link from 'next/link'; +import { env } from '@/lib/env'; interface EnvVarStatus { name: string; @@ -121,7 +121,7 @@ function LoginClientContent({ providers, isProd }: LoginClientProps) { toast.promise( signIn.social({ provider: provider.id as any, - callbackURL: `${process.env.NEXT_PUBLIC_APP_URL}/mail`, + callbackURL: `${env.NEXT_PUBLIC_APP_URL}/mail`, }), { error: 'Login redirect failed', diff --git a/apps/mail/app/(auth)/login/page.tsx b/apps/mail/app/(auth)/login/page.tsx index 2512986a9..cb6655a01 100644 --- a/apps/mail/app/(auth)/login/page.tsx +++ b/apps/mail/app/(auth)/login/page.tsx @@ -1,24 +1,28 @@ import { authProviders, customProviders, isProviderEnabled } from '@zero/server/auth-providers'; import { LoginClient } from './login-client'; +import { env } from '@/lib/env'; export default function LoginPage() { - const envNodeEnv = process.env.NODE_ENV; + const envNodeEnv = env.NODE_ENV; const isProd = envNodeEnv === 'production'; - const authProviderStatus = authProviders(process.env as Record).map( + const authProviderStatus = authProviders(env as unknown as Record).map( (provider) => { const envVarStatus = - provider.envVarInfo?.map((envVar) => ({ - name: envVar.name, - set: !!process.env[envVar.name], - source: envVar.source, - defaultValue: envVar.defaultValue, - })) || []; + provider.envVarInfo?.map((envVar) => { + const envVarName = envVar.name as keyof typeof env; + return { + name: envVar.name, + set: !!env[envVarName], + source: envVar.source, + defaultValue: envVar.defaultValue, + }; + }) || []; return { id: provider.id, name: provider.name, - enabled: isProviderEnabled(provider, process.env as Record), + enabled: isProviderEnabled(provider, env as Record), required: provider.required, envVarInfo: provider.envVarInfo, envVarStatus, diff --git a/apps/mail/app/(routes)/settings/connections/page.tsx b/apps/mail/app/(routes)/settings/connections/page.tsx index da11b5a62..28266134e 100644 --- a/apps/mail/app/(routes)/settings/connections/page.tsx +++ b/apps/mail/app/(routes)/settings/connections/page.tsx @@ -24,6 +24,7 @@ import { Button } from '@/components/ui/button'; import { Badge } from '@/components/ui/badge'; import { useTranslations } from 'next-intl'; import { useState } from 'react'; +import { env } from '@/lib/env'; import Image from 'next/image'; import { toast } from 'sonner'; @@ -147,7 +148,7 @@ export default function ConnectionsPage() { onClick={async () => { await authClient.linkSocial({ provider: connection.providerId, - callbackURL: `${process.env.NEXT_PUBLIC_APP_URL}/settings/connections`, + callbackURL: `${env.NEXT_PUBLIC_APP_URL}/settings/connections`, }); }} > diff --git a/apps/mail/app/layout.tsx b/apps/mail/app/layout.tsx index bdf968d02..cdbbcee57 100644 --- a/apps/mail/app/layout.tsx +++ b/apps/mail/app/layout.tsx @@ -2,6 +2,7 @@ import { ClientProviders } from '@/providers/client-providers'; import { ServerProviders } from '@/providers/server-providers'; import { SpeedInsights } from '@vercel/speed-insights/next'; import { Geist, Geist_Mono } from 'next/font/google'; +import { PublicEnvScript } from 'next-runtime-env'; import { siteConfig } from '@/lib/site-config'; import type { PropsWithChildren } from 'react'; import type { Viewport } from 'next'; @@ -33,6 +34,7 @@ export default async function RootLayout({ children }: PropsWithChildren) {