FROM node:18-alpine AS build

# Set working directory
WORKDIR /app

# Install system dependencies
RUN apk add --no-cache python3 make gcc g++

# Copy package management files
COPY package*.json ./

# Install dependencies
RUN npm ci

# Copy entire project
COPY . .

# Build production application
RUN npm run build

# Production stage
FROM node:18-alpine

WORKDIR /app

# Install production dependencies
COPY --from=build /app/package*.json ./
RUN npm ci --only=production

# Copy built assets
COPY --from=build /app/dist ./dist
COPY --from=build /app/server ./server

# Expose port
EXPOSE 3000

# Start command
CMD ["npm", "run", "start:production"]
