From ba4f78b27a113f1d27a68e12af1ccd0a46fcfcdc Mon Sep 17 00:00:00 2001 From: m4x809 Date: Sat, 25 Oct 2025 09:53:48 +0200 Subject: [PATCH] Refactor Dockerfile and update Next.js configuration for improved build process - Simplified the Dockerfile by consolidating dependency installation and streamlining the multi-stage build process. - Changed the base image for the builder and runner stages to `node:22-slim` for better compatibility. - Updated the Next.js configuration to remove the standalone output option and added a production start script in package.json. --- Dockerfile | 56 ++++++++++++++++++++++---------------------------- next.config.ts | 1 - package.json | 5 +++-- 3 files changed, 28 insertions(+), 34 deletions(-) diff --git a/Dockerfile b/Dockerfile index e51b0e2..78ec0c7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,59 +1,53 @@ -# Use bun as the base image +# Stage 1: Install dependencies with bun FROM oven/bun:latest AS deps -# Install dependencies only when needed WORKDIR /app -COPY package.json next.config.ts ./ +# Simplified copy of package files +COPY package.json bun.lock next.config.ts ./ +ARG NPM_FONT_AWESOME +RUN bun install -# Install dependencies including devDependencies -RUN bun install --frozen-lockfile - -# Build the application -FROM oven/bun:latest AS builder +# Stage 2: Build Next.js with bun +FROM node:22-slim AS builder_nextjs WORKDIR /app # Copy dependencies and config files COPY --from=deps /app/node_modules ./node_modules -COPY --from=deps /app/package.json ./ -COPY --from=deps /app/next.config.ts ./ +COPY --from=deps /app/package.json ./package.json +COPY --from=deps /app/bun.lock ./bun.lock +COPY --from=deps /app/next.config.ts ./next.config.ts # Copy source code COPY . . - ENV NODE_ENV=production ENV NEXT_TELEMETRY_DISABLED=1 -ENV SKIP_ENV_VALIDATION=1 -ENV BETTER_AUTH_TELEMETRY=0 +RUN npm run build +# Check the build output +RUN ls -la .next -# Build Next.js application -RUN bun run build - -# Production image -FROM oven/bun:latest AS runner +# Stage 4: Final runner stage +FROM node:22-slim AS runner WORKDIR /app -ENV NODE_ENV=production +# Copy Next.js build artifacts and dependencies +COPY --from=builder_nextjs /app/.next ./.next +COPY --from=builder_nextjs /app/node_modules ./node_modules +COPY --from=builder_nextjs /app/public ./public +COPY --from=builder_nextjs /app/package.json ./package.json +COPY --from=builder_nextjs /app/next.config.ts ./next.config.ts +# Copy src folder for runtime access +COPY --from=builder_nextjs /app/src ./src -# Copy Next.js build artifacts -COPY --from=builder /app/.next/standalone ./ -COPY --from=builder /app/.next/static ./.next/static -COPY --from=builder /app/public ./public -COPY --from=builder /app/node_modules ./node_modules -COPY --from=builder /app/package.json ./ -COPY --from=builder /app/next.config.ts ./ - ENV TZ="CET" ENV LANG="de_DE.UTF-8" ENV LANGUAGE="de_DE:de" ENV LC_ALL="de_DE.UTF-8" -ENV PORT=3000 EXPOSE 3000 +ENV PORT=3000 -# Start the application -CMD ["bun", "server.js"] - +CMD ["npm", "run", "prod"] \ No newline at end of file diff --git a/next.config.ts b/next.config.ts index 6b83410..e402e15 100644 --- a/next.config.ts +++ b/next.config.ts @@ -1,5 +1,4 @@ const nextConfig: import("next").NextConfig = { - output: "standalone", experimental: { viewTransition: true, }, diff --git a/package.json b/package.json index 351a101..2b13127 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,8 @@ "build": "next build", "start": "next start", "lint": "eslint .", - "fetch-links": "bun run scripts/fetch-song-links.ts" + "fetch-links": "bun run scripts/fetch-song-links.ts", + "prod": "next start" }, "dependencies": { "@fortawesome/fontawesome-svg-core": "^7.1.0", @@ -31,7 +32,7 @@ "@types/node": "^24.6.0", "@types/react": "^19.2.2", "@types/react-dom": "^19.2.2", - "babel-plugin-react-compiler": "^19.1.0-rc.3", + "babel-plugin-react-compiler": "^1.0.0", "eslint": "^9.36.0", "eslint-plugin-react-hooks": "^5.2.0", "globals": "^16.4.0",