FROM node:24.1.0-alpine

# Security updates
RUN apk update && apk upgrade && apk add --no-cache dumb-init curl

# Create non-root user
RUN addgroup -g 1001 -S nodejs && adduser -S cbd -u 1001 -G nodejs

# Set working directory
WORKDIR /app

# Copy package files
COPY package*.json ./

# Install dependencies including tsx
RUN npm install && npm install -g tsx

# Copy source code
COPY --chown=cbd:nodejs . .

# Set user
USER cbd

# Expose port
EXPOSE 4180

# Use dumb-init and tsx
ENTRYPOINT ["dumb-init", "--"]
CMD ["npx", "tsx", "src/start.ts"]
