-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
67 lines (48 loc) · 1.97 KB
/
Copy pathDockerfile
File metadata and controls
67 lines (48 loc) · 1.97 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
58
59
60
61
62
63
64
65
66
67
# Multi-stage build for Node.js + Angular application
# Stage 1: Build Angular frontend
FROM node:20-alpine AS frontend-builder
WORKDIR /app/frontend
COPY frontend/package*.json ./
RUN npm ci
COPY frontend/ ./
RUN npm run build
# Stage 2: Build Node.js backend
FROM node:20-alpine AS backend-builder
WORKDIR /app/backend
COPY backend/package*.json ./
RUN npm ci
COPY backend/ ./
RUN npm run build
# Stage 2.5: Install production dependencies only
FROM node:20-alpine AS backend-prod-deps
WORKDIR /app/backend
COPY backend/package*.json ./
RUN npm ci --only=production
# Stage 3: Production image
FROM node:20-alpine AS production
# Install dumb-init for proper signal handling
RUN apk add --no-cache dumb-init
# Use existing node user (UID 1000) instead of creating new user
WORKDIR /app
# Copy backend built files and dependencies
COPY --from=backend-builder --chown=node:node /app/backend/dist ./backend/dist
COPY --from=backend-prod-deps --chown=node:node /app/backend/node_modules ./backend/node_modules
COPY --from=backend-builder --chown=node:node /app/backend/package.json ./backend/
COPY --from=backend-builder --chown=node:node /app/backend/src/data ./backend/dist/data
COPY --from=backend-builder --chown=node:node /app/backend/src/resources ./backend/dist/resources
# Copy frontend built files
COPY --from=frontend-builder --chown=node:node /app/frontend/dist/frontend ./frontend/dist/browser
# Create necessary directories with correct permissions
RUN mkdir -p uploads logs results && \
chown -R node:node uploads logs results && \
chmod -R 775 uploads logs results
# Switch to non-root user
USER node
# Expose port
EXPOSE 80
# Health check
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
CMD node -e "require('http').get('http://localhost:80/api/health', (res) => { process.exit(res.statusCode === 200 ? 0 : 1) }).on('error', () => process.exit(1))"
# Start application with dumb-init
ENTRYPOINT ["dumb-init", "--"]
CMD ["node", "backend/dist/server.js"]