From cccbfb83ff8e0f10f13da545bc1e7c9609a5d8c6 Mon Sep 17 00:00:00 2001 From: morteza-mortezai Date: Sat, 13 Jun 2026 15:17:37 +0330 Subject: [PATCH] docker --- .dockerignore | 27 +++++++++++++++++++++ Dockerfile | 65 ++++++++++++++++++++++++++++----------------------- 2 files changed, 63 insertions(+), 29 deletions(-) create mode 100644 .dockerignore diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..9e61255 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,27 @@ +node_modules +.nuxt +dist +.git +.github +.vscode +.cursor + +# Logs and caches +*.log +.npm +.cache +coverage +.nyc_output + +# Environment and local config +.env +.env.* + +# Docker (not needed inside the image) +Dockerfile* +docker-compose*.yaml +docker-compose*.yml + +# Docs +README.md +*.md diff --git a/Dockerfile b/Dockerfile index b01edb6..25eff4a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,47 +1,54 @@ +# 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 /app + +COPY package.json package-lock.json ./ + +RUN --mount=type=cache,target=/root/.npm \ + npm ci 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 /app + +COPY package.json package-lock.json nuxt.config.js ./ +COPY --from=deps /app/node_modules ./node_modules +COPY . . + +ENV NODE_ENV=production + +RUN npm run build \ + && npm prune --omit=dev FROM base AS runner + WORKDIR /app -ENV NUXT_TELEMETRY_DISABLED=1 +ENV NODE_ENV=production \ + NUXT_TELEMETRY_DISABLED=1 \ + PORT=3000 \ + HOSTNAME=0.0.0.0 -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 ./ +RUN addgroup -S appgroup \ + && adduser -S appuser -G appgroup +COPY --from=builder --chown=appuser:appgroup /app/package.json ./ +COPY --from=builder --chown=appuser:appgroup /app/node_modules ./node_modules +COPY --from=builder --chown=appuser:appgroup /app/.nuxt ./.nuxt +COPY --from=builder --chown=appuser:appgroup /app/nuxt.config.js ./ +COPY --from=builder --chown=appuser:appgroup /app/static ./static +COPY --from=builder --chown=appuser:appgroup /app/server ./server 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"] \ No newline at end of file +CMD ["node", "node_modules/nuxt/bin/nuxt.js", "start"]