From 6f5431456fce0008fbc7571cb5d55e3933184cb9 Mon Sep 17 00:00:00 2001 From: Amirhossein Shaerpour Date: Mon, 20 Jan 2025 18:05:05 +0330 Subject: [PATCH 1/2] feat: Build app for production environments Signed-off-by: shaerpour --- next.config.mjs | 1 + 1 file changed, 1 insertion(+) diff --git a/next.config.mjs b/next.config.mjs index aedb702..e0e0faa 100644 --- a/next.config.mjs +++ b/next.config.mjs @@ -5,6 +5,7 @@ const nextConfig = { defaultLocale: 'fa' }, reactStrictMode: true, + output: "standalone" }; export default nextConfig; -- 2.45.3 From 34dc70e2890437d321ff0bf7243728b5d80667af Mon Sep 17 00:00:00 2001 From: Amirhossein Shaerpour Date: Mon, 20 Jan 2025 18:08:27 +0330 Subject: [PATCH 2/2] refactor(Dockerfile): Improve layer caching and use lighter base image Signed-off-by: shaerpour --- Dockerfile | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index 9713eda..1627863 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,11 +1,37 @@ -FROM node:20.10.0 +FROM node:20.10.0-alpine AS base +FROM base AS deps +RUN apk add --no-cache libc6-compat WORKDIR /app + +COPY package.json package-lock.json* ./ +RUN npm ci --legacy-peer-deps + +FROM base AS builder +WORKDIR /app +COPY --from=deps /app/node_modules ./node_modules COPY . . -RUN npm install --force RUN npm run build -EXPOSE 6080 +FROM base AS runner +WORKDIR /app -CMD ["npm", "run", "start"] +ENV NODE_ENV=production + +RUN addgroup --system --gid 1001 nodejs && \ + adduser --system --uid 1001 nextjs + +COPY --from=builder /app/public ./public + +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"] -- 2.45.3