# 10xAI SaaS Container for Google Cloud Run
FROM node:22-alpine

# Set working directory
WORKDIR /app

# Install dependencies first for optimal Docker layer caching
COPY package*.json ./
RUN npm install --omit=dev --ignore-scripts

# Copy application source code
COPY . .

# Cloud Run defaults to PORT 8080
ENV PORT=8080
ENV NODE_ENV=production

EXPOSE 8080

# Run healthcheck
HEALTHCHECK --interval=30s --timeout=5s --start-period=5s --retries=3 \
  CMD wget --no-verbose --tries=1 --spider http://localhost:8080/healthz || exit 1

# Start the unified Node.js Express server
CMD ["node", "server/server.js"]
