- Move themeColor and viewport to separate viewport export in layout.tsx - Improve Docker build process with npm ci and proper dependency handling - Add Docker-friendly Next.js configuration settings - Resolve constructor error and metadata warnings
61 lines
1.7 KiB
Docker
61 lines
1.7 KiB
Docker
# Use Node.js LTS version
|
|
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/*
|
|
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* ./
|
|
RUN npm ci --ignore-scripts
|
|
|
|
# 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
|
|
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 necessary files
|
|
COPY --from=builder --chown=nextjs:nodejs /app/public ./public
|
|
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/node_modules/.prisma ./node_modules/.prisma
|
|
COPY --from=builder --chown=nextjs:nodejs /app/node_modules/@prisma ./node_modules/@prisma
|
|
COPY --from=builder --chown=nextjs:nodejs /app/prisma ./prisma
|
|
|
|
USER nextjs
|
|
|
|
EXPOSE 3000
|
|
|
|
ENV PORT=3000
|
|
ENV HOSTNAME="0.0.0.0"
|
|
|
|
CMD ["node", "server.js"]
|