From ae180d22d642c1c5846360f85956f1f4723790cd Mon Sep 17 00:00:00 2001 From: morteza-mortezai Date: Thu, 25 Jun 2026 19:14:48 +0330 Subject: [PATCH] opt dckr --- .dockerignore | 17 ++++++++++++++++ Dockerfile | 55 ++++++++++++++++++++++++++++++--------------------- 2 files changed, 49 insertions(+), 23 deletions(-) create mode 100644 .dockerignore diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..bcad144 --- /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 504259a..518ae86 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,24 +1,33 @@ -FROM node:20-alpine AS builder +# -------- Build Stage -------- + FROM node:20-alpine AS builder -# 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 - -WORKDIR /build -COPY package*.json ./ -RUN npm install -COPY . ./ -RUN npm run build - -FROM nginx:stable-alpine AS production-stage - -COPY --from=builder /build/dist /usr/share/nginx/html - -COPY --from=builder /build/nginx.con[f] /etc/nginx/conf.d/default.conf -RUN cat /etc/nginx/conf.d/default.conf - -EXPOSE 80 - -CMD ["nginx", "-g", "daemon off;"] + WORKDIR /app + + # Copy only dependency files first (better cache) + COPY package*.json ./ + + # Use clean install for reproducible builds + RUN npm ci + + # Copy source after deps (maximizes cache usage) + COPY . . + + # Build with production mode + RUN npm run build + + + # -------- Production Stage -------- + FROM nginx:stable-alpine AS production + + # Copy built assets + COPY --from=builder /app/dist /usr/share/nginx/html + + # Copy nginx config (optional, safer naming) + COPY nginx.conf /etc/nginx/conf.d/default.conf + + # Remove default nginx config if needed (optional safety) + RUN rm -f /etc/nginx/conf.d/default.conf.default || true + + EXPOSE 80 + + CMD ["nginx", "-g", "daemon off;"] \ No newline at end of file