File size: 1,222 Bytes
d5d016f
 
 
 
 
 
 
 
 
a64ea8d
d5d016f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a64ea8d
d5d016f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# 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"]