FROM node:24-alpine AS builder

# Enable pnpm
RUN corepack enable && corepack prepare pnpm@latest --activate

WORKDIR /app

# Copy package files and install dependencies
COPY package.json pnpm-lock.yaml pnpm-workspace.yaml ./
RUN pnpm install --frozen-lockfile

# Copy the rest of the application code and build
COPY . .
RUN CI="true" pnpm run build

# Production stage
FROM node:24-alpine AS runner

WORKDIR /app

# Set environment variables for production
ENV NODE_ENV=production
ENV PORT=3000

# Copy only the built output from the builder stage
# Nitro typically outputs the production server to .output/
COPY --from=builder /app/.output ./.output
COPY --from=builder /app/package.json ./

EXPOSE 3000

# Start the production server
CMD ["node", ".output/server/index.mjs"]
