-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDockerfile
More file actions
64 lines (47 loc) · 1.65 KB
/
Dockerfile
File metadata and controls
64 lines (47 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
ARG NODE_VERSION=24
# -----------------------------------------------------------------------------
# Stage 1: Builder - Install dependencies and compile native modules
# -----------------------------------------------------------------------------
FROM node:${NODE_VERSION}-alpine AS builder
# Install build dependencies for native modules (better-sqlite3)
RUN apk add --no-cache \
python3 \
make \
g++ \
sqlite \
sqlite-dev
WORKDIR /app
# Copy package files first for better layer caching
COPY package*.json ./
# Install all dependencies (including devDependencies for native module compilation)
RUN npm ci
# Copy source code
COPY src/ ./src/
# Rebuild native modules for current Node.js version
RUN npm rebuild better-sqlite3
# Prune to production dependencies only
RUN npm prune --production
# -----------------------------------------------------------------------------
# Stage 2: Production - Minimal runtime image
# -----------------------------------------------------------------------------
FROM node:${NODE_VERSION}-alpine AS production
# Install runtime dependencies only
RUN apk add --no-cache \
sqlite
# Create non-root user for security
RUN addgroup -g 1001 -S nodejs && \
adduser -S nodejs -u 1001 -G nodejs
WORKDIR /app
# Copy production dependencies from builder
COPY --from=builder /app/node_modules ./node_modules
# Copy package.json for version info
COPY package*.json ./
# Copy application source
COPY src/ ./src/
# Create data directory for SQLite database and set permissions
RUN mkdir -p /app/data && \
chown -R nodejs:nodejs /app
# Switch to non-root user
USER nodejs
# Run the bot
CMD ["node", "src/index.js"]