dograh/ui/Dockerfile

74 lines
2.2 KiB
Text
Raw Normal View History

2025-09-18 19:51:47 +05:30
# Multi-stage build
# Stage 1: Dependencies
FROM node:20-alpine AS deps
2025-09-09 14:37:32 +05:30
WORKDIR /app
2025-11-12 14:18:10 +05:30
# Install Python and build dependencies for native modules
# This helps with ARM64 builds and native module compilation
RUN apk add --no-cache python3 make g++ libc6-compat
2025-09-18 19:51:47 +05:30
# Copy package files
COPY ui/package*.json ./
2025-11-12 14:18:10 +05:30
# Clean install with proper handling of native modules
RUN rm -rf node_modules && \
npm ci || npm install
2025-09-18 19:51:47 +05:30
# Stage 2: Builder
FROM node:20-alpine AS builder
WORKDIR /app
2025-09-09 14:37:32 +05:30
2025-11-12 14:18:10 +05:30
# Install libc6-compat for native modules in builder stage too
RUN apk add --no-cache libc6-compat
2025-09-18 19:51:47 +05:30
# Copy dependencies from deps stage
COPY --from=deps /app/node_modules ./node_modules
2025-09-09 14:37:32 +05:30
2025-09-18 19:51:47 +05:30
# Copy all files needed for build
COPY ui/package*.json ./
COPY ui/tsconfig.json ./
COPY ui/next.config.ts ./
COPY ui/components.json ./
COPY ui/sentry.edge.config.ts ./
COPY ui/sentry.server.config.ts ./
COPY ui/postcss.config.mjs ./
COPY ui/public ./public
COPY ui/src ./src
2025-09-09 14:37:32 +05:30
2025-09-18 19:51:47 +05:30
# Set build-time environment variables (needed for Next.js build)
ENV NEXT_PUBLIC_NODE_ENV="oss"
ENV NEXT_TELEMETRY_DISABLED="1"
2025-11-04 18:12:57 +05:30
ENV NEXT_PUBLIC_CHATWOOT_URL="https://chat.dograh.com"
ENV NEXT_PUBLIC_CHATWOOT_TOKEN="3fkFx2mCEjNHjM9gaNc4A82X"
ENV BACKEND_URL="http://api:8000"
2025-09-18 19:51:47 +05:30
# Build the application with standalone mode
# Increase Node.js heap size to prevent out-of-memory errors during build
ENV NODE_OPTIONS="--max-old-space-size=4096"
2025-09-18 19:51:47 +05:30
RUN npm run build && \
rm -rf /tmp/* /root/.npm /root/.next/cache
# Stage 3: Runner (production image)
FROM node:20-alpine AS runner
WORKDIR /app
# Environment variables will be provided by docker-compose
ENV NODE_ENV=production
# Create a non-root user
RUN addgroup --system --gid 1001 nodejs && \
adduser --system --uid 1001 nextjs
# Copy standalone build output
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
COPY --from=builder --chown=nextjs:nodejs /app/public ./public
# Switch to non-root user
USER nextjs
2025-09-09 14:37:32 +05:30
# Expose the port Next.js runs on
EXPOSE 3010
2025-09-09 14:37:32 +05:30
2025-09-18 19:51:47 +05:30
# Start the production server using the standalone Node.js server
CMD sh -c "echo '🚀 Application ready at http://localhost:3010' && PORT=3010 node server.js"