-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
46 lines (33 loc) · 1.04 KB
/
Dockerfile
File metadata and controls
46 lines (33 loc) · 1.04 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
FROM node:20-slim as base
# Install dependencies only when needed
FROM base AS deps
WORKDIR /app
# Install dependencies based on the preferred package manager
COPY package.json pnpm-lock.yaml* ./
RUN npm install -g pnpm && pnpm install --frozen-lockfile
# Rebuild the source code only when needed
FROM base AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .
# Install pnpm in the builder stage
RUN npm install -g pnpm
# Build the application
RUN pnpm build
# Production image, copy all the files and run the server
FROM node:20-slim AS runner
WORKDIR /app
ENV NODE_ENV=production
# Create a non-root user
RUN addgroup --system --gid 1001 nodejs && \
adduser --system --uid 1001 nodejs
# Create directory for writable files with proper permissions
RUN mkdir -p /app/data && \
chown -R nodejs:nodejs /app/data
# Copy only necessary files
COPY --from=builder /app/.output ./.output
# Expose the port the app will run on
EXPOSE 3000
USER nodejs
# Start the Node.js server
CMD ["node", ".output/server/index.mjs"]