-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
57 lines (41 loc) · 1.66 KB
/
Copy pathDockerfile
File metadata and controls
57 lines (41 loc) · 1.66 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
FROM node:24.15.0-slim AS builder
ENV NODE_ENV=build
# Create app directory
WORKDIR /usr/src/app
# Install pnpm and build dependencies
RUN npm install -g pnpm@8.15.0
# Install build deps needed for native modules and prisma generation
RUN apt-get update && \
apt-get install -y --no-install-recommends build-essential python3 curl ca-certificates gcc g++ make && \
rm -rf /var/lib/apt/lists/*
# Install app dependencies (including dev dependencies) for the build
COPY package.json pnpm-lock.yaml .npmrc ./
RUN pnpm install --no-frozen-lockfile
# Bundle app source
COPY . .
# Generate Prisma client and build
RUN pnpm run prisma:generate
RUN pnpm build
# Remove devDependencies to keep only production deps (pruned node_modules)
RUN pnpm prune --prod
# Start a fresh runtime image
FROM node:24.15.0-slim AS prod
# Set the NODE_ENV to production
ENV NODE_ENV=production
# Create app directory
WORKDIR /usr/src/app
# Create a non-root user and group with specific UID/GID to match host user
RUN groupadd -g 1001 app && useradd -u 1001 -g app -m app
# Install runtime dependencies for Sharp image processing
RUN apt-get update && \
apt-get install -y --no-install-recommends libvips-dev && \
rm -rf /var/lib/apt/lists/*
# Copy built artifacts and dependencies from builder with ownership set during copy
COPY --chown=app:app package.json pnpm-lock.yaml ./
COPY --from=builder --chown=app:app /usr/src/app/prisma ./prisma
COPY --from=builder --chown=app:app /usr/src/app/dist ./dist
COPY --from=builder --chown=app:app /usr/src/app/node_modules ./node_modules
# Switch to non-root user
USER app
# Start the server using the production build
CMD [ "node", "dist/main.js" ]