From 7c50bcc33e92150539aebc937b67db116aa3fd4e Mon Sep 17 00:00:00 2001 From: mukesh13 Date: Tue, 17 Jun 2025 16:08:52 +0530 Subject: [PATCH] Docker update --- Dockerfile | 47 ++++++++++++++++++++++++++++++++++++++--------- next.config.ts | 21 +++++++++++++++++++-- 2 files changed, 57 insertions(+), 11 deletions(-) diff --git a/Dockerfile b/Dockerfile index e873d6c..f877d14 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,21 +1,50 @@ -FROM node:18 +# Use smaller base image +FROM node:18-alpine AS base +# Install dependencies only when needed +FROM base AS deps +RUN apk add --no-cache libc6-compat WORKDIR /app # Copy package files COPY package.json pnpm-lock.yaml* ./ +RUN corepack enable pnpm && pnpm install --frozen-lockfile --production=false -# Install dependencies -RUN corepack enable pnpm && pnpm install --frozen-lockfile - -# Copy source code +# Build the source code +FROM base AS builder +WORKDIR /app +COPY --from=deps /app/node_modules ./node_modules COPY . . -# Disable telemetry +# Optimize build process +ENV NEXT_TELEMETRY_DISABLED=1 +ENV NODE_ENV=production + +# Build with optimizations +RUN corepack enable pnpm && \ + pnpm build && \ + pnpm prune --production + +# Production image +FROM base AS runner +WORKDIR /app + +ENV NODE_ENV=production ENV NEXT_TELEMETRY_DISABLED=1 -# Expose port +RUN addgroup --system --gid 1001 nodejs +RUN adduser --system --uid 1001 nextjs + +# Copy built application +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 + +USER nextjs + EXPOSE 3000 -# Skip build step - run in dev mode (much faster) -CMD ["pnpm", "dev"] \ No newline at end of file +ENV PORT=3000 +ENV HOSTNAME="0.0.0.0" + +CMD ["node", "server.js"] \ No newline at end of file diff --git a/next.config.ts b/next.config.ts index f307dcb..3836a1e 100644 --- a/next.config.ts +++ b/next.config.ts @@ -1,6 +1,23 @@ /** @type {import('next').NextConfig} */ const nextConfig = { + // Enable standalone output for Docker optimization output: 'standalone', -}; + + // Reduce build time optimizations + experimental: { + // Reduce memory usage during build + workerThreads: false, + // Skip type checking during build (do it separately) + typedRoutes: false, + }, + + // Disable source maps in production for faster builds + productionBrowserSourceMaps: false, + + // Optimize images + images: { + unoptimized: true, // Skip image optimization during build + }, +} -module.exports = nextConfig; \ No newline at end of file +module.exports = nextConfig \ No newline at end of file