# Multi-stage build for Next.js application with Bun # Stage 1: Dependencies FROM oven/bun:1-alpine AS deps WORKDIR /app # Copy package files COPY package.json bun.lockb* ./ # Install dependencies with Bun RUN bun install --frozen-lockfile # Stage 2: Builder FROM oven/bun:1-alpine AS builder WORKDIR /app # Copy dependencies from deps stage COPY --from=deps /app/node_modules ./node_modules COPY . . # Set environment variables for build ENV NEXT_TELEMETRY_DISABLED=1 ENV NODE_ENV=production # Build the application with --bun flag to use Bun runtime RUN bun --bun run build # Stage 3: Runner FROM oven/bun:1-alpine AS runner WORKDIR /app ENV NODE_ENV=production ENV NEXT_TELEMETRY_DISABLED=1 # Create a 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 # Create data directory for SQLite database RUN mkdir -p /app/data && chown -R nextjs:nodejs /app/data # Change ownership to nextjs user RUN chown -R nextjs:nodejs /app # Switch to non-root user USER nextjs # Expose port 3000 EXPOSE 3000 ENV PORT=3000 ENV HOSTNAME="0.0.0.0" # Start the application with Bun runtime CMD ["bun", "--bun", "run", "server.js"]