File size: 2,180 Bytes
7cc5dc9
 
 
 
8f7e7e8
7cc5dc9
db6dd3c
6e8d7df
8f7e7e8
6e8d7df
7cc5dc9
 
8f7e7e8
7cc5dc9
 
8f7e7e8
7cc5dc9
 
 
 
 
 
8f7e7e8
7cc5dc9
 
8f7e7e8
 
7cc5dc9
 
8f7e7e8
7cc5dc9
 
 
8f7e7e8
 
7cc5dc9
 
 
 
8f7e7e8
 
 
7cc5dc9
 
8f7e7e8
7cc5dc9
85e9869
 
 
 
 
 
 
 
8f7e7e8
7cc5dc9
 
85e9869
 
 
 
 
8f7e7e8
7cc5dc9
8f7e7e8
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
65
66
# ---- Stage 1: The "Builder" ----
# We use the full (not slim) Node.js image because it includes the build tools
# (like Python, make, g++) needed to compile native dependencies.
FROM node:20-bullseye AS builder

# Install system dependencies needed for the build
RUN apt-get update && apt-get install -y --no-install-recommends git ca-certificates && \
    apt-get clean && rm -rf /var/lib/apt/lists/*

WORKDIR /app

# Enable pnpm
RUN corepack enable

# Copy dependency files
COPY package.json pnpm-lock.yaml* ./

# Install ALL dependencies and run build scripts.
# The --unsafe-perm flag is often needed in Docker to allow build scripts to run correctly.
RUN pnpm install --unsafe-perm

# Copy the rest of your source code
COPY . .

# Run the build script ("tsc") to compile your TypeScript into JavaScript
RUN pnpm build

# Remove development dependencies to create a clean, production-only node_modules folder
RUN pnpm prune --prod


# ---- Stage 2: The Final "Production" Image ----
# We start from a slim image to keep the final size small.
FROM node:20-bullseye-slim

# Install ONLY the necessary RUNTIME system dependencies.
# - ffmpeg: For processing audio/video sent to the bot.
# - libvips-dev: Required by the 'sharp' package for image manipulation.
RUN apt-get update && apt-get install -y --no-install-recommends ffmpeg libvips-dev && \
    apt-get clean && rm -rf /var/lib/apt/lists/*

WORKDIR /app

# Enable pnpm
RUN corepack enable

# Create the directory for session data AS THE ROOT USER
RUN mkdir ./sessions

# Change ownership of the entire app directory to the 'node' user.
# This must be done BEFORE switching to the node user.
RUN chown -R node:node /app

# NOW, switch to the built-in, non-root 'node' user for security
USER node

# Copy over the essential files from the builder stage
# These files will now be correctly owned by 'node' because of the chown command above.
COPY --from=builder /app/package.json ./package.json
COPY --from=builder /app/pnpm-lock.yaml* ./
COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/dist ./dist

# Set the command to run your application using the "start" script.
CMD [ "pnpm", "start" ]