fix: resolve Docker build failure by optimizing configuration and prisma signal handling

- Added .dockerignore to prevent build poisoning from local artifacts.
- Updated Dockerfile with stable Bun version, memory limits, and missing config files.
- Refined prisma.ts signal handlers to avoid process termination during Next.js build phases.
- Synchronized eslint-config-next with Next.js version.
This commit is contained in:
2026-04-02 11:24:49 +08:00
parent 8777c45a44
commit 970949a68b
4 changed files with 77 additions and 16 deletions

47
.dockerignore Normal file
View File

@@ -0,0 +1,47 @@
node_modules
.next
.git
.env
.env.local
.env.development.local
.env.test.local
.env.production.local
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
bun-debug.log*
# Docker files
Dockerfile
.dockerignore
# OS files
.DS_Store
Thumbs.db
# Markdown/Documentation
README.md
GEMINI.md
AGENTS.md
AUDIT_REPORT.md
QWEN.md
NOTE.md
task-project-apbdes.md
MUSIK_CREATE_ANALYSIS.md
darkMode.md
/test-results
/playwright-report
/tmp_assets
/foldergambar
/googleapi
/xx
/xx.ts
/xx.txt
/test.txt
/x.json
/x.sh
/xcoba.ts
/xcoba2.ts
/gambar.ttx
/test-berita-state.ts

View File

@@ -1,5 +1,5 @@
# Stage 1: Build # Stage 1: Build
FROM oven/bun:1.3 AS build FROM oven/bun:1.1 AS build
# Install build dependencies for native modules # Install build dependencies for native modules
RUN apt-get update && apt-get install -y \ RUN apt-get update && apt-get install -y \
@@ -11,10 +11,18 @@ RUN apt-get update && apt-get install -y \
# Set the working directory # Set the working directory
WORKDIR /app WORKDIR /app
# Disable telemetry and set build-time environment
ENV NEXT_TELEMETRY_DISABLED=1
ENV NODE_ENV=production
ENV NODE_OPTIONS="--max-old-space-size=4096"
# Critical ENV for API route evaluation during build
ENV WIBU_UPLOAD_DIR=uploads
ENV DATABASE_URL="postgresql://bip:Production_123@pgbouncer:5432/desa-darmasaba-staging?pgbouncer=true"
# Copy package files # Copy package files
COPY package.json bun.lock* ./ COPY package.json bun.lock* ./
# Install dependencies # Install dependencies with frozen lockfile
RUN bun install --frozen-lockfile RUN bun install --frozen-lockfile
# Copy the rest of the application code # Copy the rest of the application code
@@ -27,14 +35,16 @@ RUN cp .env.example .env
RUN bun x prisma generate RUN bun x prisma generate
# Build the application frontend # Build the application frontend
ENV NODE_ENV=production
RUN bun run build RUN bun run build
# Stage 2: Runtime # Stage 2: Runtime
FROM oven/bun:1.3-slim AS runtime FROM oven/bun:1.1-slim AS runtime
# Set environment variables # Set environment variables
ENV NODE_ENV=production ENV NODE_ENV=production
ENV NEXT_TELEMETRY_DISABLED=1
# Ensure runtime also has critical envs if they are checked at startup
ENV WIBU_UPLOAD_DIR=uploads
# Install runtime dependencies # Install runtime dependencies
RUN apt-get update && apt-get install -y \ RUN apt-get update && apt-get install -y \
@@ -46,10 +56,12 @@ WORKDIR /app
# Copy necessary files from build stage # Copy necessary files from build stage
COPY --from=build /app/package.json ./ COPY --from=build /app/package.json ./
COPY --from=build /app/bun.lock* ./
COPY --from=build /app/next.config.ts ./
COPY --from=build /app/postcss.config.cjs ./
COPY --from=build /app/tsconfig.json ./ COPY --from=build /app/tsconfig.json ./
COPY --from=build /app/.next ./.next COPY --from=build /app/.next ./.next
COPY --from=build /app/public ./public COPY --from=build /app/public ./public
COPY --from=build /app/src ./src
COPY --from=build /app/node_modules ./node_modules COPY --from=build /app/node_modules ./node_modules
COPY --from=build /app/prisma ./prisma COPY --from=build /app/prisma ./prisma

View File

@@ -120,7 +120,7 @@
"@types/react-dom": "^19", "@types/react-dom": "^19",
"@vitest/ui": "^4.0.18", "@vitest/ui": "^4.0.18",
"eslint": "^9", "eslint": "^9",
"eslint-config-next": "15.1.6", "eslint-config-next": "15.5.12",
"jsdom": "^28.0.0", "jsdom": "^28.0.0",
"msw": "^2.12.9", "msw": "^2.12.9",
"parcel": "^2.6.2", "parcel": "^2.6.2",

View File

@@ -29,16 +29,18 @@ process.on('unhandledRejection', async (error) => {
}); });
// Handle graceful shutdown // Handle graceful shutdown
process.on('SIGINT', async () => { if (process.env.NODE_ENV === 'production' && !process.env.NEXT_PHASE) {
console.log('Received SIGINT signal. Closing database connections...'); process.on('SIGINT', async () => {
await prisma.$disconnect(); console.log('Received SIGINT signal. Closing database connections...');
process.exit(0); await prisma.$disconnect();
}); // Allow natural exit
});
process.on('SIGTERM', async () => { process.on('SIGTERM', async () => {
console.log('Received SIGTERM signal. Closing database connections...'); console.log('Received SIGTERM signal. Closing database connections...');
await prisma.$disconnect(); await prisma.$disconnect();
process.exit(0); // Allow natural exit
}); });
}
export default prisma; export default prisma;