-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
47 lines (33 loc) · 1.21 KB
/
Dockerfile
File metadata and controls
47 lines (33 loc) · 1.21 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
# Build stage
FROM node:22-alpine AS builder
WORKDIR /app
# Copy package files
COPY package*.json ./
# Install all dependencies (including devDependencies for build)
RUN npm ci && npm cache clean --force
# Copy source code
COPY . .
# Build and test the application (excluding e2e tests)
RUN npm run build && npm run test:unit
# Production stage
FROM node:22-alpine AS production
# Install curl for healthcheck and create user in single layer
RUN apk --no-cache add curl && \
addgroup -g 1001 -S nodejs && \
adduser -S nodejs -u 1001 -G nodejs
WORKDIR /app
# Copy package.json, built app, and production node_modules in single operation
COPY --from=builder --chown=nodejs:nodejs /app/package*.json ./
COPY --from=builder --chown=nodejs:nodejs /app/dist ./dist
COPY --from=builder --chown=nodejs:nodejs /app/node_modules ./node_modules
# Create logs directory
RUN mkdir -p logs && chown -R nodejs:nodejs /app
# Switch to non-root user
USER nodejs
# Health check with optimized settings
HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \
CMD curl -f http://localhost:8085/health || exit 1
# production port
EXPOSE 8085
# Use node directly with correct entry point
CMD ["node", "dist/app.js"]