Dockerfile

1# Build stage
2FROM node:20-alpine as builder
3
4WORKDIR /app
5
6COPY package*.json ./
7RUN npm i
8
9COPY . .
10RUN npm run build
11
12# Production stage
13FROM node:20-alpine
14
15WORKDIR /app
16
17COPY package*.json ./
18RUN npm i --only=production
19
20COPY --from=builder /app/dist ./dist
21COPY --from=builder /app/scripts ./scripts
22
23# Create a non-root user
24RUN addgroup -g 1001 -S nodejs
25RUN adduser -S nodejs -u 1001
26USER nodejs
27
28# Set environment variables
29ENV NODE_ENV=production
30
31# Health check
32HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 \
33    CMD node -e "require('http').request('http://localhost:3000/health', { timeout: 2000 }, (res) => process.exit(res.statusCode === 200 ? 0 : 1)).end()"
34
35# Start the bot
36CMD ["npm", "start"]