# Build stage
FROM node:20-alpine AS builder

WORKDIR /app

# Copy package files and install the exact locked dependencies (including devDependencies for TypeScript)
COPY package.json package-lock.json ./
RUN npm ci

# Copy source code and build
COPY . .
RUN npm run build

# Production stage
FROM node:20-alpine

WORKDIR /app

# Copy package files and install ONLY the locked production dependencies
COPY package.json package-lock.json ./
RUN npm ci --omit=dev

# Copy built code from the builder stage
COPY --from=builder /app/dist ./dist
COPY --from=builder /app/data ./data

# Expose the port the app runs on
EXPOSE 3000

# Run node directly so it receives SIGTERM on redeploy and can finish queued webhooks
CMD ["node", "dist/index.js"]
