-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathDockerfile
More file actions
53 lines (38 loc) · 1.33 KB
/
Copy pathDockerfile
File metadata and controls
53 lines (38 loc) · 1.33 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
# Stage 1: Build stage
FROM node:20-alpine AS builder
# Set working directory
WORKDIR /app
# Copy package files
COPY package*.json ./
COPY tsconfig.json tsoa.json ./
# Install dependencies (including devDependencies for building)
RUN npm ci
# Copy source code
COPY src/ ./src/
# Generate TypeScript definitions and build the application
RUN npm run build
# Remove development dependencies to reduce size
RUN npm prune --omit=dev
# Stage 2: Production stage
FROM node:20-alpine AS production
# Install dumb-init for proper signal handling
RUN apk add --no-cache dumb-init
# Create non-root user for security
RUN addgroup -g 1001 -S nodejs && \
adduser -S todoapp -u 1001
# Set working directory
WORKDIR /app
# Copy built application from builder stage
COPY --from=builder --chown=todoapp:nodejs /app/build ./build
COPY --from=builder --chown=todoapp:nodejs /app/node_modules ./node_modules
COPY --from=builder --chown=todoapp:nodejs /app/package.json ./package.json
COPY --from=builder --chown=todoapp:nodejs /app/public ./public
# Create directories and files needed by the application
RUN mkdir -p logs && chown -R todoapp:nodejs logs
RUN touch .env && chown todoapp:nodejs .env
# Switch to non-root user
USER todoapp
# Use dumb-init to handle signals properly
ENTRYPOINT ["dumb-init", "--"]
# Start the application
CMD ["npm", "start"]