# Multi-stage build for Translator API FROM node:20-alpine AS builder WORKDIR /app # Copy package files COPY package*.json ./ # Install all dependencies RUN npm ci # Production stage FROM node:20-alpine AS production WORKDIR /app # Install dumb-init for proper signal handling RUN apk add --no-cache dumb-init # Create non-root user RUN addgroup -g 1001 -S nodejs && \ adduser -S nodejs -u 1001 # Copy built dependencies COPY --from=builder /app/node_modules ./node_modules # Copy source code COPY --chown=nodejs:nodejs package.json ./ COPY --chown=nodejs:nodejs central ./central COPY --chown=nodejs:nodejs worker ./worker COPY --chown=nodejs:nodejs public ./public # Create logs directory RUN mkdir -p central/logs worker/logs && chown -R nodejs:nodejs central/logs worker/logs # Switch to non-root user USER nodejs # Expose port (HuggingFace Spaces uses 7860) EXPOSE 7860 # Environment variables ENV PORT=7860 ENV NODE_ENV=production # Health check HEALTHCHECK --interval=30s --timeout=10s --start-period=10s --retries=3 \ CMD wget --no-verbose --tries=1 --spider http://localhost:7860/api/health || exit 1 # Start central server ENTRYPOINT ["dumb-init", "--"] CMD ["node", "central/src/index.js"]