- Added restart button to settings page - Created /api/restart endpoint (file-flag based) - Implemented watch-restart.sh daemon - Added systemd service for restart watcher - Updated README with restart setup instructions - Container automatically restarts when settings changed Settings flow: 1. User edits settings in web UI 2. Click 'Save Settings' to persist to .env 3. Click 'Restart Bot' to apply changes 4. Watcher detects flag and restarts container 5. New settings loaded automatically
91 lines
2.2 KiB
Docker
91 lines
2.2 KiB
Docker
# Trading Bot v4 - Production Docker Image
|
|
# Multi-stage build for optimal size and security
|
|
|
|
# ================================
|
|
# Stage 1: Dependencies
|
|
# ================================
|
|
FROM node:20-alpine AS deps
|
|
|
|
# Install system dependencies for native modules
|
|
RUN apk add --no-cache \
|
|
python3 \
|
|
make \
|
|
g++ \
|
|
libc6-compat
|
|
|
|
WORKDIR /app
|
|
|
|
# Copy package files
|
|
COPY package*.json ./
|
|
|
|
# Install dependencies (use npm install since we don't have package-lock.json yet)
|
|
RUN npm install --production && \
|
|
npm cache clean --force
|
|
|
|
# ================================
|
|
# Stage 2: Builder
|
|
# ================================
|
|
FROM node:20-alpine AS builder
|
|
|
|
WORKDIR /app
|
|
|
|
# Copy dependencies from deps stage
|
|
COPY --from=deps /app/node_modules ./node_modules
|
|
|
|
# Copy source code
|
|
COPY . .
|
|
|
|
# Build Next.js application
|
|
ENV NEXT_TELEMETRY_DISABLED 1
|
|
ENV NODE_ENV production
|
|
|
|
RUN npm run build
|
|
|
|
# ================================
|
|
# Stage 3: Runner (Production)
|
|
# ================================
|
|
FROM node:20-alpine AS runner
|
|
|
|
# Install dumb-init for proper signal handling and Docker CLI for restart capability
|
|
RUN apk add --no-cache dumb-init docker-cli
|
|
|
|
WORKDIR /app
|
|
|
|
# Create non-root user
|
|
RUN addgroup --system --gid 1001 nodejs && \
|
|
adduser --system --uid 1001 nextjs && \
|
|
addgroup nextjs root
|
|
|
|
# Copy necessary files from builder
|
|
COPY --from=builder /app/next.config.js ./
|
|
COPY --from=builder /app/package*.json ./
|
|
|
|
# Copy Next.js build output
|
|
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
|
|
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
|
|
|
|
# Copy node_modules
|
|
COPY --from=deps --chown=nextjs:nodejs /app/node_modules ./node_modules
|
|
|
|
# Set environment variables
|
|
ENV NODE_ENV production
|
|
ENV NEXT_TELEMETRY_DISABLED 1
|
|
ENV PORT 3000
|
|
ENV HOSTNAME "0.0.0.0"
|
|
|
|
# Expose port
|
|
EXPOSE 3000
|
|
|
|
# Switch to non-root user
|
|
USER nextjs
|
|
|
|
# Health check
|
|
HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \
|
|
CMD node -e "require('http').get('http://localhost:3000/api/health', (r) => {process.exit(r.statusCode === 200 ? 0 : 1)})"
|
|
|
|
# Use dumb-init to handle signals properly
|
|
ENTRYPOINT ["dumb-init", "--"]
|
|
|
|
# Start the application
|
|
CMD ["node", "server.js"]
|