From e87f50ca7a47799421c8967482c0610214ca47ac Mon Sep 17 00:00:00 2001 From: morteza-mortezai Date: Thu, 25 Jun 2026 18:08:45 +0330 Subject: [PATCH] opt dckr --- .dockerignore | 17 +++++++++++++++++ Dockerfile | 39 ++++++++++++++++++++++----------------- 2 files changed, 39 insertions(+), 17 deletions(-) create mode 100644 .dockerignore diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..4bef18c --- /dev/null +++ b/.dockerignore @@ -0,0 +1,17 @@ +node_modules +dist +coverage +.git +.github +.env +.env.* +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* +.vscode +.idea +.DS_Store +*.md +Dockerfile* +docker-compose* diff --git a/Dockerfile b/Dockerfile index 6bc794f..7901699 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,37 +1,42 @@ FROM node:20-alpine AS base +ENV TZ=Asia/Tehran 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 - FROM base AS deps -WORKDIR /temp-deps -COPY package*.json ./ -RUN yarn install +WORKDIR /app +RUN corepack enable +COPY package.json yarn.lock ./ +RUN yarn install --frozen-lockfile FROM base AS builder -WORKDIR /build -COPY . ./ -COPY --from=deps /temp-deps/node_modules ./node_modules +WORKDIR /app +RUN corepack enable +COPY package.json yarn.lock nest-cli.json tsconfig.json tsconfig.build.json ./ +COPY --from=deps /app/node_modules ./node_modules +COPY src ./src +RUN yarn build \ + && mkdir -p dist/config \ + && cp src/config/swagger.json dist/config/ -# Check if a build script exists and run the build if it does -RUN if [ -f package.json ] && grep -q '"build":' package.json; then yarn build; fi +FROM base AS prod-deps +WORKDIR /app +RUN corepack enable +COPY package.json yarn.lock ./ RUN yarn install --production --frozen-lockfile - FROM base AS runner RUN addgroup -S appgroup && adduser -S appuser -G appgroup WORKDIR /app -COPY --from=builder /build ./ +ENV NODE_ENV=production -RUN chown -R appuser:appgroup /app +COPY --from=prod-deps --chown=appuser:appgroup /app/node_modules ./node_modules +COPY --from=builder --chown=appuser:appgroup /app/dist ./dist +COPY --from=builder --chown=appuser:appgroup /app/package.json ./package.json USER appuser -ENV NODE_ENV=production - EXPOSE 3000 -CMD ["npm", "start"] +CMD ["node", "dist/main"]