Files
bot-dashboard/frontend/Dockerfile
Claude 22fce19050 fix: Resolve Docker build failures for frontend and backend
Backend fixes:
- Add g++ and build-essential for complete C++ compilation support
- Upgrade pip, setuptools, and wheel before installing dependencies
- Ensures psutil and other packages with native extensions build correctly

Frontend fixes:
- Add build arguments for NEXT_PUBLIC_API_URL and NEXT_PUBLIC_WS_URL
- Pass environment variables during Docker build stage
- Set default values to prevent undefined destination in Next.js rewrites
- Configure docker-compose to pass build arguments to frontend service

These changes resolve:
- psutil build failure: "ERROR: Failed building wheel for psutil"
- Next.js build error: "Invalid rewrite found" with undefined destination
2025-11-21 11:58:56 +00:00

62 lines
1.4 KiB
Docker

# Multi-stage build for Next.js frontend
FROM node:20-alpine AS builder
WORKDIR /app
# Copy package files
COPY package.json package-lock.json ./
# Verify package-lock.json exists and install dependencies
RUN test -f package-lock.json && npm ci
# Copy source code
COPY . .
# Set environment variables for build
ENV NEXT_TELEMETRY_DISABLED 1
ENV NODE_ENV production
# Accept build arguments for API URLs
ARG NEXT_PUBLIC_API_URL=http://localhost:8000
ARG NEXT_PUBLIC_WS_URL=ws://localhost:8000
# Set environment variables for Next.js build
ENV NEXT_PUBLIC_API_URL=$NEXT_PUBLIC_API_URL
ENV NEXT_PUBLIC_WS_URL=$NEXT_PUBLIC_WS_URL
# Build the application
RUN npm run build
# Production stage
FROM node:20-alpine AS runner
WORKDIR /app
ENV NODE_ENV production
ENV NEXT_TELEMETRY_DISABLED 1
# Create non-root user
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs
# Copy necessary files from builder
COPY --from=builder /app/public ./public
COPY --from=builder /app/.next/standalone ./
COPY --from=builder /app/.next/static ./.next/static
# Set correct permissions
RUN chown -R nextjs:nodejs /app
USER nextjs
EXPOSE 3000
ENV PORT 3000
ENV HOSTNAME "0.0.0.0"
# Runtime environment variables (can be overridden by docker-compose)
ENV NEXT_PUBLIC_API_URL=http://localhost:8000
ENV NEXT_PUBLIC_WS_URL=ws://localhost:8000
CMD ["node", "server.js"]