This commit is contained in:
2026-03-19 14:36:35 +07:00
parent 6d7d86befd
commit 96635dbcf2
28 changed files with 4332 additions and 1683 deletions

View File

@@ -1,20 +1,54 @@
# Используем легкий Node.js образ
FROM node:20-alpine
# ============================================================================
# Multi-stage build for optimized production Docker image
# ============================================================================
# Stage 1: Dependencies
FROM node:20-alpine AS dependencies
# Рабочая директория
WORKDIR /app
# Копируем package.json
# Copy only package files
COPY package*.json ./
# Устанавливаем зависимости
RUN npm install --production
# Install dependencies (using npm ci for production)
RUN npm ci --prefer-offline --no-audit
# Копируем весь проект
# ============================================================================
# Stage 2: Production
FROM node:20-alpine AS production
# Install curl for healthcheck and dumb-init for signal handling
RUN apk add --no-cache curl dumb-init
# Set working directory
WORKDIR /app
# Set Node.js environment to production
ENV NODE_ENV=production
# Copy node_modules from dependencies stage
COPY --from=dependencies /app/node_modules ./node_modules
# Copy package files
COPY package*.json ./
# Copy application code
COPY . .
# Открываем порт
# Create non-root user for security
RUN addgroup -g 1001 -S nodejs && adduser -S nodejs -u 1001
USER nodejs
# Expose port
EXPOSE 3000
# Запуск сервера
CMD ["npm", "start"]
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \
CMD curl -f http://localhost:3000 || exit 1
# Use dumb-init to handle signals properly (graceful shutdown)
ENTRYPOINT ["/usr/sbin/dumb-init", "--"]
# Start application
CMD ["node", "server.js"]