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.
This commit is contained in:
m4x809 2025-10-25 09:53:48 +02:00
parent a93efe5150
commit ba4f78b27a
Signed by: m4x809
SSH key fingerprint: SHA256:YCoFF78p2DUP94EnCScqLwldjkKDwdKSZq3r8p/6EiU
3 changed files with 28 additions and 34 deletions

View file

@ -1,59 +1,53 @@
# Use bun as the base image # Stage 1: Install dependencies with bun
FROM oven/bun:latest AS deps FROM oven/bun:latest AS deps
# Install dependencies only when needed
WORKDIR /app 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 # Stage 2: Build Next.js with bun
RUN bun install --frozen-lockfile FROM node:22-slim AS builder_nextjs
# Build the application
FROM oven/bun:latest AS builder
WORKDIR /app WORKDIR /app
# Copy dependencies and config files # Copy dependencies and config files
COPY --from=deps /app/node_modules ./node_modules COPY --from=deps /app/node_modules ./node_modules
COPY --from=deps /app/package.json ./ COPY --from=deps /app/package.json ./package.json
COPY --from=deps /app/next.config.ts ./ COPY --from=deps /app/bun.lock ./bun.lock
COPY --from=deps /app/next.config.ts ./next.config.ts
# Copy source code # Copy source code
COPY . . COPY . .
ENV NODE_ENV=production ENV NODE_ENV=production
ENV NEXT_TELEMETRY_DISABLED=1 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 # Stage 4: Final runner stage
RUN bun run build FROM node:22-slim AS runner
# Production image
FROM oven/bun:latest AS runner
WORKDIR /app 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 TZ="CET"
ENV LANG="de_DE.UTF-8" ENV LANG="de_DE.UTF-8"
ENV LANGUAGE="de_DE:de" ENV LANGUAGE="de_DE:de"
ENV LC_ALL="de_DE.UTF-8" ENV LC_ALL="de_DE.UTF-8"
ENV PORT=3000
EXPOSE 3000 EXPOSE 3000
ENV PORT=3000
# Start the application CMD ["npm", "run", "prod"]
CMD ["bun", "server.js"]

View file

@ -1,5 +1,4 @@
const nextConfig: import("next").NextConfig = { const nextConfig: import("next").NextConfig = {
output: "standalone",
experimental: { experimental: {
viewTransition: true, viewTransition: true,
}, },

View file

@ -8,7 +8,8 @@
"build": "next build", "build": "next build",
"start": "next start", "start": "next start",
"lint": "eslint .", "lint": "eslint .",
"fetch-links": "bun run scripts/fetch-song-links.ts" "fetch-links": "bun run scripts/fetch-song-links.ts",
"prod": "next start"
}, },
"dependencies": { "dependencies": {
"@fortawesome/fontawesome-svg-core": "^7.1.0", "@fortawesome/fontawesome-svg-core": "^7.1.0",
@ -31,7 +32,7 @@
"@types/node": "^24.6.0", "@types/node": "^24.6.0",
"@types/react": "^19.2.2", "@types/react": "^19.2.2",
"@types/react-dom": "^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": "^9.36.0",
"eslint-plugin-react-hooks": "^5.2.0", "eslint-plugin-react-hooks": "^5.2.0",
"globals": "^16.4.0", "globals": "^16.4.0",