From 3e163f5dd4f18229d80fe59214b560a73b4df33b Mon Sep 17 00:00:00 2001 From: morteza-mortezai Date: Thu, 25 Jun 2026 22:56:16 +0330 Subject: [PATCH] opt docker --- .dockerignore | 30 ++++++++++++++++++- Dockerfile | 79 ++++++++++++++++++++++++++++++++------------------- 2 files changed, 79 insertions(+), 30 deletions(-) diff --git a/.dockerignore b/.dockerignore index bfb34f5..9de8de0 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,2 +1,30 @@ node_modules -.nuxt \ No newline at end of file +.nuxt +dist + +.git +.github +.gitignore +.editorconfig +.prettierrc + +README.md +docker-compose.yml +Dockerfile +.dockerignore + +.env +.env.* +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* + +.DS_Store +.idea +coverage +.cache +.nyc_output +*.swp + +yarn.lock diff --git a/Dockerfile b/Dockerfile index 4d2bba1..c74f453 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,47 +1,68 @@ +# syntax=docker/dockerfile:1 + FROM node:20-alpine AS base -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 apk add --no-cache tzdata \ + && cp /usr/share/zoneinfo/Asia/Tehran /etc/localtime \ + && echo "Asia/Tehran" > /etc/timezone FROM base AS deps -WORKDIR /temp-deps -COPY package*.json ./ -RUN npm install + +WORKDIR /deps + +RUN apk add --no-cache python3 make g++ vips-dev + +COPY package.json package-lock.json ./ + +RUN --mount=type=cache,target=/root/.npm \ + npm ci + +FROM base AS prod-deps + +WORKDIR /deps + +RUN apk add --no-cache python3 make g++ vips-dev + +COPY package.json package-lock.json ./ + +RUN --mount=type=cache,target=/root/.npm \ + npm ci --omit=dev FROM base AS builder -WORKDIR /build -COPY . ./ -COPY --from=deps /temp-deps/node_modules ./node_modules -RUN npm run build -RUN npm install --omit=dev +WORKDIR /build + +RUN apk add --no-cache python3 make g++ vips-dev + +COPY package.json package-lock.json nuxt.config.js ./ +COPY assets components layouts middleware mixins modules pages plugins server static store ./ + +COPY --from=deps /deps/node_modules ./node_modules + +RUN npm run build FROM base AS runner + WORKDIR /app -ENV NUXT_TELEMETRY_DISABLED=1 +RUN apk add --no-cache vips \ + && addgroup -S appgroup \ + && adduser -S appuser -G appgroup -RUN addgroup -S appgroup && adduser -S appuser -G appgroup -RUN chown -R appuser:appgroup /app - -# COPY --from=builder --chown=appuser:appgroup /build/.nuxt ./.nuxt -# COPY --from=builder --chown=appuser:appgroup /build/static ./static -# COPY --from=builder --chown=appuser:appgroup /build/package.json ./ -# COPY --from=builder --chown=appuser:appgroup /build/node_modules/ ./node_modules/ -COPY --from=builder --chown=appuser:appgroup /build ./ +ENV NODE_ENV=production \ + NUXT_TELEMETRY_DISABLED=1 \ + PORT=3000 \ + HOSTNAME=0.0.0.0 +COPY --from=prod-deps --chown=appuser:appgroup /deps/node_modules ./node_modules +COPY --from=builder --chown=appuser:appgroup /build/.nuxt ./.nuxt +COPY --from=builder --chown=appuser:appgroup /build/static ./static +COPY --from=builder --chown=appuser:appgroup /build/server ./server +COPY --from=builder --chown=appuser:appgroup /build/modules ./modules +COPY --from=builder --chown=appuser:appgroup /build/nuxt.config.js /build/package.json ./ USER appuser -# Set environment variables -ENV NODE_ENV=production -ENV PORT=3000 -ENV HOSTNAME="0.0.0.0" - - EXPOSE 3000 -# Start the Nuxt 2 app -CMD ["npm", "start"] +CMD ["node", "node_modules/nuxt/bin/nuxt.js", "start"]