From a7bb4ba73df388da5a895b114eeaeeb4ad1676cb Mon Sep 17 00:00:00 2001 From: AyrisAI Date: Sat, 16 May 2026 00:45:00 +0300 Subject: [PATCH] chore: optimize Dockerfile and next.config for production standalone build --- Dockerfile | 47 +++++++++++++++++++++++++++++++++++++++++++++++ next-env.d.ts | 2 +- next.config.ts | 1 + 3 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..3b6eb30 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,47 @@ +# 1. Base image +FROM node:20-alpine AS base + +# 2. Dependencies +FROM base AS deps +RUN apk add --no-cache libc6-compat +WORKDIR /app + +COPY package.json package-lock.json* ./ +RUN npm ci + +# 3. Builder +FROM base AS builder +WORKDIR /app +COPY --from=deps /app/node_modules ./node_modules +COPY . . + +ENV NEXT_TELEMETRY_DISABLED=1 + +RUN npm run build + +# 4. Runner +FROM base AS runner +WORKDIR /app + +ENV NODE_ENV=production +ENV NEXT_TELEMETRY_DISABLED=1 + +RUN addgroup --system --gid 1001 nodejs +RUN adduser --system --uid 1001 nextjs + +COPY --from=builder /app/public ./public + +RUN mkdir .next +RUN chown nextjs:nodejs .next + +COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./ +COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static + +USER nextjs + +EXPOSE 3000 + +ENV PORT=3000 +ENV HOSTNAME="0.0.0.0" + +CMD ["node", "server.js"] diff --git a/next-env.d.ts b/next-env.d.ts index 9edff1c..c4b7818 100644 --- a/next-env.d.ts +++ b/next-env.d.ts @@ -1,6 +1,6 @@ /// /// -import "./.next/types/routes.d.ts"; +import "./.next/dev/types/routes.d.ts"; // NOTE: This file should not be edited // see https://nextjs.org/docs/app/api-reference/config/typescript for more information. diff --git a/next.config.ts b/next.config.ts index 6889e9f..60efd05 100644 --- a/next.config.ts +++ b/next.config.ts @@ -21,6 +21,7 @@ const nextConfig: NextConfig = { } ], }, + output: 'standalone', }; export default nextConfig; \ No newline at end of file