dockerfile config
This commit is contained in:
1 parent
09d1b73ee3
commit
35455fe1ac
3 files changed
+75
No files matched your search
@@ -0,0 +1,13 @@
|
|||||||
|
node_modules
|
||||||
|
.next
|
||||||
|
out
|
||||||
|
build
|
||||||
|
.git
|
||||||
|
.idea
|
||||||
|
*.rar
|
||||||
|
*.zip
|
||||||
|
.env.local
|
||||||
|
.env*.local
|
||||||
|
npm-debug.log*
|
||||||
|
yarn-debug.log*
|
||||||
|
yarn-error.log*
|
||||||
+61
@@ -0,0 +1,61 @@
|
|||||||
|
# syntax=docker/dockerfile:1
|
||||||
|
|
||||||
|
# ====================================================
|
||||||
|
# Stage 1: Base settings & Alpine System Dependencies
|
||||||
|
# ====================================================
|
||||||
|
FROM node:20-alpine AS base
|
||||||
|
WORKDIR /app
|
||||||
|
# نصب ابزارهای مورد نیاز برای سازگاری پکیجهای بومی سیستم (مانند Sharp یا لایبرریهای ++C)
|
||||||
|
RUN apk add --no-cache libc6-compat
|
||||||
|
ENV NEXT_TELEMETRY_DISABLED 1
|
||||||
|
|
||||||
|
# ====================================================
|
||||||
|
# Stage 2: Advanced Dependency Caching
|
||||||
|
# ====================================================
|
||||||
|
FROM base AS deps
|
||||||
|
COPY package.json package-lock.json ./
|
||||||
|
|
||||||
|
# استفاده از کش سیستم میزبان برای NPM جهت جلوگیری از دانلود مجدد پکیجها
|
||||||
|
RUN --mount=type=cache,target=/root/.npm \
|
||||||
|
npm ci
|
||||||
|
|
||||||
|
# ====================================================
|
||||||
|
# Stage 3: Optimized Application Builder
|
||||||
|
# ====================================================
|
||||||
|
FROM base AS builder
|
||||||
|
COPY --from=deps /app/node_modules ./node_modules
|
||||||
|
COPY . .
|
||||||
|
|
||||||
|
# اصلاح خطای متغیر محیطی: متغیر NODE_ENV به صورت استاندارد لینوکس پاس داده شده است
|
||||||
|
RUN --mount=type=cache,target=/app/.next/cache \
|
||||||
|
NODE_ENV=production npm run build
|
||||||
|
|
||||||
|
# ====================================================
|
||||||
|
# Stage 4: Ultra-light Production Runner
|
||||||
|
# ====================================================
|
||||||
|
# ارثبری از base برای حفظ پکیجهای سیستم از جمله libc6-compat برای محیط پروداکشن
|
||||||
|
FROM base AS runner
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
# تنظیم متغیرهای محیطی با دستور رسمی داکر
|
||||||
|
ENV NODE_ENV=production
|
||||||
|
ENV PORT=3000
|
||||||
|
ENV HOSTNAME="0.0.0.0"
|
||||||
|
|
||||||
|
# ایجاد کاربر و گروه امنیتی غیر روت
|
||||||
|
RUN addgroup --system --gid 1001 nodejs && \
|
||||||
|
adduser --system --uid 1001 nextjs
|
||||||
|
|
||||||
|
# کپی کردن فایلهای استاتیک عمومی (مطمئن شوید پوشه public در ریشه پروژه شما وجود دارد)
|
||||||
|
COPY --from=builder /app/public ./public
|
||||||
|
|
||||||
|
# کپی کردن ساختار Standalone با اعمال دسترسی کاربر محدود شده
|
||||||
|
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
|
||||||
|
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
|
||||||
|
|
||||||
|
# سوئیچ به کاربر امن و غیر روت برای رعایت استانداردهای بالاترین سطح امنیت سازمان
|
||||||
|
USER nextjs
|
||||||
|
|
||||||
|
EXPOSE 3000
|
||||||
|
|
||||||
|
CMD ["node", "server.js"]
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
/** @type {import('next').NextConfig} */
|
/** @type {import('next').NextConfig} */
|
||||||
const nextConfig = {
|
const nextConfig = {
|
||||||
|
output: 'standalone',
|
||||||
typescript: {
|
typescript: {
|
||||||
// !! WARN !!
|
// !! WARN !!
|
||||||
// Dangerously allow production builds to successfully complete even if
|
// Dangerously allow production builds to successfully complete even if
|
||||||
|
|||||||
Reference in new issue
Block a user