Docker update
This commit is contained in:
47
Dockerfile
47
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"]
|
||||
ENV PORT=3000
|
||||
ENV HOSTNAME="0.0.0.0"
|
||||
|
||||
CMD ["node", "server.js"]
|
||||
@ -1,6 +1,23 @@
|
||||
/** @type {import('next').NextConfig} */
|
||||
const nextConfig = {
|
||||
// Enable standalone output for Docker optimization
|
||||
output: 'standalone',
|
||||
};
|
||||
|
||||
module.exports = nextConfig;
|
||||
// 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
|
||||
Reference in New Issue
Block a user