Detect Next.js build phase and skip DATABASE_URL check during Docker build
This commit is contained in:
@@ -11,6 +11,7 @@ WORKDIR /app
|
|||||||
COPY --from=deps /app/node_modules ./node_modules
|
COPY --from=deps /app/node_modules ./node_modules
|
||||||
COPY . .
|
COPY . .
|
||||||
ENV NEXT_TELEMETRY_DISABLED=1
|
ENV NEXT_TELEMETRY_DISABLED=1
|
||||||
|
ENV NEXT_PHASE=phase-production-build
|
||||||
RUN npm run build
|
RUN npm run build
|
||||||
|
|
||||||
FROM base AS runner
|
FROM base AS runner
|
||||||
|
|||||||
+6
-6
@@ -1,14 +1,11 @@
|
|||||||
import { Pool } from 'pg';
|
import { Pool } from 'pg';
|
||||||
|
|
||||||
|
function createPool() {
|
||||||
const connectionString = process.env.DATABASE_URL;
|
const connectionString = process.env.DATABASE_URL;
|
||||||
|
|
||||||
function createPool() {
|
|
||||||
if (!connectionString) {
|
if (!connectionString) {
|
||||||
if (process.env.NODE_ENV === 'production') {
|
if (typeof process.env.NEXT_PHASE === 'string' && process.env.NEXT_PHASE.includes('phase-production-build')) {
|
||||||
throw new Error('DATABASE_URL environment variable is not set');
|
// Next.js collects page data during the build. We don't need a real DB for that.
|
||||||
}
|
|
||||||
// During build we don't need a real connection; return a stubbed pool
|
|
||||||
// that throws clearly if someone actually tries to query.
|
|
||||||
return {
|
return {
|
||||||
query: async () => {
|
query: async () => {
|
||||||
throw new Error('DATABASE_URL environment variable is not set');
|
throw new Error('DATABASE_URL environment variable is not set');
|
||||||
@@ -21,6 +18,9 @@ function createPool() {
|
|||||||
removeListener: () => {},
|
removeListener: () => {},
|
||||||
} as unknown as Pool;
|
} as unknown as Pool;
|
||||||
}
|
}
|
||||||
|
throw new Error('DATABASE_URL environment variable is not set');
|
||||||
|
}
|
||||||
|
|
||||||
return new Pool({ connectionString });
|
return new Pool({ connectionString });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user