FROM node:18-alpine

# Set working directory
WORKDIR /app

# Install curl for health checks
RUN apk add --no-cache curl

# Copy package files
COPY package*.json ./

# Install dependencies
RUN npm install

# Copy source code
COPY . .

# Create non-root user
RUN addgroup -g 1001 -S nodejs
RUN adduser -S unified-tech-stack -u 1001

# Change ownership
RUN chown -R unified-tech-stack:nodejs /app

# Switch to non-root user
USER unified-tech-stack

# Expose port
EXPOSE 8013

# Health check
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
  CMD curl -f http://localhost:8010/health || exit 1

# Start the application
CMD ["npm", "start"]
