chore: update dependencies and add .dockerignore file

- Updated MUI packages to version 5.x and x-charts/x-date-pickers to 7.x
- Downgraded React and React-DOM to version 18.3.1
- Added .dockerignore to exclude unnecessary files from Docker context
This commit is contained in:
hamed
2025-12-10 14:06:19 +03:30
parent a8d4d5c090
commit 6f0c29d700
11 changed files with 2838 additions and 2066 deletions
+68 -27
View File
@@ -1,48 +1,89 @@
# Dockerfile for Next.js 14 - Optimized for Production
# =============================================================================
# Multi-stage Dockerfile for Next.js 15 - Production Optimized
# =============================================================================
# Stage 1: Dependencies - Install all dependencies
# Stage 2: Builder - Build the application
# Stage 3: Runner - Production runtime
# =============================================================================
# Use the official Node.js image with Alpine Linux for a smaller footprint
FROM node:22-alpine AS base
# -----------------------------------------------------------------------------
# Stage 1: Dependencies
# -----------------------------------------------------------------------------
FROM node:22-alpine AS deps
# Install system dependencies for node-gyp
RUN apk add --no-cache libc6-compat
# Set the working directory in the container
WORKDIR /app
# Copy package.json and package-lock.json (or yarn.lock)
COPY package*.json ./
# Copy dependency files
COPY package.json package-lock.json* ./
# Install dependencies - leveraging Docker cache
RUN npm i --force
# Install dependencies
# Use npm ci for reproducible builds
RUN npm ci --legacy-peer-deps || npm install --legacy-peer-deps
# Copy the rest of the application code
# -----------------------------------------------------------------------------
# Stage 2: Builder
# -----------------------------------------------------------------------------
FROM node:22-alpine AS builder
WORKDIR /app
# Copy dependencies from deps stage
COPY --from=deps /app/node_modules ./node_modules
# Copy source code
COPY . .
# Build the Next.js application
# Set build-time environment variables
ENV NEXT_TELEMETRY_DISABLED=1
ENV NODE_ENV=production
# Build application
RUN npm run build
# Stage 2: Production image - smaller and leaner
# -----------------------------------------------------------------------------
# Stage 3: Runner (Production)
# -----------------------------------------------------------------------------
FROM node:22-alpine AS runner
# Set the working directory
# Install runtime dependencies
RUN apk add --no-cache \
libc6-compat \
dumb-init
WORKDIR /app
# Set environment variables
ENV NODE_ENV $NODE_ENV
ENV NEXT_TELEMETRY_DISABLED 1
# Set production environment
ENV NODE_ENV=production
ENV NEXT_TELEMETRY_DISABLED=1
ENV PORT=3000
ENV HOSTNAME="0.0.0.0"
# Add a non-root user for security
RUN addgroup -g 1001 -S nodejs
RUN adduser -S nextjs -u 1001
# Create non-root user for security
RUN addgroup --system --gid 1001 nodejs && \
adduser --system --uid 1001 nextjs
# Copy only the necessary files from the builder stage
COPY --from=base /app/next.config.js ./
COPY --from=base /app/public ./public
COPY --from=base --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=base --chown=nextjs:nodejs /app/.next/static ./.next/static
# Copy necessary files from builder
COPY --from=builder --chown=nextjs:nodejs /app/next.config.js ./
COPY --from=builder --chown=nextjs:nodejs /app/public ./public
COPY --from=builder --chown=nextjs:nodejs /app/.next ./.next
COPY --from=builder --chown=nextjs:nodejs /app/package.json ./
COPY --from=builder --chown=nextjs:nodejs /app/node_modules ./node_modules
# Change ownership of all copied files to the non-root user
# Switch to non-root user
USER nextjs
# Expose the port Next.js listens on
# Expose port
EXPOSE 3000
# Command to start the Next.js server in production mode
CMD ["node", "server.js"]
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \
CMD node -e "require('http').get('http://localhost:3000/', (res) => { process.exit(res.statusCode === 200 ? 0 : 1); }).on('error', () => { process.exit(1); });"
# Use dumb-init to handle signals properly
ENTRYPOINT ["dumb-init", "--"]
# Start Next.js in production mode
CMD ["node_modules/.bin/next", "start"]