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:
53
Dockerfile
53
Dockerfile
@@ -1,63 +1,20 @@
|
||||
# Use Node.js LTS version
|
||||
FROM node:20-slim AS base
|
||||
FROM node:20-slim
|
||||
|
||||
# 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/*
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# Copy package files
|
||||
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* ./
|
||||
COPY package*.json ./
|
||||
RUN npm ci
|
||||
|
||||
# Copy source code
|
||||
COPY . .
|
||||
|
||||
# Generate Prisma Client for the correct platform
|
||||
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
|
||||
|
||||
# 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 NEXT_TELEMETRY_DISABLED=1
|
||||
|
||||
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
|
||||
ENV AUTH_TRUST_HOST=true
|
||||
|
||||
EXPOSE 3000
|
||||
|
||||
ENV PORT=3000
|
||||
ENV HOSTNAME="0.0.0.0"
|
||||
|
||||
CMD ["node", "server.js"]
|
||||
CMD ["npm", "start"]
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
/** @type {import('next').NextConfig} */
|
||||
const nextConfig = {
|
||||
output: 'standalone',
|
||||
experimental: {
|
||||
optimizePackageImports: ['lucide-react'],
|
||||
},
|
||||
@@ -9,18 +8,12 @@ const nextConfig = {
|
||||
exclude: ['error', 'warn'],
|
||||
} : false,
|
||||
},
|
||||
// Enable SWC minification for better performance
|
||||
swcMinify: true,
|
||||
// Optimize images
|
||||
images: {
|
||||
formats: ['image/avif', 'image/webp'],
|
||||
unoptimized: process.env.NODE_ENV === 'production',
|
||||
},
|
||||
// Enable compression
|
||||
compress: true,
|
||||
// Production source maps (smaller)
|
||||
productionBrowserSourceMaps: false,
|
||||
// Ensure proper handling in Docker
|
||||
trailingSlash: false,
|
||||
poweredByHeader: false,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user