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.
This commit is contained in:
+19
-2
@@ -1,12 +1,29 @@
|
|||||||
|
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
|
WORKDIR /app
|
||||||
ENV NODE_ENV=production
|
ENV NODE_ENV=production
|
||||||
ENV HOSTNAME="0.0.0.0"
|
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
|
EXPOSE 3000
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user