-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
53 lines (35 loc) · 956 Bytes
/
Copy pathDockerfile
File metadata and controls
53 lines (35 loc) · 956 Bytes
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
# ===========================
# stage 1 - Dependencies
# ===========================
FROM node:20-alpine AS dependencies
WORKDIR /app
COPY package*.json ./
# Install all dependencies (including dev dependencies)
RUN npm install
# ===========================
# Stage 2 - Test
# ===========================
FROM dependencies AS test
WORKDIR /app
COPY . .
CMD ["npm", "test"]
# ===========================
# Stage 3 - Production Build
# ===========================
FROM node:20-alpine AS production
WORKDIR /app
# Create non-root user
RUN addgroup -S app && adduser -S app -G app
# Copy package files
COPY package*.json ./
# Install only production dependencies
RUN npm install --omit=dev
# Copy application source only
COPY src ./src
# Change ownership
RUN chown -R app:app /app
USER app
EXPOSE 3000
HEALTHCHECK --interval=10s --timeout=3s --retries=3 \
CMD wget -qO- http://localhost:3000/health || exit 1
CMD ["node", "src/index.js"]