FROM node:20-alpine AS base # Frontend build FROM base AS frontend-deps RUN apk add --no-cache libc6-compat WORKDIR /app COPY package.json pnpm-lock.yaml ./ RUN npm install -g pnpm && \ pnpm install --frozen-lockfile FROM base AS frontend-builder WORKDIR /app COPY --from=frontend-deps /app/node_modules ./node_modules COPY . . RUN npm install -g pnpm && \ pnpm run build # Backend build FROM python:3.9-slim AS backend WORKDIR /backend COPY backend/requirements.txt . RUN pip install --no-cache-dir -r requirements.txt COPY backend . # Final image FROM python:3.9-slim AS runner WORKDIR /app ENV NODE_ENV production # Install Node.js and wget RUN apt-get update && apt-get install -y curl wget && \ curl -fsSL https://deb.nodesource.com/setup_20.x | bash - && \ apt-get install -y nodejs && \ apt-get clean && \ rm -rf /var/lib/apt/lists/* RUN addgroup --system --gid 1001 nodejs && \ adduser --system --uid 1001 nextjs COPY --from=frontend-builder /app/public ./frontend/public COPY --from=frontend-builder --chown=nextjs:nodejs /app/.next/standalone ./frontend COPY --from=frontend-builder --chown=nextjs:nodejs /app/.next/static ./frontend/.next/static COPY --from=frontend-builder --chown=nextjs:nodejs /app/.next/cache ./frontend/.next/cache COPY --from=backend /backend ./backend COPY --from=backend /usr/local/lib/python3.9/site-packages /usr/local/lib/python3.9/site-packages COPY start.sh . RUN chmod +x start.sh EXPOSE 3000 8000 CMD ["./start.sh"]