# Dating Autopilot Dockerfile
# Multi-stage build for CLI code generation tool

# =============================================================================
# Stage 1: Dependencies
# =============================================================================
FROM node:20-alpine AS deps

WORKDIR /app

# Copy package files
COPY package*.json ./

# Install dependencies
RUN npm install --frozen-lockfile

# =============================================================================
# Stage 2: Builder
# =============================================================================
FROM node:20-alpine AS builder

WORKDIR /app

# Copy dependencies from deps stage
COPY --from=deps /app/node_modules ./node_modules

# Copy source files
COPY package*.json tsconfig.json ./
COPY *.ts ./
COPY codegen/ ./codegen/
COPY platforms/ ./platforms/

# Build TypeScript
RUN npm run build

# =============================================================================
# Stage 3: Production
# =============================================================================
FROM node:20-alpine AS production

WORKDIR /app

# Create non-root user for security
RUN addgroup --system --gid 1001 nodejs && \
    adduser --system --uid 1001 autopilot

# Copy built application and production dependencies
COPY --from=builder /app/dist ./dist
COPY --from=builder /app/package.json ./
COPY --from=deps /app/node_modules ./node_modules

# Set ownership
RUN chown -R autopilot:nodejs /app

# Switch to non-root user
USER autopilot

# Environment variables
ENV NODE_ENV=production

# Default entrypoint for CLI
ENTRYPOINT ["node", "dist/cli.js"]

# Default help output if no args provided
CMD ["--help"]
