fix: Docker multi-stage build for sqlite3, health endpoint, productValidator exports
- Dockerfile: multi-stage build (builder with python3+g++ for native addons) - Dockerfile: wireguard-tools from edge/community repo - Dockerfile: removed USER appuser (start.sh needs root for wg-quick) - Dockerfile: health check on port 3000 - Added /health HTTP endpoint in index.js for Docker healthcheck - Fixed productValidator.js: added named exports (validateProductName, validateProductPrice) - Added better-sqlite3 as fallback dependency
This commit is contained in:
51
Dockerfile
51
Dockerfile
@@ -1,36 +1,47 @@
|
||||
FROM node:22-alpine AS builder
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# Install build dependencies for native modules (sqlite3, better-sqlite3)
|
||||
RUN apk add --no-cache python3 make g++
|
||||
|
||||
COPY package*.json ./
|
||||
RUN npm install && npm cache clean --force
|
||||
|
||||
# --- Runtime image ---
|
||||
FROM node:22-alpine
|
||||
|
||||
# Устанавливаем необходимые пакеты
|
||||
RUN apk update && \
|
||||
apk add --no-cache \
|
||||
# Install runtime dependencies
|
||||
# WireGuard needs community repo on some alpine versions
|
||||
RUN apk add --no-cache --repository https://dl-cdn.alpinelinux.org/alpine/edge/community \
|
||||
wireguard-tools \
|
||||
&& apk add --no-cache \
|
||||
iptables \
|
||||
iproute2 \
|
||||
openresolv \
|
||||
bash \
|
||||
curl && \
|
||||
rm -rf /var/cache/apk/*
|
||||
curl \
|
||||
&& rm -rf /var/cache/apk/*
|
||||
|
||||
# Создаём непривилегированного пользователя
|
||||
RUN addgroup -S appgroup && \
|
||||
adduser -S appuser -G appgroup
|
||||
|
||||
# Рабочая директория
|
||||
WORKDIR /app
|
||||
|
||||
# Копируем зависимости и устанавливаем их
|
||||
# Copy node_modules from builder (with native addons pre-compiled)
|
||||
COPY --from=builder /app/node_modules ./node_modules
|
||||
COPY package*.json ./
|
||||
RUN npm install
|
||||
|
||||
# Копируем исходный код с правильным владельцем
|
||||
COPY --chown=appuser:appgroup ./src ./src
|
||||
# Copy application source
|
||||
COPY ./src ./src
|
||||
|
||||
# Копируем скрипт запуска
|
||||
COPY --chown=appuser:appgroup ./wg/start.sh /app/start.sh
|
||||
# Copy startup script
|
||||
COPY ./wg/start.sh /app/start.sh
|
||||
RUN chmod +x /app/start.sh
|
||||
|
||||
# Переключаемся на непривилегированного пользователя
|
||||
USER appuser
|
||||
# Create db directory
|
||||
RUN mkdir -p /app/db
|
||||
|
||||
# Команда для запуска
|
||||
CMD ["/bin/bash", "/app/start.sh"]
|
||||
# Health check: bot responds to /health on port 3000
|
||||
HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \
|
||||
CMD curl -sf http://localhost:3000/health || exit 1
|
||||
|
||||
# start.sh runs as root (needed for wg-quick), then drops to node
|
||||
CMD ["/bin/bash", "/app/start.sh"]
|
||||
Reference in New Issue
Block a user