# ============= SIMPLE PRODUCTION BUILD =============
FROM node:22.22.0-alpine

# Install essential build tools (Alpine minimal)
RUN apk add --no-cache python3 make g++

# Install pnpm and pm2
RUN npm install -g pnpm@latest-10 pm2

WORKDIR /app

# Copy dependency files
COPY package.json ./

# Install production dependencies only
RUN pnpm install 

# Copy source code
COPY . .

# Generate Prisma client and build with increased heap
RUN NODE_OPTIONS="--max-old-space-size=4072" npx prisma generate

# Build app with increased heap memory
RUN NODE_OPTIONS="--max-old-space-size=4072" pnpm run build

# Remove unnecessary files to save space
RUN rm -rf .git .github

# Expose port
EXPOSE 3000

# Start app
CMD ["pm2-runtime", "start", ".output/server/index.mjs"]
