diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..b8ae033 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,41 @@ +# Multi-stage build for Next.js application +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.json package-lock.json* ./ +RUN npm ci + +# Build the application +FROM base AS builder +WORKDIR /app +COPY --from=deps /app/node_modules ./node_modules +COPY . . +RUN npm run build + +# Production image - run Next.js server +FROM base AS runner +WORKDIR /app + +ENV NODE_ENV=production + +RUN addgroup --system --gid 1001 nodejs \ + && adduser --system --uid 1001 nextjs + +# Copy only necessary files +COPY --from=builder /app/public ./public +COPY --from=builder /app/package.json ./package.json +COPY --from=deps /app/node_modules ./node_modules +COPY --from=builder /app/.next ./.next + +RUN chown -R nextjs:nodejs /app +USER nextjs + +ENV PORT=3000 +EXPOSE ${PORT} + +# Run Next.js with npm start +CMD ["npm", "start"] diff --git a/next.config.js b/next.config.js index 3da34cb..38caa70 100644 --- a/next.config.js +++ b/next.config.js @@ -1,13 +1,13 @@ /** @type {import('next').NextConfig} */ -const basePath = process.env.BASE_PATH || '' +const basePath = process.env.BASE_PATH || ""; const nextConfig = { - output: 'export', - trailingSlash: true, - images: { - unoptimized: true - }, - basePath -} + // output: "export", + trailingSlash: true, + images: { + unoptimized: true, + }, + basePath, +}; -module.exports = nextConfig +module.exports = nextConfig;