From d65f8cdf482222693c0c6449ee542d7a84091c31 Mon Sep 17 00:00:00 2001 From: AmirReza Jamali Date: Tue, 12 May 2026 13:07:48 +0330 Subject: [PATCH] feat(Dockerfile): restructure multi-stage build for improved efficiency - Introduced a multi-stage build process to optimize the Docker image size and build time. - Added a dedicated stage for dependencies installation using pnpm, enhancing package management. - Separated the build stage to compile the application, ensuring a cleaner final image. - Updated the runner stage to copy only necessary files from the build stage, improving runtime performance. --- Dockerfile | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index eff3bc6..8cd24e9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,13 +1,30 @@ +FROM docker-mirror.ravanertebat.ir/hub/node:22.14 AS base +ENV PNPM_HOME="/pnpm" +ENV PATH="${PNPM_HOME}:${PATH}" -FROM docker-mirror.ravanertebat.ir/hub/node:22.14 +WORKDIR /app +RUN corepack enable + +FROM base AS deps +COPY package.json pnpm-lock.yaml ./ +RUN pnpm install --frozen-lockfile + +FROM base AS builder +COPY --from=deps /app/node_modules ./node_modules +COPY . . +RUN pnpm run build + +FROM docker-mirror.ravanertebat.ir/hub/node:22.14 AS runner WORKDIR /app ENV NODE_ENV=production ENV HOSTNAME="0.0.0.0" -COPY ./artifacts/node /app +COPY --from=builder /app/.next/standalone ./ +COPY --from=builder /app/.next/static ./.next/static +COPY --from=builder /app/public ./public EXPOSE 3000 -CMD ["node", "server.js"] +CMD ["node", "server.js"] \ No newline at end of file