MedicalAIWiki / Dockerfile
AleksanderObuchowski's picture
Initial commit for Hugging Face Spaces
e4f1db2
raw
history blame
1.5 kB
# 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
# Create user with UID 1000 as required by HF Spaces
RUN addgroup -g 1000 -S user && \
adduser -S user -u 1000
# Set working directory
WORKDIR /app
# Copy backend dependencies and source
COPY --from=base --chown=user /app/backend/node_modules ./backend/node_modules
COPY --chown=user backend/ ./backend/
COPY --chown=user data/ ./data/
# Copy built frontend
COPY --from=frontend-build --chown=user /app/frontend/dist ./frontend/dist
# Switch to user
USER user
# 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"]