Spaces:
Running
Running
File size: 1,529 Bytes
e4f1db2 86aa5b0 e4f1db2 86aa5b0 e4f1db2 86aa5b0 e4f1db2 86aa5b0 e4f1db2 |
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 54 55 56 57 |
# Multi-stage build for React + Node.js application
FROM node:18-alpine AS base
# Install dumb-init for proper signal handling
RUN apk add --no-cache dumb-init
# Create app directory
WORKDIR /app
# Copy package files
COPY package*.json ./
COPY backend/package*.json ./backend/
COPY frontend/package*.json ./frontend/
# Install dependencies
RUN npm ci --only=production && \
cd backend && npm ci --only=production && \
cd ../frontend && npm ci
# Frontend build stage
FROM base AS frontend-build
WORKDIR /app/frontend
COPY frontend/ .
RUN npm run build
# Production stage
FROM node:18-alpine AS production
# Install dumb-init
RUN apk add --no-cache dumb-init
# Use existing user with UID 1000 (required by HF Spaces)
# No need to create user - HF Spaces already has one
# Set working directory
WORKDIR /app
# Copy backend dependencies and source
COPY --from=base --chown=1000:1000 /app/backend/node_modules ./backend/node_modules
COPY --chown=1000:1000 backend/ ./backend/
COPY --chown=1000:1000 data/ ./data/
# Copy built frontend
COPY --from=frontend-build --chown=1000:1000 /app/frontend/dist ./frontend/dist
# Switch to user with UID 1000
USER 1000
# Expose port
EXPOSE 3001
# Health check
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
CMD node -e "require('http').get('http://localhost:3001/api/algorithms', (res) => { process.exit(res.statusCode === 200 ? 0 : 1) }).on('error', () => process.exit(1))"
# Start the application
CMD ["dumb-init", "node", "backend/server.js"] |