immortal-bnb/Dockerfile.backend
caelum0x bea907f76e feat: Complete production readiness implementation
- Integrated all production features into main application flow
- Added metrics, tracing, caching, and health checks to API server
- Enhanced trade execution with circuit breakers and retry policies
- Integrated database persistence for trades and metrics
- Added structured logging and observability
- Enhanced middleware with missing validators and rate limiters
- Added comprehensive error handling and resilience patterns
2025-11-20 00:35:39 +03:00

87 lines
2.4 KiB
Docker

# Dockerfile for Immortal AI Trading Bot Backend (TypeScript/Node.js)
# Optimized multi-stage build for production
# ============================================================================
# Stage 1: Dependencies
# ============================================================================
FROM oven/bun:1-alpine AS deps
WORKDIR /app
# Copy package files
COPY package.json bun.lockb* ./
# Install dependencies (production only)
RUN bun install --frozen-lockfile --production && \
rm -rf /app/.bun/install/cache
# ============================================================================
# Stage 2: Builder
# ============================================================================
FROM oven/bun:1-alpine AS builder
WORKDIR /app
# Copy package files
COPY package.json bun.lockb* ./
# Install all dependencies (including dev)
RUN bun install --frozen-lockfile
# Copy source code
COPY . .
# Build TypeScript (if needed)
# Note: Bun can run TypeScript directly, but building can optimize
RUN bun run build || echo "Build optional"
# ============================================================================
# Stage 3: Runtime
# ============================================================================
FROM oven/bun:1-alpine AS runtime
# Install runtime dependencies only
RUN apk add --no-cache \
curl \
ca-certificates \
tzdata \
postgresql-client
# Create non-root user
RUN addgroup -g 1001 -S nodejs && \
adduser -S nodejs -u 1001
WORKDIR /app
# Copy production dependencies
COPY --from=deps --chown=nodejs:nodejs /app/node_modules ./node_modules
# Copy application files
COPY --from=builder --chown=nodejs:nodejs /app/src ./src
COPY --from=builder --chown=nodejs:nodejs /app/package.json ./
COPY --from=builder --chown=nodejs:nodejs /app/tsconfig.json ./
COPY --from=builder --chown=nodejs:nodejs /app/dist ./dist 2>/dev/null || true
# Create necessary directories
RUN mkdir -p /app/logs /app/backups && \
chown -R nodejs:nodejs /app
# Switch to non-root user
USER nodejs
# Expose API port
EXPOSE 3001
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \
CMD curl -f http://localhost:3001/health || exit 1
# Environment variables
ENV NODE_ENV=production \
API_PORT=3001 \
LOG_LEVEL=info \
BUN_ENV=production
# Start command - Bun can run TypeScript directly
CMD ["bun", "run", "src/api-server.ts"]