Simplify Docker setup to fix constructor error

- Remove standalone output mode from Next.js config
- Use single-stage Docker build with npm start
- Eliminate complex multi-stage build that was causing issues
This commit is contained in:
2025-12-02 13:54:26 +00:00
parent 3a3db4195f
commit 60ebf13a9c
2 changed files with 5 additions and 55 deletions

View File

@@ -1,63 +1,20 @@
# Use Node.js LTS version FROM node:20-slim
FROM node:20-slim AS base
# Install dependencies only when needed
FROM base AS deps
RUN apt-get update && apt-get install -y openssl ca-certificates && rm -rf /var/lib/apt/lists/* RUN apt-get update && apt-get install -y openssl ca-certificates && rm -rf /var/lib/apt/lists/*
WORKDIR /app WORKDIR /app
# Copy package files COPY package*.json ./
COPY package.json package-lock.json* ./
# Clean install dependencies
RUN npm ci --only=production --ignore-scripts && npm cache clean --force
# Rebuild the source code only when needed
FROM base AS builder
RUN apt-get update && apt-get install -y openssl ca-certificates && rm -rf /var/lib/apt/lists/*
WORKDIR /app
# Copy package files and install all dependencies (including dev)
COPY package.json package-lock.json* ./
RUN npm ci RUN npm ci
# Copy source code
COPY . . COPY . .
# Generate Prisma Client for the correct platform
RUN npx prisma generate RUN npx prisma generate
# Build Next.js application
ENV NEXT_TELEMETRY_DISABLED=1
ENV AUTH_TRUST_HOST=true
ENV NODE_ENV=production
RUN npm run build RUN npm run build
# Production image, copy all the files and run next
FROM base AS runner
RUN apt-get update && apt-get install -y openssl ca-certificates && rm -rf /var/lib/apt/lists/*
WORKDIR /app
ENV NODE_ENV=production ENV NODE_ENV=production
ENV NEXT_TELEMETRY_DISABLED=1 ENV NEXT_TELEMETRY_DISABLED=1
ENV AUTH_TRUST_HOST=true
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs
# Copy the standalone output
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
COPY --from=builder --chown=nextjs:nodejs /app/public ./public
# Copy Prisma files
COPY --from=builder --chown=nextjs:nodejs /app/prisma ./prisma
COPY --from=builder --chown=nextjs:nodejs /app/node_modules/.prisma ./node_modules/.prisma
COPY --from=builder --chown=nextjs:nodejs /app/node_modules/@prisma ./node_modules/@prisma
USER nextjs
EXPOSE 3000 EXPOSE 3000
ENV PORT=3000 CMD ["npm", "start"]
ENV HOSTNAME="0.0.0.0"
CMD ["node", "server.js"]

View File

@@ -1,6 +1,5 @@
/** @type {import('next').NextConfig} */ /** @type {import('next').NextConfig} */
const nextConfig = { const nextConfig = {
output: 'standalone',
experimental: { experimental: {
optimizePackageImports: ['lucide-react'], optimizePackageImports: ['lucide-react'],
}, },
@@ -9,18 +8,12 @@ const nextConfig = {
exclude: ['error', 'warn'], exclude: ['error', 'warn'],
} : false, } : false,
}, },
// Enable SWC minification for better performance
swcMinify: true, swcMinify: true,
// Optimize images
images: { images: {
formats: ['image/avif', 'image/webp'], formats: ['image/avif', 'image/webp'],
unoptimized: process.env.NODE_ENV === 'production',
}, },
// Enable compression
compress: true, compress: true,
// Production source maps (smaller)
productionBrowserSourceMaps: false, productionBrowserSourceMaps: false,
// Ensure proper handling in Docker
trailingSlash: false, trailingSlash: false,
poweredByHeader: false, poweredByHeader: false,
} }