Skip to content

🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

fix(docker): remove the need for runtime variables at build time (#1067)

Yash Khare0c1942c2b388
diff --git a/.env.dev.example b/.env.dev.example
index 284dbcd75f..d4644213ec 100644
--- a/.env.dev.example
+++ b/.env.dev.example
@@ -29,4 +29,8 @@ S3_ENDPOINT=
S3_ACCESS_KEY_ID=
S3_SECRET_ACCESS_KEY=
S3_BUCKET_NAME=
-S3_REGION=
\ No newline at end of file
+S3_REGION=
+
+# Set during docker build of application
+# Used to disable environment verification at build time
+# DOCKER_BUILD=1
\ No newline at end of file
diff --git a/.github/workflows/pipeline.yml b/.github/workflows/pipeline.yml
index 2f98ccdc6c..fae57586e7 100644
--- a/.github/workflows/pipeline.yml
+++ b/.github/workflows/pipeline.yml
@@ -33,10 +33,6 @@ jobs:
test-docker-build:
runs-on: ubuntu-latest
env:
- DATABASE_URL: postgresql://postgres:postgres@localhost:5432/postgres
- NEXTAUTH_SECRET: "secret"
- SALT: "salt"
- NEXTAUTH_URL: "http://localhost:3030"
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
@@ -54,11 +50,6 @@ jobs:
with:
context: .
push: false
- build-args: |
- DATABASE_URL=${{ env.DATABASE_URL }}
- NEXTAUTH_SECRET=${{ env.NEXTAUTH_SECRET }}
- NEXTAUTH_URL=${{ env.NEXTAUTH_URL }}
- SALT=${{ env.SALT }}
tests:
runs-on: ubuntu-latest
@@ -152,10 +143,6 @@ jobs:
environment: "protected branches"
runs-on: ubuntu-latest
env:
- DATABASE_URL: postgresql://postgres:postgres@localhost:5432/postgres
- NEXTAUTH_SECRET: "secret"
- SALT: "salt"
- NEXTAUTH_URL: "http://localhost:3030"
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
permissions:
@@ -198,8 +185,3 @@ jobs:
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
- build-args: |
- DATABASE_URL=${{ env.DATABASE_URL }}
- NEXTAUTH_SECRET=${{ env.NEXTAUTH_SECRET }}
- NEXTAUTH_URL=${{ env.NEXTAUTH_URL }}
- SALT=${{ env.SALT }}
diff --git a/Dockerfile b/Dockerfile
index 5dba0745be..dc11b77301 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -1,19 +1,11 @@
# Base image
FROM node:20-alpine AS base
-ARG DATABASE_URL
-ARG NEXTAUTH_SECRET
-ARG NEXTAUTH_URL
-ARG SALT
# It's important to update the index before installing packages to ensure you're getting the latest versions.
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
RUN apk update && apk upgrade --no-cache libcrypto3 libssl3 libc6-compat
FROM base AS deps
-ARG DATABASE_URL
-ARG NEXTAUTH_SECRET
-ARG NEXTAUTH_URL
-ARG SALT
WORKDIR /app
@@ -29,10 +21,6 @@ RUN \
# Rebuild the source code only when needed
FROM base AS builder
-ARG DATABASE_URL
-ARG NEXTAUTH_SECRET
-ARG NEXTAUTH_URL
-ARG SALT
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
@@ -46,6 +34,9 @@ RUN rm -f ./src/middleware.ts
# Uncomment the following line in case you want to disable telemetry during the build.
ENV NEXT_TELEMETRY_DISABLED 1
+# Disable validation of environment variables during build
+ENV DOCKER_BUILD 1
+
# Generate prisma client
RUN npx prisma generate
@@ -54,10 +45,6 @@ RUN npm run build
# Production image, copy all the files and run next
FROM base AS runner
-ARG DATABASE_URL
-ARG NEXTAUTH_SECRET
-ARG NEXTAUTH_URL
-ARG SALT
RUN apk add --no-cache dumb-init
@@ -66,6 +53,8 @@ WORKDIR /app
ENV NODE_ENV production
# Uncomment the following line in case you want to disable telemetry during runtime.
ENV NEXT_TELEMETRY_DISABLED 1
+# Needed to re-enable validation of environment variables during runtime
+ENV DOCKER_BUILD 0
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs
diff --git a/docker-compose.build.yml b/docker-compose.build.yml
index c59c3d63eb..5349b77b64 100644
--- a/docker-compose.build.yml
+++ b/docker-compose.build.yml
@@ -4,17 +4,11 @@ services:
langfuse-server:
build:
dockerfile: Dockerfile
- args:
- - DATABASE_URL=postgresql://postgres:postgres@db:5432/postgres
- - NEXTAUTH_SECRET=mysecret
- - SALT=mysalt
- - NEXTAUTH_URL=http://localhost:3000
depends_on:
- db
ports:
- "3000:3000"
environment:
- - NODE_ENV=production
- DATABASE_URL=postgresql://postgres:postgres@db:5432/postgres
- NEXTAUTH_SECRET=mysecret
- SALT=mysalt
diff --git a/docker-compose.yml b/docker-compose.yml
index 347d5d4740..c7a7e4849b 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -8,7 +8,6 @@ services:
ports:
- "3000:3000"
environment:
- - NODE_ENV=production
- DATABASE_URL=postgresql://postgres:postgres@db:5432/postgres
- NEXTAUTH_SECRET=mysecret
- SALT=mysalt
diff --git a/src/env.mjs b/src/env.mjs
index 9fd9e2be6e..d8f8692534 100644
--- a/src/env.mjs
+++ b/src/env.mjs
@@ -125,4 +125,7 @@ export const env = createEnv({
// Database exports
DB_EXPORT_PAGE_SIZE: process.env.DB_EXPORT_PAGE_SIZE,
},
+ // Skip validation in Docker builds
+ // DOCKER_BUILD is set in Dockerfile
+ skipValidation: process.env.DOCKER_BUILD === "1",
});