From fedb3b95da5155f4a4e21fd80cb9e06afe99f857 Mon Sep 17 00:00:00 2001 From: morteza-mortezai Date: Mon, 22 Jun 2026 20:57:54 +0330 Subject: [PATCH] opt dckr --- .dockerignore | 25 +++++++++++++++++++++++ Dockerfile | 55 ++++++++++++++++++++++++++------------------------- 2 files changed, 53 insertions(+), 27 deletions(-) create mode 100644 .dockerignore diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..ed99438 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,25 @@ +node_modules +dist +.git +.github +.husky +.env +.env.* +coverage +*.log +dump +html +none +.idea +.vscode +.DS_Store +*.md +Dockerfile +.dockerignore +docker-compose*.yml +*.test.ts +jest.config.js +.eslintrc* +.prettierrc* +commitlint.config.* +qodana.yaml diff --git a/Dockerfile b/Dockerfile index 43c4a01..d1074c1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,41 +1,42 @@ -# Stage 1: Build Stage +# syntax=docker/dockerfile:1 + FROM node:22-alpine AS base - -RUN npm install -g corepack@latest -RUN corepack enable && corepack prepare pnpm@latest --activate - -# Install tzdata to support timezone settings -RUN apk add --no-cache tzdata - -# Set the timezone to Asia/Tehran -RUN cp /usr/share/zoneinfo/Asia/Tehran /etc/localtime && echo "Asia/Tehran" > /etc/timezone - +RUN npm install -g corepack@latest \ + && corepack enable \ + && corepack prepare pnpm@9.13.0 --activate FROM base AS deps -WORKDIR /temp-deps -COPY package*.json pnpm-lock.yaml ./ -RUN pnpm install --frozen-lockfile --loglevel info - +WORKDIR /app +COPY package.json pnpm-lock.yaml ./ +RUN --mount=type=cache,id=pnpm,target=/pnpm/store \ + pnpm config set store-dir /pnpm/store \ + && pnpm install --frozen-lockfile FROM base AS builder -WORKDIR /build -COPY . ./ -COPY --from=deps /temp-deps/node_modules ./node_modules -RUN if [ -f package.json ] && grep -q '"build":' package.json; then pnpm run build; fi -RUN pnpm install --prod --frozen-lockfile --loglevel info +WORKDIR /app +COPY --from=deps /app/node_modules ./node_modules +COPY package.json pnpm-lock.yaml tsconfig.json tsconfig.build.json ./ +COPY src ./src +RUN pnpm run build && pnpm prune --prod + +FROM node:22-alpine AS runner +RUN apk add --no-cache tzdata \ + && cp /usr/share/zoneinfo/Asia/Tehran /etc/localtime \ + && echo "Asia/Tehran" > /etc/timezone \ + && addgroup -S appgroup \ + && adduser -S appuser -G appgroup -FROM base AS runner -RUN addgroup -S appgroup && adduser -S appuser -G appgroup WORKDIR /app -COPY . ./ -COPY --from=builder --chown=appuser:appgroup /build/ ./ +ENV NODE_ENV=production \ + TZ=Asia/Tehran -RUN chown -R appuser:appgroup /app +COPY --from=builder --chown=appuser:appgroup /app/node_modules ./node_modules +COPY --from=builder --chown=appuser:appgroup /app/dist ./dist +COPY --chown=appuser:appgroup package.json ./ USER appuser -ENV NODE_ENV=production EXPOSE 4000 -CMD ["npm", "start"] +CMD ["node", "--trace-warnings", "dist/server.js"]