Skip to content
Merged
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
4 changes: 3 additions & 1 deletion .github/workflows/image.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ jobs:
IMAGE="dispatch:prisma-cli-runtime"
docker build -t "$IMAGE" .
echo "Validating Prisma CLI in image: $IMAGE"
# Pass DATABASE_URL at runtime so prisma validate can load prisma.config.ts.
# The builder stage ENV is only for npm run build (Next.js static generation).
docker run --rm --env DATABASE_URL=postgresql://localhost:5432/dispatch --entrypoint ./node_modules/.bin/prisma "$IMAGE" --version
docker run --rm --env DATABASE_URL=postgresql://localhost:5432/dispatch --entrypoint ./node_modules/.bin/prisma "$IMAGE" validate

Expand All @@ -89,4 +91,4 @@ jobs:
if: github.event_name != 'pull_request' && hashFiles('trivy-results.sarif') != ''
uses: github/codeql-action/upload-sarif@7211b7c8077ea37d8641b6271f6a365a22a5fbfa # v4
with:
sarif_file: trivy-results.sarif
sarif_file: trivy-results.sarif
4 changes: 4 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ COPY --from=deps /app/node_modules ./node_modules
COPY . .
RUN apt-get update && apt-get install -y --no-install-recommends openssl ca-certificates && rm -rf /var/lib/apt/lists/*
RUN npx prisma generate
# DATABASE_URL is needed at build time for Next.js static generation (npm run build).
# The runner stage does NOT inherit this ENV; production code requires DATABASE_URL
# at runtime via the check in src/lib/prisma.ts.
ENV DATABASE_URL=postgresql://localhost:5432/dispatch
RUN npm run build

FROM base AS runner
Expand Down
7 changes: 5 additions & 2 deletions prisma.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { defineConfig } from "prisma/config";

const databaseUrl = process.env.DATABASE_URL;

if (!databaseUrl) {
if (process.env.NODE_ENV === "production" && !databaseUrl) {
throw new Error(
"DATABASE_URL is not set. Please set the DATABASE_URL environment variable before starting the application.",
);
Expand All @@ -11,6 +11,9 @@ if (!databaseUrl) {
export default defineConfig({
schema: "prisma/schema.prisma",
datasource: {
url: databaseUrl,
// Fallback to localhost for dev/CI environments where no real DB is needed
// (e.g., prisma generate, prisma validate with --no-engine). Production
// requires DATABASE_URL via the check above.
url: databaseUrl ?? "postgresql://localhost:5432/dispatch",
},
});
6 changes: 2 additions & 4 deletions src/lib/prisma.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@ import { PrismaPg } from "@prisma/adapter-pg";
import { PrFixQueueClient } from "@/lib/pr-fix-queue";
import { AgentWorkClient } from "@/lib/agent-work";

const databaseUrl = process.env.DATABASE_URL;

if (!databaseUrl) {
if (process.env.NODE_ENV === "production" && !process.env.DATABASE_URL) {
throw new Error(
"DATABASE_URL is not set. Please set the DATABASE_URL environment variable before starting the application.",
);
}

const adapter = new PrismaPg(databaseUrl);
const adapter = new PrismaPg(process.env.DATABASE_URL!);

const globalForPrisma = globalThis as unknown as {
prisma: PrismaClient | undefined;
Expand Down