FROM node:22-alpine

WORKDIR /app

# Install runtime dependencies
RUN apk add --no-cache wget curl docker-cli

# Copy package files
COPY neode-ui/package*.json ./

# Install Node dependencies (need all deps for mock backend)
RUN npm install

# Copy application code
COPY neode-ui/ ./

# Expose port
EXPOSE 5959

# Health check
HEALTHCHECK --interval=30s --timeout=15s --retries=5 --start-period=180s \
  CMD wget --quiet --tries=1 --spider http://localhost:5959/health || exit 1

# Start the mock backend with error handling
CMD ["sh", "-c", "node mock-backend.js 2>&1 || (echo 'ERROR: Backend failed to start'; cat /app/package.json; ls -la /app; sleep infinity)"]
